| 1 |
/* |
| 2 |
https://github.com/vtereshkov/umka-lang/raw/master/examples/fractal/fractal.um |
| 3 |
*/ |
| 4 |
// Fractal demo in Umka (adapted from a Wren version by Robert Nystrom) |
| 5 |
|
| 6 |
fn main() { |
| 7 |
const ( |
| 8 |
yMin = -0.2 |
| 9 |
yMax = 0.1 |
| 10 |
xMin = -1.5 |
| 11 |
xMax = -1.1 |
| 12 |
) |
| 13 |
|
| 14 |
for yPixel := 0; yPixel < 40; yPixel++ { |
| 15 |
y0 := (yPixel / 40.0) * (yMax - yMin) + yMin |
| 16 |
|
| 17 |
for xPixel := 0; xPixel < 79; xPixel++ { |
| 18 |
x0 := (xPixel / 78.0) * (xMax - xMin) + xMin |
| 19 |
x, y := x0, y0 |
| 20 |
pixel := ' ' |
| 21 |
|
| 22 |
for iter := 0; iter < 80; iter++ { |
| 23 |
x, y = x * x - y * y + x0, 2 * x * y + y0 |
| 24 |
|
| 25 |
// Stop if the point escaped |
| 26 |
if x * x + y * y > 4 { |
| 27 |
const pixels = " .:;+=xX$&" |
| 28 |
pixel = pixels[iter / 8] |
| 29 |
break |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
printf("%c", pixel) |
| 34 |
} |
| 35 |
|
| 36 |
printf("\n") |
| 37 |
} |
| 38 |
} |