Brownian tree: Difference between revisions
m
Automated syntax highlighting fixup (second round - minor fixes)
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
Thundergnat (talk | contribs) m (Automated syntax highlighting fixup (second round - minor fixes)) |
||
Line 1:
[[Category:Raster graphics operations]]
{{Wikipedia|Brownian_tree}}
{{task|Fractals}}
[[File:Brownian_tree.jpg|450px||right]]
Line 16:
<br>Because of the lax rules governing the random nature of the particle's placement and motion, no two resulting trees are really expected to be the same, or even necessarily have the same general shape. <br><br>
=={{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.
<syntaxhighlight lang=
IF Locate(x-1,y-1)=1 THEN RETURN (1) FI
IF Locate(x,y-1)=1 THEN RETURN (1) FI
Line 111 ⟶ 110:
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Brownian_tree.png Screenshot from Atari 8-bit computer]
=={{header|Ada}}==
{{libheader|SDLAda}}
<syntaxhighlight lang=
with SDL.Video.Windows.Makers;
Line 239 ⟶ 237:
SDL.Finalise;
end Brownian_Tree;</syntaxhighlight>
=={{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.<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
2 T = 1:Z = 2:E = 8:C = 234
Line 257 ⟶ 254:
14 HGR : POKE 49234,0
15 ROT= 0: SCALE= 1: RETURN</syntaxhighlight>
=={{header|AutoHotkey}}==
{{works with|AutoHotkey_L}}
Takes a little while to run, be patient.
Requires the [http://www.autohotkey.com/forum/topic32238.html GDI+ Standard Library by Tic]
<syntaxhighlight lang=
Process, Priority,, high
size := 400
Line 315 ⟶ 311:
return r
}</syntaxhighlight>Sample output file [http://www.autohotkey.net/~crazyfirex/Images/brownian.png here]
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> SYS "SetWindowText", @hwnd%, "Brownian Tree"
SIZE = 400
Line 348 ⟶ 343:
</syntaxhighlight>
[[File:Brownian_BBC.gif]]
=={{header|C}}==
{{libheader|FreeImage}}
<syntaxhighlight lang="c">#include <string.h>
#include <stdlib.h>
#include <time.h>
Line 421 ⟶ 415:
{{trans|D}}
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 <time.h>
Line 465 ⟶ 459:
}</syntaxhighlight>
Run-time about 12.4 seconds with SIDE=600, NUM_PARTICLES=10000.
=={{header|C sharp|C#}}==
{{works with|C#|3.0}}
{{libheader|System.Drawing}}
<syntaxhighlight lang="csharp">using System;
using System.Drawing;
Line 520 ⟶ 513:
}
}</syntaxhighlight>
=={{header|C++}}==
[[File:brownianTree_cpp.png|300px]]
For an animated version based on this same code see: [[Brownian tree/C++ animated]]
<syntaxhighlight lang="cpp">#include <windows.h>
#include <iostream>
#include <string>
Line 820 ⟶ 812:
}
//--------------------------------------------------------------------</syntaxhighlight>
=={{header|Common Lisp}}==
When the random walk lands on a set pixel it sets the pixel at the previous position.
Line 826 ⟶ 817:
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.
<syntaxhighlight lang="lisp">;;; brownian.lisp
;;; sbcl compile: first load and then (sb-ext:save-lisp-and-die "brownian" :executable t :toplevel #'brownian::main)
(ql:quickload "cl-gd")
Line 912 ⟶ 903:
:compression-level 6 :if-exists :supersede)))
</syntaxhighlight>
=={{header|D}}==
Uses the module of the Grayscale Image task. Partial {{trans|PureBasic}}
<syntaxhighlight lang="d">void main() {
import core.stdc.stdio, std.random, grayscale_image;
Line 955 ⟶ 945:
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>
=={{header|Delphi}}==
<syntaxhighlight lang="delphi">const
SIZE = 256;
NUM_PARTICLES = 1000;
Line 1,011 ⟶ 1,000:
end;
end;</syntaxhighlight>
=={{header|EasyLang}}==
[https://easylang.online/apps/_brownian-tree.html Run it]
<syntaxhighlight lang="text">color3 0 1 1
len f[] 200 * 200
move 50 50
Line 1,049 ⟶ 1,037:
.
.</syntaxhighlight>
=={{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.
<syntaxhighlight lang="factor">USING: accessors images images.loader kernel literals math
math.vectors random sets ;
FROM: sets => in? ;
Line 1,102 ⟶ 1,089:
{{out}}
[https://i.imgur.com/qDVylB9.png image]
=={{header|Fantom}}==
<syntaxhighlight lang="fantom">
using fwt
using gfx
Line 1,208 ⟶ 1,194:
}
</syntaxhighlight>
=={{header|Fortran}}==
{{works with|Fortran|95 and later}}
Line 1,216 ⟶ 1,201:
For RCImageBasic and RCImageIO, see [[Basic bitmap storage/Fortran]] and [[Write ppm file#Fortran]]
<syntaxhighlight lang="fortran">program BrownianTree
use RCImageBasic
use RCImageIO
Line 1,322 ⟶ 1,307:
end program</syntaxhighlight>
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">' version 16-03-2017
' compile with: fbc -s gui
Line 1,384 ⟶ 1,368:
Beep : Sleep 5000
End</syntaxhighlight>
=={{header|Gnuplot}}==
{{Works with|gnuplot|5.0 (patchlevel 3) and above}}
Line 1,391 ⟶ 1,374:
'''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.
<syntaxhighlight lang="gnuplot">
## plotff.gp 11/27/16 aev
## Plotting from any data-file with 2 columns (space delimited), and writing to png-file.
Line 1,417 ⟶ 1,400:
[[File:BT43gp.png|right|thumb|Output BT43gp.png]]
<syntaxhighlight lang="gnuplot">
## BTff.gp 11/27/16 aev
## Plotting 6 Brownian tree pictures.
Line 1,466 ⟶ 1,449:
BT1gp.png, BT2gp.png, BT3gp.png, BT41gp.png, BT43gp.png, BT43gp.png.
</pre>
=={{header|Go}}==
[[file:GoTree.png|right|thumb|Output png]]
Line 1,472 ⟶ 1,454:
Using standard image library:
<syntaxhighlight lang="go">package main
import (
Line 1,539 ⟶ 1,521:
if err != nil {
fmt.Println(err)
|