
Task
Generate and draw a Julia set.




Related tasks
   Mandelbrot Set


 
#define pix 1./120
#define zero_x 320
#define zero_y 240
#define maxiter 250
 
type complex
    r as double
    i as double
end type
 
operator + (x as complex, y as complex) as complex
    dim as complex ret
    ret.r = x.r + y.r
    ret.i = x.i + y.i
    return ret
end operator
 
operator * (x as complex, y as complex) as complex
    dim as complex ret
    ret.r = x.r*y.r - x.i*y.i
    ret.i = x.r*y.i + x.i*y.r
    return ret
end operator
 
operator abs ( x as complex ) as double
    return sqr(x.r*x.r + x.i*x.i)
end operator
 
dim as complex c, z
dim as integer x, y, iter
 
input "Real part of c? ", c.r
input "Imaginary part of c? ", c.i
 
screen 12
 
for x=0 to 639
   for y=0 to 479
      z.r = (x-zero_x)*pix
      z.i = (y-zero_y)*pix
      for iter=0 to maxiter
          z = z*z + c
          if abs(z)>2 then
              pset(x,y),iter mod 16
              goto cont
          end if
       next iter
       pset(x,y),1
       cont:
    next y
next x
 
while inkey=""
wend
end