예제 #1
0
class HangDude(HorizontalPanel):
    def __init__(self):
        HorizontalPanel.__init__(self)
        self.context = GWTCanvas(300,300,300,300)
        self.context.addStyleName("gwt-canvas")
        self.add(self.context)

    def clear(self):
        self.context.clear()

    def draw(self, guesses):
        self.context.fillStyle = '#000'
        self.context.lineWidth = 2 
        if guesses == 1:
            self.context.fillRect(20, 280, 200,10)
        elif guesses == 2:
            self.context.fillRect(40, 20, 10, 260)
        elif guesses == 3:
            self.context.fillRect(20, 20, 160,10)
        elif guesses == 4:
            self.context.saveContext()
            self.context.translate(80,30)
            self.context.rotate(130 * math.pi / 180)
            self.context.fillRect(0,0, 50,10)
            self.context.restoreContext()
        elif guesses == 5:
            self.context.fillRect(140, 20, 10, 50)
        elif guesses == 6:
            self.context.beginPath()
            self.context.arc(145, 100, 30, 0, math.pi * 2, True)
            self.context.closePath()
            self.context.stroke()
        elif guesses == 7:
            self.context.fillRect(145, 130, 2, 80)
        elif guesses == 8:
            self.context.saveContext()
            self.context.translate(147,160)
            self.context.rotate(130 * math.pi / 180)
            self.context.fillRect(0,0, 50,2)
            self.context.restoreContext()
        elif guesses == 9:
            self.context.saveContext()
            self.context.translate(147,160)
            self.context.rotate(45 * math.pi / 180)
            self.context.fillRect(0,0, 50,2)
            self.context.restoreContext()
        elif guesses == 10:
            self.context.saveContext()
            self.context.translate(147,210)
            self.context.rotate(130 * math.pi / 180)
            self.context.fillRect(0,0, 60,2)
            self.context.restoreContext()
        elif guesses == 11:
            self.context.saveContext()
            self.context.translate(147,210)
            self.context.rotate(45 * math.pi / 180)
            self.context.fillRect(0,0, 60,2)
            self.context.restoreContext()
        self.context.restoreContext()
예제 #2
0
class HangDude(HorizontalPanel):
    def __init__(self):
        HorizontalPanel.__init__(self)
        self.context = GWTCanvas(300,300,300,300)
        self.context.addStyleName("gwt-canvas")
        self.add(self.context)

    def clear(self):
        self.context.clear()

    def draw(self, guesses):
        self.context.fillStyle = '#000'
        self.context.lineWidth = 2 
        if guesses == 1:
            self.context.fillRect(20, 280, 200,10)
        elif guesses == 2:
            self.context.fillRect(40, 20, 10, 260)
        elif guesses == 3:
            self.context.fillRect(20, 20, 160,10)
        elif guesses == 4:
            self.context.saveContext()
            self.context.translate(80,30)
            self.context.rotate(130 * math.pi / 180)
            self.context.fillRect(0,0, 50,10)
            self.context.restoreContext()
        elif guesses == 5:
            self.context.fillRect(140, 20, 10, 50)
        elif guesses == 6:
            self.context.beginPath()
            self.context.arc(145, 100, 30, 0, math.pi * 2, True)
            self.context.closePath()
            self.context.stroke()
        elif guesses == 7:
            self.context.fillRect(145, 130, 2, 80)
        elif guesses == 8:
            self.context.saveContext()
            self.context.translate(147,160)
            self.context.rotate(130 * math.pi / 180)
            self.context.fillRect(0,0, 50,2)
            self.context.restoreContext()
        elif guesses == 9:
            self.context.saveContext()
            self.context.translate(147,160)
            self.context.rotate(45 * math.pi / 180)
            self.context.fillRect(0,0, 50,2)
            self.context.restoreContext()
        elif guesses == 10:
            self.context.saveContext()
            self.context.translate(147,210)
            self.context.rotate(130 * math.pi / 180)
            self.context.fillRect(0,0, 60,2)
            self.context.restoreContext()
        elif guesses == 11:
            self.context.saveContext()
            self.context.translate(147,210)
            self.context.rotate(45 * math.pi / 180)
            self.context.fillRect(0,0, 60,2)
            self.context.restoreContext()
        self.context.restoreContext()
예제 #3
0
class Canvas(HorizontalPanel):
    def __init__(self, SW, SH):
        HorizontalPanel.__init__(self)
        self.SW = SW
        self.SH = SH
        self.context = GWTCanvas(SW, SH, SW, SH)
        self.context.addStyleName("gwt-canvas")
        self.add(self.context)

    def draw(self, game):
        self.context.fillStyle = "#00AA00"
        self.context.fillRect(0, 0, SW, SH)
예제 #4
0
class MainWidget(HorizontalPanel):
    def __init__(self, SW, SH):
        HorizontalPanel.__init__(self)
        self.SW = SW
        self.SH = SH
        self.context = GWTCanvas(SW, SH, SW, SH)
        self.context.addStyleName("gwt-canvas")
        self.add(self.context)

    def draw(self, game=None):
        self.context.setFillStyle(Color.Color("#00AA00"))
        self.context.fillRect(0, 0, self.SW, self.SH)

        SP = self.SW // 8

        for x in range(0, self.SW, SP):
            self.context.beginPath()
            self.context.setStrokeStyle(Color.BLACK)
            self.context.setLineWidth(1)
            self.context.moveTo(x, 0)
            self.context.lineTo(x, self.SH)
            self.context.closePath()
            self.context.stroke()
        for y in range(0, self.SH, SP):
            self.context.beginPath()
            self.context.setStrokeStyle(Color.BLACK)
            self.context.setLineWidth(1)
            self.context.moveTo(0, y)
            self.context.lineTo(self.SW, y)
            self.context.closePath()
            self.context.stroke()

        # Draw pieces
        for (x, y) in [(x, y) for x in range(8) for y in range(8)]:
            if game.state[x][y] != Game.NONE:
                if game.state[x][y] == Game.BLACK:
                    self.context.setFillStyle(Color.BLACK)
                elif game.state[x][y] == Game.WHITE:
                    self.context.setFillStyle(Color.WHITE)
                self.context.beginPath()
                self.context.arc(x * SP + SP // 2, y * SP + SP // 2, SP // 2, 0, 2 * pi)
                self.context.closePath()
                self.context.fill()
    
        # Draw liberties
        for (x, y) in Game.liberties(game.current_player, game.state):
            self.context.setFillStyle(Color.WHITE)
            self.context.beginPath()
            self.context.arc(x * SP + SP // 2, y * SP + SP // 2, 4, 0, 2 * pi)
            self.context.closePath()
            self.context.fill()
예제 #5
0
    def onModuleLoad(self):

        self.layout = HorizontalPanel()

        # Each demo will set their own dimensions, so it doesn't matter
        # what we initialize the canvas to.
        canvas = GWTCanvas(400,400)

        canvas.addStyleName("gwt-canvas")

        self.demos = []
        # Create demos
        self.demos.append(StaticDemo(canvas))
        self.demos.append(LogoDemo(canvas))
        self.demos.append(ParticleDemo(canvas))
        self.demos.append(GradientDemo(canvas))
        self.demos.append(SuiteDemo(canvas))

        # Add them to the selection list box
        lb = ListBox()
        lb.setStyleName("listBox")

        for i in range(len(self.demos)):
            lb.addItem(self.demos[i].getName())

        lb.addChangeListener(self)

        # start off with the first demo
        self.currentDemo = self.demos[0]

        # Add widgets to self.layout and RootPanel
        vp = VerticalPanel()
        vp.add(lb)
        vp.add(canvas)
        self.layout.add(vp)
        if self.currentDemo.getControls() is not None:
            self.layout.add(self.currentDemo.getControls())

        RootPanel().add(self.layout)
        self.currentDemo.drawDemo()
예제 #6
0
파일: tester.py 프로젝트: ASayre/UCSBsketch
class CanvasTest(object):
   def __init__(self):
      self.canvas = GWTCanvas(coordX = 400, coordY= 400, pixelX = 400, pixelY = 400)
      self.canvas.addStyleName("gwt-canvas")
      DOM.sinkEvents(self.canvas.getElement(), Event.MOUSEEVENTS)
      #DOM.setEventListener(self.canvas.getElement(), self)

      self.canvas.setFillStyle(Color.Color(255, 0, 0))
      self.canvas.fillRect(4,4,10,10)

      self._dragging = False
      #Register for canvas mouse events


      RootPanel().add(self.canvas)

   def onBrowserEvent(self, event):
      print "Event happened"
      kind = DOM.eventGetType(event)
      x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(self.canvas.getElement())
      y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(self.canvas.getElement())
      print "Type of event: %s" % (kind)
      if kind == "mousedown":
         self._dragging = True
         self.onMouseDown(x,y)
      elif kind == "mousemove" and self._dragging:
         self.onMouseDrag(x,y)
      elif (kind == "mouseup" or kind == "mouseout") and self._dragging:
         self._dragging = False
         self.onMouseUp(x,y)

   def onMousedown(self, x, y):
      print "Mousedown"

   def onMouseDrag(self, x, y):
      print "Mouse dragging"

   def onMouseUp(self, x, y):
      print "Mouseup"