Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create 6 frieze patterns in Python

enter image description here

I need to be able to create a frieze pattern of six shapes. The link provides a visual of the shape and the size it needs to be.

from turtle import *

number_of_shapes = 6

# Draw six basic elements

for shape in range (number_of_shapes):
       # Draw a basic element

       for section in range(8):
              forward(30)
              right(110)
              forward(30)
              left(20)
              forward(30)
              right(110)
              forward(30)
              left(20)
              forward(30)
              right(110)
              forward(30)
              left(20)
              forward(20)
              right(110)
              forward(30)

this code creates a different shape to the pattern I need which I found quite funny.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You have just used the angles specified in the diagram, without wondering how turtle will interpret them.

The key is to think of 180 minus the stated angle.

Plus one run through the turns and forwards creates one star all on its own.

Your code should have been more like this:

from turtle import *

number_of_shapes = 6

LEFT=180-110
RIGHT=180-20
# Draw six basic elements
penup()
left(180)
forward(100*number_of_shapes // 2)
right(180)
for shape in range (number_of_shapes):
       # Draw a basic element
      left(10) 
      pendown()
      forward(30)
      left(LEFT)
      forward(30)
      right(RIGHT)
      forward(30)
      left(LEFT)
      forward(30)
      right(RIGHT)
      forward(30)
      left(LEFT)
      forward(30)
      right(RIGHT)
      forward(30)
      left(LEFT)
      forward(30)
      right(RIGHT)
      right(10)
      penup()
      forward(100)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading