示例#1
0
def init_hardware():
    global _canvas, _cabin, _ldoor, _rdoor
    _canvas = _g.Canvas(200, 600)
    _canvas.setBackgroundColor("lightblue")
    _canvas.setTitle("Elevator")
    r = _g.Rectangle(90, 160)
    r.setFillColor("yellow")
    r.setBorderColor("red")
    _ldoor = _g.Rectangle(40, 150)
    _rdoor = _g.Rectangle(40, 150)
    _ldoor.move(-20, 0)
    _rdoor.move(20, 0)
    _ldoor.adjustReference(-20, 0)
    _rdoor.adjustReference(20, 0)
    _ldoor.setFillColor("blue")
    _rdoor.setFillColor("blue")
    r.setDepth(60)
    _cabin = _g.Layer()
    _cabin.add(r)
    _cabin.add(_ldoor)
    _cabin.add(_rdoor)
    _cabin.moveTo(70, 600 - 90)
    _canvas.add(_cabin)
    for i in range(3):
        floor = _g.Rectangle(70, 6)
        floor.setFillColor("blue")
        floor.moveTo(150, 600 - i * 200 - 13)
        _canvas.add(floor)
    for i in range(4):
        floor = (i + 1) // 2
        button = Button(i, ((i % 2) == 0))
        button.moveTo(150, 600 - floor * 200 - 50)
        light = _g.Circle(10)
        light.moveTo(150, 600 - floor * 200 - 90)
        light.setFillColor("darkblue")
        if i == 1:
            button.move(15, 0)
            light.move(15, 0)
        elif i == 2:
            button.move(-15, 0)
            light.move(-15, 0)
        _canvas.add(button)
        _canvas.add(light)
        _buttons[i] = button
        _lights[i] = light
示例#2
0
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)

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)
paper = "Paper World"
paper.add(sunraySW)
cg.getCanvas()
paper = cg.Canvas()
paper.setBackgroundColor(springgreen)
paper.setBackgroundColor('skyBlue')
paper.setWidth(800)
paper.setHeight(550)
paper.setTitle("A Whole New World")
sun = cg.Circle(50, cg.Point(700,100))
paper.add(sun)
sun.setFillColor('yellow')
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 = cg.Path(cg.Point(660,140), cg.Point(635,165))
sunraySW.setBorderColor('yellow')
sunraySW.setBorderWidth(6)
paper.add(sunraySW)
sunraySW = cg.Path(cg.Point(740,140), cg.Point(735,165))
sunraySW.setBorderColor('yellow')
sunraySW.setBorderWidth(6)
paper.add(sunraySW)
sunrayNE = cg.Path(cg.Point(740,60) cg.Point(765,35))
示例#4
0
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
示例#5
0
sunCenter = cg.Point(500,300)
sun2 = cg.Circle(50, sunCenter)
paper.add(sun2)
sun3 = cg.Circle(50, cg.Point(100,800)
)
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')
paper.setHeight(400)
paper.getBackgroundColor()
paper.getWidth()
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))