コード例 #1
0
ファイル: CanvasTab.py プロジェクト: minghuascode/pyj
 def draw(self):
     for i in range(0, 6):
         for j in range(0, 6):
             self.setFillStyle(
                 Color('rgb(%d,%d,0)' %
                       (floor(255 - 42.5 * i), floor(255 - 42.5 * j))))
             self.fillRect(j * 25, i * 25, 25, 25)
コード例 #2
0
ファイル: Widgets.py プロジェクト: wkornewald/pyjs
    def draw(self):
        pi = 3.14159265358979323
        if not getattr(self, 'clock', None):
            return

        self.setGlobalCompositeOperation('destination-over')

        # clear canvas
        self.clear()

        self.saveContext()
        self.setFillStyle(Color('rgba(0,0,0,0.4)'))
        self.setStrokeStyle(Color('rgba(0,153,255,0.4)'))
        self.translate(self.width / 2, self.height / 2)

        secs = self.getTimeSeconds()
        mins = self.getTimeMinutes() + secs / 60.0
        hours = self.getTimeHours() + mins / 60.0

        # Seconds
        self.saveContext()
        self.setFillStyle(Color('rgba(255,0,0,0.4)'))
        self.rotate(((2 * pi) / 60) * secs + pi)
        self.fillRect(-1, -(self.width * 0.04), 2, self.width * 0.38)
        self.restoreContext()

        # Minutes
        self.saveContext()
        self.rotate(((2 * pi) / 60) * mins + pi)
        self.fillRect(-1, -1, 3, self.width * 0.35)
        self.restoreContext()

        # Hours
        self.saveContext()
        self.rotate(((2 * pi) / 12) * hours + pi)
        self.fillRect(-2, -2, 4, self.width * 0.2)
        self.restoreContext()

        self.restoreContext()

        self.drawImage(self.clock.getElement(), 0, 0)
コード例 #3
0
ファイル: CanvasTab.py プロジェクト: minghuascode/pyj
 def draw(self):
     self.saveContext()
     self.fillRect(0, 0, 300, 300)
     for i in range(0, 3):
         for j in range(0, 3):
             self.setStrokeStyle(Color("#9CFF00"))
             self.saveContext()
             self.translate(50 + j * 100, 50 + i * 100)
             self.drawSpirograph(20 * (j + 2) / (j + 1),
                                 -8 * (i + 3) / (i + 1), 10)
             self.restoreContext()
     self.restoreContext()
コード例 #4
0
    def drawDemo(self):
        self.canvas.resize(self.width, self.height)

        self.particles = []

        for i in range(self.numParticles):
            self.particles.append( Particle(self) )

        self.canvas.saveContext()
        self.canvas.setLineWidth(2)
        self.canvas.setStrokeStyle(Color(255,0,0))
        self.run = True
        Timer(10, self)
コード例 #5
0
ファイル: CanvasTab.py プロジェクト: minghuascode/pyj
    def draw(self):
        pi = 3.14159265358979323
        if not getattr(self, 'earth', None):
            return

        self.setGlobalCompositeOperation('destination-over')

        # clear canvas
        self.clear()

        self.saveContext()
        self.setFillStyle(Color('rgba(0,0,0,0.4)'))
        self.setStrokeStyle(Color('rgba(0,153,255,0.4)'))
        self.translate(150, 150)

        # Earth
        self.rotate(((2 * pi) / 60) * self.getTimeSeconds() +
                    ((2 * pi) / 60000) * self.getTimeMilliseconds())
        self.translate(105, 0)
        self.fillRect(0, -12, 50, 24)  # Shadow
        self.drawImage(self.earth.getElement(), -12, -12)

        # Moon
        self.saveContext()
        self.rotate(((2 * pi) / 6) * self.getTimeSeconds() +
                    ((2 * pi) / 6000) * self.getTimeMilliseconds())
        self.translate(0, 28.5)
        self.drawImage(self.moon.getElement(), -3.5, -3.5)
        self.restoreContext()

        self.restoreContext()

        self.beginPath()
        self.arc(150, 150, 105, 0, pi * 2, False)  # Earth orbit
        self.stroke()

        self.drawImage(self.sun.getElement(), 0, 0)
コード例 #6
0
ファイル: CanvasTab.py プロジェクト: minghuascode/pyj
    def draw(self):
        pi = 3.14159265358979323
        # Loop through rings (from inside to out)
        for i in range(1, 6):
            self.saveContext()
            self.setFillStyle(
                Color('rgb(%d,%d,255)' % ((51 * i), (255 - 51 * i))))

            # draw individual dots
            for j in range(0, i * 6):
                self.rotate(pi * 2 / (i * 6))
                self.beginPath()
                self.arc(0, i * 12.5, 5, 0, pi * 2, True)
                self.fill()

            self.restoreContext()
コード例 #7
0
ファイル: HTML5Canvas.py プロジェクト: sofianhw/pyjs
 def getShadowColor(self):
     return Color(self.impl.getShadowColor())
コード例 #8
0
    def drawDemo(self):
        self.canvas.resize(self.width, self.height)

        # DRAW SOME LINEAR GRADIENTS
        # Demos ported from Mozilla Development Center Canvas Tutorial
        self.canvas.saveContext()

        # Create gradients
        lingrad = self.canvas.createLinearGradient(0, 0, 0, 150)
        lingrad.addColorStop(0.0, Color("#00ABEB"))
        lingrad.addColorStop(0.5, Color("#fff"))
        lingrad.addColorStop(0.5, Color("#26C000"))
        lingrad.addColorStop(1, Color("#fff"))

        lingrad2 = self.canvas.createLinearGradient(0, 50, 0, 95)
        lingrad2.addColorStop(0.5, Color("#000"))
        lingrad2.addColorStop(1, Color("rgba(0,0,0,0)"))

        # assign gradients to fill and stroke styles
        self.canvas.setFillStyle(lingrad)
        self.canvas.setStrokeStyle(lingrad2)

        # draw shapes
        self.canvas.fillRect(10, 10, 130, 130)
        self.canvas.strokeRect(50, 50, 50, 50)

        self.canvas.restoreContext()

        # DRAW SOME RADIAL GRADIENTS
        # Demos ported from Mozilla Development Center Canvas Tutorial
        self.canvas.saveContext()
        self.canvas.translate(150, 150)

        radgrad = self.canvas.createRadialGradient(45, 45, 10, 52, 50, 30)
        radgrad.addColorStop(0, Color("#A7D30C"))
        radgrad.addColorStop(0.9, Color("#019F62"))
        radgrad.addColorStop(1, Color("rgba(1,159,98,0)"))

        radgrad2 = self.canvas.createRadialGradient(105, 105, 20, 112, 120, 50)
        radgrad2.addColorStop(0, Color("#FF5F98"))
        radgrad2.addColorStop(0.75, Color("#FF0188"))
        radgrad2.addColorStop(1, Color("rgba(255,1,136,0)"))

        radgrad3 = self.canvas.createRadialGradient(95, 15, 15, 102, 20, 40)
        radgrad3.addColorStop(0, Color("#00C9FF"))
        radgrad3.addColorStop(0.8, Color("#00B5E2"))
        radgrad3.addColorStop(1, Color("rgba(0,201,255,0)"))

        radgrad4 = self.canvas.createRadialGradient(0, 150, 50, 0, 140, 90)
        radgrad4.addColorStop(0, Color("#F4F201"))
        radgrad4.addColorStop(0.8, Color("#E4C700"))
        radgrad4.addColorStop(1, Color("rgba(228,199,0,0)"))

        # draw shapes
        self.canvas.setFillStyle(radgrad4)
        self.canvas.fillRect(0, 0, 150, 150)
        self.canvas.setFillStyle(radgrad3)
        self.canvas.fillRect(0, 0, 150, 150)
        self.canvas.setFillStyle(radgrad2)
        self.canvas.fillRect(0, 0, 150, 150)
        self.canvas.setFillStyle(radgrad)
        self.canvas.fillRect(0, 0, 150, 150)

        self.canvas.restoreContext()
コード例 #9
0
ファイル: CanvasTab.py プロジェクト: minghuascode/pyj
    def draw(self):
        # create gradients
        radgrad = self.createRadialGradient(45, 45, 10, 52, 50, 30)
        radgrad.addColorStop(0, Color('#A7D30C'))
        radgrad.addColorStop(0.9, Color('#019F62'))
        radgrad.addColorStop(1, Color('rgba(1,159,98,0)'))

        radgrad2 = self.createRadialGradient(105, 105, 20, 112, 120, 50)
        radgrad2.addColorStop(0, Color('#FF5F98'))
        radgrad2.addColorStop(0.75, Color('#FF0188'))
        radgrad2.addColorStop(1, Color('rgba(255,1,136,0)'))

        radgrad3 = self.createRadialGradient(95, 15, 15, 102, 20, 40)
        radgrad3.addColorStop(0, Color('#00C9FF'))
        radgrad3.addColorStop(0.8, Color('#00B5E2'))
        radgrad3.addColorStop(1, Color('rgba(0,201,255,0)'))

        radgrad4 = self.createRadialGradient(0, 150, 50, 0, 140, 90)
        radgrad4.addColorStop(0, Color('#F4F201'))
        radgrad4.addColorStop(0.8, Color('#E4C700'))
        radgrad4.addColorStop(1, Color('rgba(228,199,0,0)'))

        # draw shapes
        self.setFillStyle(radgrad4)
        self.fillRect(0, 0, 150, 150)
        self.setFillStyle(radgrad3)
        self.fillRect(0, 0, 150, 150)
        self.setFillStyle(radgrad2)
        self.fillRect(0, 0, 150, 150)
        self.setFillStyle(radgrad)
        self.fillRect(0, 0, 150, 150)
コード例 #10
0
 def cloneColorStop(self):
     return ColorStop(self.offset, Color(str(self.color())))
コード例 #11
0
"""*
* Use this constant as a parameter for the
* {@link #setGlobalCompositeOperation(String)} method.
"""
DESTINATION_OVER = "destination-over"
"""*
* Use this constant as a parameter for the {@link #setLineJoin(String)}
* method.
"""
MITER = "miter"
"""*
* Use this constant either as a parameter for the {@link #setLineCap(String)}
* or the {@link #setLineJoin(String)} method.
"""
ROUND = "round"
"""*
* Use this constant as a parameter for the
* {@link #setGlobalCompositeOperation(String)} method.
"""
SOURCE_OVER = "source-over"
"""*
* Use this constant as a parameter for the {@link #setLineCap(String)}
* method.
"""
SQUARE = "square"
"""*
* Use this constant as a parameter for the {@link #setBackgroundColor(Color)}
* method.
"""
TRANSPARENT = Color("")