'> Merged with Zom-B's smart $include merger 0.51
'####################################################################################################################
'# Math Library V1.0 (include)
'# By Zom-B
'####################################################################################################################
CONST sqrt2
= 1.41421356237309504880168872420969807856967187537695 ' Knuth01 CONST sqrt3
= 1.73205080756887729352744634150587236694280525381038 ' Knuth02 CONST sqrt5
= 2.23606797749978969640917366873127623544061835961153 ' Knuth03 CONST sqrt10
= 3.16227766016837933199889354443271853371955513932522 ' Knuth04 CONST cubert2
= 1.25992104989487316476721060727822835057025146470151 ' Knuth05 CONST cubert3
= 1.44224957030740838232163831078010958839186925349935 ' Knuth06 CONST q2pow025
= 1.18920711500272106671749997056047591529297209246382 ' Knuth07 CONST phi
= 1.61803398874989484820458683436563811772030917980576 ' Knuth08 CONST log2
= 0.69314718055994530941723212145817656807550013436026 ' Knuth09 CONST log3
= 1.09861228866810969139524523692252570464749055782275 ' Knuth10 CONST log10
= 2.30258509299404568401799145468436420760110148862877 ' Knuth11 CONST logpi
= 1.14472988584940017414342735135305871164729481291531 ' Knuth12 CONST logphi
= 0.48121182505960344749775891342436842313518433438566 ' Knuth13 CONST q1log2
= 1.44269504088896340735992468100189213742664595415299 ' Knuth14 CONST q1log10
= 0.43429448190325182765112891891660508229439700580367 ' Knuth15 CONST q1logphi
= 2.07808692123502753760132260611779576774219226778328 ' Knuth16 CONST pi
= 3.14159265358979323846264338327950288419716939937511 ' Knuth17 CONST deg2rad
= 0.01745329251994329576923690768488612713442871888542 ' Knuth18 CONST q1pi
= 0.31830988618379067153776752674502872406891929148091 ' Knuth19 CONST pisqr
= 9.86960440108935861883449099987615113531369940724079 ' Knuth20 CONST gamma05
= 1.7724538509055160272981674833411451827975494561224 ' Knuth21 CONST gamma033
= 2.6789385347077476336556929409746776441286893779573 ' Knuth22 CONST gamma067
= 1.3541179394264004169452880281545137855193272660568 ' Knuth23 CONST e
= 2.71828182845904523536028747135266249775724709369996 ' Knuth24 CONST q1e
= 0.36787944117144232159552377016146086744581113103177 ' Knuth25 CONST esqr
= 7.38905609893065022723042746057500781318031557055185 ' Knuth26 CONST eulergamma
= 0.57721566490153286060651209008240243104215933593992 ' Knuth27 CONST expeulergamma
= 1.7810724179901979852365041031071795491696452143034 ' Knuth28 CONST exppi025
= 2.19328005073801545655976965927873822346163764199427 ' Knuth29 CONST sin1
= 0.84147098480789650665250232163029899962256306079837 ' Knuth30 CONST cos1
= 0.54030230586813971740093660744297660373231042061792 ' Knuth31 CONST zeta3
= 1.2020569031595942853997381615114499907649862923405 ' Knuth32 CONST nloglog2
= 0.36651292058166432701243915823266946945426344783711 ' Knuth33
CONST logr10
= 0.43429448190325182765112891891660508229439700580367 CONST logr2
= 1.44269504088896340735992468100189213742664595415299 CONST pi05
= 1.57079632679489661923132169163975144209858469968755 CONST pi2
= 6.28318530717958647692528676655900576839433879875021 CONST q05log10
= 0.21714724095162591382556445945830254114719850290183 CONST q05log2
= 0.72134752044448170367996234050094606871332297707649 CONST q05pi
= 0.15915494309189533576888376337251436203445964574046 CONST q13
= 0.33333333333333333333333333333333333333333333333333 CONST q16
= 0.16666666666666666666666666666666666666666666666667 CONST q2pi
= 0.63661977236758134307553505349005744813783858296183 CONST q2sqrt5
= 0.89442719099991587856366946749251049417624734384461 CONST rad2deg
= 57.2957795130823208767981548141051703324054724665643 CONST sqrt02
= 0.44721359549995793928183473374625524708812367192231 CONST sqrt05
= 0.70710678118654752440084436210484903928483593768847 CONST sqrt075
= 0.86602540378443864676372317075293618347140262690519 CONST y2q112
= 1.05946309435929526456182529494634170077920431749419 ' Chromatic base
'####################################################################################################################
'# Screen mode selector v1.0 (include)
'# By Zom-B
'####################################################################################################################
videoaspect:
videomodes:
'####################################################################################################################
'# Ultra Fractal Gradient library v1.0 (include)
'# By Zom-B
'#
'# Smooth Gradient algorithm from Ultra Fractal (www.ultrafractal.com)
'####################################################################################################################
'$dynamic
'####################################################################################################################
'# Sierpinsky Rays+aet for QB64
'# By Zom-B
'#
'# Original art by Daniele (alcamese@libero.it)
'# Tweaked by Athena Tracey (athena_1963@hotmail.com)
'####################################################################################################################
'####################################################################################################################
PRINT TAB(18);
"Original art by Daniele (alcamese@libero.it)" PRINT TAB(15);
"Tweaked by Athena Tracey (athena_1963@hotmail.com)" PRINT TAB(19);
"Converted to Quick Basic and QB64 by Zom-B"
selectScreenMode 7, 32
'####################################################################################################################
maxX% = sizeX% - 1
maxY% = sizeY% - 1
halfX% = sizeX% \ 2
halfY% = sizeY% \ 2
magX = 1.300052002080083203328133125325 / halfY%
magY = 1.300052002080083203328133125325 / halfY%
'####################################################################################################################
setNumGradients 5
addGradientPoint 0, -0.0450, 0.710, 1.000, 1.000
addGradientPoint 0, 0.0025, 1.000, 0.702, 0.729
addGradientPoint 0, 0.0850, 0.082, 0.431, 0.000
addGradientPoint 0, 0.2300, 0.812, 0.745, 0.824
addGradientPoint 0, 0.5500, 0.380, 0.000, 0.000
addGradientPoint 0, 0.7600, 1.000, 0.757, 1.000
addGradientPoint 0, 0.8800, 0.000, 0.263, 0.000
addGradientPoint 0, 0.9550, 0.710, 1.000, 1.000
addGradientPoint 0, 1.0025, 1.000, 0.702, 0.729
setGradientSmooth 0, -1
addGradientPoint 1, -0.0450, 0.165, 0.000, 0.184
addGradientPoint 1, 0.7475, 0.718, 0.918, 1.000
addGradientPoint 1, 0.8425, 0.945, 0.710, 1.000
addGradientPoint 1, 0.9550, 0.165, 0.000, 0.184
addGradientPoint 1, 1.7475, 0.718, 0.918, 1.000
setGradientSmooth 1, -1
addGradientPoint 2, -0.2750, 0.000, 0.973, 0.114
addGradientPoint 2, 0.0475, 1.000, 0.545, 0.875
addGradientPoint 2, 0.1725, 0.000, 0.345, 0.000
addGradientPoint 2, 0.5500, 1.000, 0.071, 1.000
addGradientPoint 2, 0.7250, 0.000, 0.973, 0.114
addGradientPoint 2, 1.0475, 1.000, 0.545, 0.875
setGradientSmooth 2, -1
addGradientPoint 3, -0.0675, 1.000, 0.502, 1.000
addGradientPoint 3, 0.0700, 0.000, 0.000, 0.698
addGradientPoint 3, 0.1650, 0.725, 0.741, 0.000
addGradientPoint 3, 0.3300, 0.290, 0.000, 0.757
addGradientPoint 3, 0.4550, 0.000, 0.251, 0.039
addGradientPoint 3, 0.6375, 0.584, 0.918, 1.000
addGradientPoint 3, 0.8250, 0.000, 0.165, 0.000
addGradientPoint 3, 0.9325, 1.000, 0.502, 1.000
addGradientPoint 3, 1.0700, 0.000, 0.000, 0.698
setGradientSmooth 3, -1
addGradientPoint 4, -0.1025, 1.000, 0.282, 0.082
addGradientPoint 4, 0.0775, 0.306, 0.376, 1.000
addGradientPoint 4, 0.2225, 0.333, 0.298, 0.000
addGradientPoint 4, 0.3000, 1.000, 1.000, 0.208
addGradientPoint 4, 0.3800, 0.337, 0.271, 0.741
addGradientPoint 4, 0.6400, 0.651, 0.404, 0.220
addGradientPoint 4, 0.8075, 0.000, 1.000, 1.000
addGradientPoint 4, 0.8975, 1.000, 0.282, 0.082
addGradientPoint 4, 1.0775, 0.306, 0.376, 1.000
setGradientSmooth 4, -1
renderProgressive 256, 4
'####################################################################################################################
SUB renderProgressive
(startSize%
, endSize%
) pixStep% = startSize%
pixWidth% = pixStep% - 1
calcPoint x%, y%, r%, g%, b%
LINE (x%
, y%
)-STEP(pixWidth%
, pixWidth%
), _RGB(r%
, g%
, b%
), BF
pixSize% = pixStep% \ 2
pixWidth% = pixSize% - 1
y1% = y% + pixSize%
x1% = x% + pixSize%
calcPoint x1%, y%, r%, g%, b%
LINE (x1%
, y%
)-STEP(pixWidth%
, pixWidth%
), _RGB(r%
, g%
, b%
), BF
calcPoint x%, y1%, r%, g%, b%
LINE (x%
, y1%
)-STEP(pixWidth%
, pixWidth%
), _RGB(r%
, g%
, b%
), BF
calcPoint x1%, y1%, r%, g%, b%
LINE (x1%
, y1%
)-STEP(pixWidth%
, pixWidth%
), _RGB(r%
, g%
, b%
), BF
pixStep% = pixStep% \ 2
y1% = y% + 1
x1% = x% + 1
calcPoint x1%, y%, r%, g%, b%
calcPoint x%, y1%, r%, g%, b%
calcPoint x1%, y1%, r%, g%, b%
endArea% = endSize% * endSize%
DO 'Marsaglia polar method for random gaussian s! = u! * u! + v! * v!
s!
= SQR(-2 * LOG(s!
) / s!
) * 0.5 u! = u! * s!
v! = v! * s!
calcPoint x% + u!, y% + v!, r1%, g1%, b1%
r% = r% + r1%
g% = g% + g1%
b% = b% + b1%
r% = 0
g% = 0
b% = 0
FOR v%
= 0 TO endSize%
- 1 y1! = y% + v% / endSize%
FOR u%
= 0 TO endSize%
- 1 x1! = x% + u% / endSize%
calcPoint x1!, y1!, r1%, g1%, b1%
r% = r% + r1%
g% = g% + g1%
b% = b% + b1%
'####################################################################################################################
SUB calcPoint
(screenX!
, screenY!
, r%
, g%
, b%
) applyLocation screenX!, screenY!, px, py
fractal px, py, numIter1%, numIter2%
outside1 numIter1%, index!
getGradient 0, index!, r!, g!, b!
outside2 numIter2%, index!
getGradient 1, index!, r2!, g2!, b2!
r!
= ABS(r!
- r2!
): g!
= ABS(g!
- g2!
): b!
= ABS(b!
- b2!
)
outside3 numIter2%, index!
getGradient 2, index!, r2!, g2!, b2!
r1! = r!: g1! = g!: b1! = b!
mergeOverlay r!, g!, b!, r2!, g2!, b2!
r! = r1! + (r! - r1!) * 0.45
g! = g1! + (g! - g1!) * 0.45
b! = b1! + (b! - b1!) * 0.45
outside4 numIter2%, index!
getGradient 3, index!, r2!, g2!, b2!
r! = r! + r2!: g! = g! + g2!: b! = b! + b2!
outside5 px, py, numIter2%, index!
getGradient 4, index!, r2!, g2!, b2!
r1! = r!: g1! = g!: b1! = b!
mergeColor r!, g!, b!, r2!, g2!, b2!
r! = r1! + (r! - r1!) * 0.5
g! = g1! + (g! - g1!) * 0.5
b! = b1! + (b! - b1!) * 0.5
r% = r! * 255
g% = g! * 255
b% = b! * 255
'####################################################################################################################
SUB applyLocation
(inX!
, inY!
, outX
, outY
) x = (inX! - halfX%) * magX
y = (halfY% - inY!) * magY
outX = 0.99999998476912904932780850903444 * x - 1.7453292431333680334067268304459D-4 * y - 0.01168313399#
outY = 1.7453292431333680334067268304459D-4 * x + 0.99999998476912904932780850903444 * y - 0.00626625065#
'####################################################################################################################
SUB fractal
(px
, py
, numIter1%
, numIter2%
) xx = px * px: yy = py * py
x
= ABS(px
* xx
- 3 * px
* yy
) * 0.2 y
= ABS(3 * xx
* py
- py
* yy
) * 0.2 x
= x
- INT(x
* 2.5 + 0.5) * 0.4 y
= y
- INT(y
* 2.5 + 0.5) * 0.4
zx(0) = x: zy(0) = y
numIter1% = -1
numIter2% = -1
x = x * 2: y = y * 2
y = y - 1
x = x - 1
zx(numIter%) = x: zy(numIter%) = y
IF numIter2%
= -1 THEN numIter2%
= numIter%
- 1
IF numIter1%
= -1 THEN numIter1%
= numIter%
- 1
IF numIter1%
= -1 THEN numIter1%
= 149 IF numIter2%
= -1 THEN numIter2%
= 149
'####################################################################################################################
SUB outside1
(numIter%
, index!
) index!
= ATN(numIter%
/ 25)
'####################################################################################################################
SUB outside2
(numIter%
, index!
) closest = 1E+38
ix = 0
iy = 0
x = zx(a%) * zx(a%): y = zy(a%) * zy(a%)
d = x * x + y * y
closest = d
ix = zx(a%)
iy = zy(a%)
index!
= SQR(SQR(ix
* ix
+ iy
* iy
) * 2) / 2
'####################################################################################################################
SUB outside3
(numIter%
, index!
) x = zx(numIter% + 1)
y = zy(numIter% + 1)
d = atan2(y, x) / pi2
index!
= SQR((6.349563872353654#
- 4.284804271440222#
* LOG(LOG(SQR(x
* x
+ y
* y
))) + ABS((d
- INT(d
)) * 4 - 2)) * 2) / 2
'####################################################################################################################
SUB outside4
(numIter%
, index!
) closest = 1E+38
zy2 = zy(a%) * zy(a%)
d = zx(a%) + zx(a%) * zx(a%) + zy2
closest = d
index! = asin(closest ^ .1) ^ (1 / 1.5) * .41577394#
'####################################################################################################################
SUB outside5
(px
, py
, numIter%
, index!
) r
= SQR(px
* px
+ py
* py
) cost = px / r
sint = py / r
ave = 0
i% = 0
prevave = ave
x = zx(a%)
y = zy(a%)
x = zx(a%) / r + cost
y = zy(a%) / r + sint
ave
= ave
+ SQR(x
* x
+ y
* y
)
cost = -cost
sint = -sint
i% = i% + 1
ave = ave / numIter%
prevave = prevave / (numIter% - 1)
x = zx(numIter% + 1)
y = zy(numIter% + 1)
f
= 2.2762545841680618369458486886285 - 1.4426950408889634073599246810019 * LOG(LOG(SQR(x
* x
+ y
* y
))) index! = prevave + (ave - prevave) * f
index! = index! * 2
'####################################################################################################################
'# Math Library V0.11 (routines)
'# By Zom-B
'####################################################################################################################
'> merger: Skipping unused FUNCTION remainder% (a%, b%)
'> merger: Skipping unused FUNCTION fRemainder (a, b)
'####################################################################################################################
'> merger: Skipping unused FUNCTION safeLog (x)
'####################################################################################################################
asin
= ATN(y
/ SQR(1 - y
* y
))
'> merger: Skipping unused FUNCTION acos (y)
'> merger: Skipping unused FUNCTION safeAcos (y)
atan2 = pi / 2
atan2 = -pi / 2
'####################################################################################################################
'# Screen mode selector v1.0 (routines)
'# By Zom-B
'####################################################################################################################
SUB selectScreenMode
(yOffset%
, colors%
) DIM aspectName$
(10), aspectCol%
(10) READ aspectName$
(y%
), aspectCol%
(y%
)
DIM vidX%
(100), vidY%
(100), vidA%
(100) READ vidX%
(y%
), vidY%
(y%
), vidA%
(y%
)
PRINT "Select video mode:";
TAB(61);
"Click " POKE yOffset%
* 160 + 132, 31
y% = 0
lastY% = 0
selectedAspect% = 0
reprint% = 1
lastButton% = 0
reprint% = 0
COLOR aspectCol%
(vidA%
(x%
))
PRINT "<"; aspectName$
(x%
);
">"
y% = (yOffset% + y%) * 160 + 1
y% = 0
selectedAspect% = y% - 1
reprint% = 1
y% = (yOffset% + y%) * 160 + 1
y% = 0
lastY% = y%
CLS 'bug evasion for small video modes
'####################################################################################################################
'# Ultra Fractal Gradient library v1.1 (routines)
'# By Zom-B
'#
'# Smooth Gradient algorithm from Ultra Fractal (www.ultrafractal.com)
'####################################################################################################################
'> merger: Skipping unused SUB defaultGradient (gi%)
'> merger: Skipping unused SUB grayscaleGradient (gi%)
'####################################################################################################################
SUB setNumGradients
(gi%
) offset%
= LBOUND(gradientPoints
) - 1
SUB addGradientPoint
(gi%
, index!
, r!
, g!
, b!
) p% = gradientPoints(gi%)
gradient(gi%, p%).index = index!
gradient(gi%, p%).r = r!
gradient(gi%, p%).g = g!
gradient(gi%, p%).b = b!
gradientPoints(gi%) = p% + 1
SUB setGradientSmooth
(gi%
, s%
) gradientSmooth(gi%) = s%
FOR i%
= 0 TO gradientPoints
(gi%
) - 1 ip1% = i% + 1
IF ip1%
= gradientPoints
(gi%
) THEN ip1%
= 2 in1% = i% - 1
IF in1%
= -1 THEN in1%
= gradientPoints
(gi%
) - 3
dxl! = gradient(gi%, i%).index - gradient(gi%, in1%).index
dxr! = gradient(gi%, ip1%).index - gradient(gi%, i%).index
IF dxl!
< 0 THEN dxl!
= dxl!
+ 1 IF dxr!
< 0 THEN dxr!
= dxr!
+ 1
d! = (gradient(gi%, i%).r - gradient(gi%, in1%).r) * dxr!
gradient(gi%, i%).rdr = 0
gradient(gi%, i%).rdl = 0
d! = (gradient(gi%, ip1%).r - gradient(gi%, i%).r) * dxl! / d!
gradient(gi%, i%).rdr = 0
gradient(gi%, i%).rdl = 0
gradient(gi%, i%).rdr = 1 / (1 + d!)
gradient(gi%, i%).rdl = gradient(gi%, i%).rdr - 1
d! = (gradient(gi%, i%).g - gradient(gi%, in1%).g) * dxr!
gradient(gi%, i%).gdr = 0
gradient(gi%, i%).gdl = 0
d! = (gradient(gi%, ip1%).g - gradient(gi%, i%).g) * dxl! / d!
gradient(gi%, i%).gdr = 0
gradient(gi%, i%).gdl = 0
gradient(gi%, i%).gdr = 1 / (1 + d!)
gradient(gi%, i%).gdl = gradient(gi%, i%).gdr - 1
d! = (gradient(gi%, i%).b - gradient(gi%, in1%).b) * dxr!
gradient(gi%, i%).bdr = 0
gradient(gi%, i%).bdl = 0
d! = (gradient(gi%, ip1%).b - gradient(gi%, i%).b) * dxl! / d!
gradient(gi%, i%).bdr = 0
gradient(gi%, i%).bdl = 0
gradient(gi%, i%).bdr = 1 / (1 + d!)
gradient(gi%, i%).bdl = gradient(gi%, i%).bdr - 1
'####################################################################################################################
SUB getGradient
(gi%
, index!
, red!
, green!
, blue!
)
FOR l%
= gradientPoints
(gi%
) - 2 TO 1 STEP -1 IF gradient
(gi%
, l%
).index
<= x!
THEN
r% = l% + 1
u! = (x! - gradient(gi%, l%).index) / (gradient(gi%, r%).index - gradient(gi%, l%).index)
u2! = u! * u!
u3! = u2! * u!
ur! = u3! - (u2! + u2!) + u!
ul! = u2! - u3!
red! = gradient(gi%, l%).r + (gradient(gi%, r%).r - gradient(gi%, l%).r) * (u3! + 3 * (gradient(gi%, l%).rdr * ur! + (1 + gradient(gi%, r%).rdl) * ul!))
green! = gradient(gi%, l%).g + (gradient(gi%, r%).g - gradient(gi%, l%).g) * (u3! + 3 * (gradient(gi%, l%).gdr * ur! + (1 + gradient(gi%, r%).gdl) * ul!))
blue! = gradient(gi%, l%).b + (gradient(gi%, r%).b - gradient(gi%, l%).b) * (u3! + 3 * (gradient(gi%, l%).bdr * ur! + (1 + gradient(gi%, r%).bdl) * ul!))
red! = gradient(gi%, l%).r + (gradient(gi%, r%).r - gradient(gi%, l%).r) * u!
green! = gradient(gi%, l%).g + (gradient(gi%, r%).g - gradient(gi%, l%).g) * u!
blue! = gradient(gi%, l%).b + (gradient(gi%, r%).b - gradient(gi%, l%).b) * u!
'> merger: Skipping unused SUB testGradient (gi%)
'####################################################################################################################
'# Merge modes library v0.1 (routines)
'# By Zom-B
'####################################################################################################################
'> merger: Skipping unused SUB testMerge
'####################################################################################################################
SUB mergeOverlay
(br!
, bg!
, bb!
, tr!
, tg!
, tb!
) IF br!
<= 0.5 THEN br!
= br!
* tr!
* 2 ELSE br!
= 1 - (1 - br!
) * (1 - tr!
) * 2 IF bg!
<= 0.5 THEN bg!
= bg!
* tg!
* 2 ELSE bg!
= 1 - (1 - bg!
) * (1 - tg!
) * 2 IF bb!
<= 0.5 THEN bb!
= bb!
* tb!
* 2 ELSE bb!
= 1 - (1 - bb!
) * (1 - tb!
) * 2
'> merger: Skipping unused SUB mergeHardLight (br!, bg!, bb!, tr!, tg!, tb!)
'> merger: Skipping unused SUB mergeSoftLight (br!, bg!, bb!, tr!, tg!, tb!)
SUB mergeColor
(r!
, g!
, b!
, r2!
, g2!
, b2!
) max! = r!
min! = r!
lum1! = max! + min!
max! = r2!
min! = r2!
sum! = max! + min!
dif! = max! - min!
sat2! = dif! / sum!
sat2! = dif! / (2 - sum!)
lum1! = lum1! * 0.5
r! = lum1!: g! = lum1!: b! = lum1!
chr! = sat2! * lum1!
chr! = sat2! * (2 - lum1!)
min! = (lum1! - chr!) * 0.5
hue2! = (g2! - b2!) / dif!
r! = chr! + min!: g! = min!: b! = chr! * -hue2! + min!
r! = chr! + min!: g! = chr! * hue2! + min!: b! = min!
hue2! = (b2! - r2!) / dif!
r! = chr! * -hue2! + min!: g! = chr! + min!: b! = min!
r! = min!: g! = chr! + min!: b! = chr! * hue2! + min!
hue2! = (r2! - g2!) / dif!
r! = min!: g! = chr! * -hue2! + min!: b! = chr! + min!
r! = chr! * hue2! + min!: g! = min!: b! = chr! + min!
'> merger: Skipping unused SUB mergeHSLAddition (r!, g!, b!, r2!, g2!, b2!)
'####################################################################################################################
'> merger: Skipping unused SUB mergeHue (r!, g!, b!, r2!, g2!, b2!)
'> merger: Skipping unused SUB rgb2hsl (r!, g!, b!, chr!, smallest!, hue!, sat!, lum!)
'> merger: Skipping unused SUB hsl2rgb (hue!, sat!, lum!, r!, g!, b!)
'> merger: Skipping unused SUB hsl2rgb2 (hue!, chr!, smallest!, r!, g!, b!)