only a lens in 2d (use mouse)
#constant freq = 128
#constant tab = 32
#constant dia = 128
#constant mag = 32
set display mode 640, 480, 32
sync rate 60 : sync on
dim cosi(511)
dim color(255)
dim lens(dia * dia)
w1 as byte
w2 as byte
w3 as byte
get image 1, 0, 0, 256, 256
make memblock from image 1, 1
for i = 0 to 511
cosi(i) = cos((360 * i) / 256) * freq + tab
next i
for i = 0 to 85 : color(i) = rgb(255 - i * 3, i * 3, 0) : next i
for i = 86 to 170 : color(i) = rgb(0, 255 - i * 3, i * 3) : next i
for i = 171 to 255 : color(i) = rgb(i * 3, 0, 255 - i * 3) : next i
gosub _plasma
MakeLens(dia, mag)
get image 2, x, y, x + dia, y + dia
make memblock from image 2, 2
set sprite 2, 1, 0
repeat
x = mousex()
y = mousey()
if x > 256 then x = 256
if y > 256 then y = 256
DrawLens(x, y, dia)
sync
until mouseclick()
end
_plasma:
inc w1, 2
inc w2, 2
inc w3, 3
for y = 0 to 255
d = cosi(y + w2) + cosi(y + w3)
for x = 0 to 255
c = (cosi(x + w1) + cosi(x + y) + d) and 255
write memblock dword 1, 12 + (x + y * 256) * 4, color(c)
next x
next y
make image from memblock 1, 1
paste image 1, 0, 0
return
function MakeLens(d, m)
r = d / 2
s = sqrt(r ^ 2 - m ^ 2)
for y = -r to r - 1
for x = -r to r - 1
If x ^ 2 + y ^ 2 > s ^ 2
a = x
b = y
else
z = sqrt(r ^ 2 - x ^ 2 - y ^ 2)
a = x * m / (z - 0.5)
b = y * m / (z - 0.5)
endif
lens((y + r) * d + (x + r)) = (b + r) * d + (a + r)
next x
next y
endfunction
Function DrawLens(x, y, d)
get image 2, x, y, x + d , y + d
make memblock from image 3, 2
for p = 0 to d * d - 1
m = memblock dword(3, 12 + lens(p) * 4)
write memblock dword 2, 12 + p * 4, m
next p
make image from memblock 2, 2
sprite 2, x, y, 2
endfunction