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 square that is centered in the window. Your program should be no more than 5 lines long, and MUST use a loop.
Write a python program that prints the first 100 integers. Your
program must use the range
function.
$ python3 practice2.py 0 1 2 3 4 ...omitted for space... 96 97 98 99
A convex regular polygon is a shape that consists of a sequence of straight lines that all have the same length and meet at the same angle. Convex regular polygons can be parameterized according to the number of sides the shape has. For example, the convex regular polygons with 3, 4, and 5 sides are an equilateral triangle, a square, and a pentagon. As the number of sides increases the names of the polygons get more complicated, for example a 36-sided convex regular polygon is called a triacontakaihexagon. In this activity you will create a function that can create any convex regular polygon.
In Emacs, create a Python program in a filed called polygon.py that uses turtle graphics to draw a convex regular polygon. It should prompt the user for the number of sides and for the circumference of the polygon it draws.
Test your program by running it multiple times with different input values. Make sure your code follows the courses code conventions.
$ python3 polygon.py Enter the number of sides: 5 Enter the circumference: 100
$ python3 polygon.py Enter the number of sides: 6 Enter the circumference: 200
As the number of sides in a convex regular polygon approaches infinity, it becomes a circle. Write a program that takes advantage of this to draw a circle. The program should prompt the user for the circumference of the circle. Note that at some point adding more edges to a polygon approximating a circle does not produce a better looking circle, so the number of edges depends on the size of the circle. The program should calculate the number of edges needed to draw a good looking circle assuming that if all edges are 2 units long, the circle will look good.
The human visual system did not evolve to percieve the types of regular patterns that are simple to create with programming. A spiral of contrasting colors can produce the illusion of motion when you move your eyes over the static image.
In Emacs, create a Python program in a file called spiral.py that uses turtle graphics to draw a square spiral. The spiral can be any size, but it looks cooler if it is bigger with little distance between each layer of the spiral. Make sure your code follows the courses code conventions.
$ python3 spiral.py
Create a circular spiral like the following: