Joshy
Code: Select all
/'
* Metatunnel demo effect
* Original by FRequency
* http://www.pouet.net/prod.php?which=52777
*
* Canvas 2D version by PauloFalcao
* http://demoscene.appjet.net/
*
* Canvas 3D port by vlad
* http://people.mozilla.com/~vladimir/misc/metatunnel-3d.html
*
* Processing.org port by luis2048
* http://luis.net/projects/processing/metatunnel/
*
* FreeBasic port by D.J.Peters
* http://www.freebasic.net/forum/viewtopic.php?p=140112
'/
#include "fbgfx.bi"
using fb
type float as single
dim shared as float time_
dim shared as float maxrX
dim shared as float maxrY
dim shared as Image ptr megatunnelEffect
dim shared as float dxx,dyy,dzz
dim shared as float vy,ox,oy,oz,dx,dy,dz,tt,g,kolor,dxtt,dytt,dztt,nx,ny,nz,d,f,px,py,objd',nx,ny,nz
dim shared as float cost,cost07,cost05,cost0505p2,costm03,sint,sint07,sint05,sint05p2,sint02,sint0205,costsint02
dim shared as integer rr,gg,bb
'dim shared as float dxtt,dytt,dztt
const SCR_W = 640
const SCR_H = 480
const IMG_W = 100
const IMG_H = 100
sub setup()
screenres SCR_W,SCR_H,32,,1
megatunnelEffect = ImageCreate(IMG_W,IMG_H)
maxrX=megatunnelEffect->width
maxrY=megatunnelEffect->height
end sub
function distance(ax as float,ay as float,az as float,bx as float,by as float,bz as float) as float
dxx = bx-ax
dyy = by-ay
dzz = bz-az
return sqr(dxx*dxx + dyy*dyy + dzz*dzz)
end function
function obj(x as float,y as float,z as float,t as float) as float
dim as float f=1.0
dxx=x-costsint02:dyy=y-0.3:dzz=z-cost0505p2
f*=sqr(dxx*dxx + dyy*dyy + dzz*dzz)
dxx=x- -cost07:dyy=y-0.3:dzz=z-sint05p2
f*=sqr(dxx*dxx + dyy*dyy + dzz*dzz)
dxx=x- -sint0205:dyy=y-sint:dzz=z-2.0
f*=sqr(dxx*dxx + dyy*dyy + dzz*dzz)
'f*=distance(x,y,z,costsint02,0.3,cost0505p2)
'f*=distance(x,y,z,-cost07,0.3,sint05p2)
'f*=distance(x,y,z,-sint0205,sint,2.0)
f*=cos(y)*cos(x)-0.1-cos(z*7.0+t*7.0)*cos(x*3.0)*cos(y*4.0)*0.1
return f
end function
function max(a as float, b as float) as float
if a>b then return a
return b
end function
function eval(xx as integer,yy as integer,t as float) as uinteger
px = xx / maxrX
ox=px*2.0-1.0
oz=0.0
dx=(ox+costm03)/64.0
'dz=1.0/64.0
dz=0.015625
tt=0.0
g=1.0
while((g>0.4) and (tt<375))
g=obj(ox+dx*tt,oy+dy*tt,oz+dz*tt,t)
tt+=g*4
wend
kolor=0.0
dxtt=ox+dx*tt
dytt=oy+dy*tt
dztt=oz+dz*tt
objd=obj(dxtt,dytt,dztt,t)
nx=objd-obj(dxtt+0.01,dytt,dztt,t)
ny=objd-obj(dxtt,dytt+0.01,dztt,t)
nz=objd-obj(dxtt,dytt,dztt+0.01,t)
d=sqr(nx*nx+ny*ny+nz*nz)
ny=ny/d
nz=nz/d
kolor+=max(-0.5*nz,0.0) + max(-0.5*ny+0.5*nz,0.0)*0.5
dim as float mult = tt*0.025
rr=max((kolor+0.1*mult)*240,0):if rr>255 then rr=255
gg=max((kolor+0.2*mult)*240,0):if gg>255 then gg=255
bb=max((kolor+0.5*mult)*240,0):if bb>255 then bb=255
return rgb(rr,gg,bb)
end function
' integer based bit shift multiplication
function mul(m as integer,n as integer) as integer
if (n>0) then
dim as integer mp = m shl 1
dim as integer np = n shr 1
return mul(mp,np) + iif((n and 1)>0,m,0)
end if
return 0
end function
sub DrawIt()
dim as float t = time_
cost = cos(t)
cost07 = cos(t*.7)
cost05 = cos(t*.5)
cost0505p2 = cost05 * 0.5 + 2
costm03 = cost * 0.3
sint = sin(t)
sint07 = sin(t*.7)
sint05 = sin(t*.5)
sint05p2 = sint05 + 2
sint02 = sin(t*.2)
sint0205 = sint02*0.5
costsint02 = cost+sint02
dim as uinteger ptr pixels = cptr(uinteger ptr,megatunnelEffect)
pixels+=8
for y as integer = 0 to megatunnelEffect->height-1
py = y / maxrY
vy=-py*2.0+1.0
oy=vy*1.25
dy=vy/maxrY
for x as integer = 0 to megatunnelEffect->width-1
*pixels = eval(x,y,time_)
pixels+=1
next
next
put (0,0),megatunnelEffect,PSET
time_+=0.05
end sub
Setup()
while inkey()=""
DrawIt()
sleep 10
wend