def create_layer(self): # compute tilesize and border coordinates w, h = _scene.getWidth(), _scene.getHeight() tsx = w / (self.num_cols + 2) tsy = h / (self.num_rows + 2) self.ts = min(tsx, tsy) self.left = 2 * self.ts self.right = self.left + 2 * self.ts * self.av self.bottom = h - 2 * self.ts self.top = self.bottom - 2 * self.ts * self.st self.layer = _g.Layer() # Create avenues for av in range(self.av): x = self.left + self.ts * (2 * av + 1) l = _g.Path([_g.Point(x, self.top), _g.Point(x, self.bottom)]) l.setBorderColor("light gray") self.layer.add(l) self.layer.add( _g.Text("%d" % (av + 1), 10, _g.Point(x, self.bottom + self.ts))) # Create streets for st in range(self.st): y = self.bottom - self.ts * (2 * st + 1) l = _g.Path([_g.Point(self.left, y), _g.Point(self.right, y)]) l.setBorderColor("light gray") self.layer.add(l) self.layer.add( _g.Text("%d" % (st + 1), 10, _g.Point(self.left - self.ts, y))) # Create border border = _g.Polygon(_g.Point(self.left, self.bottom), _g.Point(self.right, self.bottom), _g.Point(self.right, self.top), _g.Point(self.left, self.top)) border.setBorderWidth(5) border.setBorderColor("dark red") border.setDepth(10) self.layer.add(border) # Create walls for (col, row) in self.walls: if col % 2 == 0: # vertical wall x1, y1 = self.cr2xy(col, row - 1) x2, y2 = self.cr2xy(col, row + 1) else: # horizontal wall x1, y1 = self.cr2xy(col - 1, row) x2, y2 = self.cr2xy(col + 1, row) w = _g.Path([_g.Point(x1, y1), _g.Point(x2, y2)]) w.setBorderWidth(5) w.setBorderColor("dark red") w.setDepth(10) self.layer.add(w) # Create beepers for (av, st) in self.beepers: self._create_beeper(av, st) # Layer finished _scene.add(self.layer)
def make_cat_appear(self): cat = cg.Circle(100, cg.Point(self.center_x, self.center_y)) cat.setFillColor(self.color) eye1 = cg.Circle(10, cg.Point(self.center_x - 50, self.center_y - 25)) eye1.setFillColor("black") eye2 = cg.Circle(10, cg.Point(self.center_x + 50, self.center_y - 25)) eye2.setFillColor("black") ear1 = cg.Polygon(cg.Point(self.center_x + 90, self.center_y - 25), cg.Point(self.center_x + 125, self.center_y - 125), cg.Point(self.center_x + 30, self.center_y - 90)) ear2 = cg.Polygon(cg.Point(self.center_x - 90, self.center_y - 25), cg.Point(self.center_x - 125, self.center_y - 125), cg.Point(self.center_x - 30, self.center_y - 90)) nose = cg.Polygon(cg.Point(self.center_x - 15, self.center_y), cg.Point(self.center_x, self.center_y + 15), cg.Point(self.center_x + 15, self.center_y)) nose_line1 = cg.Path(cg.Point(self.center_x + 15, self.center_y + 30), cg.Point(self.center_x, self.center_y + 15)) nose_line2 = cg.Path(cg.Point(self.center_x - 15, self.center_y + 30), cg.Point(self.center_x, self.center_y + 15)) nose.setFillColor("pink") ear1.setFillColor(self.color) ear1.setDepth(70) ear2.setFillColor(self.color) ear2.setDepth(70) nose.setDepth(25) nose_line1.setBorderWidth(2.5) nose_line2.setBorderWidth(2.5) nose_line1.setDepth(25) nose_line2.setDepth(25) paper.add(nose) paper.add(ear1) paper.add(ear2) paper.add(cat) paper.add(eye1) paper.add(eye2) paper.add(nose_line1) paper.add(nose_line2)
def make_bird_appear(self): bird = cg.Circle(100, cg.Point(self.center_x, self.center_y)) bird.setFillColor(self.color) eye1 = cg.Circle(10, cg.Point(self.center_x - 50, self.center_y - 25)) eye1.setFillColor("black") eye2 = cg.Circle(10, cg.Point(self.center_x + 50, self.center_y - 25)) eye2.setFillColor("black") nose = cg.Polygon(cg.Point(self.center_x - 25, self.center_y - 25), cg.Point(self.center_x, self.center_y), cg.Point(self.center_x + 25, self.center_y - 25)) nose.setFillColor("yellow") nose.setDepth(25) paper.add(nose) paper.add(bird) paper.add(eye1) paper.add(eye2)
# coding: utf-8 roof = cg.Polygon(cg.Point(300, 250), cg.Point(500, 250), cg.Point(400, 250)) roof.setFillColor('brown') roof.setDepth(45) paper.add(roof) import cs1graphics as cg roof = cg.Polygon(cg.Point(300, 250), cg.Point(500, 250), cg.Point(400, 250)) roof.setFillColor('brown') roof.setDepth(45) paper.add(roof) paper = cy.Canvas() paper = cg.Canvas() paper.setBackgroundColor('skyBlue') paper.setWidth(800) paper.setHeight(600) paper.setTitle('My World') sun = cg.Circle() paper.add(sun) sun.setFillColor('yellow') sun.setRadius(50) sun.moveTo(700, 100) paper.add(sun) facade = cg.Square(200, cg.Point(400, 350)) facade.setFillColor('white') paper.add(facade) chimney = cg.Rectangle(50, 70, cg.Point(450, 215)) chimney.setFillColor('red') paper.add(chimney)
def draw_landscape(): """Creates two suns, sunrays, house, tree, and grass""" paper = cg.Canvas() paper.setBackgroundColor('skyBlue') paper.setWidth(800) paper.setHeight(600) paper.setTitle('Welcome to Tattoine') sun = cg.Circle() paper.add(sun) sun.setFillColor('yellow') sun.setRadius(50) sun.moveTo(700, 100) sunCenter = cg.Point(670, 110) sun2 = cg.Circle(50, sunCenter) sun2.setDepth(60) sun2.setFillColor('orange') paper.add(sun2) facade = cg.Square(200, cg.Point(400, 350)) facade.setFillColor('white') paper.add(facade) chimney = cg.Rectangle(50, 70, cg.Point(450, 215)) chimney.setFillColor('red') paper.add(chimney) tree = cg.Polygon(cg.Point(150, 220), cg.Point(120, 380), cg.Point(180, 380)) tree.setFillColor('darkGreen') paper.add(tree) sunraySW = cg.Path(cg.Point(660, 140), cg.Point(635, 165)) sunraySW.setBorderColor('yellow') sunraySW.setBorderWidth(6) paper.add(sunraySW) sunraySE = cg.Path(cg.Point(740, 140), cg.Point(765, 165)) sunraySE.setBorderColor('yellow') sunraySE.setBorderWidth(6) paper.add(sunraySE) sunrayNE = cg.Path(cg.Point(740, 60), cg.Point(765, 35)) sunrayNE.setBorderColor('yellow') sunrayNE.setBorderWidth(6) paper.add(sunrayNE) sunrayNW = cg.Path(cg.Point(660, 60), cg.Point(635, 35)) sunrayNW.setBorderColor('yellow') sunrayNW.setBorderWidth(6) paper.add(sunrayNW) grass = cg.Rectangle(800, 300, cg.Point(400, 450)) grass.setFillColor('green') grass.setBorderColor('green') grass.setDepth(75) paper.add(grass) landscape_objects = {'paper': paper, 'sun1': sun, 'sun2': sun2, 'facade': facade, 'sunrays': [sunrayNE, sunrayNW, sunraySW, sunraySE], 'chimney': chimney, 'tree': tree, 'grass': grass} return landscape_objects
) paper.add(sun3) sun3 = cg.Circle(50, cg.Point(100,500) ) sun3 = cg.Circle(50, cg.Point(100,500)) paper.add(sun3) sun2.setFillColor('lightYellow') facade = cg.Square(200, cg.Point(400,350)) facade.setFillColor('purple') paper.add(facade) chimney = (50, 70, cg.Point(450, 215)) chimney = cg.Rectangle(50, 70, cg.Point(450, 215)) chimney.setFillColor('red') paper.add(chimney) tree = cg.Polygon(cg.Point(150,220), cg.Point(120,380), cg.Point(180,380)) tree.setFillColor('darkGreen') paper.add(tree) sunraySW = cg.Path(cg.Point(660,140), cg.Point(635,165)) paper.add(sunraySW) sunraySE = cg.Path(cg.Point(740, 140), cg.Point(765, 165)) sunraySE.setBorderColor('yellow') sunraySE.setBorderWidth(6) paper.add(sunraySE) sunrayNE = cg.Path(cg.Point(740, 60), cg.Point(765, 35)) sunrayNE.setBorderColor('yellow') sunrayNE.setBorderWidth(6) paper.add(sunrayNE) sunrayNW = cg.Path(cg.Point(660, 60), cg.Point(635, 35)) sunrayNW.setBorderColor('yellow')
paper.add(sun) sun.setFillColor('yellow') sun.setRadius(50) sun.moveTo(700,100) sunCenter = cg.Point(700, 100) sun2 = cg.Circle(50, sunCenter) sun2.setFillColor('lightYellow') paper.add(sun2) facade = cg.Square(200, cg.Point(400, 350)) facade.setFillColor('white') paper.add(facade) chimney = cg.Rectangle(50, 70, cg.Point(450, 215)) chimney.setFillColor('red') paper.add(chimney) tree = cg.Polygon(cg.Point(150, 220), cg.Point(120, 380), cg.Point(180, 380)) tree.setFillColor('darkGreen') paper.add(tree) sunraySW = cg.Path(cg.Point(660, 140), cg.Point(635,165)) sunraySW.setBorderColor('yellow') sunraySW.setBorderWidth(6) paper.add(sunraySW) sunraySE = cg.Path(cg.Point(740, 140), cg.Point(765,165)) sunraySE.setBorderColor('yellow') sunraySE.setBorderWidth(6) paper.add(sunraySE) sunrayNE = cg.Path(cg.Point(740, 60), cg.Point(765,35)) sunrayNE.setBorderColor('yellow') sunrayNE.setBorderWidth(6) paper.add(sunrayNE)
sun = cg.Circle() paper.add(sun) sun.setFillColor("Orange") sun.setRadius(50) sun.moveTo(700, 100) sunCenter = cg.Point(500, 150) sun2 = cg.Circle(50, sunCenter) paper.add(sun2) sun2.setFillColor('Yellow') facade = cg.Square(200, cg.Point(400, 350)) facade.setFillColor('brown') paper.add(facade) chimney = cg.Rectangle(50, 70, cg.Point(450, 215)) chimney.setFillColor('red') paper.add(chimney) tree = cg.Polygon(cg.Point(150, 220)), tree = cg.Polygon(cg.Point(150, 220), cg.Point(120, 380), cg.Point(180, 380)) tree.setFillColor("limeGreen") paper.add(tree) sunraySW = cg.Path(cg.Point(660, 140), cg.Point(635, 165)) sunraySW.setBorderColor("white") sunraySW.setBorderWidth(6) paper.add(sunraySW) sunraySE = cg.Path(cg.Point(740, 140), cg.Point(765, 165)) sunraySE.setBorderColor('white') sunraySE.setBorderWidth(6) paper.add(sunraySE) sunrayNE = cg.Path(cg.Point(740, 60), cg.Point(765, 35)) sunrayNE.setBorderColor('white') sunrayNE.setBorderWidth(6) paper.add(sunrayNE)
sun.setFillColor('skyblue') sun.getFillColor() sun2.moveTo(700, 100) sun2.moveTo(900, 100) sun2.moveTo(800, 100) sun2.moveTo(700, 100) sun2.moveTo(700, 300) sun2.moveTo(700, 100) sun2.setFillColor('yellow') facade = cg.Square(200, cg.Point(400, 350)) paper.add(facade) facade.setFillColor('white') chimney = cg.Rectangle(50, 70, cg.Point(450, 215)) chimney.setFillColor('red') paper.add(chimney) tree = cg.Polygon(cg.Point(150, 220), cg.Point(120, 380), cg.Point(180, 380)) tree.setFillColor('darkGreen') paper.add(tree) sunraySW = cg.Path(cg.Point(660, 140), cg.Point(635, 165)) paper.add(sunraySW) sunraySW.setBorderColor('yellow') sunraySW.setBorderWidth(6) sunraySW.setBorderWidth(10) sunraySE = cd.Path(cg.Point(740, 140), cg.Point(765, 165)) sunraySE = cg.Path(cg.Point(740, 140), cg.Point(765, 165)) paper.add(sunraySE) sunraySE.setBorderWidth(10) sunraySE.setBorderColor('yellow') sunrayNE = cg.Path(cg.Point(740, 60), cg.Point(765, 35)) paper.add(sunraySE) paper.add(sunrayNE)
# The Sun! sun = cg.Circle() paper.add(sun) sun.setFillColor("orange") sun.moveTo(800, 0) sun.setRadius(300) sun.setBorderWidth(0) # The House! facade = cg.Square(200, cg.Point(400, 350)) facade.setFillColor('white') paper.add(facade) # The Tree! tree = cg.Polygon(cg.Point(150, 220), cg.Point(120, 380), cg.Point(180, 380)) tree.setFillColor('darkGreen') paper.add(tree) # The Chimney! chimney = cg.Rectangle(50, 70, cg.Point(450, 215)) chimney.setFillColor('red') paper.add(chimney) # The Grass! grass = cg.Rectangle(800, 300, cg.Point(400, 550)) grass.setFillColor('darkGreen') grass.setBorderColor('darkGreen') grass.setDepth(75) # must be behind house and tree paper.add(grass)