As usual, create a directory to hold today's files. All programs that you write today should be stored in this directory.
$ cd ~/cs120/labs $ mkdir lab5 $ cd lab5
Write a Python program that uses turtle graphics to draw a diamond.
Write a Python program that uses turtle graphics to draw a square that is centered in the window.
Computer displays are made up of a grid of pixels. Because the displays are not continuous, curved objects must be broken into many non-continuous pieces. So curves are often simply represented as many straight lines. In this activity you will approximate a curve by drawing many lines.
In Emacs, create a Python program in a file called curve.py. Your program should use the turtle module to draw a curve using overlapping straight lines between the x-axis and the y-axis.
Do not hard code the location of the line segment end points. Your program should have a variable that determines the size of the drawing. Your program should calculate the end point locations based on the size variable. Make sure you use proper variable names and follow the courses code conventions.
$ python3 curve.py
turtle.goto
.turtle.goto
function to move the turtle
to the start point, then use the turtle.goto
function again to move the turtle to the end point.turtle.up
and turtle.down
functions to prevent the turtle
from drawing a line when it moves to the line's start end
point.This same technique can be used to draw a myriad of different curves, by changing the length and angle of the axes. Add variable to your program that specify the length and angle of each of the axes to create curves like the following.
One of the first shapes you learned to draw in grade school was probably a star. It is a pretty easy shape to draw, looks pretty cool, and can be done entirely with straight lines. The only tricky part is determining how to go from one point of the star to the next. Today, you will figure that part out.
In Emacs, create a Python program in a file called star.py. Your program should use the turtle module to draw a five-pointed star.
Your program should have a variable for the length of the lines that make up the star. It should also use arithmetic expressions that calculate angles needed to draw the star. Make sure you use proper variable names follow the course's code conventions.
$ python3 star.py
turtle.forward
and
either turtle.left
or turtle.right
.
Use
the turtle.circle
function to draw a pentagram like the following: