Advertisement
sjfroos

GFA Mandelbrot

Aug 16th, 2020
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. REM -----------------------------------------------
  2. REM   Mandel and buddhabrot program
  3. REM   Written by: Johan Roos Tibbelin
  4. REM               (sjfroos)
  5. REM   Date: 2020-08-13     Last changed:2020-08-16
  6. REM -----------------------------------------------
  7. REM
  8. REM
  9. REM mandelbrot render precalc.
  10. INLINE brot%,32000
  11. REM Number of iterations per pixel is saved here
  12. DIM pixels%(320,200)
  13. REM pixel part of set or not
  14. DIM brot!(320,200)
  15. SETCOLOR 0,0,0,0
  16. SETCOLOR 15,7,7,7
  17. REM mandelmenu(x1,y1,x2,y2)
  18. REM foo=INP(2)
  19. REM END
  20. mandelbrot(-2.5,-1.2,2.5,1.2)
  21. REM BMOVE XBIOS(2),brot%,32000
  22. REPEAT
  23. UNTIL MOUSEK=2
  24. SETCOLOR 0,7,7,7
  25. SETCOLOR 15,0,0,0
  26. END
  27. PROCEDURE mandelbrot(x1,y1,x2,y2)
  28.   FOR py=0 TO 199
  29.     FOR px=0 TO 319
  30.       IF x1=0  AND x2=0 AND y1=0 AND y2=0 THEN
  31.         x0=3.5/320*px-2.5
  32.         y0=2.4/200*py-1.2
  33.       ELSE
  34.         x0=(x2-x1)/320*px+x1
  35.         y0=(y2-y1)/200*py+y1
  36.       ENDIF
  37.       x=0
  38.       y=0
  39.       iteration=0
  40.       max_iteration=40
  41.       WHILE (x*x+y*y<=2*2 AND iteration<max_iteration)
  42.         xtemp=x*x-y*y+x0
  43.         y=2*x*y+y0
  44.         x=xtemp
  45.         iteration=iteration+1
  46.       WEND
  47.       IF iteration=max_iteration THEN
  48.         color=0
  49.         brot!(px,py)=TRUE
  50.       ELSE
  51.         color=iteration MOD 15
  52.         color=color+1
  53.         brot!(px,py)=FALSE
  54.       ENDIF
  55.       COLOR color
  56.       PLOT px,py
  57.       pixels%(px,py)=iteration
  58.       IF MOUSEK=2 THEN
  59.         END
  60.       ENDIF
  61.     NEXT px
  62.   NEXT py
  63. RETURN
  64. PROCEDURE mandelmenu(VAR x1,y1,x2,y2)
  65.   BMOVE brot%,XBIOS(2),32000
  66.   SETCOLOR 0,0,0,0
  67.   SETCOLOR 15,7,7,7
  68.   foo=EVNT_BUTTON(1,1,1,mx%,my%,bu%,kb%)
  69.   foo=GRAF_RUBBERBOX(mx%,my%,1,1,w%,h%)
  70.   PRINT "x:";mx%;" y:";my%;" w:";w%;" h:";h%
  71.   x1=3.5/320*mx%-2.5
  72.   y1=2.4/200*my%-1.2
  73.   x2=3.5/320*(mx%+w%)-2.5
  74.   y2=2.4/200*(my%+h%)-1.2
  75.   PRINT "p1:";x1;",";y1;" p2:";x2;",";y2
  76. RETURN
  77. PROCEDURE brotpack
  78.   DIM bsum%(8)
  79.   FOR y%=0 TO 199
  80.     FOR x%=0 TO 319 STEP 8
  81.       FOR bit%=0 TO 7
  82.         b%=brot!(x%+bit%,y%)*bsum%(bit%)
  83.       NEXT bit%
  84.     NEXT x%
  85.   NEXT y%
  86. RETURN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement