News:

Welcome to RetroCoders Community

Main Menu

FB Mandelbrot Set

Started by ron77, Feb 12, 2023, 01:05 PM

Previous topic - Next topic

ron77

#INCLUDE "fbgfx.bi"


CONST AS INTEGER WIDTH_screen = 1000
CONST AS INTEGER HEIGHT_screen = 1000

DIM SHARED AS double min_num = -2.84
DIM SHARED as double max_num = 1.0
DIM SHARED AS double factor = 1
DIM SHARED AS INTEGER MAX_ITERATIONS = 200


function map( value AS double, in_min AS Double, in_max AS Double, out_min AS double, out_max AS Double) AS double

    return (value - in_min) * (out_max - out_min) / (in_max - out_max) + out_min

END FUNCTION



SUB PRINTtoSCREEN(x AS INTEGER, y AS INTEGER, red AS Ulong, green AS Ulong, blue AS ULONG)

   pset(x,y),RGBA(red,green,blue,255)

END SUB



SUB main()

   SCREENRES WIDTH_SCREEN, HEIGHT_SCREEN, 32

   DIM counter AS INTEGER = 0
  

   WHILE TRUE:

      max_num -= 0.1*factor
      min_num += 0.15 * factor

      factor *= 0.9349

      MAX_ITERATIONS += 5
      

      FOR x AS INTEGER = 0 TO WIDTH_SCREEN - 1
         FOR y AS INTEGER = 0 TO HEIGHT_screen - 1
            IF INKEY() = "q" THEN END
            
            DIM AS double a = map(x, 0, WIDTH_screen, min_num, max_num)
            DIM AS double b = map(y, 0, WIDTH_screen, min_num, max_num)
            DIM AS double ai = a
            DIM AS double bi = b

            DIM AS INTEGER n = 0

            FOR i AS INTEGER = 0 TO MAX_ITERATIONS

               DIM AS DOUBLE a1 = a * a - b * b
               DIM AS DOUBLE b1 = 2 * a * b

               a = a1 + ai
               b = b1 + bi

               IF ((a+ b) > 20 ) THEN EXIT FOR

               n += 1

            NEXT

            DIM bright AS INTEGER = (MAP(n, 0, MAX_ITERATIONS, 0 , 255))

            IF ((n = MAX_ITERATIONS)) THEN ' maybe add OR bright > 20

               bright = 0

            ENDIF


            'DIM AS ULONG red = MAP(bright * bright, 0 , 6502, 0, 255)
            'DIM AS ULONG green = bright
            'DIM AS ULONG blue = MAP(SQR(bright), 0, sqr(255), 0, 255)

            DIM AS Ubyte red = MAP(bright * bright, 0 , 6502, 0, 255)
            DIM AS Ubyte green = bright
            DIM AS Ubyte blue = MAP(SQR(bright), 0, sqr(255), 0, 255)
           

            SCREENLOCK()

            PRINTTOSCREEN(x,y,red,green,blue)

            SCREENUNLOCK()

         NEXT
      NEXT

      counter +=1

   WEND

END SUB

MAIN()

You cannot view this attachment.

CharlieJV

That's a beautiful thing, and I'll never get tired of seeing that in every incarnation.