def render(self): # get the cos and sin of the current orientation theta = math.pi * self.angle / 180. cth = math.cos(theta) sth = math.sin(theta) # rotate each point around the object's center pts = [] for vertex in self.bodypts + self.flamepts: # move the object's center to 0, 0, which it is already in model coordinates xt = vertex[0] yt = vertex[1] # rotate the vertex by theta around the Z axis xtt = cth * xt - sth * yt ytt = sth * xt + cth * yt # move the object's center back to its original location xf = xtt + self.pos[0] yf = ytt + self.pos[1] # create a point with the screen space coordinates pts.append( gr.Point(self.scale * xf, self.win.getHeight() - self.scale * yf)) # make the two objects self.vis = [gr.Polygon(pts[:3]), gr.Polygon(pts[3:])] self.vis[0].setFill("purple") self.vis[0].setOutline("dark red") self.vis[1].setOutline("yellow")
def draw_house(): walls = gr.Polygon(gr.Point(200, 300), gr.Point(400, 300), gr.Point(400, 450), gr.Point(200, 450)) walls.setFill('firebrick') walls.setOutline('saddlebrown') walls.setWidth(2) big_window = gr.Rectangle(gr.Point(250, 325), gr.Point(350, 400)) big_window.setFill('lightcyan') big_window.setOutline('saddlebrown') big_window.setWidth(2) reshetka1 = gr.Line(gr.Point(300, 325), gr.Point(300, 400)) resetka2 = gr.Line(gr.Point(250, 350), gr.Point(350, 350)) roof = gr.Polygon(gr.Point(185, 315), gr.Point(300, 150), gr.Point(415, 315)) roof.setOutline('saddlebrown') roof.setWidth(2) roof.setFill('peru') small_window = gr.Circle(gr.Point(300, 250), 20) small_window.setOutline('saddlebrown') small_window.setWidth(2) small_window.setFill('lightcyan') walls.draw(window) roof.draw(window) big_window.draw(window) reshetka1.draw(window) resetka2.draw(window) small_window.draw(window)
def fir_tree(): """ Рисуем елку """ bole_of_fir_tree = gr.Rectangle(gr.Point(320, 300), gr.Point(330, 330)) bole_of_fir_tree.setFill('brown') bole_of_fir_tree.setOutline('black') bole_of_fir_tree.draw(window) first_stage_of_fir_tree = gr.Polygon(gr.Point(295, 300), gr.Point(315, 280), gr.Point(335, 280), gr.Point(355, 300)) first_stage_of_fir_tree.setFill('green') first_stage_of_fir_tree.draw(window) second_stage_of_fir_tree = gr.Polygon(gr.Point(305, 280), gr.Point(320, 260), gr.Point(330, 260), gr.Point(345, 280)) second_stage_of_fir_tree.setFill('green') second_stage_of_fir_tree.draw(window) third_stage_of_fir_tree = gr.Polygon(gr.Point(315, 260), gr.Point(325, 230), gr.Point(335, 260)) third_stage_of_fir_tree.setFill('green') third_stage_of_fir_tree.draw(window)
def PrlpdWiz(Prxy, root, color1, color2, color3, color4): Prxy = list(Prxy) Ax = Prxy[0][0] Ay = Prxy[0][1] Bx = Prxy[1][0] By = Prxy[1][1] Ix = Prxy[2][0] Iy = Prxy[2][1] Mx = Prxy[3][0] My = Prxy[3][1] obj = gp.Polygon(gp.Point(Ax, Ay), gp.Point(Bx, By), gp.Point(Ix, Iy)) obj.setFill(color1) obj.setOutline(color2) obj.draw(root) obj = gp.Polygon(gp.Point(Ax, Ay), gp.Point(Mx, My), gp.Point(Ix, Iy)) obj.setFill(color1) obj.setOutline(color3) obj.draw(root) obj = gp.Polygon(gp.Point(Bx, By), gp.Point(Mx, My), gp.Point(Ix, Iy)) obj.setOutline(color4) obj.draw(root) return PrlpdWiz
def draw_tree(): tree_1 = gr.Polygon(gr.Point(525, 450), gr.Point(625, 350), gr.Point(725, 450)) tree_2 = gr.Polygon(gr.Point(525, 400), gr.Point(625, 300), gr.Point(725, 400)) tree_3 = gr.Polygon(gr.Point(525, 350), gr.Point(625, 250), gr.Point(725, 350)) tree_1.setFill(gr.color_rgb(60, 200, 160)) tree_2.setFill(gr.color_rgb(60, 200, 160)) tree_3.setFill(gr.color_rgb(60, 200, 160)) tree_1.setOutline(gr.color_rgb(50, 160, 150)) tree_2.setOutline(gr.color_rgb(50, 160, 150)) tree_3.setOutline(gr.color_rgb(50, 160, 150)) tree_1.setWidth(5) tree_2.setWidth(5) tree_3.setWidth(5) tree_leg = gr.Rectangle(gr.Point(600, 450), gr.Point(650, 525)) tree_leg.setFill(gr.color_rgb(100, 65, 70)) tree_leg.setOutline(gr.color_rgb(80, 55, 50)) tree_leg.setWidth(5) tree_leg.draw(window) tree_1.draw(window) tree_2.draw(window) tree_3.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_spartak(x): # Рисует лого Спартака и табличку под ним romb = gr.Polygon(gr.Point(x - 75, 150), gr.Point(x, 100), gr.Point(x + 75, 150), gr.Point(x, 200)) romb.setFill('red') romb.draw(window) stripe = gr.Polygon(gr.Point(x - 55, 164), gr.Point(x + 20, 113), gr.Point(x + 55, 137), gr.Point(x - 20, 188)) stripe.setFill('white') stripe.draw(window) letterc = gr.Text(gr.Point(x, 150), "с") letterc.setSize(35) letterc.setFill('red') letterc.draw(window) plate = gr.Polygon(gr.Point(x - 70, 200), gr.Point(x - 70, 250), gr.Point(x + 70, 250), gr.Point(x + 70, 200)) plate.setFill('white') plate.draw(window) post = gr.Polygon(gr.Point(x - 5, 250), gr.Point(x - 5, 500), gr.Point(x + 5, 500), gr.Point(x + 5, 250)) post.setFill('white') post.draw(window) lettername = gr.Text(gr.Point(x, 230), "Спартак Москва") lettername.setSize(10) lettername.setFill('red') lettername.draw(window)
def draw_birds(): bird1 = gr.Polygon(gr.Point(270, 200), gr.Point(320, 250), gr.Point(370, 200), gr.Point(320, 270)) bird1.draw(window) bird1.setFill('black') bird2 = gr.Polygon(gr.Point(200, 300), gr.Point(250, 350), gr.Point(300, 300), gr.Point(250, 370)) bird2.draw(window) bird2.setFill('black')
def createGameBackground(): win = gr.GraphWin("Flappy Mule", 400, 600) win.setBackground('steelblue1') #Here I will draw Miller Library, the backdrop for my game base = gr.Rectangle(gr.Point(10, 600), gr.Point(390, 500)) left_rect = gr.Rectangle(gr.Point(10, 600), gr.Point(90, 500)) right_rect = gr.Rectangle(gr.Point(310, 600), gr.Point(390, 500)) right_tri = gr.Polygon(gr.Point(300, 500), gr.Point(400, 500), gr.Point(350, 450)) left_tri = gr.Polygon(gr.Point(0, 500), gr.Point(100, 500), gr.Point(50, 450)) mid_rect = gr.Rectangle(gr.Point(110, 600), gr.Point(290, 425)) mid_tri = gr.Polygon(gr.Point(120, 500), gr.Point(280, 500), gr.Point(200, 450)) pillar1 = gr.Rectangle(gr.Point(120, 580), gr.Point(130, 500)) pillar2 = gr.Rectangle(gr.Point(150, 580), gr.Point(160, 500)) pillar3 = gr.Rectangle(gr.Point(180, 580), gr.Point(190, 500)) pillar4 = gr.Rectangle(gr.Point(210, 580), gr.Point(220, 500)) pillar5 = gr.Rectangle(gr.Point(240, 580), gr.Point(250, 500)) pillar6 = gr.Rectangle(gr.Point(270, 580), gr.Point(280, 500)) stair_rect = gr.Rectangle(gr.Point(110, 600), gr.Point(290, 580)) mid_rect2 = gr.Rectangle(gr.Point(170, 425), gr.Point(230, 375)) mid_rect3 = gr.Rectangle(gr.Point(180, 375), gr.Point(220, 325)) mid_rect4 = gr.Rectangle(gr.Point(185, 325), gr.Point(215, 275)) mid_rect5 = gr.Rectangle(gr.Point(190, 275), gr.Point(210, 240)) clock = gr.Circle(gr.Point(200, 350), 10) pointer = gr.Polygon(gr.Point(190, 240), gr.Point(210, 240), gr.Point(200, 175)) dot_top = gr.Circle(gr.Point(200, 172), 5) vert_line = gr.Line(gr.Point(200, 167.5), gr.Point(200, 157.5)) hor_line = gr.Line(gr.Point(195, 162.5), gr.Point(205, 162.5)) topper = gr.Polygon(gr.Point(205, 157.5), gr.Point(195, 157.5), gr.Point(197, 152.5), gr.Point(200, 152.5), gr.Point(200, 155), gr.Point(205, 155)) sun = gr.Circle(gr.Point(50, 50), 50) sun.setFill('yellow') sun.setOutline('yellow') grass = gr.Rectangle(gr.Point(0, 600), gr.Point(400, 595)) grass.setFill('green') grass.setOutline('green') objects = [ base, right_rect, left_rect, right_tri, left_tri, mid_rect, mid_tri, pillar1, pillar2, pillar3, pillar4, pillar5, pillar6, stair_rect, mid_rect2, mid_rect3, mid_rect4, mid_rect5, clock, pointer, dot_top, vert_line, hor_line, topper, sun, grass ] for item in objects: item.draw(win) return win
def create_win(self, num_cubies, width, height): self.num_cubies = num_cubies self.win = grp.GraphWin("Rubik's Cube", width, height) # Set the coordinates such that the cube allows for one cubie_width's space on the left # and top sides. self.win.setCoords(0, 0, self.left_margin + (self.num_cubies * (self.cubie_width + self.cubie_angle_width)) + self.right_margin,\ self.bottom_margin + (self.num_cubies * (self.cubie_width + self.cubie_angle_width)) + self.top_margin) self.front = np.full((num_cubies, num_cubies), grp.Polygon()) self.left = np.full((num_cubies, num_cubies), grp.Polygon()) self.top = np.full((num_cubies, num_cubies), grp.Polygon())
def draw_sails(): global sail1, sail2 sail1 = gr.Polygon(gr.Point(x, x + 43), gr.Point(x, x + 118), gr.Point(x + 48, x + 118)) sail1.setFill('white') sail1.setOutline('white') sail2 = gr.Polygon(gr.Point(x - 42, x + 113), gr.Point(x - 4, x + 58), gr.Point(x - 4, x + 113)) sail2.setFill('white') sail2.setOutline('white') sail1.draw(window) sail2.draw(window)
def ship_init(x, y, scale): """ Create the list of objects needed to draw a ship at position (x,y) with the given scale """ shapes = [] '''separate rectangles triangles for the body of the ship, mast, and flag and circle for the windows''' body = gr.Rectangle(gr.Point(x, y), gr.Point(x + scale * 200, y + scale * 100)) body.setFill(gr.color_rgb(218, 165, 32)) shapes.append(body) mast = gr.Rectangle(gr.Point(x + scale * 100, y - 250 * scale), gr.Point(x + scale * 110, y)) mast.setFill(gr.color_rgb(222, 184, 135)) shapes.append(mast) t1 = gr.Polygon(gr.Point(x, y), gr.Point(x - scale * 50, y + scale * 50), gr.Point(x, y + scale * 100)) t1.setFill(gr.color_rgb(218, 165, 32)) shapes.append(t1) t2 = gr.Polygon(gr.Point(x + scale * 200, y), gr.Point(x + scale * 250, y + scale * 50), gr.Point(x + scale * 200, y + scale * 100)) t2.setFill(gr.color_rgb(218, 165, 32)) shapes.append(t2) flag = gr.Polygon(gr.Point(x + scale * 110, y - 150 * scale), gr.Point(x + scale * 160, y - 200 * scale), gr.Point(x + scale * 110, y - 250 * scale)) flag.setFill(gr.color_rgb(255, 0, 255)) shapes.append(flag) window1 = gr.Circle(gr.Point(x + 40 * scale, y + 50 * scale), 10) window1.setFill(gr.color_rgb(230, 230, 250)) shapes.append(window1) window2 = gr.Circle(gr.Point(x + 100 * scale, y + 50 * scale), 10) window2.setFill(gr.color_rgb(230, 230, 250)) shapes.append(window2) window3 = gr.Circle(gr.Point(x + 160 * scale, y + 50 * scale), 10) window3.setFill(gr.color_rgb(230, 230, 250)) shapes.append(window3) return shapes
def mast(): mast1 = gr.Polygon(gr.Point(680, 450), gr.Point(850, 300), gr.Point(850, 450)) mast2 = gr.Polygon(gr.Point(720, 350), gr.Point(850, 250), gr.Point(850, 350)) mast3 = gr.Polygon(gr.Point(770, 280), gr.Point(850, 200), gr.Point(850, 280)) mast1.setFill('white') mast2.setFill('white') mast3.setFill('white') mast1.draw(window) mast2.draw(window) mast3.draw(window)
def show_info(self, lander): """gets the lander info, displays as a text, and then redraws the lander """ alt = lander.get_altitude() # if lander polygon is drawn, undraw it if self.lander_polygon: self.lander_polygon.undraw() fuel = 'FUEL: ' + str(lander.get_fuel()) altitude = 'ALTITUDE: ' + str(lander.get_altitude()) velocity = 'VELOCITY: ' + str(lander.get_velocity()) self.f_label.setText(fuel) self.alt_label.setText(altitude) self.v_label.setText(velocity) self.lander_polygon = graphics.Polygon( graphics.Point(self.win.width / 2 - 10, alt), graphics.Point(self.win.width / 2 - 3, alt + 10), graphics.Point(self.win.width / 2 + 3, alt + 10), graphics.Point(self.win.width / 2 + 10, alt)) self.lander_polygon.setFill("blue") self.lander_polygon.draw(self.win)
def drawRoof(color, windowWidth, windowHeight, win): centerRoofPoint = g.Point(200, 50) triangleRoof = g.Polygon(centerRoofPoint, g.Point(100, 125), g.Point(300, 125)) triangleRoof.setFill(color) triangleRoof.draw(win) return triangleRoof
def bird_init(x, y, scale): """ Create the list of objects needed to draw a bird at position (x,y) with the given scale """ bird = [] '''separate rectangles triangle and circle for the body of the bird, beak, and legs''' body = gr.Rectangle(gr.Point(x, y), gr.Point(x + scale * 75, y + scale * 25)) body.setFill(gr.color_rgb(107, 142, 35)) bird.append(body) leg1 = gr.Rectangle(gr.Point(x, y + 25 * scale), gr.Point(x + scale * 10, y + 40 * scale)) leg1.setFill(gr.color_rgb(95, 158, 160)) bird.append(leg1) leg2 = gr.Rectangle(gr.Point(x + 30, y + 25 * scale), gr.Point(x + scale * 40, y + 40 * scale)) leg2.setFill(gr.color_rgb(95, 158, 160)) bird.append(leg2) head = gr.Circle(gr.Point(x + 75 * scale, y - 5 * scale), 15) head.setFill(gr.color_rgb(127, 255, 215)) bird.append(head) beak = gr.Polygon(gr.Point(x + 85 * scale, y * scale), gr.Point(x + scale * 105, y - scale * 10), gr.Point(x + scale * 85, y - scale * 20)) beak.setFill(gr.color_rgb(255, 215, 0)) bird.append(beak) return bird
def build_polygon(points, cline, cfill): p1, p2, p3, p4 = build_points(points) poly = graphics.Polygon(p1, p2, p3, p4) poly.setWidth(3) poly.setOutline(cline) poly.setFill(cfill) poly.draw(win)
def draw_house(): house = gr.Rectangle(gr.Point(425, 325), gr.Point(575, 475)) house.setFill('grey') house.setWidth(5) roof = gr.Polygon(gr.Point(425, 325), gr.Point(500, 270), gr.Point(575, 325)) roof.setFill('brown') roof.setWidth(5) win1 = gr.Rectangle(gr.Point(465, 365), gr.Point(500, 400)) win1.setFill('yellow') win1.setWidth(5) win2 = gr.Rectangle(gr.Point(500, 365), gr.Point(535, 400)) win2.setFill('yellow') win2.setWidth(5) win3 = gr.Rectangle(gr.Point(465, 400), gr.Point(500, 435)) win3.setFill('yellow') win3.setWidth(5) win4 = gr.Rectangle(gr.Point(500, 400), gr.Point(535, 435)) win4.setFill('yellow') win4.setWidth(5) house.draw(window) roof.draw(window) win1.draw(window) win2.draw(window) win3.draw(window) win4.draw(window)
def showInfo(self, lander): '''This method gets the lander's info and displays them to the user. Then a lander is drawn in the graphics window.''' self.text = graphics.Text(graphics.Point(80, 520), "") alt = lander.getAltitude() vel = lander.getVelocity() fuel = lander.getFuel() infoString = str(alt) + " " + str( vel) + " " + str(fuel) self.text.setText( infoString) #putting the lander's values into self.text self.text.setTextColor("white") self.text.setStyle("bold") self.text.draw(self.win) self.descriptors = graphics.Text(graphics.Point(85, 540), "Altitude Velocity Fuel") self.descriptors.setTextColor("white") self.descriptors.setStyle("bold") self.descriptors.draw(self.win) # if lander polygon is drawn, undraw it if self.landerPolygon: self.landerPolygon.undraw() self.landerPolygon = graphics.Polygon( graphics.Point(self.win.width / 2 - 10, alt), graphics.Point(self.win.width / 2 - 3, alt + 10), graphics.Point(self.win.width / 2 + 3, alt + 10), graphics.Point(self.win.width / 2 + 10, alt)) self.landerPolygon.setFill("gray") self.landerPolygon.draw(self.win)
def tree(x, y): """ Draws tree in windows Parameters ---------- x : INT Horizontal position - middle of rod. y : INT Vertical position - lower position of rod. Returns ------- None. """ tree_rod = gr.Rectangle(gr.Point(x - 10, y - 50), gr.Point(x + 10, y)) tree_rod.setFill('Brown') tree_rod.draw(window) for i in range(3): tree = gr.Polygon(gr.Point(x - 100 + 25 * i, y - 50 - 50 * i), gr.Point(x, y - 50 - 60 - 50 * i), gr.Point(x + 100 - 25 * i, y - 50 - 50 * i)) tree.setFill('Green') tree.draw(window)
def __init__(self, win, x0, y0, width, height, coloring='blue'): #assign self.width = width self.height = height self.coloring = coloring Thing.__init__(self, win, "block", x0, y0, mass=0, radius=0) self.vis = [ gr.Polygon( gr.Point( self.x0 * self.scale, self.win.getHeight() - (self.y0 + self.height / 2) * self.scale), gr.Point((self.x0 + self.width / 4) * self.scale, self.win.getHeight() - (self.y0 + self.height) * self.scale), gr.Point((self.x0 + self.width * 0.75) * self.scale, self.win.getHeight() - (self.y0 + self.height) * self.scale), gr.Point((self.x0 + self.width) * self.scale, self.win.getHeight() - (self.y0 + self.height / 2) * self.scale), gr.Point((self.x0 + self.width * 0.75) * self.scale, self.win.getHeight() - self.y0 * self.scale), gr.Point((self.x0 + self.width / 4) * self.scale, self.win.getHeight() - self.y0 * self.scale)) ] for ball in self.vis: ball.setFill(self.coloring)
def draw_ghost(win): body = gr.Polygon(gr.Point(460, 615), gr.Point(450, 645), gr.Point(410, 700), gr.Point(390, 730), gr.Point(435, 720), gr.Point(445, 740), gr.Point(490, 715), gr.Point(525, 735), gr.Point(550, 710), gr.Point(540, 670), gr.Point(510, 640), gr.Point(500, 600)) body.draw(win) body.setFill('silver') head = gr.Circle(gr.Point(475, 600), 25) head.draw(win) head.setFill('silver') eye = gr.Circle(gr.Point(462, 602), 6) eye.draw(win) eye.setFill('lightblue') eye = gr.Circle(gr.Point(488, 598), 6) eye.draw(win) eye.setFill('lightblue') pupil = gr.Circle(gr.Point(461, 603), 2) pupil.draw(win) pupil.setFill('black') pupil = gr.Circle(gr.Point(487, 599), 2) pupil.draw(win) pupil.setFill('black')
def draw_house(): house = gr.Rectangle(gr.Point(220, 210), gr.Point(380, 350)) house.setOutline('gray') house.setFill("gray") roof = gr.Polygon(gr.Point(220, 210), gr.Point(300, 160), gr.Point(380, 210)) roof.setFill('black') roof.setOutline('black') windows = gr.Rectangle(gr.Point(265, 250), gr.Point(335, 310)) windows.setFill('lightblue') windows.setOutline('black') house.draw(window) roof.draw(window) windows.draw(window) for start_line_x, start_line_y, end_line_x, end_line_y in [ (300, 250, 300, 310), (265, 280, 335, 280) ]: line = gr.Line(gr.Point(start_line_x, start_line_y), gr.Point(end_line_x, end_line_y)) line.setWidth(1) line.setOutline('black') line.draw(window)
def draw_roof(x=50, y=40, color="brown"): """Draw house roof""" roof = gr.Polygon(gr.Point(x, y), gr.Point(x + 25, y - 10), gr.Point(x + 50, y)) roof.draw(window) roof.setFill(color)
def draw_needles(x, y): o_needles = gr.Polygon(gr.Point(x, y + 80), gr.Point(x + 85, y), gr.Point(x + 170, y + 80)) o_needles.setFill('green') o_needles.setWidth(5) o_needles.draw(window)
def house(): house_body = gr.Rectangle(gr.Point(450, 250), gr.Point(650, 450)) house_body.setFill('Gray') house_body.draw(window) house_chimney = gr.Rectangle(gr.Point(590, 170), gr.Point(610, 250)) house_chimney.setFill('Gray') house_chimney.draw(window) house_roof = gr.Polygon(gr.Point(450, 250), gr.Point(550, 150), gr.Point(650, 250)) house_roof.setFill('Maroon') house_roof.draw(window) house_roof_window = gr.Circle(gr.Point(550, 215), 15) house_roof_window.setFill(gr.color_rgb(255, 251, 130)) house_roof_window.draw(window) for i in range(2): for j in range(2): house_body_window = gr.Rectangle( gr.Point(520 + 30 * j, 320 + 30 * i), gr.Point(550 + 30 * j, 350 + 30 * i)) house_body_window.setFill('Yellow') house_body_window.setWidth(3) house_body_window.draw(window)
def draw_house(): house_body = gr.Rectangle(gr.Point(200, 220), gr.Point(400, 420)) house_body.setFill(gr.color_rgb(200, 180, 140)) house_body.setOutline(gr.color_rgb(160, 140, 100)) house_body.setWidth(5) house_body.draw(window) house_roof = gr.Polygon(gr.Point(190, 220), gr.Point(300, 110), gr.Point(410, 220)) house_roof.setFill(gr.color_rgb(140, 25, 30)) house_roof.setOutline(gr.color_rgb(100, 5, 10)) house_roof.setWidth(5) house_roof.draw(window) house_window = gr.Rectangle(gr.Point(250, 260), gr.Point(350, 360)) house_window.setFill(gr.color_rgb(132, 205, 255)) house_window.setWidth(5) house_window.draw(window) line1 = gr.Line(gr.Point(300, 260), gr.Point(300, 360)) line2 = gr.Line(gr.Point(250, 310), gr.Point(350, 310)) line1.setWidth(5) line2.setWidth(5) line1.draw(window) line2.draw(window)
def render(self): """ This function renders the Line object so it rotates around some axis """ theta = self.angle * math.pi / 180.0 cth = math.cos(theta) sth = math.sin(theta) pts = [] cornerpts = [] for vertex in self.points: x = vertex[0] + self.pos[0] - self.anchor[0] y = vertex[1] + self.pos[1] - self.anchor[1] xt = x * cth - y * sth yt = x * sth + y * cth x = xt + self.anchor[0] y = yt + self.anchor[1] cornerpts.append([x, y]) pts.append( gr.Point(self.scale * x, self.win.getHeight() - self.scale * y)) self.corners = cornerpts self.vis = [gr.Polygon(pts)]
def draw_house(): house = gr.Rectangle(gr.Point(20, 210), gr.Point(180, 350)) house.setOutline('gray') house.setFill("gray") roof = gr.Polygon(gr.Point(20, 210), gr.Point(100, 160), gr.Point(180, 210)) roof.setFill('black') roof.setOutline('black') windows = gr.Rectangle(gr.Point(65, 250), gr.Point(135, 310)) windows.setFill('lightblue') windows.setOutline('black') line1 = gr.Line(gr.Point(100, 250), gr.Point(100, 310)) line1.setWidth(1) line1.setOutline('black') line2 = gr.Line(gr.Point(65, 280), gr.Point(135, 280)) line2.setWidth(1) line2.setOutline('black') house.draw(window) roof.draw(window) windows.draw(window) line1.draw(window) line2.draw(window)
def draw_roof(): #крыша vertices = [gr.Point(100, 250), gr.Point(200, 140), gr.Point(300, 250)] roof = gr.Polygon(vertices) roof.setFill('#B22222') roof.setWidth(3) roof.draw(window)