#
# mandelbrot.jako
#
# Print the Mandlebrot set.
#
# Translated from Parrot assembler to Jako by Gregor Purdy <gregor@focusresearch.com>.
# Translated from C to Parrot assembler by Leon Brocard <acme@astray.com>.
# Original C version by Glenn Rhodes.
#
# The C code is:
#
# main(){
#  int x, y, k;
#  char *b = " .:,;!/>)|&IH%*#";
#  float r, i, z, Z, t, c, C;
#
#  for (y=30; puts(""), C = y*0.1 - 1.5, y--;){
#     for (x=0; c = x*0.04 - 2, z=0, Z=0, x++ < 75;){
#        for (r=c, i=C, k=0; t = z*z - Z*Z + r, Z = 2*z*Z + i, z=t, k<112; k++)
#           if (z*z + Z*Z > 10) break;
#        printf ("%c", b[k%16]);
#        }
#     }
# }
#
# Copyright (C) 2001-2003 Gregor N. Purdy. All rights reserved.
# This program is free software. It is subject to the same
# license as the Parrot interpreter.
#

use sys;
use string;

var str b = " .:,;!/>)|&IH%*#";

var int x, y, k;
var num r, i, z, Z, t, c, C;

y = 30;

YREDO:

goto END if (y == 0);

C  = y;
C *= 0.1;
C -= 1.5;

y--;
x = 0;

XREDO:

goto YLOOP if (x == 75);

c  = x;
c *= 0.04;
c -= 2.0;

z = 0.0;
Z = 0.0;
x++;

r = c;
i = C;
k = 0;

KREDO:

goto PRINT if (k == 112);

var num temp_8;
var num temp_9;

temp_8 = z * z;
temp_9 = Z * Z;
t = temp_8 - temp_9;
t += r;

Z *= 2.0;
Z *= z;
Z += i;

z = t;

temp_8 = z * z;
temp_9 = Z * Z;
temp_8 += temp_9;

goto PRINT if (temp_8 > 10.0);

KLOOP:

k++;
goto KREDO;

PRINT:

var int temp_int_4;
var int temp_int_5;

temp_int_4 = k % 16;
temp_int_5 = 1;

var str ch;

ch = string::substr(b, temp_int_4, temp_int_5);
sys::print(ch);

XLOOP:

goto XREDO;

YLOOP:

sys::print("\n");
goto YREDO;

END:

