Python — Turtle Graphics Notes

Law of Cosine
3 min readNov 11, 2022

--

Things I have learned from Turtle Graphics:

If I want to use rgb color in turtle graphics, I need to add colormode method: turtle.colormode(255)

for generate random color we will have to create a tuple (r,g,b) and then use randint with range (0,255) to return a random rgb color:

An example of a function to generate random rgb color in turtle graphics

For Hirst painting project, I feel that my code is easier than the instructor’s answer.

This is instructor’s code:

I have noticed that Angela really likes to use setheading method and playing with angles. But I really think the goto method is a lot easier to understand expecially Algebra teacher like me deals with x and y coordinates on a daily basis, it is easier to just set up the coordinates and have turtle go straight there.

Here’s my solution:

It prints the same random dots:

I do need to practice using setheading more though. I came across this post showing the code to use turtle to print a random cherry blossom tree and I liked it so much so I copied and typed the code and I noticed that they have used some math trig functions and used setheading method a lot.

Here’s a screenshot of the cool looking cherry blossom tree:

Hopefully someday I can draw something this nice on my own:)

I did manage to draw something less cool with some simple code though:

--

--