Skip to content
Newer
Older
100644 66 lines (57 sloc) 1.61 KB
84abd4f @keesbos CanvasProcessing example now uses GWTCanvas
keesbos authored Apr 23, 2011
1 from pyjamas.Canvas.GWTCanvas import GWTCanvas
65dd2ed Updating canvasprocessing example with latest version
keesbos authored Aug 18, 2009
2 from pyjamas.ui.RootPanel import RootPanel
3 from pyjamas.DOM import getFirstChild
4 from pyjamas import Window
84abd4f @keesbos CanvasProcessing example now uses GWTCanvas
keesbos authored Apr 23, 2011
5 from pyjamas.ui.HTML import HTML
65dd2ed Updating canvasprocessing example with latest version
keesbos authored Aug 18, 2009
6 import math
4b2b685 fix canvasprocessing - also remove processing.js and use download tri…
Luke Leighton authored Feb 25, 2012
7 from __pyjamas__ import jsimport
65dd2ed Updating canvasprocessing example with latest version
keesbos authored Aug 18, 2009
8
9 # Include the processing.js in the module scope
4b2b685 fix canvasprocessing - also remove processing.js and use download tri…
Luke Leighton authored Feb 25, 2012
10 jsimport("processing.js")
65dd2ed Updating canvasprocessing example with latest version
keesbos authored Aug 18, 2009
11 from __javascript__ import Processing # defined by processing.js
12
84abd4f @keesbos CanvasProcessing example now uses GWTCanvas
keesbos authored Apr 23, 2011
13
65dd2ed Updating canvasprocessing example with latest version
keesbos authored Aug 18, 2009
14 p = None
15 radius = 50.0
16 delay = 16
17
18 def setup():
19 global p,radius,delay,X,Y,nX,nY
20 p.size(200,200)
21 p.strokeWeight( 10 )
22 p.frameRate( 15 )
23 X = p.width / 2
24 Y = p.width / 2
25 nX = X
64eff55 find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
C Anthony Risinger authored May 14, 2012
26 nY = Y
65dd2ed Updating canvasprocessing example with latest version
keesbos authored Aug 18, 2009
27
28 def draw():
29 global p,radius,delay,X,Y,nX,nY
30 radius = radius + math.sin( p.frameCount / 4 )
31 X+=(nX-X)/delay
32 Y+=(nY-Y)/delay
33 p.background( 100 )
34 p.fill( 0, 121, 184 )
35 p.stroke(255)
36 p.ellipse(X, Y, radius, radius )
64eff55 find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
C Anthony Risinger authored May 14, 2012
37
65dd2ed Updating canvasprocessing example with latest version
keesbos authored Aug 18, 2009
38 def mouseMoved():
39 global p,nX,nY
40 nX = p.mouseX
41 nY = p.mouseY
42
84abd4f @keesbos CanvasProcessing example now uses GWTCanvas
keesbos authored Apr 23, 2011
43 class ProcessingCanvas(GWTCanvas):
65dd2ed Updating canvasprocessing example with latest version
keesbos authored Aug 18, 2009
44 def __init__(self):
84abd4f @keesbos CanvasProcessing example now uses GWTCanvas
keesbos authored Apr 23, 2011
45 GWTCanvas.__init__(self, 150, 150, 150, 150)
4b2b685 fix canvasprocessing - also remove processing.js and use download tri…
Luke Leighton authored Feb 25, 2012
46 self.c = self.getCanvasElement()
65dd2ed Updating canvasprocessing example with latest version
keesbos authored Aug 18, 2009
47 self.p = Processing (self.c)
48 global p
49 p = self.p
64eff55 find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
C Anthony Risinger authored May 14, 2012
50
65dd2ed Updating canvasprocessing example with latest version
keesbos authored Aug 18, 2009
51 if __name__ == '__main__':
84abd4f @keesbos CanvasProcessing example now uses GWTCanvas
keesbos authored Apr 23, 2011
52 note = HTML("""
53 Note that this is an example of using processing.js.<br>
54 See <a href=http://ejohn.org/blog/processingjs/>http://ejohn.org/blog/processingjs/</a> for more info.<br>
55 Since processing.js is built for state-of-the-art browser<br>
56 that properly implement canvas, IE is not supported.<br>
57 <br>
58 """)
59 RootPanel().add(note)
65dd2ed Updating canvasprocessing example with latest version
keesbos authored Aug 18, 2009
60 PC = ProcessingCanvas()
61 PC.p.setup = setup
62 PC.p.draw = draw
63 PC.p.mouseMoved = mouseMoved
64 PC.p.init()
65 RootPanel().add(PC)
Something went wrong with that request. Please try again.