bubble-chamber: Refactoring
parent
b4c9bbdf80
commit
a135aa479b
|
@ -32,6 +32,8 @@ IN: processing.gallery.bubble-chamber
|
||||||
|
|
||||||
: dim ( -- dim ) 1000 ;
|
: dim ( -- dim ) 1000 ;
|
||||||
|
|
||||||
|
: center ( -- point ) dim 2 / dup {2} ; foldable
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
VAR: collision-theta
|
VAR: collision-theta
|
||||||
|
@ -73,7 +75,7 @@ VARS: particles muons quarks hadrons axions ;
|
||||||
T{ rgba f 0.47 0.42 0.56 1 }
|
T{ rgba f 0.47 0.42 0.56 1 }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
: good-color ( i -- color ) good-colors nth-of ;
|
: anti-colors ( -- seq ) good-colors <reversed> ;
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
@ -89,6 +91,26 @@ VARS: particles muons quarks hadrons axions ;
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
: theta-dd-small? ( par limit -- par ? ) >r dup theta-dd>> abs r> < ;
|
||||||
|
|
||||||
|
: random-theta-dd ( par a b -- par ) 2random >>theta-dd ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
: turn ( particle -- particle )
|
||||||
|
dup
|
||||||
|
[ speed>> ] [ theta>> { sin cos } <arr> ] bi n*v
|
||||||
|
>>vel ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
: step-theta ( p -- p ) [ ] [ theta>> ] [ theta-d>> ] tri + >>theta ;
|
||||||
|
: step-theta-d ( p -- p ) [ ] [ theta-d>> ] [ theta-dd>> ] tri + >>theta-d ;
|
||||||
|
: step-speed-sub ( p -- p ) [ ] [ speed>> ] [ speed-d>> ] tri - >>speed ;
|
||||||
|
: step-speed-mul ( p -- p ) [ ] [ speed>> ] [ speed-d>> ] tri * >>speed ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
TUPLE: particle pos vel speed speed-d theta theta-d theta-dd myc mya ;
|
TUPLE: particle pos vel speed speed-d theta theta-d theta-dd myc mya ;
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
@ -120,9 +142,25 @@ TUPLE: muon < particle ;
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
: color-fraction ( particle -- particle fraction ) dup theta>> pi + 2 pi * / ;
|
||||||
|
|
||||||
|
: set-good-color ( particle -- particle )
|
||||||
|
color-fraction dup 0 1 between?
|
||||||
|
[ good-colors at-fraction-of >>myc ]
|
||||||
|
[ drop ]
|
||||||
|
if ;
|
||||||
|
|
||||||
|
: set-anti-color ( particle -- particle )
|
||||||
|
color-fraction dup 0 1 between?
|
||||||
|
[ anti-colors at-fraction-of >>mya ]
|
||||||
|
[ drop ]
|
||||||
|
if ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
METHOD: collide { muon }
|
METHOD: collide { muon }
|
||||||
|
|
||||||
dim 2 / dup 2array >>pos
|
center >>pos
|
||||||
2 32 [a,b] random >>speed
|
2 32 [a,b] random >>speed
|
||||||
0.0001 0.001 2random >>speed-d
|
0.0001 0.001 2random >>speed-d
|
||||||
|
|
||||||
|
@ -130,22 +168,10 @@ METHOD: collide { muon }
|
||||||
0 >>theta-d
|
0 >>theta-d
|
||||||
0 >>theta-dd
|
0 >>theta-dd
|
||||||
|
|
||||||
[ dup theta-dd>> abs 0.001 < ]
|
[ 0.001 theta-dd-small? ] [ -0.1 0.1 random-theta-dd ] [ ] while
|
||||||
[ -0.1 0.1 2random >>theta-dd ]
|
|
||||||
[ ]
|
|
||||||
while
|
|
||||||
|
|
||||||
dup theta>> pi +
|
set-good-color
|
||||||
2 pi * /
|
set-anti-color
|
||||||
good-colors length 1 - *
|
|
||||||
[ ] [ good-colors length >= ] [ 0 < ] tri or
|
|
||||||
[ drop ]
|
|
||||||
[
|
|
||||||
[ good-color >>myc ]
|
|
||||||
[ good-colors length swap - 1 - good-color >>mya ]
|
|
||||||
bi
|
|
||||||
]
|
|
||||||
if
|
|
||||||
|
|
||||||
drop ;
|
drop ;
|
||||||
|
|
||||||
|
@ -163,14 +189,11 @@ METHOD: move { muon }
|
||||||
[ speed>> ] [ theta>> { sin cos } <arr> ] bi n*v
|
[ speed>> ] [ theta>> { sin cos } <arr> ] bi n*v
|
||||||
move-by
|
move-by
|
||||||
|
|
||||||
[ ] [ theta>> ] [ theta-d>> ] tri + >>theta
|
step-theta
|
||||||
[ ] [ theta-d>> ] [ theta-dd>> ] tri + >>theta-d
|
step-theta-d
|
||||||
[ ] [ speed>> ] [ speed-d>> ] tri - >>speed
|
step-speed-sub
|
||||||
|
|
||||||
out-of-bounds?
|
out-of-bounds? [ collide ] [ drop ] if ;
|
||||||
[ collide ]
|
|
||||||
[ drop ]
|
|
||||||
if ;
|
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
@ -182,7 +205,7 @@ TUPLE: quark < particle ;
|
||||||
|
|
||||||
METHOD: collide { quark }
|
METHOD: collide { quark }
|
||||||
|
|
||||||
dim 2 / dup 2array >>pos
|
center >>pos
|
||||||
collision-theta> -0.11 0.11 2random + >>theta
|
collision-theta> -0.11 0.11 2random + >>theta
|
||||||
0.5 3.0 2random >>speed
|
0.5 3.0 2random >>speed
|
||||||
|
|
||||||
|
@ -190,10 +213,7 @@ METHOD: collide { quark }
|
||||||
0 >>theta-d
|
0 >>theta-d
|
||||||
0 >>theta-dd
|
0 >>theta-dd
|
||||||
|
|
||||||
[ dup theta-dd>> abs 0.00001 < ]
|
[ 0.00001 theta-dd-small? ] [ -0.001 0.001 random-theta-dd ] [ ] while
|
||||||
[ -0.001 0.001 2random >>theta-dd ]
|
|
||||||
[ ]
|
|
||||||
while
|
|
||||||
|
|
||||||
drop ;
|
drop ;
|
||||||
|
|
||||||
|
@ -208,26 +228,20 @@ METHOD: move { quark }
|
||||||
|
|
||||||
[ ] [ vel>> ] bi move-by
|
[ ] [ vel>> ] bi move-by
|
||||||
|
|
||||||
dup
|
turn
|
||||||
[ speed>> ] [ theta>> { sin cos } <arr> ] bi n*v
|
|
||||||
>>vel
|
|
||||||
|
|
||||||
[ ] [ theta>> ] [ theta-d>> ] tri + >>theta
|
step-theta
|
||||||
[ ] [ theta-d>> ] [ theta-dd>> ] tri + >>theta-d
|
step-theta-d
|
||||||
[ ] [ speed>> ] [ speed-d>> ] tri * >>speed
|
step-speed-mul
|
||||||
|
|
||||||
! 1000 random 997 >
|
1000 random 997 >
|
||||||
3/1000 chance
|
|
||||||
[
|
[
|
||||||
dup speed>> neg >>speed
|
dup speed>> neg >>speed
|
||||||
2 over speed-d>> - >>speed-d
|
2 over speed-d>> - >>speed-d
|
||||||
]
|
]
|
||||||
when
|
when
|
||||||
|
|
||||||
out-of-bounds?
|
out-of-bounds? [ collide ] [ drop ] if ;
|
||||||
[ collide ]
|
|
||||||
[ drop ]
|
|
||||||
if ;
|
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
@ -239,18 +253,14 @@ TUPLE: hadron < particle ;
|
||||||
|
|
||||||
METHOD: collide { hadron }
|
METHOD: collide { hadron }
|
||||||
|
|
||||||
dim 2 / dup 2array >>pos
|
center >>pos
|
||||||
2 pi * 1random >>theta
|
2 pi * 1random >>theta
|
||||||
0.5 3.5 2random >>speed
|
0.5 3.5 2random >>speed
|
||||||
|
|
||||||
0.996 1.001 2random >>speed-d
|
0.996 1.001 2random >>speed-d
|
||||||
0 >>theta-d
|
0 >>theta-d
|
||||||
0 >>theta-dd
|
0 >>theta-dd
|
||||||
|
|
||||||
[ dup theta-dd>> abs 0.00001 < ]
|
[ 0.00001 theta-dd-small? ] [ -0.001 0.001 random-theta-dd ] [ ] while
|
||||||
[ -0.001 0.001 2random >>theta-dd ]
|
|
||||||
[ ]
|
|
||||||
while
|
|
||||||
|
|
||||||
0 1 0 <rgb> >>myc
|
0 1 0 <rgb> >>myc
|
||||||
|
|
||||||
|
@ -268,34 +278,22 @@ METHOD: move { hadron }
|
||||||
|
|
||||||
dup vel>> move-by
|
dup vel>> move-by
|
||||||
|
|
||||||
dup
|
turn
|
||||||
[ speed>> ] [ theta>> { sin cos } <arr> ] bi n*v
|
|
||||||
>>vel
|
|
||||||
|
|
||||||
[ ] [ theta>> ] [ theta-d>> ] tri + >>theta
|
step-theta
|
||||||
[ ] [ theta-d>> ] [ theta-dd>> ] tri + >>theta-d
|
step-theta-d
|
||||||
[ ] [ speed>> ] [ speed-d>> ] tri * >>speed
|
step-speed-mul
|
||||||
|
|
||||||
! 1000 random 997 >
|
1000 random 997 >
|
||||||
3/1000 chance
|
|
||||||
[
|
[
|
||||||
1.0 >>speed-d
|
1.0 >>speed-d
|
||||||
0.00001 >>theta-dd
|
0.00001 >>theta-dd
|
||||||
|
|
||||||
! 100 random 70 >
|
100 random 70 > [ dup collide ] when
|
||||||
30/100 chance
|
|
||||||
[
|
|
||||||
dim 2 / dup 2array >>pos
|
|
||||||
dup collide
|
|
||||||
]
|
|
||||||
when
|
|
||||||
]
|
]
|
||||||
when
|
when
|
||||||
|
|
||||||
out-of-bounds?
|
out-of-bounds? [ collide ] [ drop ] if ;
|
||||||
[ collide ]
|
|
||||||
[ drop ]
|
|
||||||
if ;
|
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
@ -307,82 +305,59 @@ TUPLE: axion < particle ;
|
||||||
|
|
||||||
METHOD: collide { axion }
|
METHOD: collide { axion }
|
||||||
|
|
||||||
dim 2 / dup 2array >>pos
|
center >>pos
|
||||||
2 pi * 1random >>theta
|
2 pi * 1random >>theta
|
||||||
1.0 6.0 2random >>speed
|
1.0 6.0 2random >>speed
|
||||||
|
|
||||||
0.998 1.000 2random >>speed-d
|
0.998 1.000 2random >>speed-d
|
||||||
0 >>theta-d
|
0 >>theta-d
|
||||||
0 >>theta-dd
|
0 >>theta-dd
|
||||||
|
|
||||||
[ dup theta-dd>> abs 0.00001 < ]
|
[ 0.00001 theta-dd-small? ] [ -0.001 0.001 random-theta-dd ] [ ] while
|
||||||
[ -0.001 0.001 2random >>theta-dd ]
|
|
||||||
[ ]
|
|
||||||
while
|
|
||||||
|
|
||||||
drop ;
|
drop ;
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
: dy>alpha ( dy -- alpha ) neg 6 * 30 + 255.0 / ;
|
||||||
|
|
||||||
|
: axion-white ( dy -- dy ) dup 1 swap dy>alpha {2} stroke ;
|
||||||
|
: axion-black ( dy -- dy ) dup 0 swap dy>alpha {2} stroke ;
|
||||||
|
|
||||||
|
: axion-point- ( particle dy -- particle ) >r dup pos>> r> v-y point ;
|
||||||
|
: axion-point+ ( particle dy -- particle ) >r dup pos>> r> v+y point ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
METHOD: move { axion }
|
METHOD: move { axion }
|
||||||
|
|
||||||
{ 0.06 0.59 } stroke
|
{ 0.06 0.59 } stroke
|
||||||
dup pos>> point
|
dup pos>> point
|
||||||
|
|
||||||
1 4 [a,b]
|
1 4 [a,b] [ axion-white axion-point- ] each
|
||||||
[| dy |
|
1 4 [a,b] [ axion-black axion-point+ ] each
|
||||||
1 30 dy 6 * - 255.0 / 2array stroke
|
|
||||||
dup pos>> 0 dy neg 2array v+ point
|
|
||||||
] with-locals
|
|
||||||
each
|
|
||||||
|
|
||||||
1 4 [a,b]
|
|
||||||
[| dy |
|
|
||||||
0 30 dy 6 * - 255.0 / 2array stroke
|
|
||||||
dup pos>> dy v+y point
|
|
||||||
] with-locals
|
|
||||||
each
|
|
||||||
|
|
||||||
dup vel>> move-by
|
dup vel>> move-by
|
||||||
|
|
||||||
dup
|
turn
|
||||||
[ speed>> ] [ theta>> { sin cos } <arr> ] bi n*v
|
|
||||||
>>vel
|
|
||||||
|
|
||||||
[ ] [ theta>> ] [ theta-d>> ] tri + >>theta
|
step-theta
|
||||||
[ ] [ theta-d>> ] [ theta-dd>> ] tri + >>theta-d
|
step-theta-d
|
||||||
[ ] [ speed>> ] [ speed-d>> ] tri * >>speed
|
step-speed-mul
|
||||||
|
|
||||||
[ ] [ speed-d>> 0.9999 * ] bi >>speed-d
|
[ ] [ speed-d>> 0.9999 * ] bi >>speed-d
|
||||||
|
|
||||||
! 1000 random 996 >
|
1000 random 996 >
|
||||||
4/1000 chance
|
|
||||||
[
|
[
|
||||||
dup speed>> neg >>speed
|
dup speed>> neg >>speed
|
||||||
dup speed-d>> neg 2 + >>speed-d
|
dup speed-d>> neg 2 + >>speed-d
|
||||||
|
|
||||||
! 100 random 30 >
|
100 random 30 > [ collide ] [ drop ] if
|
||||||
70/100 chance
|
|
||||||
[
|
|
||||||
dim 2 / dup 2array >>pos
|
|
||||||
collide
|
|
||||||
]
|
|
||||||
[ drop ]
|
|
||||||
if
|
|
||||||
]
|
]
|
||||||
[ drop ]
|
[ drop ]
|
||||||
if ;
|
if ;
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
! : draw ( -- )
|
|
||||||
|
|
||||||
! boom>
|
|
||||||
! [ particles> [ move ] each ]
|
|
||||||
! when ;
|
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
|
|
||||||
: collide-all ( -- )
|
: collide-all ( -- )
|
||||||
|
|
||||||
2 pi * 1random >collision-theta
|
2 pi * 1random >collision-theta
|
||||||
|
|
Loading…
Reference in New Issue