Chaos Game on a Semi-Circle
Author
Arnoud Buzing
Title
Chaos Game on a Semi-Circle
Description
Fast Implementation of the Chaos Game with the Wolfram Language
Category
Educational Materials
Keywords
compiler
URL
http://www.notebookarchive.org/2021-09-0jcrmrd/
DOI
https://notebookarchive.org/2021-09-0jcrmrd
Date Added
2021-09-01
Date Last Modified
2021-09-01
File Size
2.01 megabytes
Supplements
Rights
Redistribution rights reserved



The “Chaos Game” on a semi-circle
The “Chaos Game” on a semi-circle
Out[]=
The Chaos game on a semi-circle is defined as follows: To start, randomly pick two points on a semi-circle. Connect them with a line and create a new point 2/3s down that line. Draw this point. Repeat this process using this point and a new randomly selected point on the semi-circle. The emerging point cloud will look like the one above (which has also been colorized in placed where the point density is greater).
In[]:=
SeedRandom[1];pts={Cos[#],Sin[#]}&/@RandomReal[π,2];Graphics[{Circle[{0,0},1,{0,π}],Gray,Line[pts],Red,AbsolutePointSize[7],Point[pts],Blue,Point[pts[[1]]+2/3*(pts[[2]]-pts[[1]])]}]
Out[]=
The following function can be compiled for extra speed. It takes a blank canvas (image data) and draws n points on that canvas, which is returned and can be passed to Image.
In[]:=
f=Function[{Typed[data,TypeSpecifier["PackedArray"]["Real64",3]],Typed[n,"MachineInteger"]},Module[{r,c,q,rr,p1,p2,row,col,res=data},{r,c,q}=Dimensions[data];rr=RandomReal[1.0*π];p1={Cos[rr],Sin[rr]};Do[rr=RandomReal[1.0*π];p2={Cos[rr],Sin[rr]};p1=p1+0.666*(p2-p1);row=Round[r-(r-1)p1[[2]]];col=Round[Quotient[c,2]+(Quotient[c,2]-1)*p1[[1]]];res[[row,col]]=Mod[{0.001,0.002,0.003}+res[[row,col]],1];,n];res]];
In[]:=
cf=FunctionCompile[f]
Out[]=
CompiledCodeFunction
|
In[]:=
data=ConstantArray[{0.0,0.0,0.0},{360,640}];
In[]:=
Image[cf[data,10^8],ColorSpace"RGB"]
Out[]=


Cite this as: Arnoud Buzing, "Chaos Game on a Semi-Circle" from the Notebook Archive (2021), https://notebookarchive.org/2021-09-0jcrmrd

Download

