Trig Demo

Back to index

Get the following short program up and running.
#!/usr/bin/python from tkinter import * import math tk = Tk() canvas = Canvas(tk,width=300, height=300, background="black") canvas.pack() for a in range(0,360,10): x = math.cos(a*math.pi/180) * 80 + 150 y = math.sin(a*math.pi/180) * 80 + 150 canvas.create_line(150,150,x,y,fill="red", width=2) canvas.create_text(150,15,text="Trigonometry Demonstration", fill="red")
If you haven't taken a trig course yet, these two lines might be incomprehensible to you. They use the cosine function and sin function to compute the location of a point along the circumference of a circle. The angle must be converted to radians (multiply by PI divided by 180) in order to produce a correct calculation.
x = math.cos(a*math.pi/180) * 80 + 150; y = math.sin(a*math.pi/180) * 80 + 150;
By the way 80 is the radius of this circle. To make a larger or smaller circle, just change this value. Where do you think the center of the circle is located?
ASSIGNMENT:

Use trig functions to plot a regular decagon with a height of about one hundred screen units.