Julia RingsAuthor: Relsoft
Source: [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] Forum
URL:
/forum/index.php?topic=128.0]http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=128.0Version: QB64
Tags: [fractal] [julia set]
Description:
Automated Julia set explorer.Source Code:
' The Lord of the Julia Rings
' The Fellowship of the Julia Ring
' Free Basic
' Relsoft
' Rel.BetterWebber.com
'
' Converted to QB64 format by Galleon (FB specific code commented)
''$include: 'TinyPTC.bi'
''$include: 'user32.bi'
'option explicit
CONST SCR_WIDTH
= 320 * 2 CONST SCR_HEIGHT
= 240 * 2
CONST SCR_SIZE
= SCR_WIDTH
* SCR_HEIGHT
CONST SCR_MIDX
= SCR_WIDTH \
2 CONST SCR_MIDY
= SCR_HEIGHT \
2
'if( ptc_open( "FreeBASIC Julia (Relsoft)", SCR_WIDTH, SCR_HEIGHT ) = 0 ) then
' end -1
'end if
'pointers to array "buffer"
'dim p_buffer as long ptr, p_bufferl as long ptr
xmin = -2.0
xmax = 2.0
ymin = -1.5
ymax = 1.5
deltax = (xmax - xmin) / (SCR_WIDTH - 1)
deltay = (ymax - ymin) / (SCR_HEIGHT - 1)
FOR i
= 0 TO SCR_WIDTH
- 1 Lx(i) = xmin + i * deltax
FOR i
= 0 TO SCR_HEIGHT
- 1 Ly(i) = ymax - i * deltay
FOR i
= 0 TO SCR_SIZE
- 1
'dim hwnd as long
'hwnd = GetActiveWindow
' p_buffer = @buffer(0)
' p_bufferl = @buffer(SCR_SIZE-1)
frame
= (frame
+ 1) AND &H7FFFFFFF theta = frame * PI / 180
p
= COS(theta
) * SIN(theta
* .7) p = p * .6
q = q * .6
cmag
= SQR(p
* p
+ q
* q
) cmagsq = (p * p + q * q)
drad = 0.04
drad_L = (cmag - drad)
drad_L = drad_L * drad_L
drad_H = (cmag + drad)
drad_H = drad_H * drad_H
FOR py
= 0 TO (SCR_HEIGHT \
2) - 1 ty = Ly(py)
FOR px
= 0 TO SCR_WIDTH
- 1 x = Lx(px)
y = ty
xsquare = 0
ysquare = 0
ztot = 0
i = 0
WHILE (i
< MAXITER
) AND ((xsquare
+ ysquare
) < MAXSIZE
) xsquare = x * x
ysquare = y * y
ytemp = x * y * 2
x = xsquare - ysquare + p
y = ytemp + q
zmag = (x * x + y * y)
ztot
= ztot
+ (1 - (ABS(zmag
- cmagsq
) / drad
)) i_last = i
i = i + 1
i = 0
red = i
red = 255
grn = i - 256
grn = 255
grn = 0
blu = i - 512
blu = 255
blu = 0
tmp
= INT((red
+ grn
+ blu
) \
3) red
= INT((red
+ grn
+ tmp
) \
3) grn
= INT((grn
+ blu
+ tmp
) \
3) blu
= INT((blu
+ red
+ tmp
) \
3)
tmp = red
red = grn
grn = blu
blu = tmp
tmp = red
blu = grn
red = blu
grn = tmp
'pixel = red shl 16 or grn shl 8 or blu
'*p_buffer = pixel
'*p_bufferl = pixel
'p_buffer = p_buffer + Len(long)
'p_bufferl = p_bufferl - Len(long)
PSET (SCR_WIDTH
- 1 - px
, SCR_HEIGHT
- 1 - py
), pixel
'calc fps
Fps = Fps + 1
Fps2 = Fps
Fps = 0
' SetWindowText hwnd, "FreeBasic Julia Rings FPS:" + str$(Fps2)
'ptc_update @buffer(0)
'ptc_close