Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6581 | leency | 1 | --BRUSH Scene: Mandelbrot fractal v0.5 |
2 | -- |
||
3 | --Draws a Mandelbrot fractal in the current brush. |
||
4 | -- |
||
5 | --by Richard Fhager |
||
6 | --http://hem.fyristorg.com/dawnbringer/ |
||
7 | |||
8 | -- Copyright 2010 Richard Fhager |
||
9 | -- |
||
10 | -- This program is free software; you can redistribute it and/or |
||
11 | -- modify it under the terms of the GNU General Public License |
||
12 | -- as published by the Free Software Foundation; version 2 |
||
13 | -- of the License. See |
||
14 | |||
15 | -- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project |
||
16 | --http://goto.glocalnet.net/richard_fhager/evalion/evalion.html |
||
17 | |||
18 | |||
19 | colors = 64 |
||
20 | |||
21 | x0 = -1.7 |
||
22 | x1 = 0.7 |
||
23 | ym = 0 |
||
24 | iter = 64 |
||
25 | |||
26 | |||
27 | ok, x0, x1, ym, iter = inputbox("Fractal data", |
||
28 | "X0", x0, -2, 2,4, |
||
29 | "X1", x1, -2, 2,4, |
||
30 | "midY", ym, -2, 2,4, |
||
31 | "Iter", iter, 1, 2048,0 |
||
32 | ); |
||
33 | |||
34 | -- -0.831116819,-0.831116815,0.2292112435,192 |
||
35 | |||
36 | |||
37 | function mandel(x,y,l,r,o,i) -- pos. as fraction of 1, left coord, right coord, y coord, iterations |
||
38 | |||
39 | local w,s,a,p,q,n,v,w |
||
40 | |||
41 | s=math.abs(r-l); |
||
42 | |||
43 | a = l + s*x; |
||
44 | p = a; |
||
45 | b = o - s*(y-0.5); |
||
46 | q = b; |
||
47 | n = 1; |
||
48 | v = 0; |
||
49 | w = 0; |
||
50 | |||
51 | while (v+w<4 and n |
||
52 | |||
53 | return n |
||
54 | end |
||
55 | |||
56 | |||
57 | w, h = getbrushsize() |
||
58 | |||
59 | for x = 0, w - 1, 1 do |
||
60 | for y = 0, h - 1, 1 do |
||
61 | q = mandel(x/w,y/h,x0,x1,ym,iter) % colors; |
||
62 | putbrushpixel(x, y, q); |
||
63 | end |
||
64 | end4> |