Skip to content

Instantly share code, notes, and snippets.

@chaim1221
Last active May 6, 2016 05:49
Show Gist options
  • Save chaim1221/1838b443a36fb439275828a68d20bd0d to your computer and use it in GitHub Desktop.
Save chaim1221/1838b443a36fb439275828a68d20bd0d to your computer and use it in GitHub Desktop.
my first attempt at using python, tutoring, educational purposes, don't sue me, etc.
CANVAS_WIDTH = 640
CANVAS_HEIGHT = 480
from Gui import *
# draws a bullseye circle from yellow,green,cyan, and red in the center,
# a black circle, a green and blue vertical line, and a magenta square in the middle of the red circle in the bullseye
def part1():
canvas.line([[-100, -100], [-100, 100]], fill = 'green')
canvas.line([[100, 100], [100, -100]], fill = 'blue')
canvas.circle([-50, 50], 30, fill = 'black')
canvas.circle([0, 0], 50, fill = 'yellow')
canvas.circle([0, 0], 40, fill = 'green')
canvas.circle([0, 0], 30, fill = 'cyan')
canvas.circle([0, 0], 20, fill = 'red')
canvas.rectangle([[10, -10], [-10, 10]], fill = 'red')
canvas.rectangle([[-20, 20], [0, 0]], fill = 'magenta')
#What occurs after the button is pushed to create the location of the bullseye and targets,
#magenta canvas color, on the canvas
def part2():
canvas.clear()
canvas.config(bg = "green")
target(canvas, [0, -100])
target(canvas, [0, 0])
target(canvas, [0, 100])
target(canvas, [0, 150])
bullseye(canvas, [-100, 20])
bullseye(canvas, [0, 0])
bullseye(canvas, [150, 0])
def target(myCanvas, myPoint):
x, y = myPoint
myCanvas.rectangle([[x - 20, y - 20],[x + 20, y + 20]], fill = 'magenta')
myCanvas.circle([x - 10, y - 10], 10, fill = 'cyan', outline = 'blue')
myCanvas.circle([x - 10, y + 10], 10, fill = 'cyan', outline = 'blue')
myCanvas.circle([x + 10, y - 10], 10, fill = 'cyan', outline = 'blue')
myCanvas.circle([x + 10, y + 10], 10, fill = 'cyan', outline = 'blue')
myCanvas.circle([x - 10, y - 10], 8, fill = 'blue', outline = 'blue')
myCanvas.circle([x - 10, y + 10], 8, fill = 'blue', outline = 'blue')
myCanvas.circle([x + 10, y - 10], 8, fill = 'blue', outline = 'blue')
myCanvas.circle([x + 10, y + 10], 8, fill = 'blue', outline = 'blue')
myCanvas.circle([x - 10, y - 10], 5, fill = 'black', outline = 'blue')
myCanvas.circle([x - 10, y + 10], 5, fill = 'black', outline = 'blue')
myCanvas.circle([x + 10, y - 10], 5, fill = 'black', outline = 'blue')
myCanvas.circle([x + 10, y + 10], 5, fill = 'black', outline = 'blue')
#lines
#canvas.line([[, ], [, ]], 'white')
# the outer circle is cyan; the middle circle is blue; the inner circle is black
# all 3 circles have a border of 2
# the space between the circles is 10.
def bullseye(myCanvas, myPoint):
x, y = myPoint
myCanvas.circle([x, y], 30, fill = 'cyan', outline = 'blue')
myCanvas.circle([x, y], 25, fill = 'blue', outline = 'blue')
myCanvas.circle([x, y], 20, fill = 'black', outline = 'blue')
###################################################################
# Feel free to read what's here, but do not change
g = Gui()
g.title('Homework 4')
# canvas is the drawing area
canvas = g.ca(width = CANVAS_WIDTH, height = CANVAS_HEIGHT)
part1()
# this sets up the padded row with one button
# the button callback is to the part2() function
g.row(pady = 10, padx = 100)
button = g.bu(text='click this', command=part2, bg='yellow')
g.endrow()
g.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment