Skip to content

Commit db97ebd

Browse files
author
Martin Prout
committed
use arcball rotation csplant
1 parent 43311c2 commit db97ebd

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

lsystems+fractals/csplant3.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from pyprocessing import *
22
from math import pi, sin
33
from lsystems import csgrammar
4+
from lsystems.arcball import ArcBall
45

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
78
production = None # needs exposure at module level
8-
distance = 140
9+
distance = 90
910
repeat = 1
1011
count = 0
1112
scale_factor = [0.55, 0.65, 0.72, 0.75, 0.8, 0.85]
@@ -21,27 +22,26 @@ def setup():
2122
processing setup
2223
"""
2324
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)
2528
production = csgrammar.repeat(6, AXIOM, RULES, IGNORE)
2629
fill(0, 200, 0)
27-
noStroke()
28-
30+
noStroke()
2931

3032
def draw():
3133
"""
3234
Animate a 3D context free plant in processing/pyglet draw loop
3335
"""
3436
background(20, 20, 180)
35-
lights()
37+
lights()
3638
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) )
3939
lightSpecular(204, 204, 204)
4040
specular(255, 255, 255)
41-
shininess(1.0)
41+
shininess(1.0)
42+
update()
4243
for val in production:
43-
evaluate(val)
44-
44+
evaluate(val)
4545

4646
def __noop():
4747
pass
@@ -82,8 +82,7 @@ def __drawRod():
8282
radius1 = distance/6
8383
radius2 = distance/(6 * scale_factor[count])
8484
angle = 0
85-
angleIncrement = TWO_PI / sides
86-
85+
angleIncrement = TWO_PI / sides
8786
beginShape(QUAD_STRIP)
8887
for i in range(sides+1):
8988
normal(cos(angle), 0, sin(angle))
@@ -116,6 +115,19 @@ def __drawRod():
116115
'A' : __noop,
117116
'E' : __noop
118117
}
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)
119131

120132
def evaluate(key):
121133
"""

0 commit comments

Comments
 (0)