News:

Welcome to RetroCoders Community

Main Menu

AlienMandelbrot

Started by aurel, May 25, 2023, 02:57 PM

Previous topic - Next topic

aurel

Did you ever see such a ugly and alien mandelbrot
 ;D
WOULD YOU LIKE TO KNOW MORE?
basic4us.epizy.com/forum/index.php

ron77


aurel

and here is code based on old toy interpreter

' Ed Davis toyMandel from o2Toy Interpreter 
var x, y, i, zm, miter, zx, zy, cx, cy, tmp,r,g,b,zxy
x      = 0
y      = 0
i      = 0
zm     = 30
miter  = 5
zx     = 0
zy     = 0
cx     = 0
cy     = 0
tmp    = 0

y = 0
while y < 480
  x = 0
  while x < 640 
    zx=0.1
    zy=0.1
    cx= (x-320)/zm
    cy= (y-240)/zm
    i = miter
    zxy = zx*zx+zy*zy
    while zxy < 4 & i > 0
      tmp = zx * zx - zy * zy + cx+0.1
      zy = 1.73 * zx * zy + cy
      zx = tmp
      i=i-1
    wend
    r=tmp+i*4 : g=tmp +i*8 : b=i*12
    fcolor r,g,b
    rect x, y,2,2 
    x = x + 2
    'swap
  wend
swap
  y = y + 2

wend
 
WOULD YOU LIKE TO KNOW MORE?
basic4us.epizy.com/forum/index.php

aurel

OMG
this must be mandelbrot core ...and looks fine
WOULD YOU LIKE TO KNOW MORE?
basic4us.epizy.com/forum/index.php

ron77

Hi Aurel  8)

here is a Mandelbrot in freebasic...

You cannot view this attachment.

code:

SCREEN 12 ' Set graphics mode

CONST width2 AS INTEGER = 800
CONST height AS INTEGER = 600
CONST maxIterations AS INTEGER = 1000

DIM SHARED AS INTEGER buffer(width2, height)

FUNCTION Mandelbrot(cX AS DOUBLE, cY AS DOUBLE) AS INTEGER
    DIM AS DOUBLE zx, zy, tmp, zX2, zY2
    DIM AS INTEGER i
    
    zx = 0.0
    zy = 0.0
    
    FOR i = 0 TO maxIterations - 1
        zX2 = zx * zx
        zY2 = zy * zy
        
        IF (zX2 + zY2) > 4.0 THEN
            RETURN i
        END IF
        
        tmp = zX2 - zY2 + cX
        zy = 2.0 * zx * zy + cY
        zx = tmp
    NEXT
    
    RETURN maxIterations
END FUNCTION

SUB DrawMandelbrot()
    DIM AS DOUBLE minX = -2.5, maxX = 1.0
    DIM AS DOUBLE minY = -1.0, maxY = 1.0
    DIM AS DOUBLE dx = (maxX - minX) / width2
    DIM AS DOUBLE dy = (maxY - minY) / height
    
    DIM AS DOUBLE x, y
    DIM AS INTEGER i, j, iteration
    
    FOR j = 0 TO height - 1
        FOR i = 0 TO width2 - 1
            x = minX + i * dx
            y = minY + j * dy
            
            iteration = Mandelbrot(x, y)
            
            IF iteration = maxIterations THEN
                buffer(i, j) = 0 ' Set pixel to black if it is in the set
            ELSE
                buffer(i, j) = iteration ' Set pixel color based on the number of iterations
            END IF
        NEXT
    NEXT
END SUB

SUB RenderMandelbrot()
    DIM AS INTEGER x, y
    
    FOR y = 0 TO height - 1
        FOR x = 0 TO width2 - 1
            PSET (x, y), buffer(x, y)
        NEXT
    NEXT
    
    SLEEP
END SUB

DrawMandelbrot()
RenderMandelbrot()

aurel

wow that one is big
and code is different and much more complex.
As i said this one i show was from old Toy Interpreter
written by Ed Davis and in toy looking good
WOULD YOU LIKE TO KNOW MORE?
basic4us.epizy.com/forum/index.php

aurel

here is a toy code:
float x, y, i, zm, miter, zx, zy, cx, cy, tmp
wcolor 0,0,0
x      = 0
y      = 0
i      = 0
zm    = 120
miter  = 60
zx    = 0
zy    = 0
cx    = 0
cy    = 0
tmp    = 0

y = 0
while y <= 479 
  x = 0
  while x <= 639 
    zx=0
    zy=0
    cx= (x-320)/zm
    cy= (y-240)/zm
    i = miter
    while zx*zx+zy*zy <4 and i >0 
      tmp = zx * zx - zy * zy + cx+0.01
      zy = 1.73 * zx * zy + cy
      zx = tmp
      i=i-1
    wend
    'pset x, y, rgb(i*12,i*8,i*4)
    frontpen i*12,i*8,i*4
    rect x,y,2,2
    
    x = x + 1
  wend
  y = y + 1
wend
 
WOULD YOU LIKE TO KNOW MORE?
basic4us.epizy.com/forum/index.php

ZXDunny

For a change, this is a SpecBAS code that's way bigger than usual - a Mandelbrot with optimisations, a random palette and adaptable iteration count based on zoom level:

10 DEF FN r=MIN(INT(RND*5)*64,255): PROC rain
20 xmin=-2,ymin=-1.5,xmax=1.5,ymax=1.5,hs=0:
 INK 0:
 DIM xm(),ym(),xn(),yn()
30 OVER 0:
 GO SUB 40:
 PROC getinput:
 GO TO 30
40 PROC aspect(xmin,xmax,ymin,ymax):
 hs+=1,xn(hs)=xmin,yn(hs)=ymin,xm(hs)=xmax,ym(hs)=ymax
50 maxiters=INT(5*(1.5^(ABS(LN((xmax-xmin)/SCRw))))),xs=(xmax-xmin)/SCRw,ys=(ymax-ymin)/SCRh
60 y1=ymin:
 FOR y=0 TO SCRh-1:
    x1=xmin:
    FOR x=0 TO SCRw-1:
       u,v,n=0:
       p2y=y1*y1,q=POWERTWO(x1-0.25)+p2y:
       IF POWERTWO(x1+1)+p2y<1/16 OR q*(q+(x1-0.25))<p2y/4 THEN
          PLOT x,y: x1+=xs:
          NEXT x:
          y1+=ys:
          NEXT y:
          RETURN
       ELSE
          zr=x1,zi=y1,p=0,ptot=8
70       ckr=zr,cki=zi,ptot+=ptot:
       IF ptot>maxiters THEN
          ptot=maxiters
80       p+=1,tmp=zr*zr-zi*zi+x1,zi=(zi*2*zr)+y1,zr=tmp
90       IF zr*zr+zi*zi>4 THEN
          PLOT INK p;x,y: x1+=xs:
          NEXT x:
          y1+=ys:
          NEXT y:
          RETURN
       ELSE
          IF zr=ckr AND zi=cki THEN
             PLOT x,y: x1+=xs:
             NEXT x:
             y1+=ys:
             NEXT y:
             RETURN
          ELSE
             IF p<ptot THEN
                GO TO 80
             ELSE
                IF ptot<>maxiters THEN
                   GO TO 70
                ELSE
                   PLOT x,y:
                   INC x1,xs:
                   NEXT x:
                   INC y1,ys:
                   NEXT y:
                   RETURN
100 DEF PROC aspect(REF xmin,REF xmax,REF ymin,REF ymax):
    w=xmax-xmin,h=ymax-ymin,rs=SCRw/SCRh,rr=w/h,nw=w,nh=h:
    IF rr<rs THEN
       nw=h*rs
    ELSE
       nh=w/rs:
    END IF:
    wa=ABS(nw-w)/2,ha=ABS(nh-h)/2,xmin-=wa,xmax+=wa,ymin-=ha,ymax+=ha:
 END PROC
110 DEF PROC getinput
120    mw=MOUSEWHEEL:
    OVER 1:
    DO:
   YIELD:
       IF INKEY$="p" THEN
          PROC rain:
          DO:
          LOOP UNTIL INKEY$<>"p"
       ELSE
          IF KEYST KEY_C THEN
             PALETTE SHL 1,1 TO 255:
             WAIT SCREEN
          ELSE
             IF MOUSEWHEEL<>mw THEN
                IF MOUSEWHEEL<mw THEN
                   PALETTE SHL 1,1 TO 255
                ELSE
                   PALETTE SHR 1,1 TO 255:
                END IF:
                mw=MOUSEWHEEL
130    LOOP UNTIL MOUSEBTN<>0:
    x1=MOUSEx,y1=MOUSEy
140    IF MOUSEBTN=2 THEN
       IF hs>1 THEN
          hs-=1,xmin=xn(hs),ymin=yn(hs),xmax=xm(hs),ymax=ym(hs),hs-=1:
          GO TO 200
       ELSE
          GO TO 120
150    x2=MOUSEx,y2=MOUSEy:
    RECTANGLE ink 255;x1,y1 TO x2,y2 FILL
160    DO:
       WAIT SCREEN:
    LOOP UNTIL MOUSEdx<>0 OR MOUSEdy<>0 OR MOUSEBTN=0
170    RECTANGLE ink 255;x1,y1 TO x2,y2 FILL:
    IF MOUSEBTN<>0 THEN
       GO TO 150
    ELSE
       IF x1=x2 OR y1=y2 THEN
          GO TO 120
180    IF x1>x2 THEN
       SWAP x1,x2:
    END IF:
    IF y1>y2 THEN
       SWAP y1,y2
190    xs=(xmax-xmin)/SCRw,ys=(ymax-ymin)/SCRh,
    xa=xmin+(xs*x1),
    xmax=xmin+(xs*x2),xmin=xa,ya=ymin+(ys*y1),
    ymax=ymin+(ys*y2),ymin=ya
200 END PROC
210 DEF PROC rain:
    b=2 SHL (INT(RND*4)+2),bs=256/b:
    FOR i=0 TO b-1:
       PALETTE i*bs,FN r,FN r,FN r:
    NEXT i:
    FOR i=0 TO b-1:
       j=i*bs:
       RAINBOW j TO j+bs:
    NEXT i:
    PALETTE 0,0,0,0:
 END PROC

Line 50 sets the iterations, lines 60 to 90 draw the brot. The rest is UI stuff. Click and drag to zoom.


aurel

WOULD YOU LIKE TO KNOW MORE?
basic4us.epizy.com/forum/index.php