2 USING: kernel sequences combinators
3 math math.vectors math.functions multi-methods
4 accessors combinators.cleave processing
5 bubble-chamber.common colors ;
7 IN: bubble-chamber.particle
9 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
11 GENERIC: collide ( particle -- )
12 GENERIC: move ( particle -- )
14 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16 TUPLE: particle pos vel speed speed-d theta theta-d theta-dd myc mya ;
18 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20 : initialize-particle ( particle -- particle )
31 0 0 0 1 rgba boa >>myc
32 0 0 0 1 rgba boa >>mya ;
34 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
36 : move-by ( obj delta -- obj ) over pos>> v+ >>pos ;
38 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
40 : theta-dd-small? ( par limit -- par ? ) >r dup theta-dd>> abs r> < ;
42 : random-theta-dd ( par a b -- par ) 2random >>theta-dd ;
44 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
46 : turn ( particle -- particle )
48 [ speed>> ] [ theta>> { sin cos } <arr> ] bi n*v
51 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
53 : step-theta ( p -- p ) [ ] [ theta>> ] [ theta-d>> ] tri + >>theta ;
54 : step-theta-d ( p -- p ) [ ] [ theta-d>> ] [ theta-dd>> ] tri + >>theta-d ;
55 : step-speed-sub ( p -- p ) [ ] [ speed>> ] [ speed-d>> ] tri - >>speed ;
56 : step-speed-mul ( p -- p ) [ ] [ speed>> ] [ speed-d>> ] tri * >>speed ;
58 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
60 : x ( particle -- x ) pos>> first ;
61 : y ( particle -- x ) pos>> second ;
63 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
65 : out-of-bounds? ( particle -- particle ? )
67 { [ x dim neg < ] [ x dim 2 * > ] [ y dim neg < ] [ y dim 2 * > ] } cleave