31
Programs / Re: courtesy cubes :)
« on: February 15, 2022, 05:30:20 pm »
wow nice! here is a nice screensaver us newbs here can appreciate. Now are the momenta and velocities gaussian distributed?
Join the live talk at Discord.
Be part of the conversation at
http://discord.qb64.org.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
You can't use a circle to solve that problem because the slope of the slope of the slope won't slope the slope of the sloping, making a sloping mess! All you can do is use a bezier curve to find the solution, and that's not possible with circles.
This is QB64 man! You don't have to Declare Sub nor "Call" Subs. :)
The IDE doesn't even cap Declare Sub, interesting...
if a> 5 then b = b +1
this can also be the case:
b = b + abs (a> 5)
I am not seeing all that cloud making code being activated which BTW came from here:
https://qb64forum.alephc.xyz/index.php?topic=4615.msg140454#msg140454
defdbl a-z
dim shared pi as double
pi = 4*atn(1)
sw = 800
sh = 600
screen _newimage(sw, sh, 32)
zoom = 100
a = 0.5
k = 0.09
sx = 2
sy = 1
tx = a*exp(k*16)*cos(16) + sx
ty = a*exp(k*16)*sin(16) + sy
x = a*exp(k*0)*cos(0) + sx - tx
y = a*exp(k*0)*sin(0) + sy - ty
r = sqr(x*x + y*y)
arg = _atan2(y, x)
for tt = r to 0 step -1
xl = tt*cos(arg)
yl = tt*sin(arg)
for yy=0 to sh
for xx=0 to sw
u = (xx - sw/2)/zoom
v = (sh/2 - yy)/zoom
cdiv uu, vv, u - xl, v - yl, u + xl, v + yl
clog uu, vv, uu, vv
mm = sqr(uu*uu + vv*vv)
aa = (pi + _atan2(vv, uu))/(2*pi)
pset (xx, yy), hrgb(aa, mm)
next
next
sleep
next
dim pp(5)
pp(5) = 0
pp(4) = 7
pp(3) = 10
pp(2) = 12
pp(1) = 15
pp(0) = 15.9
for ttt= 0 to 5
tt = pp(ttt)
for yy=0 to sh
for xx=0 to sw
u = (xx - sw/2)/zoom
v = (sh/2 - yy)/zoom
uu = 0
vv = 0
for t=tt to 16 step 0.1
x = a*exp(k*t)*cos(t) + sx - tx
y = a*exp(k*t)*sin(t) + sy - ty
cdiv p, q, 1, 0, x - u, y - v
dx = a*exp(k*t)*(k*cos(t) - sin(t))
dy = a*exp(k*t)*(k*sin(t) + cos(t))
cmul p, q, p, q, dx, dy
uu = uu + 0.1*p
vv = vv + 0.1*q
next
for t=16 - 0.1 to tt step -0.1
x =-a*exp(k*t)*cos(t) - sx + tx
y =-a*exp(k*t)*sin(t) - sy + ty
cdiv p, q, 1, 0, x - u, y - v
dx = a*exp(k*t)*(k*cos(t) - sin(t))
dy = a*exp(k*t)*(k*sin(t) + cos(t))
cmul p, q, p, q, dx, dy
uu = uu + 0.1*p
vv = vv + 0.1*q
next
cmul uu, vv, uu, vv, 0, -1/(2*pi)
mm = sqr(uu*uu + vv*vv)
aa = (pi + _atan2(vv, uu))/(2*pi)
pset (xx, yy), hrgb(aa, mm)
next
next
sleep
next
sleep
system
function hrgb&(h, m)
r = 0.5 - 0.5*sin(2*pi*h - pi/2)
g = (0.5 + 0.5*sin(2*pi*h*1.5 - pi/2)) * -(h < 0.66)
b = (0.5 + 0.5*sin(2*pi*h*1.5 + pi/2)) * -(h > 0.33)
n = 128
mm = m*10000 mod 500
p = abs((h*n) - int(h*n))
rr = 200*r - 0.15*mm - 35*p
gg = 200*g - 0.15*mm - 35*p
bb = 200*b - 0.15*mm - 35*p
if rr < 0 then rr = 0
if gg < 0 then gg = 0
if bb < 0 then bb = 0
hrgb& = _rgb(rr, gg, bb)
end function
function cosh#(x as double)
cosh# = 0.5*(exp(x) + exp(-x))
end function
function sinh#(x as double)
sinh# = 0.5*(exp(x) - exp(-x))
end function
'u + iv = (x + iy)^(a + ib)
sub cexp(u, v, xx, yy, aa, bb)
x = xx
y = yy
a = aa
b = bb
lnz = x*x + y*y
if lnz = 0 then
u = 0
v = 0
else
lnz = 0.5*log(lnz)
argz = atan2(y, x)
mag = exp(a*lnz - b*argz)
ang = a*argz + b*lnz
u = mag*cos(ang)
v = mag*sin(ang)
end if
end sub
'u + iv = (x + iy)*(a + ib)
sub cmul(u, v, xx, yy, aa, bb)
x = xx
y = yy
a = aa
b = bb
u = x*a - y*b
v = x*b + y*a
end sub
'u + iv = (x + iy)/(a + ib)
sub cdiv(u, v, xx, yy, aa, bb)
x = xx
y = yy
a = aa
b = bb
d = a*a + b*b
u = (x*a + y*b)/d
v = (y*a - x*b)/d
end sub
sub clog(u, v, xx, yy)
x = xx
y = yy
lnz = x*x + y*y
if lnz = 0 then
u = 0
v = 0
else
u = 0.5*log(lnz)
v = _atan2(y, x)
end if
end sub
Plays OK, slow too much, fast too much (can't read word as it blurs or doubles going down screen). Frankly I'd rather do something else.
I see that you can really improve a lot on this as well. The solution at the beginning of this thread is still sufficient for the purpose for which it was written. I will publish the exact use and the reason why I deal with it soon. It is again just one fragment from a larger program. Thank you all for your many inspiring suggestions!
Prime spiral with zoom in / out and number ID at mouse point:
With non-monospaced fonts, the routine has to check and build width pixel by pixel as it goes. A "W" might spread and use 64 pixels, an "i" might use 8... non-monospaced fonts are *much* slower to calculate print widths with, and that's something I wanted to emphasize with my demo.