Brownian tree: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 19: | Line 19: | ||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
Calculations on a real Atari 8-bit computer take quite long time. It is recommended to use an emulator capable with increasing speed of Atari CPU. |
Calculations on a real Atari 8-bit computer take quite long time. It is recommended to use an emulator capable with increasing speed of Atari CPU. |
||
< |
<syntaxhighlight lang=Action!>BYTE FUNC CheckNeighbors(CARD x BYTE y) |
||
IF Locate(x-1,y-1)=1 THEN RETURN (1) FI |
IF Locate(x-1,y-1)=1 THEN RETURN (1) FI |
||
IF Locate(x,y-1)=1 THEN RETURN (1) FI |
IF Locate(x,y-1)=1 THEN RETURN (1) FI |
||
Line 108: | Line 108: | ||
DrawTree() |
DrawTree() |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Brownian_tree.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Brownian_tree.png Screenshot from Atari 8-bit computer] |
||
Line 114: | Line 114: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
{{libheader|SDLAda}} |
{{libheader|SDLAda}} |
||
< |
<syntaxhighlight lang=Ada>with Ada.Numerics.Discrete_Random; |
||
with SDL.Video.Windows.Makers; |
with SDL.Video.Windows.Makers; |
||
Line 238: | Line 238: | ||
Window.Finalize; |
Window.Finalize; |
||
SDL.Finalise; |
SDL.Finalise; |
||
end Brownian_Tree;</ |
end Brownian_Tree;</syntaxhighlight> |
||
=={{header|Applesoft BASIC}}== |
=={{header|Applesoft BASIC}}== |
||
Uses XDRAW to plot to Hi-res GRaphics, in fullscreen [POKE 49234,0] 280 x 192, effectively 140 x 192 because colors stretch over two pixels, using a single pixel shape. The POKEs create one shape in a shape table starting at address 768 and point addresses 232 and 233 to this address. Address 234 is the collision counter which is used to detect if the randomly placed seed has hit anything and if the moving seed has collided with the tree. Plotting the seed creates an animation effect of the seed moving around in it's Brownian way.< |
Uses XDRAW to plot to Hi-res GRaphics, in fullscreen [POKE 49234,0] 280 x 192, effectively 140 x 192 because colors stretch over two pixels, using a single pixel shape. The POKEs create one shape in a shape table starting at address 768 and point addresses 232 and 233 to this address. Address 234 is the collision counter which is used to detect if the randomly placed seed has hit anything and if the moving seed has collided with the tree. Plotting the seed creates an animation effect of the seed moving around in it's Brownian way.<syntaxhighlight lang=applesoftbasic>0GOSUB2:FORQ=0TOTSTEP0:X=A:Y=B:FORO=0TOTSTEP0:XDRAWTATX,Y:X=INT(RND(T)*J)*Z:Y=INT(RND(T)*H):XDRAWTATX,Y:O=PEEK(C)>0:NEXTO:FORP=0TOTSTEP0:A=X:B=Y:R=INT(RND(T)*E):X=X+X(R):Y=Y+Y(R):IFX<0ORX>MORY<0ORY>NTHENNEXTQ |
||
1 XDRAW T AT X,Y:P = NOT PEEK (C): XDRAW T AT A,B: NEXT P: XDRAW T AT X,Y:Q = A = 0 OR A = M OR B = 0 OR B = N: NEXT Q: END |
1 XDRAW T AT X,Y:P = NOT PEEK (C): XDRAW T AT A,B: NEXT P: XDRAW T AT X,Y:Q = A = 0 OR A = M OR B = 0 OR B = N: NEXT Q: END |
||
2 T = 1:Z = 2:E = 8:C = 234 |
2 T = 1:Z = 2:E = 8:C = 234 |
||
Line 256: | Line 256: | ||
13 POKE 232,0: POKE 233,3 |
13 POKE 232,0: POKE 233,3 |
||
14 HGR : POKE 49234,0 |
14 HGR : POKE 49234,0 |
||
15 ROT= 0: SCALE= 1: RETURN</ |
15 ROT= 0: SCALE= 1: RETURN</syntaxhighlight> |
||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
Line 262: | Line 262: | ||
Takes a little while to run, be patient. |
Takes a little while to run, be patient. |
||
Requires the [http://www.autohotkey.com/forum/topic32238.html GDI+ Standard Library by Tic] |
Requires the [http://www.autohotkey.com/forum/topic32238.html GDI+ Standard Library by Tic] |
||
< |
<syntaxhighlight lang=AHK>SetBatchLines -1 |
||
Process, Priority,, high |
Process, Priority,, high |
||
size := 400 |
size := 400 |
||
Line 314: | Line 314: | ||
Random, r, min, max |
Random, r, min, max |
||
return r |
return r |
||
}</ |
}</syntaxhighlight>Sample output file [http://www.autohotkey.net/~crazyfirex/Images/brownian.png here] |
||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
{{works with|BBC BASIC for Windows}} |
{{works with|BBC BASIC for Windows}} |
||
< |
<syntaxhighlight lang=bbcbasic> SYS "SetWindowText", @hwnd%, "Brownian Tree" |
||
SIZE = 400 |
SIZE = 400 |
||
Line 346: | Line 346: | ||
UNTIL FALSE |
UNTIL FALSE |
||
</syntaxhighlight> |
|||
</lang> |
|||
[[File:Brownian_BBC.gif]] |
[[File:Brownian_BBC.gif]] |
||
=={{header|C}}== |
=={{header|C}}== |
||
{{libheader|FreeImage}} |
{{libheader|FreeImage}} |
||
< |
<syntaxhighlight lang=c>#include <string.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
#include <time.h> |
#include <time.h> |
||
Line 415: | Line 415: | ||
FreeImage_Save(FIF_BMP, img, "brownian_tree.bmp", 0); |
FreeImage_Save(FIF_BMP, img, "brownian_tree.bmp", 0); |
||
FreeImage_Unload(img); |
FreeImage_Unload(img); |
||
}</ |
}</syntaxhighlight> |
||
'''Bold text''' |
'''Bold text''' |
||
Line 421: | Line 421: | ||
{{trans|D}} |
{{trans|D}} |
||
This version writes the image as Portable Bit Map to stdout and doesn't move already set particles. |
This version writes the image as Portable Bit Map to stdout and doesn't move already set particles. |
||
< |
<syntaxhighlight lang=c>#include <stdio.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
#include <time.h> |
#include <time.h> |
||
Line 463: | Line 463: | ||
} |
} |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
Run-time about 12.4 seconds with SIDE=600, NUM_PARTICLES=10000. |
Run-time about 12.4 seconds with SIDE=600, NUM_PARTICLES=10000. |
||
Line 469: | Line 469: | ||
{{works with|C#|3.0}} |
{{works with|C#|3.0}} |
||
{{libheader|System.Drawing}} |
{{libheader|System.Drawing}} |
||
< |
<syntaxhighlight lang=csharp>using System; |
||
using System.Drawing; |
using System.Drawing; |
||
Line 519: | Line 519: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
Line 525: | Line 525: | ||
For an animated version based on this same code see: [[Brownian tree/C++ animated]] |
For an animated version based on this same code see: [[Brownian tree/C++ animated]] |
||
< |
<syntaxhighlight lang=cpp>#include <windows.h> |
||
#include <iostream> |
#include <iostream> |
||
#include <string> |
#include <string> |
||
Line 819: | Line 819: | ||
return 0; |
return 0; |
||
} |
} |
||
//--------------------------------------------------------------------</ |
//--------------------------------------------------------------------</syntaxhighlight> |
||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
Line 826: | Line 826: | ||
The former produces denser trees than the latter. If compiled with SBCL, providing a command line argument will invoke the latter method. |
The former produces denser trees than the latter. If compiled with SBCL, providing a command line argument will invoke the latter method. |
||
Requires Quicklisp library manager and the CL-GD package for producing PNG images. |
Requires Quicklisp library manager and the CL-GD package for producing PNG images. |
||
< |
<syntaxhighlight lang=lisp>;;; brownian.lisp |
||
;;; sbcl compile: first load and then (sb-ext:save-lisp-and-die "brownian" :executable t :toplevel #'brownian::main) |
;;; sbcl compile: first load and then (sb-ext:save-lisp-and-die "brownian" :executable t :toplevel #'brownian::main) |
||
(ql:quickload "cl-gd") |
(ql:quickload "cl-gd") |
||
Line 911: | Line 911: | ||
(write-image-to-file "brownian.png" |
(write-image-to-file "brownian.png" |
||
:compression-level 6 :if-exists :supersede))) |
:compression-level 6 :if-exists :supersede))) |
||
</ |
</syntaxhighlight> |
||
=={{header|D}}== |
=={{header|D}}== |
||
Uses the module of the Grayscale Image task. Partial {{trans|PureBasic}} |
Uses the module of the Grayscale Image task. Partial {{trans|PureBasic}} |
||
< |
<syntaxhighlight lang=d>void main() { |
||
import core.stdc.stdio, std.random, grayscale_image; |
import core.stdc.stdio, std.random, grayscale_image; |
||
Line 952: | Line 952: | ||
data[] += 255; |
data[] += 255; |
||
Image!ubyte.fromData(data, side, side).savePGM("brownian_tree.pgm"); |
Image!ubyte.fromData(data, side, side).savePGM("brownian_tree.pgm"); |
||
}</ |
}</syntaxhighlight> |
||
World side = 600, num_particles = 10_000, cropped (about 20 seconds run-time with dmd, about 4.3 seconds with ldc2): |
World side = 600, num_particles = 10_000, cropped (about 20 seconds run-time with dmd, about 4.3 seconds with ldc2): |
||
<center>[[File:Dla_10000_d.png]]</center> |
<center>[[File:Dla_10000_d.png]]</center> |
||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
< |
<syntaxhighlight lang=delphi>const |
||
SIZE = 256; |
SIZE = 256; |
||
NUM_PARTICLES = 1000; |
NUM_PARTICLES = 1000; |
||
Line 1,010: | Line 1,010: | ||
FreeAndNil(B); |
FreeAndNil(B); |
||
end; |
end; |
||
end;</ |
end;</syntaxhighlight> |
||
=={{header|EasyLang}}== |
=={{header|EasyLang}}== |
||
Line 1,016: | Line 1,016: | ||
[https://easylang.online/apps/_brownian-tree.html Run it] |
[https://easylang.online/apps/_brownian-tree.html Run it] |
||
<lang>color3 0 1 1 |
<syntaxhighlight lang=text>color3 0 1 1 |
||
len f[] 200 * 200 |
len f[] 200 * 200 |
||
move 50 50 |
move 50 50 |
||
Line 1,048: | Line 1,048: | ||
. |
. |
||
. |
. |
||
.</ |
.</syntaxhighlight> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
This example sets four spawn points, one in each corner of the image, giving the result a vague x-shaped appearance. For visual reasons, movement is restricted to diagonals. So be careful if you change the seed or spawns — they should all fall on the same diagonal. |
This example sets four spawn points, one in each corner of the image, giving the result a vague x-shaped appearance. For visual reasons, movement is restricted to diagonals. So be careful if you change the seed or spawns — they should all fall on the same diagonal. |
||
< |
<syntaxhighlight lang=factor>USING: accessors images images.loader kernel literals math |
||
math.vectors random sets ; |
math.vectors random sets ; |
||
FROM: sets => in? ; |
FROM: sets => in? ; |
||
Line 1,099: | Line 1,099: | ||
brownian-img "brownian.png" save-graphic-image ; |
brownian-img "brownian.png" save-graphic-image ; |
||
MAIN: save-brownian-tree-image</ |
MAIN: save-brownian-tree-image</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://i.imgur.com/qDVylB9.png image] |
[https://i.imgur.com/qDVylB9.png image] |
||
Line 1,105: | Line 1,105: | ||
=={{header|Fantom}}== |
=={{header|Fantom}}== |
||
< |
<syntaxhighlight lang=fantom> |
||
using fwt |
using fwt |
||
using gfx |
using gfx |
||
Line 1,207: | Line 1,207: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
Line 1,216: | Line 1,216: | ||
For RCImageBasic and RCImageIO, see [[Basic bitmap storage/Fortran]] and [[Write ppm file#Fortran]] |
For RCImageBasic and RCImageIO, see [[Basic bitmap storage/Fortran]] and [[Write ppm file#Fortran]] |
||
< |
<syntaxhighlight lang=fortran>program BrownianTree |
||
use RCImageBasic |
use RCImageBasic |
||
use RCImageIO |
use RCImageIO |
||
Line 1,321: | Line 1,321: | ||
end subroutine draw_brownian_tree |
end subroutine draw_brownian_tree |
||
end program</ |
end program</syntaxhighlight> |
||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang=freebasic>' version 16-03-2017 |
||
' compile with: fbc -s gui |
' compile with: fbc -s gui |
||
Line 1,383: | Line 1,383: | ||
Beep : Sleep 5000 |
Beep : Sleep 5000 |
||
End</ |
End</syntaxhighlight> |
||
=={{header|Gnuplot}}== |
=={{header|Gnuplot}}== |
||
Line 1,391: | Line 1,391: | ||
'''plotff.gp''' - Plotting from any data-file with 2 columns (space delimited), and writing to png-file.<br> |
'''plotff.gp''' - Plotting from any data-file with 2 columns (space delimited), and writing to png-file.<br> |
||
Especially useful to plot colored fractals using points. |
Especially useful to plot colored fractals using points. |
||
< |
<syntaxhighlight lang=gnuplot> |
||
## plotff.gp 11/27/16 aev |
## plotff.gp 11/27/16 aev |
||
## Plotting from any data-file with 2 columns (space delimited), and writing to png-file. |
## Plotting from any data-file with 2 columns (space delimited), and writing to png-file. |
||
Line 1,406: | Line 1,406: | ||
plot dfn using 1:2 with points pt 7 ps 0.5 lc @clr |
plot dfn using 1:2 with points pt 7 ps 0.5 lc @clr |
||
set output |
set output |
||
</ |
</syntaxhighlight> |
||
===Versions #1 - #4. Plotting from PARI/GP generated dat-files=== |
===Versions #1 - #4. Plotting from PARI/GP generated dat-files=== |
||
Line 1,417: | Line 1,417: | ||
[[File:BT43gp.png|right|thumb|Output BT43gp.png]] |
[[File:BT43gp.png|right|thumb|Output BT43gp.png]] |
||
< |
<syntaxhighlight lang=gnuplot> |
||
## BTff.gp 11/27/16 aev |
## BTff.gp 11/27/16 aev |
||
## Plotting 6 Brownian tree pictures. |
## Plotting 6 Brownian tree pictures. |
||
Line 1,459: | Line 1,459: | ||
ttl = "Brownian Tree v.#4-3" |
ttl = "Brownian Tree v.#4-3" |
||
load "plotff.gp" |
load "plotff.gp" |
||
</ |
</syntaxhighlight> |
||
{{Output}} |
{{Output}} |
||
<pre> |
<pre> |
||
Line 1,472: | Line 1,472: | ||
Using standard image library: |
Using standard image library: |
||
< |
<syntaxhighlight lang=go>package main |
||
import ( |
import ( |
||
Line 1,556: | Line 1,556: | ||
} |
} |
||
return false |
return false |
||
}</ |
}</syntaxhighlight> |
||
Nearly the same, version below works with code from the bitmap task: |
Nearly the same, version below works with code from the bitmap task: |
||
< |
<syntaxhighlight lang=go>package main |
||
// Files required to build supporting package raster are found in: |
// Files required to build supporting package raster are found in: |
||
Line 1,636: | Line 1,636: | ||
} |
} |
||
return false |
return false |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
Line 1,642: | Line 1,642: | ||
The modules <code>[[Bitmap#Haskell|Bitmap]]</code>, <code>[[Bitmap/Write a PPM file#Haskell|Bitmap.Netpbm]]</code>, and <code>[[Bitmap/Histogram#Haskell|Bitmap.BW]]</code> are on Rosetta Code. The commented-out type signatures require [http://hackage.haskell.org/trac/haskell-prime/wiki/ScopedTypeVariables scoped type variables] in order to function. |
The modules <code>[[Bitmap#Haskell|Bitmap]]</code>, <code>[[Bitmap/Write a PPM file#Haskell|Bitmap.Netpbm]]</code>, and <code>[[Bitmap/Histogram#Haskell|Bitmap.BW]]</code> are on Rosetta Code. The commented-out type signatures require [http://hackage.haskell.org/trac/haskell-prime/wiki/ScopedTypeVariables scoped type variables] in order to function. |
||
< |
<syntaxhighlight lang=haskell>import Control.Monad |
||
import Control.Monad.ST |
import Control.Monad.ST |
||
import Data.STRef |
import Data.STRef |
||
Line 1,687: | Line 1,687: | ||
liftM2 (,) [1 .. width - 2] [0, height - 1] |
liftM2 (,) [1 .. width - 2] [0, height - 1] |
||
off = black |
off = black |
||
on = white</ |
on = white</syntaxhighlight> |
||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
Line 1,693: | Line 1,693: | ||
In this version the seed is randomly set within an inner area and particles are injected in an outer ring. |
In this version the seed is randomly set within an inner area and particles are injected in an outer ring. |
||
< |
<syntaxhighlight lang=Icon>link graphics,printf |
||
procedure main() # brownian tree |
procedure main() # brownian tree |
||
Line 1,758: | Line 1,758: | ||
pt +:= ( pt > (1-core)/2, core) |
pt +:= ( pt > (1-core)/2, core) |
||
return pt |
return pt |
||
end</ |
end</syntaxhighlight> |
||
{{libheader|Icon Programming Library}} |
{{libheader|Icon Programming Library}} |
||
Line 1,766: | Line 1,766: | ||
=={{header|J}}== |
=={{header|J}}== |
||
< |
<syntaxhighlight lang=j>brtr=:4 :0 |
||
seed=. ?x |
seed=. ?x |
||
clip=. 0 >. (<:x) <."1 ] |
clip=. 0 >. (<:x) <."1 ] |
||
Line 1,784: | Line 1,784: | ||
end. |
end. |
||
field |
field |
||
)</ |
)</syntaxhighlight> |
||
Example use: |
Example use: |
||
< |
<syntaxhighlight lang=j> require'viewmat' |
||
viewmat 480 640 brtr 30000</ |
viewmat 480 640 brtr 30000</syntaxhighlight> |
||
Note that building a brownian tree like this takes a while and would be more interesting if this were animated. |
Note that building a brownian tree like this takes a while and would be more interesting if this were animated. |
||
Line 1,795: | Line 1,795: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{libheader|Swing}} {{libheader|AWT}} |
{{libheader|Swing}} {{libheader|AWT}} |
||
< |
<syntaxhighlight lang=java>import java.awt.Graphics; |
||
import java.awt.image.BufferedImage; |
import java.awt.image.BufferedImage; |
||
import java.util.*; |
import java.util.*; |
||
Line 1,866: | Line 1,866: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
This is an alternate version which is a port of most of the code here. |
This is an alternate version which is a port of most of the code here. |
||
This code does not use a GUI and saves the output to image.png. |
This code does not use a GUI and saves the output to image.png. |
||
< |
<syntaxhighlight lang=Java>import java.awt.Point; |
||
import java.awt.image.BufferedImage; |
import java.awt.image.BufferedImage; |
||
import java.io.File; |
import java.io.File; |
||
Line 1,959: | Line 1,959: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
===Using canvas=== |
===Using canvas=== |
||
[http://switchb.org/kpreid/2010/brownian-tree/ Live version] <!-- If changing this example, add note this link is outdated --> |
[http://switchb.org/kpreid/2010/brownian-tree/ Live version] <!-- If changing this example, add note this link is outdated --> |
||
< |
<syntaxhighlight lang=javascript>function brownian(canvasId, messageId) { |
||
var canvas = document.getElementById(canvasId); |
var canvas = document.getElementById(canvasId); |
||
var ctx = canvas.getContext("2d"); |
var ctx = canvas.getContext("2d"); |
||
Line 2,092: | Line 2,092: | ||
}, 1); |
}, 1); |
||
}</ |
}</syntaxhighlight> |
||
< |
<syntaxhighlight lang=html><html> |
||
<head> |
<head> |
||
<script src="brownian.js"></script> |
<script src="brownian.js"></script> |
||
Line 2,102: | Line 2,102: | ||
<div id="message"></div> |
<div id="message"></div> |
||
</body> |
</body> |
||
</html></ |
</html></syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
Line 2,108: | Line 2,108: | ||
This solution puts the seed in the center of the canvas. Motes are generated randomly in space and do a simple drunkard's walk until they hit the tree or leave the canvas (unless the sides are made <tt>side</tt>). The Motes are colorized according to their θ in polar coordinates. |
This solution puts the seed in the center of the canvas. Motes are generated randomly in space and do a simple drunkard's walk until they hit the tree or leave the canvas (unless the sides are made <tt>side</tt>). The Motes are colorized according to their θ in polar coordinates. |
||
< |
<syntaxhighlight lang=julia>using Images, FileIO |
||
function main(h::Integer, w::Integer, side::Bool=false) |
function main(h::Integer, w::Integer, side::Bool=false) |
||
Line 2,149: | Line 2,149: | ||
imgwtside = main(256, 256, true) |
imgwtside = main(256, 256, true) |
||
save("data/browniantree_noside.jpg", imgnoside) |
save("data/browniantree_noside.jpg", imgnoside) |
||
save("data/browniantree_wtside.jpg", imgwtside)</ |
save("data/browniantree_wtside.jpg", imgwtside)</syntaxhighlight> |
||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
< |
<syntaxhighlight lang=scala>// version 1.1.2 |
||
import java.awt.Graphics |
import java.awt.Graphics |
||
Line 2,216: | Line 2,216: | ||
b.isVisible = true |
b.isVisible = true |
||
Thread(b).start() |
Thread(b).start() |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Liberty BASIC}}== |
=={{header|Liberty BASIC}}== |
||
< |
<syntaxhighlight lang=lb>'[RC]Brownian motion tree |
||
nomainwin |
nomainwin |
||
dim screen(600,600) |
dim screen(600,600) |
||
Line 2,301: | Line 2,301: | ||
timer 0 |
timer 0 |
||
close #1 |
close #1 |
||
end</ |
end</syntaxhighlight> |
||
=={{header|Locomotive Basic}}== |
=={{header|Locomotive Basic}}== |
||
{{trans|ZX Spectrum Basic}} |
{{trans|ZX Spectrum Basic}} |
||
This program is ideally run in [https://benchmarko.github.io/CPCBasic/cpcbasic.html CPCBasic] and should finish after about 20 to 25 minutes (Chrome, desktop CPU). At normal CPC speed, it would probably take several days to run when set to 10000 particles. |
This program is ideally run in [https://benchmarko.github.io/CPCBasic/cpcbasic.html CPCBasic] and should finish after about 20 to 25 minutes (Chrome, desktop CPU). At normal CPC speed, it would probably take several days to run when set to 10000 particles. |
||
< |
<syntaxhighlight lang=locobasic>10 MODE 1:DEFINT a-z:RANDOMIZE TIME:np=10000 |
||
20 INK 0,0:INK 1,26:BORDER 0 |
20 INK 0,0:INK 1,26:BORDER 0 |
||
30 PLOT 320,200 |
30 PLOT 320,200 |
||
Line 2,321: | Line 2,321: | ||
1010 x=RND*640 |
1010 x=RND*640 |
||
1020 y=RND*400 |
1020 y=RND*400 |
||
1030 RETURN</ |
1030 RETURN</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
Line 2,328: | Line 2,328: | ||
[[Grayscale image#Lua]], |
[[Grayscale image#Lua]], |
||
[[Basic bitmap storage#Lua]]. |
[[Basic bitmap storage#Lua]]. |
||
< |
<syntaxhighlight lang=lua>function SetSeed( f ) |
||
for i = 1, #f[1] do -- the whole boundary of the scene is used as the seed |
for i = 1, #f[1] do -- the whole boundary of the scene is used as the seed |
||
f[1][i] = 1 |
f[1][i] = 1 |
||
Line 2,394: | Line 2,394: | ||
end |
end |
||
end |
end |
||
Write_PPM( "brownian_tree.ppm", ConvertToColorImage(f) )</ |
Write_PPM( "brownian_tree.ppm", ConvertToColorImage(f) )</syntaxhighlight> |
||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
Line 2,400: | Line 2,400: | ||
Loose {{trans|D}} |
Loose {{trans|D}} |
||
< |
<syntaxhighlight lang=Mathematica>canvasdim = 1000; |
||
n = 0.35*canvasdim^2; |
n = 0.35*canvasdim^2; |
||
canvas = ConstantArray[0, {canvasdim, canvasdim}]; |
canvas = ConstantArray[0, {canvasdim, canvasdim}]; |
||
Line 2,425: | Line 2,425: | ||
{i, (particle + ds), MatrixPlot@canvas} |
{i, (particle + ds), MatrixPlot@canvas} |
||
] |
] |
||
MatrixPlot[canvas,FrameTicks->None,ColorFunction->"DarkRainbow",ColorRules->{0 -> None}]</ |
MatrixPlot[canvas,FrameTicks->None,ColorFunction->"DarkRainbow",ColorRules->{0 -> None}]</syntaxhighlight> |
||
Result: |
Result: |
||
Line 2,434: | Line 2,434: | ||
{{libheader|imageman}} |
{{libheader|imageman}} |
||
< |
<syntaxhighlight lang=Nim>import random |
||
import imageman |
import imageman |
||
Line 2,476: | Line 2,476: | ||
# Save into a PNG file. |
# Save into a PNG file. |
||
image.savePNG("brownian.png", compression = 9)</ |
image.savePNG("brownian.png", compression = 9)</syntaxhighlight> |
||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
{{trans|D}} |
{{trans|D}} |
||
< |
<syntaxhighlight lang=ocaml>let world_width = 400 |
||
let world_height = 400 |
let world_height = 400 |
||
let num_particles = 20_000 |
let num_particles = 20_000 |
||
Line 2,528: | Line 2,528: | ||
dla ~world; |
dla ~world; |
||
to_pbm ~world; |
to_pbm ~world; |
||
;;</ |
;;</syntaxhighlight> |
||
better to compile to native code to get a faster program: |
better to compile to native code to get a faster program: |
||
Line 2,538: | Line 2,538: | ||
{{trans|C}} |
{{trans|C}} |
||
< |
<syntaxhighlight lang=octave>function r = browniantree(xsize, ysize = xsize, numparticle = 1000) |
||
r = zeros(xsize, ysize, "uint8"); |
r = zeros(xsize, ysize, "uint8"); |
||
r(unidrnd(xsize), unidrnd(ysize)) = 1; |
r(unidrnd(xsize), unidrnd(ysize)) = 1; |
||
Line 2,564: | Line 2,564: | ||
r = browniantree(200); |
r = browniantree(200); |
||
r( r > 0 ) = 255; |
r( r > 0 ) = 255; |
||
jpgwrite("browniantree.jpg", r, 100); % image package</ |
jpgwrite("browniantree.jpg", r, 100); % image package</syntaxhighlight> |
||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |
||
Line 2,573: | Line 2,573: | ||
===Plotting helper functions=== |
===Plotting helper functions=== |
||
< |
<syntaxhighlight lang=parigp> |
||
\\ 2 old plotting helper functions 3/2/16 aev |
\\ 2 old plotting helper functions 3/2/16 aev |
||
\\ insm(): Check if x,y are inside matrix mat (+/- p deep). |
\\ insm(): Check if x,y are inside matrix mat (+/- p deep). |
||
Line 2,602: | Line 2,602: | ||
plothraw(Vec(vx),Vec(vy)); |
plothraw(Vec(vx),Vec(vy)); |
||
} |
} |
||
</ |
</syntaxhighlight> |
||
===Version #1. Translated from AutoHotkey.=== |
===Version #1. Translated from AutoHotkey.=== |
||
{{trans|AutoHotkey}} |
{{trans|AutoHotkey}} |
||
[[File:BTAH1.png|right|thumb|Output BTAH1.png]] |
[[File:BTAH1.png|right|thumb|Output BTAH1.png]] |
||
< |
<syntaxhighlight lang=parigp> |
||
\\ Brownian tree v.#1. Translated from AutoHotkey |
\\ Brownian tree v.#1. Translated from AutoHotkey |
||
\\ 3/8/2016, upgraded 11/27/16 aev |
\\ 3/8/2016, upgraded 11/27/16 aev |
||
Line 2,634: | Line 2,634: | ||
{BrownianTree1(400,15000,"c:\\pariData\\BTAH1.dat"); |
{BrownianTree1(400,15000,"c:\\pariData\\BTAH1.dat"); |
||
plotff("c:\\pariData\\BTAH1.dat");} \\BTAH1.png |
plotff("c:\\pariData\\BTAH1.dat");} \\BTAH1.png |
||
</ |
</syntaxhighlight> |
||
{{Output}} |
{{Output}} |
||
Line 2,653: | Line 2,653: | ||
[[File:BTOC1.png|right|thumb|Output BTOC1.png]] |
[[File:BTOC1.png|right|thumb|Output BTOC1.png]] |
||
< |
<syntaxhighlight lang=parigp> |
||
\\ Brownian tree v.#2. Translated from Octave |
\\ Brownian tree v.#2. Translated from Octave |
||
\\ 3/8/2016, upgraded 11/27/16 aev |
\\ 3/8/2016, upgraded 11/27/16 aev |
||
Line 2,678: | Line 2,678: | ||
{BrownianTree2(1000,3000,"c:\\pariData\\BTOC1.dat"); |
{BrownianTree2(1000,3000,"c:\\pariData\\BTOC1.dat"); |
||
plotff("c:\\pariData\\BTOC1.dat");} \\BTOC1.png |
plotff("c:\\pariData\\BTOC1.dat");} \\BTOC1.png |
||
</ |
</syntaxhighlight> |
||
{{Output}} |
{{Output}} |
||
Line 2,696: | Line 2,696: | ||
[[File:BTSE1.png|right|thumb|Output BTSE1.png]] |
[[File:BTSE1.png|right|thumb|Output BTSE1.png]] |
||
< |
<syntaxhighlight lang=parigp> |
||
\\ Brownian tree v.#3. Translated from Seed7 |
\\ Brownian tree v.#3. Translated from Seed7 |
||
\\ 3/8/2016, upgraded 11/27/16 aev |
\\ 3/8/2016, upgraded 11/27/16 aev |
||
Line 2,723: | Line 2,723: | ||
{BrownianTree3(400,5000,"c:\\pariData\\BTSE1.dat"); |
{BrownianTree3(400,5000,"c:\\pariData\\BTSE1.dat"); |
||
plotff("c:\\pariData\\BTSE1.dat");} \\BTSE1.png |
plotff("c:\\pariData\\BTSE1.dat");} \\BTSE1.png |
||
</ |
</syntaxhighlight> |
||
{{Output}} |
{{Output}} |
||
Line 2,743: | Line 2,743: | ||
[[File:BTPB3.png|right|thumb|Output BTPB3.png]] |
[[File:BTPB3.png|right|thumb|Output BTPB3.png]] |
||
< |
<syntaxhighlight lang=parigp> |
||
\\ Brownian tree v.#4. Translated from PureBasic |
\\ Brownian tree v.#4. Translated from PureBasic |
||
\\ 3/8/2016, upgraded 11/27/16 aev |
\\ 3/8/2016, upgraded 11/27/16 aev |
||
Line 2,783: | Line 2,783: | ||
{BrownianTree4(200,4000,"c:\\pariData\\BTPB3.dat",2,5); |
{BrownianTree4(200,4000,"c:\\pariData\\BTPB3.dat",2,5); |
||
plotff("c:\\pariData\\BTPB3.dat");} \\BTPB3.png |
plotff("c:\\pariData\\BTPB3.dat");} \\BTPB3.png |
||
</ |
</syntaxhighlight> |
||
{{Output}} |
{{Output}} |
||
Line 2,820: | Line 2,820: | ||
Code runs until the tree reached specified radius. Output is written to "test.eps" of wherever the current directory is. |
Code runs until the tree reached specified radius. Output is written to "test.eps" of wherever the current directory is. |
||
< |
<syntaxhighlight lang=perl>sub PI() { atan2(1,1) * 4 } # The, er, pi |
||
sub STEP() { .5 } # How far does the particle move each step. Affects |
sub STEP() { .5 } # How far does the particle move each step. Affects |
||
# both speed and accuracy greatly |
# both speed and accuracy greatly |
||
Line 2,975: | Line 2,975: | ||
} |
} |
||
write_eps;</ |
write_eps;</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
As-is, runs in about 2s, but can be very slow when bigger or (even worse) resize-able. |
As-is, runs in about 2s, but can be very slow when bigger or (even worse) resize-able. |
||
{{libheader|Phix/pGUI}} |
{{libheader|Phix/pGUI}} |
||
<!--< |
<!--<syntaxhighlight lang=Phix>(phixonline)--> |
||
<span style="color: #000080;font-style:italic;">-- demo\rosetta\BrownianTree.exw</span> |
<span style="color: #000080;font-style:italic;">-- demo\rosetta\BrownianTree.exw</span> |
||
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
||
Line 3,043: | Line 3,043: | ||
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span> |
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span> |
||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
< |
<syntaxhighlight lang=PicoLisp>(load "@lib/simul.l") |
||
(de brownianTree (File Size Cnt) |
(de brownianTree (File Size Cnt) |
||
Line 3,064: | Line 3,064: | ||
(for This L |
(for This L |
||
(prin (if (: pix) 1 0)) ) |
(prin (if (: pix) 1 0)) ) |
||
(prinl) ) ) ) )</ |
(prinl) ) ) ) )</syntaxhighlight> |
||
Use: |
Use: |
||
<pre>(brownianTree "img.pbm" 300 9000) |
<pre>(brownianTree "img.pbm" 300 9000) |
||
Line 3,070: | Line 3,070: | ||
=={{header|Processing}}== |
=={{header|Processing}}== |
||
< |
<syntaxhighlight lang=java>boolean SIDESTICK = false; |
||
boolean[][] isTaken; |
boolean[][] isTaken; |
||
Line 3,108: | Line 3,108: | ||
noLoop(); |
noLoop(); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
==={{header|Processing Python mode}}=== |
==={{header|Processing Python mode}}=== |
||
Line 3,114: | Line 3,114: | ||
{{trans|Processing}} |
{{trans|Processing}} |
||
< |
<syntaxhighlight lang=python>SIDESTICK = False |
||
def setup() : |
def setup() : |
||
Line 3,144: | Line 3,144: | ||
if frameCount > width * height: |
if frameCount > width * height: |
||
noLoop()</ |
noLoop()</syntaxhighlight> |
||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
< |
<syntaxhighlight lang=PureBasic>#Window1 = 0 |
||
#Image1 = 0 |
#Image1 = 0 |
||
#ImgGadget = 0 |
#ImgGadget = 0 |
||
Line 3,185: | Line 3,185: | ||
Event = WaitWindowEvent() |
Event = WaitWindowEvent() |
||
Until Event = #PB_Event_CloseWindow |
Until Event = #PB_Event_CloseWindow |
||
EndIf</ |
EndIf</syntaxhighlight>[[File:BrownianTree.pb.png]] |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
{{libheader|pygame}} |
{{libheader|pygame}} |
||
< |
<syntaxhighlight lang=python>import pygame, sys, os |
||
from pygame.locals import * |
from pygame.locals import * |
||
from random import randint |
from random import randint |
||
Line 3,289: | Line 3,289: | ||
while True: |
while True: |
||
input(pygame.event.get()) |
input(pygame.event.get()) |
||
pygame.display.flip()</ |
pygame.display.flip()</syntaxhighlight> |
||
=={{header|R}}== |
=={{header|R}}== |
||
Line 3,313: | Line 3,313: | ||
file could be very slow too. Actually, plotv2() shows almost "pure" plotting time. |
file could be very slow too. Actually, plotv2() shows almost "pure" plotting time. |
||
<syntaxhighlight lang=r> |
|||
<lang r> |
|||
# plotmat(): Simple plotting using a square matrix mat (filled with 0/1). v. 8/31/16 |
# plotmat(): Simple plotting using a square matrix mat (filled with 0/1). v. 8/31/16 |
||
# Where: mat - matrix; fn - file name; clr - color; ttl - plot title; |
# Where: mat - matrix; fn - file name; clr - color; ttl - plot title; |
||
Line 3,353: | Line 3,353: | ||
cat(" *** END:", date(), "\n"); |
cat(" *** END:", date(), "\n"); |
||
} |
} |
||
</ |
</syntaxhighlight> |
||
===Versions #1- #4.=== |
===Versions #1- #4.=== |
||
Line 3,361: | Line 3,361: | ||
====Version #1.==== |
====Version #1.==== |
||
<syntaxhighlight lang=r> |
|||
<lang r> |
|||
# Generate and plot Brownian tree. Version #1. |
# Generate and plot Brownian tree. Version #1. |
||
# 7/27/16 aev |
# 7/27/16 aev |
||
Line 3,395: | Line 3,395: | ||
} |
} |
||
gpBrownianTree1(400,15000,"red", "BT1R", "Brownian Tree v.1", 1); |
gpBrownianTree1(400,15000,"red", "BT1R", "Brownian Tree v.1", 1); |
||
</ |
</syntaxhighlight> |
||
{{Output}} |
{{Output}} |
||
Line 3,408: | Line 3,408: | ||
====Version #2.==== |
====Version #2.==== |
||
<syntaxhighlight lang=r> |
|||
<lang r> |
|||
# Generate and plot Brownian tree. Version #2. |
# Generate and plot Brownian tree. Version #2. |
||
# 7/27/16 aev |
# 7/27/16 aev |
||
Line 3,446: | Line 3,446: | ||
## Rename BT2R.dmp to BT2aR.dmp |
## Rename BT2R.dmp to BT2aR.dmp |
||
plotv2("BT2aR", "orange", "Brownian Tree v.2a", 640) |
plotv2("BT2aR", "orange", "Brownian Tree v.2a", 640) |
||
</ |
</syntaxhighlight> |
||
{{Output}} |
{{Output}} |
||
Line 3,467: | Line 3,467: | ||
====Version #3.==== |
====Version #3.==== |
||
<syntaxhighlight lang=r> |
|||
<lang r> |
|||
# Generate and plot Brownian tree. Version #3. |
# Generate and plot Brownian tree. Version #3. |
||
# 7/27/16 aev |
# 7/27/16 aev |
||
Line 3,507: | Line 3,507: | ||
} |
} |
||
gpBrownianTree3(400,5000,"dark green", "BT3R", "Brownian Tree v.3", 1); |
gpBrownianTree3(400,5000,"dark green", "BT3R", "Brownian Tree v.3", 1); |
||
</ |
</syntaxhighlight> |
||
{{Output}} |
{{Output}} |
||
Line 3,521: | Line 3,521: | ||
====Version #4.==== |
====Version #4.==== |
||
<syntaxhighlight lang=r> |
|||
<lang r> |
|||
# Generate and plot Brownian tree. Version #4. |
# Generate and plot Brownian tree. Version #4. |
||
# 7/27/16 aev |
# 7/27/16 aev |
||
Line 3,563: | Line 3,563: | ||
} |
} |
||
gpBrownianTree4(400,15000,"navy", "BT4R", "Brownian Tree v.4", 1); |
gpBrownianTree4(400,15000,"navy", "BT4R", "Brownian Tree v.4", 1); |
||
</ |
</syntaxhighlight> |
||
{{Output}} |
{{Output}} |
||
Line 3,577: | Line 3,577: | ||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang=racket>#lang racket |
||
(require 2htdp/image) |
(require 2htdp/image) |
||
Line 3,700: | Line 3,700: | ||
img |
img |
||
(save-image img "brownian-tree.png")</ |
(save-image img "brownian-tree.png")</syntaxhighlight> |
||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
Line 3,711: | Line 3,711: | ||
{{works with|Rakudo|2015.12}} |
{{works with|Rakudo|2015.12}} |
||
<lang |
<syntaxhighlight lang=raku line>constant size = 100; |
||
constant particlenum = 1_000; |
constant particlenum = 1_000; |
||
Line 3,777: | Line 3,777: | ||
} |
} |
||
display;</ |
display;</syntaxhighlight> |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Line 3,786: | Line 3,786: | ||
Program note: to keep things simple, the (system) command to clear the screen was hard-coded as '''CLS'''. |
Program note: to keep things simple, the (system) command to clear the screen was hard-coded as '''CLS'''. |
||
< |
<syntaxhighlight lang=rexx>/*REXX program animates and displays Brownian motion of dust in a field (with one seed).*/ |
||
mote = '·' /*character for a loose mote (of dust).*/ |
mote = '·' /*character for a loose mote (of dust).*/ |
||
hole = ' ' /* " " an empty spot in field.*/ |
hole = ' ' /* " " an empty spot in field.*/ |
||
Line 3,863: | Line 3,863: | ||
if yb<loY then loY= max(1, yb); if yb>hiY then hiY= min(sd, yb) |
if yb<loY then loY= max(1, yb); if yb>hiY then hiY= min(sd, yb) |
||
end /*y*/ /* [↑] limit mote's movement to field.*/ |
end /*y*/ /* [↑] limit mote's movement to field.*/ |
||
end /*x*/; return</ |
end /*x*/; return</syntaxhighlight> |
||
This REXX program makes use of '''scrsize''' REXX program (or BIF) which is used to determine the screen size of the terminal (console). |
This REXX program makes use of '''scrsize''' REXX program (or BIF) which is used to determine the screen size of the terminal (console). |
||
Line 3,986: | Line 3,986: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang=ring> |
||
# Project : Brownian tree |
# Project : Brownian tree |
||
Line 4,085: | Line 4,085: | ||
next |
next |
||
return number(str) |
return number(str) |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
Line 4,092: | Line 4,092: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
{{libheader|RMagick}} |
{{libheader|RMagick}} |
||
< |
<syntaxhighlight lang=ruby>require 'rubygems' |
||
require 'RMagick' |
require 'RMagick' |
||
Line 4,147: | Line 4,147: | ||
draw.draw img |
draw.draw img |
||
img.write "brownian_tree.bmp"</ |
img.write "brownian_tree.bmp"</syntaxhighlight> |
||
=={{header|Run BASIC}}== |
=={{header|Run BASIC}}== |
||
[[File:BrownianTreeKokenge.png|thumb|right|]] |
[[File:BrownianTreeKokenge.png|thumb|right|]] |
||
< |
<syntaxhighlight lang=runbasic>numParticles = 3000 |
||
dim canvas(201,201) |
dim canvas(201,201) |
||
graphic #g, 200,200 |
graphic #g, 200,200 |
||
Line 4,171: | Line 4,171: | ||
next i |
next i |
||
render #g |
render #g |
||
#g "flush"</ |
#g "flush"</syntaxhighlight> |
||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
Line 4,177: | Line 4,177: | ||
{{libheader|rand}} |
{{libheader|rand}} |
||
{{libheader|image}} |
{{libheader|image}} |
||
< |
<syntaxhighlight lang=rust> |
||
extern crate image; |
extern crate image; |
||
extern crate rand; |
extern crate rand; |
||
Line 4,281: | Line 4,281: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
For a 512 x 512 field and 100k motes, run time is around 200 s on ~2019 hardware (Ryzen 5 3600X). |
For a 512 x 512 field and 100k motes, run time is around 200 s on ~2019 hardware (Ryzen 5 3600X). |
||
<center>[[File:Rust-Brownian-512-20k.png]]</center> |
<center>[[File:Rust-Brownian-512-20k.png]]</center> |
||
Line 4,287: | Line 4,287: | ||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
===Java Swing Interoperability=== |
===Java Swing Interoperability=== |
||
< |
<syntaxhighlight lang=Scala>import java.awt.Graphics |
||
import java.awt.image.BufferedImage |
import java.awt.image.BufferedImage |
||
Line 4,336: | Line 4,336: | ||
new Thread(new BrownianTree).start() |
new Thread(new BrownianTree).start() |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
{{works with|Guile}} |
{{works with|Guile}} |
||
< |
<syntaxhighlight lang=scheme>; Save bitmap to external file |
||
(define (save-pbm bitmap filename) |
(define (save-pbm bitmap filename) |
||
(define f (open-output-file filename)) |
(define f (open-output-file filename)) |
||
Line 4,447: | Line 4,447: | ||
; Save to a portable bitmap file |
; Save to a portable bitmap file |
||
(save-pbm bitmap "brownian-tree.pbm")</ |
(save-pbm bitmap "brownian-tree.pbm")</syntaxhighlight> |
||
[[File:Scheme-guile-brownian-tree-large.png]] |
[[File:Scheme-guile-brownian-tree-large.png]] |
||
Line 4,454: | Line 4,454: | ||
The program below generates a small brownian tree. You can watch how it grows. |
The program below generates a small brownian tree. You can watch how it grows. |
||
< |
<syntaxhighlight lang=seed7>$ include "seed7_05.s7i"; |
||
include "draw.s7i"; |
include "draw.s7i"; |
||
include "keybd.s7i"; |
include "keybd.s7i"; |
||
Line 4,506: | Line 4,506: | ||
genBrownianTree(SIZE, 20000); |
genBrownianTree(SIZE, 20000); |
||
readln(KEYBOARD); |
readln(KEYBOARD); |
||
end func;</ |
end func;</syntaxhighlight> |
||
Original source: [http://seed7.sourceforge.net/algorith/graphic.htm#brownian_tree] |
Original source: [http://seed7.sourceforge.net/algorith/graphic.htm#brownian_tree] |
||
Line 4,512: | Line 4,512: | ||
=={{header|SequenceL}}== |
=={{header|SequenceL}}== |
||
'''SequenceL Code:'''<br> |
'''SequenceL Code:'''<br> |
||
< |
<syntaxhighlight lang=sequencel>import <Utilities/Random.sl>; |
||
import <Utilities/Sequence.sl>; |
import <Utilities/Sequence.sl>; |
||
Line 4,558: | Line 4,558: | ||
j within 1 ... worldSize; |
j within 1 ... worldSize; |
||
in |
in |
||
(World: world, Rand: seedRandom(seed), Point: (X: worldSize / 2, Y: worldSize / 2));</ |
(World: world, Rand: seedRandom(seed), Point: (X: worldSize / 2, Y: worldSize / 2));</syntaxhighlight> |
||
'''C++ Driver Code:'''<br> |
'''C++ Driver Code:'''<br> |
||
{{libheader|CImg}} |
{{libheader|CImg}} |
||
< |
<syntaxhighlight lang=c>#include <time.h> |
||
#include <cstdlib> |
#include <cstdlib> |
||
#include "CImg.h" |
#include "CImg.h" |
||
Line 4,605: | Line 4,605: | ||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 4,612: | Line 4,612: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang=ruby>const size = 100 |
||
const mid = size>>1 |
const mid = size>>1 |
||
const particlenum = 1000 |
const particlenum = 1000 |
||
Line 4,689: | Line 4,689: | ||
} |
} |
||
display()</ |
display()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 4,731: | Line 4,731: | ||
</pre> |
</pre> |
||
=={{header|Simula}}== |
=={{header|Simula}}== |
||
< |
<syntaxhighlight lang=simula>BEGIN |
||
INTEGER NUM_PARTICLES; |
INTEGER NUM_PARTICLES; |
||
INTEGER LINES, COLUMNS; |
INTEGER LINES, COLUMNS; |
||
Line 4,797: | Line 4,797: | ||
END; |
END; |
||
END.</ |
END.</syntaxhighlight> |
||
{{in}} |
{{in}} |
||
<pre>656565</pre> |
<pre>656565</pre> |
||
Line 4,852: | Line 4,852: | ||
=={{header|Sinclair ZX81 BASIC}}== |
=={{header|Sinclair ZX81 BASIC}}== |
||
Requires at least 2k of RAM. If you have more, you can plot it on a larger grid—up to and including full-screen, provided you don't mind spending literally hours watching the first few dots maunder about without hitting anything. |
Requires at least 2k of RAM. If you have more, you can plot it on a larger grid—up to and including full-screen, provided you don't mind spending literally hours watching the first few dots maunder about without hitting anything. |
||
< |
<syntaxhighlight lang=basic> 10 DIM A$(20,20) |
||
20 LET A$(10,10)="1" |
20 LET A$(10,10)="1" |
||
30 FOR Y=42 TO 23 STEP -1 |
30 FOR Y=42 TO 23 STEP -1 |
||
Line 4,875: | Line 4,875: | ||
220 GOTO 130 |
220 GOTO 130 |
||
230 LET A$(X,Y)="1" |
230 LET A$(X,Y)="1" |
||
240 NEXT I</ |
240 NEXT I</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Screenshot [http://www.edmundgriffiths.com/zx81browniantree.jpg here]. |
Screenshot [http://www.edmundgriffiths.com/zx81browniantree.jpg here]. |
||
Line 4,881: | Line 4,881: | ||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
{{libheader|Tk}} |
{{libheader|Tk}} |
||
< |
<syntaxhighlight lang=tcl>package require Tcl 8.5 |
||
package require Tk |
package require Tk |
||
Line 4,932: | Line 4,932: | ||
update |
update |
||
makeBrownianTree 1000 |
makeBrownianTree 1000 |
||
brownianTree write tree.ppm</ |
brownianTree write tree.ppm</syntaxhighlight> |
||
=={{header|TI-83 BASIC}}== |
=={{header|TI-83 BASIC}}== |
||
< |
<syntaxhighlight lang=ti83b>:StoreGDB 0 |
||
:ClrDraw |
:ClrDraw |
||
:FnOff |
:FnOff |
||
Line 4,961: | Line 4,961: | ||
:End |
:End |
||
:Pause |
:Pause |
||
:RecallGDB 0</ |
:RecallGDB 0</syntaxhighlight> |
||
=={{header|Visual Basic .NET}}== |
=={{header|Visual Basic .NET}}== |
||
Windows Forms Application. |
Windows Forms Application. |
||
< |
<syntaxhighlight lang=vbnet> |
||
Imports System.Drawing.Imaging |
Imports System.Drawing.Imaging |
||
Line 5,096: | Line 5,096: | ||
End Sub |
End Sub |
||
End Class |
End Class |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out|Final output}} |
{{out|Final output}} |
||
[[File:SH_BrownianTree.jpg]] |
[[File:SH_BrownianTree.jpg]] |
||
Line 5,104: | Line 5,104: | ||
{{trans|Go}} |
{{trans|Go}} |
||
As you'd expect, not very fast so have halved Go's parameters to draw the tree in around 45 seconds. |
As you'd expect, not very fast so have halved Go's parameters to draw the tree in around 45 seconds. |
||
< |
<syntaxhighlight lang=ecmascript>import "graphics" for Canvas, Color |
||
import "dome" for Window |
import "dome" for Window |
||
import "random" for Random |
import "random" for Random |
||
Line 5,194: | Line 5,194: | ||
} |
} |
||
var Game = BrownianTree.new(200, 150, 7500)</ |
var Game = BrownianTree.new(200, 150, 7500)</syntaxhighlight> |
||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
[[File:BrownXPL0.gif|right]] |
[[File:BrownXPL0.gif|right]] |
||
< |
<syntaxhighlight lang=XPL0>include c:\cxpl\codes; \intrinsic 'code' declarations |
||
def W=128, H=W; \width and height of field |
def W=128, H=W; \width and height of field |
||
int X, Y; |
int X, Y; |
||
Line 5,215: | Line 5,215: | ||
if KeyHit then [SetVid(3); quit]; \restore text mode |
if KeyHit then [SetVid(3); quit]; \restore text mode |
||
]; |
]; |
||
]</ |
]</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
Line 5,223: | Line 5,223: | ||
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl |
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl |
||
[[File:Brownian.zkl.jpg|250px|thumb|right]] |
[[File:Brownian.zkl.jpg|250px|thumb|right]] |
||
< |
<syntaxhighlight lang=zkl>w:=h:=400; numParticles:=20_000; |
||
bitmap:=PPM(w+2,h+2,0); // add borders as clip regions |
bitmap:=PPM(w+2,h+2,0); // add borders as clip regions |
||
Line 5,255: | Line 5,255: | ||
} |
} |
||
} |
} |
||
bitmap.writeJPGFile("brownianTree.zkl.jpg"); // the final image</ |
bitmap.writeJPGFile("brownianTree.zkl.jpg"); // the final image</syntaxhighlight> |
||
=={{header|ZX Spectrum Basic}}== |
=={{header|ZX Spectrum Basic}}== |
||
{{trans|Run BASIC}} |
{{trans|Run BASIC}} |
||
Very, very slow on a ZX Spectrum (even emulate and at maximum speed). Best use SpecBAS, changing the value of the variable np to 6000. |
Very, very slow on a ZX Spectrum (even emulate and at maximum speed). Best use SpecBAS, changing the value of the variable np to 6000. |
||
< |
<syntaxhighlight lang=zxbasic>10 LET np=1000 |
||
20 PAPER 0: INK 4: CLS |
20 PAPER 0: INK 4: CLS |
||
30 PLOT 128,88 |
30 PLOT 128,88 |
||
Line 5,276: | Line 5,276: | ||
1020 LET y=RND*174 |
1020 LET y=RND*174 |
||
1030 RETURN |
1030 RETURN |
||
</syntaxhighlight> |
|||
</lang> |
|||
[[Category:Geometry]] |
[[Category:Geometry]] |