Wavy Thing

Back to index

You don't necessarily create only straight lines with create_line. Consider this example:
#!/usr/bin/python from tkinter import * import math tk = Tk(); canvas = Canvas(tk,width=480, height=100, background="black") canvas.pack() for c in range (20,424,80): for a in range(0,180): x = math.cos(a*math.pi/180) * 20 + c; y = math.sin(a*math.pi/180) * 20 + 50; canvas.create_line(x,y,x+1,y+1,fill="red", width=2); for a in range(180,360): x = math.cos(a*math.pi/180) * 20 + c+40; y = math.sin(a*math.pi/180) * 20 + 50; canvas.create_line(x,y,x+1,y+1,fill="red", width=2);
Keep in mind that the c variable is used to keep track of the center of each half circle. Since the waves are arranged horizontally, the x-coordinate is determined through use of the c variable.

Although the create_line function is used in this example, all that is created by each call of create_line is a single dot.


ASSIGNMENT:

Make your waves vertical instead of horizontal and create five of them, side by side. Also make the radius ten units and create seven peaks and seven valleys for each wave.