1
1
from pyprocessing import *
2
2
from math import pi , sin
3
3
from lsystems import csgrammar
4
+ from lsystems .arcball import ArcBall
4
5
5
-
6
- THETA = (6.5 * pi )/ 36 # 25 degrees in radians
6
+ myball = None # needs exposure at module level
7
+ THETA = (6.5 * pi )/ 36 # 32.5 degrees in radians
7
8
production = None # needs exposure at module level
8
- distance = 140
9
+ distance = 90
9
10
repeat = 1
10
11
count = 0
11
12
scale_factor = [0.55 , 0.65 , 0.72 , 0.75 , 0.8 , 0.85 ]
@@ -21,27 +22,26 @@ def setup():
21
22
processing setup
22
23
"""
23
24
size (800 , 600 )
24
- global production
25
+ global production , myball
26
+ myball = ArcBall (width / 2.0 , height / 2.0 , (width - 20 ) * 0.5 )
27
+ myball .selectAxis (1 )
25
28
production = csgrammar .repeat (6 , AXIOM , RULES , IGNORE )
26
29
fill (0 , 200 , 0 )
27
- noStroke ()
28
-
30
+ noStroke ()
29
31
30
32
def draw ():
31
33
"""
32
34
Animate a 3D context free plant in processing/pyglet draw loop
33
35
"""
34
36
background (20 , 20 , 180 )
35
- lights ()
37
+ lights ()
36
38
translate (width / 2.0 , height * 0.8 )
37
- camera (250 , 250 , 800 , 0 , - 340 , 0 , 0 , 1 , 0 )
38
- rotateY (radians ((frame .count * 2 )% 720 ) )
39
39
lightSpecular (204 , 204 , 204 )
40
40
specular (255 , 255 , 255 )
41
- shininess (1.0 )
41
+ shininess (1.0 )
42
+ update ()
42
43
for val in production :
43
- evaluate (val )
44
-
44
+ evaluate (val )
45
45
46
46
def __noop ():
47
47
pass
@@ -82,8 +82,7 @@ def __drawRod():
82
82
radius1 = distance / 6
83
83
radius2 = distance / (6 * scale_factor [count ])
84
84
angle = 0
85
- angleIncrement = TWO_PI / sides
86
-
85
+ angleIncrement = TWO_PI / sides
87
86
beginShape (QUAD_STRIP )
88
87
for i in range (sides + 1 ):
89
88
normal (cos (angle ), 0 , sin (angle ))
@@ -116,6 +115,19 @@ def __drawRod():
116
115
'A' : __noop ,
117
116
'E' : __noop
118
117
}
118
+
119
+ def update ():
120
+ """
121
+ wrap arcball update and rotation as a local function
122
+ """
123
+ theta , x , y , z = myball .update ()
124
+ rotate (theta , x , y , z )
125
+
126
+ def mousePressed ():
127
+ myball .mousePressed (mouse .x , mouse .y )
128
+
129
+ def mouseDragged ():
130
+ myball .mouseDragged (mouse .x , mouse .y )
119
131
120
132
def evaluate (key ):
121
133
"""
0 commit comments