Catalogue of Posts

Thursday, October 22, 2020

Basic Graphics #8 - Wave

 
8.  WAVE
WAVE  #1


SAVE AS
>>> import turtle
>>>
>>> Pt = turtle.Turtle()
>>>
>>> def SquareArcAC(radius):
         n = radius/57.35
         a = n/2
         for i in range(4):
              Pt.forward(radius)
              Pt.left(90)
         Pt.forward(a)
         Pt.left(1)
         for i in range(89):
              Pt.forward(n)
              Pt.left(1)
         Pt.forward(a)


>>> def SquareArcC(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.backward(200)
>>> Pt.right(90)
>>>
>>> SquareArcAC(100)
>>> SquareArcAC(100)
>>>
>>> SquareArcC(100)
>>> SquareArcC(100)
>>>
>>>
>>> turtle.done()
>>> 
SAVE
 

The tiles used here, are –

            SquareArcAC(radius)
            Square  Arc  Anti-Clockwise
            Which turns to the    left
 
            SquareArcC(radius)
            Square  Arc  Clockwise
            Which turns to the    right
 

POSITION

Firstly,
The  Pt  has been positioned,
so that the wave will end up being centred in the screen.

 

Two anti-clockwise Square Arcs,
are followed by,
two clockwise Square Arcs.
 
This arrangement produces,
the    Wave    mechanism.



We can simplify the    Wave    mechanism,
in  Wave  #2 -


WAVE  #2
 

SAVE AS
>>> import turtle
>>>
>>> Pt = turtle.Turtle()
>>>
>>> def SquareArcAC(radius):
         n = radius/57.35
         a = n/2
         for i in range(4):
              Pt.forward(radius)
              Pt.left(90)
         Pt.forward(a)
         Pt.left(1)
         for i in range(89):
              Pt.forward(n)
              Pt.left(1)
         Pt.forward(a)



>>> def SquareArcC(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 Wave(radius):
         for i in range(2):
             SquareArcAC(radius)
         for i in range(2):
             SquareArcC(radius)
 
         
>>>
>>> Pt.backward(200)
>>> Pt.right(90)
>>>
>>> Wave(100)
>>>
>>>
>>> turtle.done()
>>> 
SAVE
 

 
For a Wave of any size,
we introduced, into the mechanism,
the variable -
            radius
 
Here, 
 
radius  =  number of pixels distance,
                from the centre of the rotation, 
                to its arc,
                which is also the length of the side of the square,
                in the SquareArc tiles


SquareArcAC(radius)    and    
SquareArcC(radius)
need to have  radius  inside them.
 
This is because, they are inside 
Wave(radius),
and this syncs them with
Wave(radius).
              
 
Then,
all we have to do,
to draw a wave of a certain size,
is write the  Wave(radius)  mechanism, in the program,
and put in the size of the radius that we want, for example -
           
Wave(100)



(c) Katherine Stuart 2020
Dochas Books Film

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