Catalogue of Posts

Thursday, August 27, 2020

Basic Graphics #3 - Angle

Using  -  The Python Computer Language
                Turtle Graphics Library


3.   ANGLE
ROTATION RIGHT
 
 
SAVE AS
 
>>> import turtle
>>>
>>> Pt = turtle.Turtle()
>>>
>>> Pt.right(45)
>>>
>>> turtle.done()
>>> 
 
SAVE
 
 

Pt.right(number of degrees)
    Arrow head turns around to its right     
    side   
 
The arrow head spins at its position,
    which is the pixel at its front point



ROTATION LEFT
 

SAVE AS
 
>>> import turtle
>>>
>>> Pt = turtle.Turtle()
>>>
>>> Pt.left(45)
>>>
>>> turtle.done()
>>> 
 
SAVE
 


Pt.left(number of degrees)
    Arrow head turns around to its left side
     
The arrow head spins at its position, 
    which is the pixel at its front point



ROTATED LINE
 
 
SAVE AS
 
>>> import turtle
>>>
>>> Pt = turtle.Turtle()
>>>
>>> Pt.right(120)
>>> Pt.forward(200)
>>>
>>> turtle.done()
>>> 
 
SAVE
 





Pt.right(number of degrees)
Pt.forward(number of pixels)
            x 1





ANGLE
 
 

SAVE AS
 
>>> import turtle
>>>
>>> Pt = turtle.Turtle()
>>>
>>> Pt.right(120)
>>> Pt.forward(200)
>>> Pt.right(120)
>>> Pt.forward(200)
>>>
>>> turtle.done()
>>> 
 
SAVE
 




Pt.right(number of degrees)
Pt.forward(number of pixels)
            x 2






TRIANGLE
 

SAVE AS
 
>>> import turtle
>>>
>>> Pt = turtle.Turtle()
>>>
>>> Pt.right(120)
>>> Pt.forward(200)
>>> Pt.right(120)
>>> Pt.forward(200)
>>> Pt.right(120)
>>> Pt.forward(200)
>>>
>>> turtle.done()
>>>
 
SAVE





Pt.right(number of degrees)
Pt.forward(number of pixels)
            x 3







USING THE OUTSIDE ANGLE


Pt.forward(number of pixels)
Pt.right(number of degrees)
    the line proceeds in the direction,
      - of, number of degrees, right,
      - from, the previous direction
         of the arrow






THE LOOP
 
 
When there is a repetition of
a sequence of actions,
instead of writing out the sequence,
a number of times,
it is easier to write it as a loop.
 
So,
 
Pt.right(120)
Pt.forward(200)
Pt.right(120)
Pt.forward(200)
 
Can be written, as the “for” loop  -
 
for i in range(2):
    Pt.right(120)
    Pt.forward(200)
 
i   means “integer”, “whole number”

  
Also,
 
Pt.right(120)
Pt.forward(200)
Pt.right(120)
Pt.forward(200)
Pt.right(120)
Pt.forward(200)
 
Can be written, as the “for” loop  -
 
for i in range(3):
    Pt.right(120)
    Pt.forward(200)

 
for i in range(number of times):
     sequence of actions
    number of times,
    is the number of times to do (loop)
    this sequence of actions 



(c) Katherine Stuart 2020
Dochas Books Film

No comments:

Post a Comment