Catalogue of Posts

Tuesday, October 6, 2020

Basic Graphics #7 - Scroll

7.  SCROLL
SCROLL  #1
 
 
SAVE AS
>>> import turtle
>>>
>>> Pt = turtle.Turtle()
>>>
>>> def SquareArc(radius):
     n = radius/57.35
     a = n/2
     for i in range(4):
          Pt.forward(radius)
          Pt.right(90)
     Pt.forward(a)
     Pt.right(1)
     for i in range(89):
          Pt.forward(n)
          Pt.right(1)
     Pt.forward(a) 
>>>
>>> Pt.forward(50)
>>> Pt.right(90)
>>>
>>> SquareArc(50)
>>> SquareArc(50)
>>>
>>> SquareArc(100)
>>> SquareArc(100)
>>>
>>> SquareArc(150)
>>> SquareArc(150)
>>>
>>> SquareArc(200)
>>> SquareArc(200)
>>>
>>>
>>> turtle.done()
>>> 
SAVE


the Pt has been positioned where the first arc will eventually start.

Then,
2 SquareArcs have been drawn with the initial radius of    50,

And then,
2 SquareArcs have been drawn with the increased radius of    + 50,

And so on.

 
This arrangement of the SquareArcs produces the Scroll pattern.



 
 
Variables are amounts, in the program, which can change / vary.
 
Number of pixels, and,
Number of degrees,
are variables.
 
We can write variables into items in the program, within the parentheses    ( )    ,
as in the generalised versions of the previous programs.
Where, they will only apply to the item that they are attached to, such as –
 
Pt.forward(number of pixels)
Pt.right(number of degrees)
  
We can also write the variables into the name of a mechanism,
within the parentheses    ( )    .
But, then they will apply to the whole mechanism, such as –
 
SquareArc(radius)
 
Here, the variable is -
            radius
  
Using variables, we can simplify  Scroll  #1, into  Scroll  #2, below -



SCROLL  #2
 
 
SAVE AS
>>> import turtle
>>>
>>> def SquareArc(radius):
     n = radius/57.35
     a = n/2
     for i in range(4):
          Pt.forward(radius)
          Pt.right(90)
     Pt.forward(a)
     Pt.right(1)
     for i in range(89):
          Pt.forward(n)
          Pt.right(1)
     Pt.forward(a)






>>> def Scroll(radius, radius_increase, t):
      nht = 2*t
      for i in range(nht):
          for i in range(2):
              SquareArc(radius)
          radius = radius + radius_increase

         
>>>
>>> Pt.forward(50)
>>> Pt.right(90)
>>>
>>> Scroll(50, 50, 2)
>>>
>>>
>>> turtle.done()
>>>
SAVE









TILE
The SquareArc  can be called a  “tile”,
in that, all the elements within it are connected,
and it can move as one unit.
 
ARRANGEMENT
This arrangement of the SquareArcs,
using the mechanism -

            Scroll(radius, radius_increase, t)

produces the Scroll pattern.
 
 

radius  =  same radius as in SquareArc(radius)
radius_increase  =  increase in the radius after drawing each set of 2 SquareArcs
                               (The bottom bar _  joins the two words, so that the computer knows it is
                                one item, not two)
t  =  number of complete turns / cycles of the scroll that is required
nht  =  number of half turns of the scroll,
            which is the number of sets of  2  SquareArcs
 
Firstly,
the Pt has been positioned where the first arc will eventually start.
 
For,
Each turn / cycle needed of the scroll,
there needs to be -

            2  x  t    half turns / sets of  2  SquareArcs 
 
But,
after each set is completed,
there needs to be an increase in the radius,
to make the next set larger.
This is achieved by using the equation –
            (outside the “for” loop for the set of  2  SquareArcs,
            by tabbing it backwards in line with the beginning of that loop)
  
            radius  =  radius  +  radius_increase
           
            The computer can understand this type of equation, as saying –
 
                        new radius  =  previous radius  +  radius_increase
 
            In this mechanism, the radius increases by its original amount, each time,
            which is said to be a  “regular”  increase -  that is, “the same” increase each time.



(c) Katherine Stuart 2020
Dochas Books Film

No comments:

Post a Comment