-
Notifications
You must be signed in to change notification settings - Fork 0
/
Circles.fsx
41 lines (31 loc) · 1.25 KB
/
Circles.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// load the script containing the helper functions, and open the module
#load "FractalFunctions.fsx"
open Fractal
let next colour =
let red, green, blue = colour
(red, green + 30, blue)
let rand seed =
let rnd = System.Random(seed)
rnd.Next(0, 255)
let randCol seed =
let r = rand seed
let g = rand r
let b = rand g
(r,g,b)
// Function which draws a line then calls itself recursively, to create the pattern
let rec sphere (x:float) (y:float) (radius:float) seed (iteration:int) =
if iteration < 5 then
circle x y (int radius) <| randCol seed
let nextDist = radius/2.0
sphere (x-nextDist) (y-nextDist) nextDist (seed*2) (iteration+1)
sphere (x+nextDist) (y-nextDist) nextDist (seed/2) (iteration+1)
sphere (x+nextDist) (y+nextDist) nextDist (seed/3) (iteration+1)
sphere (x-nextDist) (y+nextDist) nextDist (seed*3) (iteration+1)
// Call the branch function with the initial parameters
sphere
(float formWidth/2.0) // x position - start in the middle
(float formHeight/2.0) // y position
200.0 // length of branch
System.DateTime.Now.Millisecond
0 // iteration. Could use this to decide how many times to loop. Or use something else, and get rid of it.
form.Show()