 |
| Author |
Message |
flibX0r
User
Joined: Fri Feb 14th 2003
Location: Western Australia
|
|
Posted: 6th Mar 2005 11:32 Edited: 6th Mar 2005 12:23 |
| link | toggle |
twas quite bored lately, whipped this up. it pretty much explains itself when you watch it. But stare at it for too long, it has a hypnotic effect. Its mostly commented so you can understand whats happening (gravity function isn't though)
+ Code Snippet` me so bored, dunno what to do tonight
` set teh display mode
set display mode 640, 480, 32
` define teh constants
#constant TOTAL_PARTICLE_COUNT 1023
#constant GRAVITY_CONSTANT 20
#constant BOUNCEREDUCTION 0.5
sync on
sync rate 60
randomize timer()
hide mouse
type Particle
x as float
y as float
vx as float
vy as float
mass as float
colour
endtype
dim p(TOTAL_PARTICLE_COUNT+1) as Particle
dim c(10) as integer
c(0) = rgb(255,0,0)
c(1) = rgb(255,128,0)
c(2) = rgb(255,255,0)
c(3) = rgb(128,255,0)
c(4) = rgb(0,255,0)
c(4) = rgb(0,255,128)
c(5) = rgb(0,255,255)
c(6) = rgb(0,128,255)
c(7) = rgb(0,0,255)
c(8) = rgb(0,128,0)
c(9) = 0
`INITILISATION
`for i=0 to TOTAL_PARTICLE_COUNT
for i=0 to 31
for j=0 to 31
p(i+j*32).x = rnd(100) + 270.5
p(i+j*32).y = rnd(100) + 190.5
p(i+j*32).vx = 0
p(i+j*32).vy = 0
p(i+j*32).mass = 4
p(i+j*32).colour = 0
next j
next i
make memblock 1, 640*480*4+12
write memblock dword 1, 0, 640
write memblock dword 1, 4, 480
write memblock dword 1, 8, 32
for i=12 to (640*480*4+11) step 4
write memblock byte 1, i, 0 :`Blue
write memblock byte 1, i+1, 0 :`Green
write memblock byte 1, i+2, 0 :`Red
write memblock byte 1, i+3, 10 :`Alpha
next i
make image from memblock 1, 1
`MAIN LOOP
`This is the part to edit. basically it just applies
`forces to the particles, draws them, and repeats
do
`cls
`Apply forces
if inkey$()<>" "
FORCE_GRAV_POINT(-1, 100, 100)
FORCE_GRAV_POINT(-1, 540, 100)
FORCE_GRAV_POINT(-1, 100, 380)
FORCE_GRAV_POINT(-1, 540, 380)
`Update positions
for i=0 to TOTAL_PARTICLE_COUNT
p(i).x = p(i).x + p(i).vx
p(i).y = p(i).y + p(i).vy
next i
endif
`No going outside the screen
`if one does, then its back to the start
for i=0 to TOTAL_PARTICLE_COUNT
if (p(i).vx*p(i).vx)+(p(i).vy*p(i).vy)>36
p(i).x = rnd(100) + 270.5
p(i).y = rnd(100) + 190.5
p(i).vx = 0
p(i).vy = 0
p(i).colour = p(i).colour+1
if p(i).colour=9
p(i).colour=0
p(i).x = rnd(100) + 270.5
p(i).y = rnd(100) + 190.5
endif
endif
next i
`Draw the particles
for i=0 to TOTAL_PARTICLE_COUNT
ink c(p(i).colour), 0
dot p(i).x, p(i).y
next i
`draw the image to create the trail effect
paste image 1, 0, 0, 1
sync
loop
`Functions
`Gravity Point
function FORCE_GRAV_POINT(particle, gx, gy)
ink RGB(255,255,255), 0
circle gx, gy, 10
dist as float
accel as float
if particle = -1
for i=0 to TOTAL_PARTICLE_COUNT
dist = (gx-p(i).x)*(gx-p(i).x) + (gy-p(i).y)*(gy-p(i).y)
accel = GRAVITY_CONSTANT*(p(i).mass)/dist
dist = sqrt(dist)
p(i).vx = p(i).vx + accel*(gx-p(i).x)/dist
p(i).vy = p(i).vy + accel*(gy-p(i).y)/dist
next i
else
dist = (gx-p(particle).x)*(gx-p(particle).x) + (gy-p(particle).y)*(gy-p(particle).y)
dist = sqrt(dist)
accel = GRAVITY_CONSTANT*(p(particle).mass)/dist
p(particle).vx = p(particle).vx + accel*(gx-p(particle).x)/dist
p(particle).vy = p(particle).vy + accel*(gy-p(particle).y)/dist
endif
endfunction
feedback would be much appreciated
EDIT: Updated code
EDIT2: here's a screenshot from my codebase entry
You can't wield supreme executive power just because a watery tart threw a sword a you
|
Back to top
 |
|
Trev
User
Joined: Fri Feb 20th 2004
Location: Canada, Ontario
|
|
Posted: 6th Mar 2005 23:12 Edited: 24th Feb 2008 15:19 |
| link | toggle |
|
Back to top
 |
|
flibX0r
User
Joined: Fri Feb 14th 2003
Location: Western Australia
|
well, tis just something i did when i was bored, and its got some features that people might find interesting (trail effect, gravityness)
You can't wield supreme executive power just because a watery tart threw a sword a you
|
Back to top
 |
|
BatVink
TGC Newsletter Editor
 Joined: Fri Apr 4th 2003
Location: Chilling
|
That's not useless, it's a damn good tech demo! On it's own, maybe useless, but incorporated into another app it has much potential.
Good work!
BatVink

|
Back to top
 |
|
flibX0r
User
Joined: Fri Feb 14th 2003
Location: Western Australia
|
Cheers BatVink. I'm bored again tonight, so i'm gonna play around with my code and add some stuff to it
You can't wield supreme executive power just because a watery tart threw a sword a you
|
Back to top
 |
|
Baggers
User
Joined: Mon May 31st 2004
Location: Yonder over dem dere hills
|
Very nice effect, would be cool to be able to move the gravity wells with the cursor.
|
Back to top
 |
|
Benjamin
User
Joined: Sun Nov 24th 2002
Location: France
|
Cooooool! Its even cooler when you control the first gravity well with the mouse:
+ Code Snippet` me so bored, dunno what to do tonight
` set teh display mode
set display mode 640, 480, 32
` define teh constants
#constant TOTAL_PARTICLE_COUNT 1023
#constant GRAVITY_CONSTANT 20
#constant BOUNCEREDUCTION 0.5
sync on
sync rate 60
randomize timer()
hide mouse
type Particle
x as float
y as float
vx as float
vy as float
mass as float
colour
endtype
dim p(TOTAL_PARTICLE_COUNT+1) as Particle
dim c(10) as integer
c(0) = rgb(255,0,0)
c(1) = rgb(255,128,0)
c(2) = rgb(255,255,0)
c(3) = rgb(128,255,0)
c(4) = rgb(0,255,0)
c(4) = rgb(0,255,128)
c(5) = rgb(0,255,255)
c(6) = rgb(0,128,255)
c(7) = rgb(0,0,255)
c(8) = rgb(0,128,0)
c(9) = 0
`INITILISATION
`for i=0 to TOTAL_PARTICLE_COUNT
for i=0 to 31
for j=0 to 31
p(i+j*32).x = rnd(100) + 270.5
p(i+j*32).y = rnd(100) + 190.5
p(i+j*32).vx = 0
p(i+j*32).vy = 0
p(i+j*32).mass = 4
p(i+j*32).colour = 0
next j
next i
make memblock 1, 640*480*4+12
write memblock dword 1, 0, 640
write memblock dword 1, 4, 480
write memblock dword 1, 8, 32
for i=12 to (640*480*4+11) step 4
write memblock byte 1, i, 0 :`Blue
write memblock byte 1, i+1, 0 :`Green
write memblock byte 1, i+2, 0 :`Red
write memblock byte 1, i+3, 10 :`Alpha
next i
make image from memblock 1, 1
`MAIN LOOP
`This is the part to edit. basically it just applies
`forces to the particles, draws them, and repeats
do
`cls
`Apply forces
if inkey$()<>" "
FORCE_GRAV_POINT(-1, mousex(), mousey())
FORCE_GRAV_POINT(-1, 540, 100)
FORCE_GRAV_POINT(-1, 100, 380)
FORCE_GRAV_POINT(-1, 540, 380)
`Update positions
for i=0 to TOTAL_PARTICLE_COUNT
p(i).x = p(i).x + p(i).vx
p(i).y = p(i).y + p(i).vy
next i
endif
`No going outside the screen
`if one does, then its back to the start
for i=0 to TOTAL_PARTICLE_COUNT
if (p(i).vx*p(i).vx)+(p(i).vy*p(i).vy)>36
p(i).x = rnd(100) + 270.5
p(i).y = rnd(100) + 190.5
p(i).vx = 0
p(i).vy = 0
p(i).colour = p(i).colour+1
if p(i).colour=9
p(i).colour=0
p(i).x = rnd(100) + 270.5
p(i).y = rnd(100) + 190.5
endif
endif
next i
`Draw the particles
for i=0 to TOTAL_PARTICLE_COUNT
ink c(p(i).colour), 0
dot p(i).x, p(i).y
next i
`draw the image to create the trail effect
paste image 1, 0, 0, 1
sync
loop
`Functions
`Gravity Point
function FORCE_GRAV_POINT(particle, gx, gy)
ink RGB(255,255,255), 0
circle gx, gy, 10
dist as float
accel as float
if particle = -1
for i=0 to TOTAL_PARTICLE_COUNT
dist = (gx-p(i).x)*(gx-p(i).x) + (gy-p(i).y)*(gy-p(i).y)
accel = GRAVITY_CONSTANT*(p(i).mass)/dist
dist = sqrt(dist)
p(i).vx = p(i).vx + accel*(gx-p(i).x)/dist
p(i).vy = p(i).vy + accel*(gy-p(i).y)/dist
next i
else
dist = (gx-p(particle).x)*(gx-p(particle).x) + (gy-p(particle).y)*(gy-p(particle).y)
dist = sqrt(dist)
accel = GRAVITY_CONSTANT*(p(particle).mass)/dist
p(particle).vx = p(particle).vx + accel*(gx-p(particle).x)/dist
p(particle).vy = p(particle).vy + accel*(gy-p(particle).y)/dist
endif
endfunction

"Lets migrate like bricks" - Me
|
Back to top
 |
|
|
Google Ad
AdBot
Joined: Aug 26th 2002
Location: Everywhere
|
|
Back to top
 |
|
spooky
User
Joined: Fri Aug 30th 2002
Location: United Kingdom
|
For some extra speed, replace the VERY slow dot command with:
box p(i).x,p(i).y,p(i).x+1,p(i).y+1
and try changing sync rate to 0
Boo!
|
Back to top
 |
|
BatVink
TGC Newsletter Editor
 Joined: Fri Apr 4th 2003
Location: Chilling
|
Woooah, what's all that about then!!
Changed the dot to a box as Spooky suggested, and the frame rate rockets from 20 FPS to 135 FPS !!!!
BatVink

|
Back to top
 |
|
HowDo
3DMaster - Champion
 Joined: Thu Nov 28th 2002
Location: United Kingdom
|
How would you make the mouse wheel very the gravity pull on this?
Very cool will be even better when I see how you made it do it.
In Space No One can Hear You Scream! (When your comm Line is cut?)
|
Back to top
 |
|
Sepheus
User
Joined: Fri Jun 18th 2004
Location: Lemuria
|
Top notch program. Really quite interesting to watch.
Cogeto Ergo Sum
|
Back to top
 |
|
Tommy S
User
Joined: Tue Sep 9th 2003
Location: Cyberspace
|
i am sooo impressed tried to do something like that in 3d for the tanks/operation wolf compo and failed miserably. It bloody hypnotic too!!!
|
Back to top
 |
|
TEH_CODERER
User
Joined: Wed Nov 12th 2003
Location: Right behind you!
|
Replaced with boxes:
+ Code Snippet
` me so bored, dunno what to do tonight
` set teh display mode
set display mode 640, 480, 32
` define teh constants
#constant TOTAL_PARTICLE_COUNT 1023
#constant GRAVITY_CONSTANT 20
#constant BOUNCEREDUCTION 0.5
sync on
sync rate 0
randomize timer()
hide mouse
type Particle
x as float
y as float
vx as float
vy as float
mass as float
colour
endtype
dim p(TOTAL_PARTICLE_COUNT+1) as Particle
dim c(10) as integer
c(0) = rgb(255,0,0)
c(1) = rgb(255,128,0)
c(2) = rgb(255,255,0)
c(3) = rgb(128,255,0)
c(4) = rgb(0,255,0)
c(4) = rgb(0,255,128)
c(5) = rgb(0,255,255)
c(6) = rgb(0,128,255)
c(7) = rgb(0,0,255)
c(8) = rgb(0,128,0)
c(9) = 0
`INITILISATION
`for i=0 to TOTAL_PARTICLE_COUNT
for i=0 to 31
for j=0 to 31
p(i+j*32).x = rnd(100) + 270.5
p(i+j*32).y = rnd(100) + 190.5
p(i+j*32).vx = 0
p(i+j*32).vy = 0
p(i+j*32).mass = 4
p(i+j*32).colour = 0
next j
next i
make memblock 1, 640*480*4+12
write memblock dword 1, 0, 640
write memblock dword 1, 4, 480
write memblock dword 1, 8, 32
for i=12 to (640*480*4+11) step 4
write memblock byte 1, i, 0 :`Blue
write memblock byte 1, i+1, 0 :`Green
write memblock byte 1, i+2, 0 :`Red
write memblock byte 1, i+3, 10 :`Alpha
next i
make image from memblock 1, 1
`MAIN LOOP
`This is the part to edit. basically it just applies
`forces to the particles, draws them, and repeats
do
`cls
set cursor 0,0
print screen fps()
`Apply forces
if inkey$()<>" "
FORCE_GRAV_POINT(-1, mousex(), mousey())
FORCE_GRAV_POINT(-1, 540, 100)
FORCE_GRAV_POINT(-1, 100, 380)
FORCE_GRAV_POINT(-1, 540, 380)
`Update positions
for i=0 to TOTAL_PARTICLE_COUNT
p(i).x = p(i).x + p(i).vx
p(i).y = p(i).y + p(i).vy
next i
endif
`No going outside the screen
`if one does, then its back to the start
for i=0 to TOTAL_PARTICLE_COUNT
if (p(i).vx*p(i).vx)+(p(i).vy*p(i).vy)>36
p(i).x = rnd(100) + 270.5
p(i).y = rnd(100) + 190.5
p(i).vx = 0
p(i).vy = 0
p(i).colour = p(i).colour+1
if p(i).colour=9
p(i).colour=0
p(i).x = rnd(100) + 270.5
p(i).y = rnd(100) + 190.5
endif
endif
next i
`Draw the particles
for i=0 to TOTAL_PARTICLE_COUNT
ink c(p(i).colour), 0
box p(i).x, p(i).y,p(i).x+1, p(i).y+1
next i
`draw the image to create the trail effect
paste image 1, 0, 0, 1
sync
loop
`Functions
`Gravity Point
function FORCE_GRAV_POINT(particle, gx, gy)
ink RGB(255,255,255), 0
circle gx, gy, 10
dist as float
accel as float
if particle = -1
for i=0 to TOTAL_PARTICLE_COUNT
dist = (gx-p(i).x)*(gx-p(i).x) + (gy-p(i).y)*(gy-p(i).y)
accel = GRAVITY_CONSTANT*(p(i).mass)/dist
dist = sqrt(dist)
p(i).vx = p(i).vx + accel*(gx-p(i).x)/dist
p(i).vy = p(i).vy + accel*(gy-p(i).y)/dist
next i
else
dist = (gx-p(particle).x)*(gx-p(particle).x) + (gy-p(particle).y)*(gy-p(particle).y)
dist = sqrt(dist)
accel = GRAVITY_CONSTANT*(p(particle).mass)/dist
p(particle).vx = p(particle).vx + accel*(gx-p(particle).x)/dist
p(particle).vy = p(particle).vy + accel*(gy-p(particle).y)/dist
endif
endfunction
That looks so cool!
|
Back to top
 |
|
qwe
User
Joined: Wed Sep 3rd 2003
Location: place
|
awsome program
If you want anything DB related hosted, log in (with ws ftp or something) www.lysergium.net with username public@lysergium.net and password public. you'll be directed to lysergium.net/public
|
Back to top
 |
|
Eddie B
User
Joined: Sun Apr 10th 2005
Location: Cyberspace
|
This is cool
|
Back to top
 |
|
Sorry, but it has been so long since anyone replied to this Thread that it has been automatically locked.
You may read it but not reply.
Enter a word or phrase to search our Forum for:
|
|
 |