maekawatoshiki
6/28/2018 - 7:54 AM

mandelbrot

int w0, x, y, c, i, dx, dy, xn, yn, xn1, yn1, t, t2, xmin, ymin, xp, yp;
w0 = openWin(512, 256);
ymin = 0 - 256;
xmin = 0 - 512;
for (y = 256; y > ymin; y--) {
	for (x = xmin; x < 256; x++) {
		xn = 0;
		yn = 0;
		xn1 = 0;
		yn1 = 0;
		for (i = 0; i < 200; i++) {
			t = xn*xn;
			if (t >= 0) { t += 128; t /= 256; } else { t -= 128; t /= 256; }
			xn1 = t;
			t = yn*yn;
			if (t >= 0) { t += 128; t /= 256; } else { t -= 128; t /= 256; }
			xn1 -= t; xn1 += x;

			t = xn*yn; t *= 2;
			if (t >= 0) { t += 128; t /= 256; } else { t -= 128; t /= 256; }
			yn1 = t + y;

			t = xn1*xn1;
			if (t >= 0) { t += 128; t /= 256; } else { t -= 128; t /= 256; }
			t2 = yn1*yn1;
			if (t2 >= 0) { t2 += 128; t2 /= 256; } else { t2 -= 128; t2 /= 256; }
			t+=t2;

			if (t > 1024) {
				xp = x + 512; xp /= 2;
				yp = y + 256; yp /= 2;
				c = rgb(255, 0, 0);
				setPix(w0, xp, yp, c);
				i = 200; // break; だとエラーになる
			} else {
				xn = xn1;
				yn = yn1;
			}
		}
		
	}
}

time;
end;