# Pages CS 151 Computational Thinking Fall 2012 Mingchen Li's CS151 project 1 Page History

## Key

• This line was removed.
• Formatting was changed.
Comment: Migrated to Confluence 4.0

This project aims at learning to draw images using turtle program in python computer language. It begins with drawing very simple diagrams like triangle. Then the we learn to draw more complex diagrams by composing two known diagrams and zooming the diagram using different multitudes.

The first image I draw is a star. Compare to triangle, the star image is more complex due to the fact that it is harder to calculate the angle within the star. To calculate the angle for each arrow, it is necessary to calculate the angle within the pentagon which is 108 degree. Then it is possible to calculate the arrow which is 36 degree and the turtle need to turn 144 degree to complete another arrow in the diagram.

left(36)

forward(100)

left(144)

The second image I draw is a pentagon, since I already got the angle in a right pentagon which is 108 degree, it becomes not hard to calculate the degree that turtle need to turn which is 72 degree.

The third image i design to put the star into the pentagon. Since the codes are made already, it is not hard to put them together into one file. However, it is hard to calculate the exact distance of the pentagon so that each angle of pentagon fits with star’s angles. Such calculation requires trigonometry and the result turn out to be around 61.8.

The fourth image, as shown below, is a composition of the first image which is a star. By defining the parameter, it become possible to compose the same image with different sizes using fewer lines of code as shown below.

def shapeA (distance):

left(36)

forward(distance)

left(144)

forward(distance)

shapeA (100)

shapeA (50)

Extension 1: I learned that to have a set of instruction repeat in numbers of time, it is necessary to introduce another algorithm:

for i in range(n):

Extension 2: By using the algorithm above, it is possible to create an n-gon as written below:

def ngon(n,k):

for i in range(n):

forward(k)

left(360/n)

ex.

ngon(8,70)

The image on the right shows a right octagon

Extension3: Combing both the new algorithm and what I learned in homework which is to draw a triangle, I can make a Colby logo which is based on twenty four congruent triangles and a icosagon, a right polygon with twenty sides.

what I learned: i learned to draw simple images using python code. Base on given code, I learned to control the parameters and create complicated images that are composed out of simple image.

I learned the algorithm of repeating command on Prof. Maxwell’s computer science class.