PDA

View Full Version : Electrons on function surface



Petr Schreiber
23-01-2007, 21:06
Hi kryton9,

thanks for nice words. It is almost just trial an error :)

Optimize your and Eros version of effect makes my head really pressed ;)

100 x 136 objects/points = 13 600 as Eros said. If I will do it by polygons, I can get 13 600 quads, which does mean quite high number of vertices. And now set them properties dynamically ... trouble.

It is very interesting problem. When optimized using lists, you will get super framerate ( thousands of FPS ).
But it is static. I tried to do the same effect via virtual model, but it was still quite slow.

Meanwhile, I will continue in stream of "script associations" and add another variation : Crazy electrons/photons/...
You will see how fast are cached points and how to perform fake blur of points using ... lines :)

On my box it runs at 53 FPS


'
' More crazy points 1.1
'

Uses "TBGL"
Uses "UI"

randomize timer ' -- Seed for random number is given by time

DIM hWnd as dword

' TBGL 0.1.8 shiny new window creation, just change 0 to 1 to get fullscreen ;)
hWnd = tbgl_CreateWindowex ("Crazy points", 800, 600, 32, 0)
tbgl_ShowWindow ' This will display the window on the screen
tbgl_SetDrawDistance 500

dim cx,cy,cz as long
dim squareSideHalf as long = 50

tbgl_NewList 1
tbgl_BeginPoly %GL_points

for cx = -squareSideHalf to squareSideHalf
for cz = -squareSideHalf to squareSideHalf
tbgl_color 0, 75 + rnd(1, 130), 0
tbgl_Vertex cx, SurfaceEquation( cx, cz ), cz
next
next

tbgl_EndPoly
tbgl_EndList

type electronXY
x as single
y as single
z as single
dx as single ' Destination
dy as single
dz as single
end type

dim NumElectrons as long = 64
dim Electron(NumElectrons) as electronXY

dim i as long

for i = 1 to NumElectrons
BornParticle (i, rnd(-squareSideHalf, squareSideHalf), 100, rnd(-squareSideHalf, squareSideHalf))
next

dim FrameRate as single
dim Distance as single

GetAsyncKeyState %VK_ESCAPE ' Reset status of the ESCAPE to prevent immediate quit

dim oldx, oldy, oldz as single
dim CountSheeps as long
tbgl_LineWidth 3

while IsWindow (hWnd) ' While window exists, we will draw and check for ESCAPE

FrameRate = tbgl_getFrameRate
incr CountSheeps

if CountSheeps = 250 then
win_settitle(hWnd, "Crazy points: " & FrameRate & " FPS")
CountSheeps = 0
end if

tbgl_ClearFrame ' This clears the frame and prepares it for drawing

tbgl_Camera 0, 60, 100, 0, 10, 0
TBGL_Rotate GetTickCount/80, 0, 1, 0

tbgl_CallList 1

tbgl_UseBlend 1 ' Because of particle tail fading out

tbgl_BeginPoly %GL_LINES
for i = 1 to NumElectrons
oldx = Electron(i).x
oldy = Electron(i).y
oldz = Electron(i).z

' Is electron in its destination ?
if Electron(i).x + 1 > Electron(i).dx and Electron(i).x - 1 < Electron(i).dx and _
Electron(i).y + 1 > Electron(i).dy and Electron(i).y - 1 < Electron(i).dy and _
Electron(i).z + 1 > Electron(i).dz and Electron(i).z - 1 < Electron(i).dz then

Electron(i).dx = rnd(-squareSideHalf, squareSideHalf)
Electron(i).dz = rnd(-squareSideHalf, squareSideHalf)
Electron(i).dy = SurfaceEquation( Electron(i).dx, Electron(i).dz )

end if

' ... if not, he must approach
if Electron(i).x < Electron(i).dx then
Electron(i).x += abs(Electron(i).dx - Electron(i).x)/FrameRate*2
elseif Electron(i).x > Electron(i).dx then
Electron(i).x -= abs(Electron(i).x - Electron(i).dx)/FrameRate*2
end if

if Electron(i).z < Electron(i).dz then
Electron(i).z += abs(Electron(i).dz - Electron(i).z)/FrameRate*2
elseif Electron(i).z > Electron(i).dz then
Electron(i).z -= abs(Electron(i).z - Electron(i).dz)/FrameRate*2
end if

' Surface equation
Electron(i).y = SurfaceEquation( Electron(i).x, Electron(i).z )

' Tail
tbgl_Color 0,0,0
tbgl_Vertex Electron(i).x + (oldx-Electron(i).x)*5, Electron(i).y + (oldy-Electron(i).y)*5, Electron(i).z + (oldz-Electron(i).z)*5

' Head
tbgl_Color 255,128,0
tbgl_Vertex Electron(i).x, Electron(i).y, Electron(i).z

next
tbgl_EndPoly

tbgl_UseBlend 0

tbgl_DrawFrame ' This will display the scene

' -- Key checking
IF GetWindowKeyState( hWnd, %VK_ESCAPE ) THEN EXIT while
sleep 0

Wend

tbgl_DestroyWindow ' This will destroy the window

function SurfaceEquation( byval x as single, byval z as single ) as single

x /= 10
z /= 10
'function = x^4 - z^4
'function = x^4 + z^4
'function = cos(x^2 + z^2)*4
'function = sin(abs(x^2) - abs(z^4))
function = -1 / iif(x^2 + z^2=0, 1, x^2 + z^2)*50
'function = X^2 + z^2 + Z^3 - x^3
'function = cos(x+z)*5
'function = (cos(x^2 - z)*5)
'function = (cos(abs( x ) + abs( z ))*5)
'function = (cos(x/10*abs( x) + abs( z))*5)*z
'function = (x^2+x+1+z^3+10)/(z+x+6.1)
end function

sub BornParticle( e as long, x as single, y as single, z as single)

Electron(e).x = x
Electron(e).y = y
Electron(e).z = z
Electron(e).dx = rnd(-squareSideHalf, squareSideHalf)
Electron(e).dz = rnd(-squareSideHalf, squareSideHalf)
Electron(e).dy = SurfaceEquation( Electron(e).dx, Electron(e).dz )

end sub

Bye,
Petr

ErosOlmi
23-01-2007, 21:14
You are super Petr.
205 FPS on my box.

Thanks
Eros

ErosOlmi
23-01-2007, 22:26
Petr,

I'm checking your example and I have to say you are a genious!
Just changing SurfaceEquation function with a different equation, script is able to charge surface with so nice images that I'm getting so astonished.

Thank you, thank you.
Eros

kryton9
23-01-2007, 23:25
@Petr:Oh WOW!!!, I come home and find this incredible new example. That looks so sweet and awesome!!
I got around 120 fps, just amazing looking can't wait to study the code. Thanks, really an impressive demo Petr!!!

@Eros: sorry I must have missed the discussion about syntaxing and IE, you are right, I am using Firefox and that is probably the problem. The paste and copy from notepad is easy enough to do. Your second reply about surface changes got me intrigued even more about Petr's example, can't wait to study it!!!

Petr Schreiber
23-01-2007, 23:36
Hi kryton,

please try following mod:


function SurfaceEquation( byval x as single, byval z as single ) as single
x /= 10
z /= 10
function = (cos(x/10*abs(x) + abs(z*x))*5)*z
end function


BYVAL variables won't be affected by x/= ...

You can also try another weird ones:
cos(abs(x) + abs(z))*5
cos(x+z)*5
(x^2+x+1+z^3+10)/(z+x+6.1)
... let us now if you'll find some interesting :)


Bye,
Petr

ErosOlmi
23-01-2007, 23:38
kryton9,

regarding FireFox copy/paste Roberto should have a possible solution. We will see next release.
On Petr example, expect from him an incredible new example with dynamic function plotting ...

Eros

Petr Schreiber
23-01-2007, 23:49
Hi,

Eros found a problem in BornParticle procedure, it should be:


sub BornParticle( e as long, x as single, y as single, z as single)

Electron(e).x = x
Electron(e).y = y
Electron(e).z = z
Electron(e).dx = rnd(-squareSideHalf, squareSideHalf)
Electron(e).dz = rnd(-squareSideHalf, squareSideHalf)
Electron(e).dy = SurfaceEquation( Electron(e).dx, Electron(e).dz )

end sub


I corrected it in original code and marked it as version 1.1 :)


Bye,
Petr

ErosOlmi
23-01-2007, 23:54
Worth to see some images ...
... and maybe open a new thread specific for this nice script.

Images are from a 256 electrons example script.

ErosOlmi
24-01-2007, 00:00
Some nice variations from Petr to test:


function SurfaceEquation( byval x as single, byval z as single ) as single

x /= 10
z /= 10
'function = x^4 - z^4
'function = x^4 + z^4
function = cos(x^2 + z^2) * 4
'function = X^2 + z^2 + Z^3 - x^3
'function = cos(x+z)*5
'function = (cos(x^2 - z)*5)
'function = (cos(abs( x ) + abs( z ))*5)
'function = (cos(x/10*abs( x) + abs( z))*5)*z
'function = (x^2+x+1+z^3+10)/(z+x+6.1)

end function

ErosOlmi
24-01-2007, 00:27
function SurfaceEquation( byval x as single, byval z as single ) as single

x /= 10
z /= 10
'function = x^4 - z^4
'function = x^4 + z^4
'function = cos(x^2 + z^2)*4
'function = sin(abs(x^2) - abs(z^4))
function = -1 / iif(x^2 + z^2=0, 1, x^2 + z^2)*50
'function = X^2 + z^2 + Z^3 - x^3
'function = cos(x+z)*5
'function = (cos(x^2 - z)*5)
'function = (cos(abs( x ) + abs( z ))*5)
'function = (cos(x/10*abs( x) + abs( z))*5)*z
'function = (x^2+x+1+z^3+10)/(z+x+6.1)

end function

kryton9
24-01-2007, 03:40
Absolutely Incredible and Beautiful!!! Amazing stuff guys, so impressive and fun to look at!!
Thanks for your creativity and talents!!!

ErosOlmi
24-01-2007, 13:04
This post is named "TBGL Help" but this latest function script seems to merit a dedicated thread.
What about splitting it?

Eros

Petr Schreiber
24-01-2007, 16:04
Hi Eros,

thanks a lot for splitting the thread,
it will be easier for new visitors to follow the ideas too :)


Thanks a lot,
Petr

ErosOlmi
24-01-2007, 19:31
Some ideas on this script:


make function dynamic using Eval module
create function surface with triangles instead of dots
use a degrade color depending on high/low position on Z
draw X, Y, Z axis from 0, 0, 0
add key usage for rotationon lef, right, up, down, zoom-in, zoom-out or maybe better free fly over math world
place a number on every electron
slow moving
electrons collisions and annihilation


Quite enough ::)

Eros

kryton9
24-01-2007, 21:44
It is so fascinating see those equations come to life and those electrons moving around the surface.
Those new ideas by Eros will make it too fun to stop playing, but that is the idea I guess.

Can't wait to see what you guys come up with!!!

Petr Schreiber
24-01-2007, 22:36
Hi kryton9,

I am happy you find it interesting.



Can't wait to see what you guys come up with!!!

We ? You are we now too :). So if you want to take some of the points as TBGL practise, please do it !
I will probably start with solid surface / coloring and EVAL module.


Bye,
Petr

ErosOlmi
24-01-2007, 22:38
Why "you guy"?
"We guy". Do your job too ! ;D

Just joking, of course, but if you find something nice to put inside fantastic and clever Petr's code, let us know.

Ciao
Eros

kryton9
24-01-2007, 22:46
Thanks guys, but I am having too much fun playing with it and dreaming of things to come, but of course if an inspiration for something cool comes up, I will post it for sure.

I am just in awe of these examples and how cool they are!!

Petr Schreiber
26-01-2007, 18:11
Hi,

I was upgrading TBGL help to be compatible with F1 in all cases, so I had less time for tuning this sample. File was sent to Eros, so expect it in next release ;)

Regarding this sample, I will post here its modified version hopefully in few days, when I get more free time :)


Bye,
Petr