Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: Hezad on July 23, 2009
-
Hey :) I was playing with my [magnification] entry and I came with this. It's funny how it really looks like (imho) a real 3D bumpmap or something like this .. (Of course, the light is moving :) ) Here's a screen. I can't post the source since I use the code from the magnification entry, but once the contest is over, I'll post it here ;) If someone wants the linux binary, please ask.
For information, there's absolutely no 3D calcs, the program just calculates new positions with an exponential rule and uses the moving blobs as a texture.
-
At the very least you have created a beautiful glass like texture that would look wonderful in some 3D app :)
-
looks like a very interesting lighting technique.. looking forward to hearing an explanation/seeing the source for it :)
-
At the very least you have created a beautiful glass like texture that would look wonderful in some 3D app Smiley
thanks, yeah I guess that could look nice as a dynamic texture ;D
looks like a very interesting lighting technique.. looking forward to hearing an explanation/seeing the source for it Smiley
Well to be honnest there's no light calc, the program just looks for a pixel in the basic background ("light" blobs) with an exponential calc (this explains the sides look rounded), anyway, the source will be posted :)
Little update, still in the same kind of wanderings : moving mercury liquid :P
-
Very nice, I wish I could see it moving :D It might help explain the technique
-
thats cool, hats off to you Hezad
-
This reminds me of photoshop filters alot of people use to make "interfaces" and buttons and so on.
-
thanks a lot mates :) I'll post all sources once the magnifying contest will be over :cheers:
-
@Hezad:
Wow... the screenshots are really cool... as shockwave said, i would i like to the the stuff in action (animated) and explaining how does it works too ;)
Still looking forward to your entry and this routine ;)
-
Awesome stuff, mate. Really looking forward to see this in motion.
-
The voting is open :) So as promised here is the source code of those snippets. Each stuff is already in the same code (particules entry, square stuff and mercury stuff. You just have to uncomment the desired one (and to comment the previous uncommented one of course ^^)
Randomize Timer
Const NB_BLOBS = 20
Const SPEED = 5
Type BlobT
as single x,y,r
as single vx,vy,vr
as integer cr,cg,cb
end type
Screenres 320,240,32,2
Dim shared as BlobT Blob(NB_BLOBS-1)
Dim shared as uinteger ptr scrptr,realscrptr
dim shared as single t
scrptr = Callocate(320*240,sizeof(Uinteger))
realscrptr = screenptr
Sub MoveBlobs()
static as single r1
for k as integer = 0 to NB_BLOBS-1
r1 = rnd
if rnd<.07 then blob(k).vx = SPEED*cos(r1*6.283)
if rnd<.07 then blob(k).vy = SPEED*sin(r1*6.283)
blob(k).x += blob(k).vx
blob(k).y += blob(k).vy
if blob(k).x>320 or blob(k).x<0 then blob(k).x-=blob(k).vx : blob(k).vx = -blob(k).vx
if blob(k).y>240 or blob(k).y<0 then blob(k).y-=blob(k).vy : blob(k).vy = -blob(k).vy
next
End sub
Sub DrawBlobs()
'' idée : interpolation de couleurs entre chaque blob
static as single sum, xp,yp, xp2,yp2
for i as integer = 0 to 319
for j as integer = 0 to 239
sum = 0
for k as integer = 0 to NB_BLOBS-1
xp = (i-blob(k).x)*(i-blob(k).x)
yp = (j-blob(k).y)*(j-blob(k).y)
sum += blob(k).r/(.03*(xp + yp + 5*(blob(k).vx*blob(k).vx + blob(k).vy*blob(k).vy)))
if sum > 1 then sum = 1
next
sum = sum*255
ScrPtr[i+j*320] = rgb(sum*.9,sum*.85,sum)
next
next
end sub
Sub Magnify_Blobs()
static as integer newx,newy,intensity
static as single calc
For i as integer = -160 to 159
For j as integer = -120 to 119
'' === Mercury stuff ===
'realscrptr[(i+160)+(j+120)*320] = scrptr[(i+160)+(j+120)*320]
'intensity = scrptr[(i+160)+(j+120)*320] and 255
'newx = i*(sqr(i*i+j*j)*.001)*.0001 * intensity *i*i
'newy = j*(sqr(i*i+j*j)*.001)*.0001 * intensity *j*j
'' =====================
'' === squared stuff ===
'realscrptr[(i+160)+(j+120)*320] = scrptr[(i+160)+(j+120)*320]
'intensity = scrptr[(i+160)+(j+120)*320] and 255
'newx = i*(exp(((i*i-160)*.001)))*.05
'newy = j*(exp(((j*j-120)*.001)))*.05
'' =====================
'' === magnification ===
calc = .000017*(i*i+j*j+17000)
newx = i*calc
newy = j*calc
'' =====================
if newx+160>=0 and newx+160<320 then
if newy+120>=0 and newy+120<240 then
realscrptr[(i+160)+(j+120)*320] = scrptr[(newx+160)+(newy+120)*320]
end if
end if
next
next
End sub
Sub InitBlobs()
For k as integer = 0 to NB_BLOBS-1
blob(k).r = .05+5*rnd*exp(rnd*.5)
blob(k).x = 320*rnd
blob(k).y = 240*rnd
blob(k).vx = SPEED*(1-2*rnd)
blob(k).vy = SPEED*(1-2*rnd)
next
End sub
initBlobs
Do
MoveBlobs
DrawBlobs
screenlock : cls
magnify_Blobs
Screenunlock : sleep 1,1
Loop until multikey(&h01)
deallocate scrptr
I'll post some youtube vids in some minutes
edit : Vids added on the top post
-
Great! I was looking forward to this code. thanks for sharing
-
K+ for making the source code available.
Thanks!