#ezgraphicsTest.py # pip install ezgraphics-2.1.tar.gz # draw points, lines, ovals/circles, rectangles/squares, polygons, text #in colors, line widths, fills ... import random from ezgraphics import GraphicsWindow width = int(input("Enter width of graphics window: ")) height = int(input("Enter height of graphics window: ")) win = GraphicsWindow(width,height) #REQD. create a drawing window win.setTitle("Hello world") canvas = win.canvas() #REQD. create a 'canvas' to draw on in the window #(0,0) origin is upper left. x grows to the right, y grows down! #canvas.setBackground("yellow") #default background is white #default drawing color is black, no fill canvas.drawLine(1,1, width,height) #x,y of one endpoint, x,y of the other endpoint canvas.setColor("green") #outline and fill canvas.drawLine(1,height, width,1) canvas.drawRectangle(40,40, 100, 200) #upper-left x y, width, height canvas.setOutline("red") canvas.setFill("magenta") canvas.setLineWidth(4) canvas.drawRectangle(150,300, 150, 50) canvas.drawLine(100,100, 250,175) #x,y of one endpoint, x,y of the other endpoint canvas.setLineWidth(1) canvas.setColor("black") samplePoly = [200,1, 350,100, 400,50] #list of x,y vertices in counter-clockwise canvas.drawPolygon(samplePoly) canvas.setColor("blue") canvas.setFill() #no fills canvas.drawOval(40,300, 60, 30) #x,y upper left of "bounding box", width, height canvas.drawOval(width-60,height-60, 60, 60) #same width, height makes a circle (diameter) canvas.drawText(10,20, "Hello world") #x,y starting position (upper lefthand corner) for i in range(200): canvas.drawPoint(random.randint(1,width), random.randint(1,height)) xc = width/2 yc = height/2 gap = 10 for i in range(1,20): canvas.drawOval(xc-i*gap/2,yc-i*gap/2, i*gap,i*gap) win.showStatus() #status bar on win.setStatus("hello world") win.wait() #until window closed. Not necessary.