https://www.deviantart.com/barnababaruch/art/Rainbow-Circle-780241856
import math
try:
import tkinter
except ImportError:
import Tkinter as tkinter
def parabola(page, size):
for x in range(size):
y = x * x / size
plot(page, x, y)
plot(page, -x, y)
#Modify the circle function so that it allows the color of the circle to be specified
#and defaults to red if a color is not given. you may want to review the previous lectures
#about named parameters and default values.
import itertools
color_iteration = itertools.cycle(( 'red', 'orange', 'yellow','green','blue', 'indigo', 'violet'))
next(color_iteration)
def circle(page, radius, g, h):
page.create_oval(g + radius, h + radius, g - radius, h - radius, outline=next(color_iteration),
width=3, fill=next(color_iteration))
# for x in range(g * 100, (g + radius)* 100):
# x /= 100
# print(x)
# y = h +(math.sqrt(radius ** 2 - ((x-g) ** 2)))
# plot(page, x, y)
# plot(page, x,2* h - y)
# plot(page, 2 * g - x, y)
# plot(page, 2 * g - x, 2 * h - y)
def draw_axes(page):
page.update()
x_origin = page.winfo_width() / 2
y_origin = page.winfo_height() / 2
page.configure(scrollregion=(-x_origin, -y_origin, x_origin, y_origin))
page.create_line(-x_origin, 0, x_origin, 0, fill="black")
page.create_line(0, y_origin, 0, -y_origin, fill="black")
print(locals())
def plot(page, x, y):
page.create_line(x, -y, x + 1, -y + 1, fill="red")
mainWindow = tkinter.Tk()
mainWindow.title("Parabola")
mainWindow.geometry("640x480")
canvas = tkinter.Canvas(mainWindow, width=640, height=480)
canvas.grid(row=0, column=0)
draw_axes(canvas)
parabola(canvas, 100)
parabola(canvas, 200)
parabola(canvas, 100)
parabola(canvas, 200)
circle(canvas, 100, 100, 100)
circle(canvas, 100, 100, -100)
circle(canvas, 100, -100, 100)
circle(canvas, 100, -100, -100)
circle(canvas, 10, 30, 30)
circle(canvas, 10, 30, -30)
circle(canvas, 10, -30, 30)
circle(canvas, 10, -30, -30)
circle(canvas, 30, 0, 0)
mainWindow.mainloop()