Tuesday, July 31, 2012

Turtle

I'm learning Python during the summer. Today I used Turtle, a drawing program in
Python, to draw a star. It might look simple BUT IT REALLY ISN'T. Programming takes a lot of focus and concentration.




I could have made it any color, but my little brother wanted blue. I used two different ways to get this star. One is the long but easy way, and the other is the short but harder way. The easier way actually looks harder than it actually is, and the difficult way looks easier than it is.

This is the code that I had to figure out for myself, my father helped me a little but I did most of it myself.


Easier Way =      
Difficult Way =      

from turtle import*
speed('slow')
color('pink')
begin_fill()
forward(300)
right(144)
forward(300)
right(144)
forward(300)
right(144)
forward(300)
right(144)
forward(300)
end_fill()
hideturtle()
exitonclick()

from turtle import*
def star(n,col):
    color(col)
    begin_fill()
    i = 0
    while (i < 5):
        forward(300)
        right(144)
        i = i + 1
    end_fill()

hideturtle()
exitonclick()

I used a loop for the harder one. 

Do you know what a loop is? A loop repeats itself over and over again until it is stopped. Well, instead of writing 'forward(300), right(144)' five times, just put it in a loop, and it still makes a star! Just quicker.

Priya's Hints: 

1. I used 'speed', to... make the turtle draw the star faster! I don't have all day.

2. Before I can start drawing, I need to get the turtle to appear. I can write 'import turtle', at the top, and to draw, I'll have to write next to my code: turtle.forward(value). Or, I can write 'from turtle import*', and write in my code like this: forward(value).

3. I use hideturtle() to get rid of the turtle after it has finished drawing the picture. It looks bad on the picture.

4. I use exitonclick() to prevent the turtle screen from crashing after it has drawn the picture and I want to close the window.


5. To add color, I write: color("color of your choice"), and under that, I write: begin_fill(). At the end of my code, I write: end_fill()

Some other things: When I put things like, 'color of your choice,' or 'value' inside parentheses, you are supposed to put a number or a color inside the brackets. DO NOT write the actual words in there or you will get an error message.


Yesterday my father helped me with these designs.

  It might look like a simple design and easy but to create these designs from using code was hard.





No comments:

Post a Comment