def rot(x, y): mouth = gr.Line(gr.Point(x - 20, y + 30), gr.Point(x + 20, y + 30)) mouth.setWidth(10) mouth.setOutline('black') mouth.draw(window)
def draw_roof(): roof = gr.Polygon(gr.Point(135, 300), gr.Point(250, 200), gr.Point(365, 300)) roof.setFill('black') roof.draw(window)
def draw_tree(): tree = gr.Polygon(gr.Point(450, 500), gr.Point(500, 400), gr.Point(460, 400), gr.Point(510, 300), gr.Point(470, 300), gr.Point(600, 200), gr.Point(730, 300), gr.Point(690, 300), gr.Point(740, 400), gr.Point(700, 400), gr.Point(750, 500), gr.Point(750, 500), gr.Point(750, 500)) tree.setFill('green') tree.draw(window)
def draw_glass(): glass = gr.Rectangle(gr.Point(175, 350), gr.Point(250, 425)) glass.setFill('white') glass.draw(window)
def draw_vLine(): vLine = gr.Line(gr.Point(215, 380), gr.Point(215, 425)) vLine.draw(window)
def __init__(self, object2DList): self.objectList = object2DList self.window1 = graphics.GraphWin("window1", 800, 800) self.window1.setCoords(0, 0, 100, 100) self.graphicsObjectList = [] self.text = graphics.Text(graphics.Point(1, 50), str(""))
def draw_sun(): sun = gr.Circle(gr.Point(75, 75), 100) sun.setFill('yellow') sun.draw(window)
def draw_ship(): ship_side = gr.Polygon(gr.Point(80, 420), gr.Point(180, 420), gr.Point(250, 370), gr.Point(50, 370)) ship_side.setFill('grey') ship_side.draw(window) ship_deck = gr.Rectangle(gr.Point(80, 370), gr.Point(140, 320)) ship_deck.setFill('white') ship_deck.draw(window) ship_window1 = gr.Circle(gr.Point(95, 345), 5) ship_window1.setFill('black') ship_window1.draw(window) ship_window2 = gr.Circle(gr.Point(125, 345), 5) ship_window2.setFill('black') ship_window2.draw(window) ship_flag = gr.Rectangle(gr.Point(125, 305), gr.Point(135, 315)) ship_flag.setFill('red') ship_flag.draw(window) ship_flagline = gr.Line(gr.Point(125, 320), gr.Point(125, 315)) ship_flagline.draw(window)
def draw_palm(): palm_ground = gr.Polygon(gr.Point(260, 460), gr.Point(460, 460), gr.Point(360, 420)) palm_ground.setFill('brown') palm_ground.draw(window) palm1 = gr.Polygon(gr.Point(360, 420), gr.Point(345, 395), gr.Point(375, 395)) palm1.setFill('brown') palm1.draw(window) palm2 = gr.Polygon(gr.Point(360, 395), gr.Point(345, 370), gr.Point(375, 370)) palm2.setFill('brown') palm2.draw(window) palm3 = gr.Polygon(gr.Point(360, 370), gr.Point(345, 345), gr.Point(375, 345)) palm3.setFill('brown') palm3.draw(window) palm4 = gr.Polygon(gr.Point(360, 345), gr.Point(345, 320), gr.Point(375, 320)) palm4.setFill('brown') palm4.draw(window) palm5 = gr.Polygon(gr.Point(360, 320), gr.Point(345, 295), gr.Point(375, 295)) palm5.setFill('brown') palm5.draw(window) palm6 = gr.Polygon(gr.Point(360, 295), gr.Point(345, 270), gr.Point(375, 270)) palm6.setFill('brown') palm6.draw(window) palm7 = gr.Polygon(gr.Point(360, 270), gr.Point(345, 245), gr.Point(375, 245)) palm7.setFill('brown') palm7.draw(window) palm_list1 = gr.Polygon(gr.Point(360, 245), gr.Point(270, 235), gr.Point(330, 290)) palm_list1.setFill('green') palm_list1.draw(window) palm_list2 = gr.Polygon(gr.Point(360, 245), gr.Point(275, 205), gr.Point(280, 170)) palm_list2.setFill('green') palm_list2.draw(window) palm_list3 = gr.Polygon(gr.Point(360, 245), gr.Point(350, 180), gr.Point(370, 180)) palm_list3.setFill('green') palm_list3.draw(window) palm_list4 = gr.Polygon(gr.Point(360, 245), gr.Point(420, 205), gr.Point(400, 165)) palm_list4.setFill('green') palm_list4.draw(window) palm_list5 = gr.Polygon(gr.Point(360, 245), gr.Point(440, 235), gr.Point(370, 290)) palm_list5.setFill('green') palm_list5.draw(window)
def draw_sea(): sea = gr.Rectangle(gr.Point(0, 400), gr.Point(500, 500)) sea.setFill('blue') sea.draw(window)
def draw_bird(): bird1_1 = gr.Line(gr.Point(200, 75), gr.Point(215, 70)) bird1_2 = gr.Line(gr.Point(215, 70), gr.Point(210, 85)) bird1_1.draw(window) bird1_2.draw(window) bird2_1 = gr.Line(gr.Point(230, 90), gr.Point(245, 85)) bird2_2 = gr.Line(gr.Point(245, 85), gr.Point(240, 100)) bird2_1.draw(window) bird2_2.draw(window) bird3_1 = gr.Line(gr.Point(225, 65), gr.Point(240, 60)) bird3_2 = gr.Line(gr.Point(240, 60), gr.Point(235, 75)) bird3_1.draw(window) bird3_2.draw(window)
def draw_wall(x=50, y=40, color="brown"): """Draw house wall""" house = gr.Rectangle(gr.Point(x, y), gr.Point(x + 50, y + 40)) house.draw(window) house.setFill(color)
def draw_tree(): """Draw tree""" tree = gr.Rectangle(gr.Point(170, 20), gr.Point(180, 80)) tree.draw(window) tree.setFill("brown")
def oblaka(x, y, r): oblako = gr.Circle(gr.Point(x, y), r) oblako.setFill('gray') oblako.draw(window)
def draw_sky(color): sky = gr.Rectangle(gr.Point(0, 0), gr.Point(640, 200)) sky.setFill(color) sky.draw(window)
def draw_sun(): sun = gr.Circle(gr.Point(500, 0), 60) sun.setFill('yellow') sun.draw(window)
def draw_tree(): trunk = gr.Rectangle(gr.Point(400, 370), gr.Point(410, 430)) trunk.setFill('#663300') trunk.setWidth(3) trunk.draw(window) vertices_tree1 = [ gr.Point(300, 370), gr.Point(405, 300), gr.Point(500, 370) ] vertices_tree1 = gr.Polygon(vertices_tree1) vertices_tree1.setFill('#003300') vertices_tree1.setWidth(3) vertices_tree1.draw(window) vertices_tree2 = [ gr.Point(330, 330), gr.Point(405, 270), gr.Point(480, 330) ] vertices_tree2 = gr.Polygon(vertices_tree2) vertices_tree2.setFill('#003300') vertices_tree2.setWidth(3) vertices_tree2.draw(window) vertices_tree3 = [ gr.Point(360, 290), gr.Point(405, 240), gr.Point(450, 290) ] vertices_tree3 = gr.Polygon(vertices_tree3) vertices_tree3.setFill('#003300') vertices_tree3.setWidth(3) vertices_tree3.draw(window)
def draw_sky(): sky = gr.Rectangle(gr.Point(0, 400), gr.Point(500, 0)) sky.setFill('skyblue') sky.draw(window)
def draw_earth(): earth = gr.Rectangle(gr.Point(0, 399), gr.Point(799, 599)) earth.setFill('grey') earth.draw(window)
def draw(airport, coords, numrunways, result_vormstrategie=None, mean_vormstrategie=None, construct_vormstrategie=None, filenamenum=None, ofnum=None, merge=False): win = graphics.GraphWin('airport', 1040, 800) # give title and dimensions airportwidth = airport.bounds[2] - airport.bounds[0] + 1000 airportheight = airport.bounds[3] - airport.bounds[1] + 200 maxdimension = max(airportwidth / 13, airportheight / 10) win.setCoords( airport.bounds[0] - (maxdimension * 13 - airportwidth) / 2 - 500, airport.bounds[1] - (maxdimension * 10 - airportheight) / 2 - 100, airport.bounds[2] + (maxdimension * 13 - airportwidth) / 2 + 500, airport.bounds[3] + (maxdimension * 10 - airportheight) / 2 + 100) rectangle = graphics.Polygon(graphics.Point(-100000, -100000), graphics.Point(-100000, 100000), graphics.Point(100000, 100000), graphics.Point(100000, -100000)) rectangle.setFill('#869685') rectangle.draw(win) airportgraphic = graphics.Polygon( map(lambda (x, y): graphics.Point(x, y), airport.exterior.coords)) airportgraphic.setFill('white') airportgraphic.draw(win) ###scale 5 blokje ymin = airport.bounds[1] - 10 if airportwidth / airportheight < 0.79: xmax = airport.bounds[2] + 10 + 500 else: xmax = airport.bounds[2] + 10 - 200 heightbox = 50 widthbox = 100 for i in range(0, 5): rectangle = graphics.Polygon( graphics.Point(xmax - widthbox, ymin + heightbox), graphics.Point(xmax, ymin + heightbox), graphics.Point(xmax, ymin), graphics.Point(xmax - widthbox, ymin)) rectangle.setFill("gray" if i % 2 else "white") rectangle.draw(win) xmax -= widthbox ## Compass rose if ofnum: ##numbre of iterations label = graphics.Text( graphics.Point(xmax + widthbox + 140, ymin + heightbox + 100), "%d of %d" % (filenamenum + 1 if filenamenum else ofnum, ofnum)) label.setFill("gray") label.draw(win) for i in range(0, numrunways + 1): if i < numrunways: isrunway = True isgate = False else: isrunway = False isgate = True x = coords[i * 5 + 0] y = coords[i * 5 + 1] if isrunway: length = coords[i * 5 + 2] else: length = coords[i * 5 + 2] / 10 if isrunway: width = coords[i * 5 + 3] / 100 else: width = coords[i * 5 + 3] / 10 angle = coords[i * 5 + 4] / 1000 x1 = x - width * math.sin(angle) / 2 + length * math.cos(angle) / 2 y1 = y + width * math.cos(angle) / 2 + length * math.sin(angle) / 2 x2 = x + width * math.sin(angle) / 2 + length * math.cos(angle) / 2 y2 = y - width * math.cos(angle) / 2 + length * math.sin(angle) / 2 x3 = x + width * math.sin(angle) / 2 - length * math.cos(angle) / 2 y3 = y - width * math.cos(angle) / 2 - length * math.sin(angle) / 2 x4 = x - width * math.sin(angle) / 2 - length * math.cos(angle) / 2 y4 = y + width * math.cos(angle) / 2 - length * math.sin(angle) / 2 runway = geometry.Polygon([(x1, y1), (x2, y2), (x3, y3), (x4, y4)]) runwayinside = runway.intersection(airport) runwayoutside = runway.difference(airport) try: runwayinside = runwayinside.geoms except AttributeError: runwayinside = [runwayinside] try: runwayoutside = runwayoutside.geoms except AttributeError: runwayoutside = [runwayoutside] for r in runwayinside: runwayinsidegraphic = graphics.Polygon( map(lambda (x, y): graphics.Point(x, y), r.exterior.coords)) runwayinsidegraphic.setOutline("black") runwayinsidegraphic.draw(win) for r in runwayoutside: runwayoutsidegraphic = graphics.Polygon( map(lambda (x, y): graphics.Point(x, y), r.exterior.coords)) runwayoutsidegraphic.setOutline("white") runwayoutsidegraphic.draw(win) if result_vormstrategie is not None: polygon_vormstrategie = construct_vormstrategie(result_vormstrategie) if isinstance(polygon_vormstrategie, list): gatebuildings = polygon_vormstrategie else: try: gatebuildings = polygon_vormstrategie.geoms except AttributeError: gatebuildings = [polygon_vormstrategie] if merge: mergedbuilding = gatebuildings[0] for gatebuilding in gatebuildings[1:]: mergedbuilding = mergedbuilding.union(gatebuilding) gatebuildings = [mergedbuilding] for gatebuilding in gatebuildings: if gatebuilding: gatebuildinggraphic = graphics.Polygon( map(lambda (x, y): graphics.Point(x, y), gatebuilding.exterior.coords)) if not filenamenum: gatebuildinggraphic.setFill("grey") gatebuildinggraphic.setOutline("black") gatebuildinggraphic.draw(win) for interior in gatebuilding.interiors: gatebuildinggraphic = graphics.Polygon( map(lambda (x, y): graphics.Point(x, y), interior.coords)) gatebuildinggraphic.setFill("white") gatebuildinggraphic.setOutline("black") gatebuildinggraphic.draw(win) if mean_vormstrategie is not None: polygon_vormstrategie = construct_vormstrategie(mean_vormstrategie) if isinstance(polygon_vormstrategie, list): gatebuildings = polygon_vormstrategie else: try: gatebuildings = polygon_vormstrategie.geoms except AttributeError: gatebuildings = [polygon_vormstrategie] for gatebuilding in gatebuildings: if gatebuilding: gatebuildinggraphic = graphics.Polygon( map(lambda (x, y): graphics.Point(x, y), gatebuilding.exterior.coords)) if not filenamenum: gatebuildinggraphic.setFill("grey") gatebuildinggraphic.setOutline("black") gatebuildinggraphic.draw(win) for interior in gatebuilding.interiors: gatebuildinggraphic = graphics.Polygon( map(lambda (x, y): graphics.Point(x, y), interior.coords)) gatebuildinggraphic.setFill("white") gatebuildinggraphic.setOutline("black") gatebuildinggraphic.draw(win) if filenamenum is not None: win.postscript(file="output/step-%05d.ps" % filenamenum, colormode='color') else: win.postscript(file="output/stepfinal.ps", colormode='color') win.getMouse() win.close()
def draw_wall(): wall = gr.Rectangle(gr.Point(150, 300), gr.Point(350, 500)) wall.setFill('grey') wall.draw(window)
import graphics as g win = g.GraphWin("gradient bar", 400, 100) Rectangle1 = g.Rectangle(g.Point(1, 1), g.Point(34, 400)) #found the rgb color value fill here https://stackoverflow.com/questions/41383849/setting-the-fill-of-a-rectangle-drawn-with-canvas-to-an-rgb-value?rq=1 rectangleColor = "#%02x%02x%02x" % (255, 0, 0) Rectangle1.setFill(rectangleColor) Rectangle1.setWidth("0") Rectangle1.draw(win) Rectangle2 = Rectangle1.clone() Rectangle2.move(33, 0) rectangleColor = "#%02x%02x%02x" % (255, 24, 0) Rectangle2.setFill(rectangleColor) Rectangle2.draw(win) Rectangle3 = Rectangle2.clone() Rectangle3.move(33, 0) rectangleColor = "#%02x%02x%02x" % (255, 48, 0) Rectangle3.setFill(rectangleColor) Rectangle3.draw(win) Rectangle4 = Rectangle3.clone() Rectangle4.move(33, 0) rectangleColor = "#%02x%02x%02x" % (255, 71, 0) Rectangle4.setFill(rectangleColor) Rectangle4.draw(win) Rectangle5 = Rectangle4.clone() Rectangle5.move(33, 0) rectangleColor = "#%02x%02x%02x" % (255, 94, 0)
def draw_hLine(): hLine = gr.Line(gr.Point(175, 380), gr.Point(250, 380)) hLine.draw(window)
def draw_ground(color): ground = gr.Rectangle(gr.Point(0, 200), gr.Point(640, 480)) ground.setFill(color) ground.draw(window)
def draw_door(): door = gr.Rectangle(gr.Point(275, 375), gr.Point(325, 499)) door.setFill('brown') door.draw(window)
def draw_sun(): sun = gr.Circle(gr.Point(530, 110), 50) sun.setFill('yellow') sun.draw(window)
def draw_handle(): handle = gr.Circle(gr.Point(285, 440), 3) handle.draw(window)
def draw_body(): #стены body = gr.Rectangle(gr.Point(110, 250), gr.Point(290, 410)) body.setFill('#FFDF83') body.setWidth(3) body.draw(window)
def draw_sky(): sky = gr.Rectangle(gr.Point(0, 0), gr.Point(799, 399)) sky.setFill('blue') sky.draw(window)
def palka(x, y): stick = gr.Polygon(gr.Point(x - 3, y / 2), gr.Point(x - 3, y), gr.Point(x + 3, y), gr.Point(x + 3, y / 2)) stick.setFill('black') stick.draw(window)