Skip to content

Instantly share code, notes, and snippets.

@tom-ricci
Created September 27, 2022 14:45
Show Gist options
  • Select an option

  • Save tom-ricci/4fc01ce19bdcf8fdf34f55c3698e8416 to your computer and use it in GitHub Desktop.

Select an option

Save tom-ricci/4fc01ce19bdcf8fdf34f55c3698e8416 to your computer and use it in GitHub Desktop.
from cmu_graphics import *
class Settings:
color = ""
x = []
y = []
points = []
def createSettings():
color = input("What color do you want the shape to be? ")
Settings.color = color
createSettings()
def onMouseRelease(mouseX, mouseY):
Settings.x.append(mouseX)
Settings.y.append(mouseY)
drawPoint(mouseX, mouseY)
def onKeyRelease(key):
if key == "enter" and len(Settings.x) > 0 and len(Settings.y) > 0:
drawShape()
def drawShape():
p = Polygon(Settings.x[0], Settings.y[0], fill=Settings.color, border=None, borderWidth=2, opacity=100, rotateAngle=0, dashes=False, visible=True)
for i in range(len(Settings.x)):
p.addPoint(Settings.x[i], Settings.y[i])
p.addPoint(Settings.x[0], Settings.y[0])
Settings.x = []
Settings.y = []
for point in Settings.points:
point.opacity = 0
Settings.points = []
def drawPoint(x, y):
c = Circle(x, y, 2, fill=Settings.color, border=None, borderWidth=2, opacity=100, rotateAngle=0, dashes=False, align='center', visible=True)
Settings.points.append(c)
cmu_graphics.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment