Mirror Images, Flowers, and other Designs

 

JUMP procedure:

We want to shift the Turtle some distance on the X axis and some distance on the Y axis (relative to its current orientation), without drawing anything.

ERASE "jump

TO jump :x :y

  PU FD :y RT 90 FD :x LT 90 PD

END

 

 

By using negative numbers, we can shift the Turtle anywhere. For example,

Jump 100 -50 will shift the Turtle 100 steps east and 50 steps south.

Array of squares:

We will use the jump procedure defined above. Using REPEAT, we can draw any number of squares:

 

REPEAT 10 [

  Square 100

  Jump 20 20

]

Mirror image of Circle:

Regular circle:

ERASE "circle

TO circle

  REPEAT 360 [FD 1 RT 1]

END

 

The mirror image would be:

ERASE "circle.m

TO circle.m

  REPEAT 360 [FD 1 LT 1]

END

 

To draw the circles side-by-side:

Circle Circle.m

Flowers of Square:

Imagine holding a plastic square pinned at one corner and rotating it in a clockwise fashion.

 

Note that, to get the 2x2 paned window we have to consider 3 important factors:

1.      The basic pattern is a square.

2.      It is drawn 4 times.

3.      To draw it 4 times, the Turtle must turn 360/4 degrees each time.

 

REPEAT 4 [

  Square 100

  RT 90

]

 

We can similarly draw the other 2 designs using the Square procedure:

REPEAT 6 [

  square 100 RT 360/6

]

 

REPEAT 8 [

  square 100 RT 360/8

]

Flower Procedure for Square:

We could put the above instructions in the form of a procedure:

 

First without input; a flower of 8 petals of size 100:

ERASE "sqflower

TO sqflower

  REPEAT 8 [

    square 100 RT 360/8

  ]

END

 

Next, let's first add the 'size' input:

ERASE "sqflower

TO sqflower :size

  REPEAT 8 [

    square :size RT 360/8

  ]

END

 

After testing this to verify that we are able to draw 8-petal flowers of different sizes, we will next add the input for number of petals:

 

ERASE "sqflower

TO sqflower :size :n

  REPEAT :n [

    square :size RT 360/:n

  ]

END


Polygon flower:

; 3 inputs: L is polygon type, S is polygon size,

;           M is # of petals

ERASE "polygon.flower

TO polygon.flower :L :S :M

  REPEAT :M [

    REPEAT :L [FD :S RT 360/:L]

    RT 360/:M

  ]

END

Flowers of circle:

REPEAT 360 [FD 1 RT 1] gives a simple circle.

 

Four circles:

REPEAT 4 [

  REPEAT 360 [FD 1 RT 1]

  RT 360/4

]

 

Ten circles:

REPEAT 10 [

  REPEAT 360 [FD 1 RT 1]

  RT 360/10

]

 

Earth design:

ERASE "circle

TO circle :size

  REPEAT 360 [FD :size/360 RT 1]

END

 

ERASE "c.pattern

TO c.pattern :n :size

  REPEAT :n [

    circle :size RT 360/:n

  ]

END

 

Setpensize 2 SETPC 10 c.pattern 36 300

SETPC 4 c.pattern 36 100

Row of squares:

ERASE "square

TO square :size

  REPEAT 4 [FD :size RT 90]

END

 

ERASE "row.of.squares

TO row.of.squares :size :n

  REPEAT :n [

    square :size

    jump :size+10 0

  ]

END

 

row.of.squares 50 5

row.of.squares 30 8