Created
June 11, 2018 10:43
-
-
Save iamgreaser/c4866f51ac4b4c553d76791bf68a1c51 to your computer and use it in GitHub Desktop.
mandelbrot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*> vim: set syntax= et sts=2 sw=2 : | |
*> free syntax. compile like so: | |
*> cobc -x -free -o actualmandel actualmandel.cbl | |
identification division. | |
program-id. actualmandel. | |
environment division. | |
data division. | |
working-storage section. | |
01 template-string. | |
03 template-elems occurs 10 times pic x. | |
01 output-string. | |
03 output-elems occurs 97 times pic x. | |
01 base-r pic 9(5). | |
01 base-i pic 9(5). | |
01 iter-index pic 9(5). | |
01 iter-div pic 9(5). | |
01 iter-rem pic 9(5). | |
01 dist2 pic 9(10)V9(9). | |
01 zoom pic 9(10)V9(9). | |
01 zr pic S9(5)V9(9). | |
01 zi pic S9(5)V9(9). | |
01 cr pic S9(5)V9(9). | |
01 ci pic S9(5)V9(9). | |
01 tr pic S9(5)V9(9). | |
01 ti pic S9(5)V9(9). | |
procedure division. | |
display "start" | |
move " .,;:|$%#@" to template-string | |
move 1.2 to zoom | |
move 0 to base-i | |
perform until base-i > 40 | |
compute ci = (((base-i / 40.000) * 2.0) - 1.0) * zoom | |
move 0 to base-r | |
perform until base-r > 96 | |
compute cr = (((base-r / 96.000) * 2.0) - 1.5) * zoom | |
move " " to output-elems(base-r) | |
perform iter-start thru iter-end | |
add 1 to base-r | |
end-perform | |
display output-string | |
add 1 to base-i | |
end-perform | |
display "done" | |
stop run. | |
iter-start. | |
move 0 to zr | |
move 0 to zi | |
move 0 to iter-index | |
perform until iter-index >= 1000 | |
compute tr = ((zr * zr) - (zi * zi) + cr) | |
compute ti = ((2 * zr * zi) + ci) | |
move tr to zr | |
move ti to zi | |
compute dist2 = (zr * zr) + (zi * zi) | |
if dist2 > 4.0 | |
go to iter-end | |
end-if | |
add 1 to iter-index | |
end-perform. | |
iter-end. | |
if iter-index < 1000 then | |
perform until iter-index < 10 | |
subtract 10 from iter-index | |
end-perform | |
add 1 to iter-index | |
move template-elems(iter-index) to output-elems(base-r) | |
end-if | |
exit. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment