Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
|
|
@ -5,29 +5,29 @@ rect 0.5 0.5
|
|||
f[100 * 200 + 100] = 1
|
||||
n = 9000
|
||||
while i < n
|
||||
repeat
|
||||
x = randint 200 - 1
|
||||
y = randint 200 - 1
|
||||
until f[y * 200 + x + 1] <> 1
|
||||
.
|
||||
while 1 = 1
|
||||
xo = x
|
||||
yo = y
|
||||
x += randint 3 - 2
|
||||
y += randint 3 - 2
|
||||
if x < 0 or y < 0 or x >= 200 or y >= 200
|
||||
break 1
|
||||
.
|
||||
if f[y * 200 + x + 1] = 1
|
||||
move xo / 2 yo / 2
|
||||
rect 0.5 0.5
|
||||
f[yo * 200 + xo + 1] = 1
|
||||
i += 1
|
||||
if i mod 16 = 0
|
||||
color3 0.2 + i / n 1 1
|
||||
sleep 0
|
||||
repeat
|
||||
x = random 200 - 1
|
||||
y = random 200 - 1
|
||||
until f[y * 200 + x + 1] <> 1
|
||||
.
|
||||
while 1 = 1
|
||||
xo = x
|
||||
yo = y
|
||||
x += random 3 - 2
|
||||
y += random 3 - 2
|
||||
if x < 0 or y < 0 or x >= 200 or y >= 200
|
||||
break 1
|
||||
.
|
||||
break 1
|
||||
.
|
||||
.
|
||||
if f[y * 200 + x + 1] = 1
|
||||
move xo / 2 yo / 2
|
||||
rect 0.5 0.5
|
||||
f[yo * 200 + xo + 1] = 1
|
||||
i += 1
|
||||
if i mod 16 = 0
|
||||
color3 0.2 + i / n 1 1
|
||||
sleep 0
|
||||
.
|
||||
break 1
|
||||
.
|
||||
.
|
||||
.
|
||||
|
|
|
|||
47
Task/Brownian-tree/Factor/brownian-tree.factor
Normal file
47
Task/Brownian-tree/Factor/brownian-tree.factor
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
USING: accessors images images.loader kernel literals math
|
||||
math.vectors random sets ;
|
||||
FROM: sets => in? ;
|
||||
EXCLUDE: sequences => move ;
|
||||
IN: rosetta-code.brownian-tree
|
||||
|
||||
CONSTANT: size 512
|
||||
CONSTANT: num-particles 30000
|
||||
CONSTANT: seed { 256 256 }
|
||||
CONSTANT: spawns { { 10 10 } { 502 10 } { 10 502 } { 502 502 } }
|
||||
CONSTANT: bg-color B{ 0 0 0 255 }
|
||||
CONSTANT: fg-color B{ 255 255 255 255 }
|
||||
|
||||
: in-bounds? ( loc -- ? )
|
||||
dup { 0 0 } ${ size 1 - dup } vclamp = ;
|
||||
|
||||
: move ( loc -- loc' )
|
||||
dup 2 [ { 1 -1 } random ] replicate v+ dup in-bounds?
|
||||
[ nip ] [ drop ] if ;
|
||||
|
||||
: grow ( particles -- particles' )
|
||||
spawns random dup
|
||||
[ 2over swap in? ] [ drop dup move swap ] until nip
|
||||
swap [ adjoin ] keep ;
|
||||
|
||||
: brownian-data ( -- seq )
|
||||
HS{ $ seed } clone num-particles 1 - [ grow ] times { }
|
||||
set-like ;
|
||||
|
||||
: blank-bitmap ( -- bitmap )
|
||||
size sq [ bg-color ] replicate B{ } concat-as ;
|
||||
|
||||
: init-img ( -- img )
|
||||
<image>
|
||||
${ size size } >>dim
|
||||
BGRA >>component-order
|
||||
ubyte-components >>component-type
|
||||
blank-bitmap >>bitmap ;
|
||||
|
||||
: brownian-img ( -- img )
|
||||
init-img dup brownian-data
|
||||
[ swap [ fg-color swap first2 ] dip set-pixel-at ] with each ;
|
||||
|
||||
: save-brownian-tree-image ( -- )
|
||||
brownian-img "brownian.png" save-graphic-image ;
|
||||
|
||||
MAIN: save-brownian-tree-image
|
||||
Loading…
Add table
Add a link
Reference in a new issue