The scariest thing in nature ... (other than IanM that is)
This is really just mucking about more than anything else.
Its an incredibly simple black hole simulator. I say incredibly simple because I haven't bothered to set a decent event horizon constant and so a lot of the particles escape.
Arrow keys, return and shift to control the camera. Escape to reset it. A and S to increase or deceased gravity. Minus gravity of course repels particles from the "black hole".
You'll need Cloggy's D3dfunc plugin to run this.
Rem PJY - the Bear's veeery simple black hole model
Rem PJY - (with apologies to Professor Stephen Hawking)
sync on
sync rate 60
autocam off
d3d_init
disable escapekey
Rem PJY - for simplicity, lets assume the black hole is at 0, 0, 0
position camera 0, 10, 200, -250
point camera 0, 0, 0, 0
rem set camera fov 0, 45
Rem PJY - make a matrix
make object sphere 1, 5, 20, 20
position object 1, 0, 0, 0
color object 1, rgb(0, 0, 0)
set object light 1, 1
set object ambient 1, 0
total_particles = 1000
global gravity# = 400.0
TYPE t_vec
x as float
y as float
z as float
ENDTYPE
TYPE t_particle
pos as t_vec
velocity as t_vec
ENDTYPE
dim particles(total_particles) AS t_particle
Rem PJY - randomise the position of the particles and their starting velocities
for i = 1 to total_particles
recycle_particle(i)
next i
previous_time = timer()
repeat
text 0, 00, "FPS: " + str$(screen fps())
text 0, 30, "Camera position: " + str$(camera position x(0)) + " " + str$(camera position y(0)) + " " + str$(camera position z(0))
text 0, 60, "Gravity: " + str$(gravity#) + " A / S to increase/decrease"
control()
current_time = timer() - previous_time
for i = 1 to total_particles
if current_time > 400
Rem PJY - sanity check
if particles(i).pos.x > 500 OR particles(i).pos.x < -500 OR particles(i).pos.y > 500 OR particles(i).pos.y < -500 OR particles(i).pos.z > 500 OR particles(i).pos.z < -500
recycle_particle(i)
endif
Rem PJY - move the particle by applying velocity to its position
particles(i).pos.x = particles(i).pos.x + particles(i).velocity.x
particles(i).pos.y = particles(i).pos.y + particles(i).velocity.y
particles(i).pos.z = particles(i).pos.z + particles(i).velocity.z
dsx# = particles(i).pos.x * particles(i).pos.x
dsy# = particles(i).pos.y * particles(i).pos.y
dsz# = particles(i).pos.z * particles(i).pos.z
dp2# = dsx# + dsy# + dsz#
if dp2# > 2
g# = gravity# / (dp2# * 1.0)
dist# = sqrt(dp2#)
else
text (screen width() / 2), 0, "Died!"
recycle_particle(i)
endif
Rem PJY - ok the particle is still with us, so its time for gravity to take hold
grav_x# = -g# * (particles(i).pos.x / dist#)
grav_y# = -g# * (particles(i).pos.y / dist#)
grav_z# = -g# * (particles(i).pos.z / dist#)
particles(i).velocity.x = particles(i).velocity.x + grav_x#
particles(i).velocity.y = particles(i).velocity.y + grav_y#
particles(i).velocity.z = particles(i).velocity.z + grav_z#
endif
d3d_dot3d particles(i).pos.x, particles(i).pos.y, particles(i).pos.z, 3, rgb(255,215,000), 1
d3d_line3d particles(i).pos.x, particles(i).pos.y, particles(i).pos.z, particles(i).pos.x - particles(i).velocity.x, particles(i).pos.y - particles(i).velocity.y, particles(i).pos.z - particles(i).velocity.z, rgb(255, 0, 0), 1
next i
sync
previous_time = current_time
until spacekey() > 0
FUNCTION recycle_particle(i)
null = make vector3(1)
particles(i).pos.x = rnd(1000) - 500
particles(i).pos.y = rnd(20) - 10
particles(i).pos.z = rnd(1000) - 500
particles(i).velocity.x = rnd(100) - 50
particles(i).velocity.y = rnd(20) - 10
particles(i).velocity.z = rnd(100) - 50
set vector3 1, particles(i).velocity.x, particles(i).velocity.y, particles(i).velocity.z
normalize vector3 1, 1
random# = (rnd(100) * 0.01)
if random# =< 0.3 then random# = 0.3
multiply vector3 1, random#
particles(i).velocity.x = x vector3(1)
particles(i).velocity.y = y vector3(1)
particles(i).velocity.z = z vector3(1)
null = delete vector3(1)
ENDFUNCTION
FUNCTION control()
Rem PJY - A key
if keystate(30) > 0
gravity# = gravity# + 1
endif
Rem PJY - S key
if keystate(31) > 0
gravity# = gravity# - 1
endif
if upkey() > 0
pitch camera up 0, 1
endif
if downkey() > 0
pitch camera down 0,1
endif
if leftkey() > 0
turn camera left 0, 1
endif
if rightkey() > 0
turn camera right 0,1
endif
if returnkey() > 0
move camera 0, 2
endif
if shiftkey() > 0
move camera 0, -2
endif
if escapekey() > 0
position camera 0, 10, 200, -250
point camera 0, 0, 0, 0
endif
ENDFUNCTION
Cheer if you like bears! Cheer if you like jam sandwiches!
Quote of the week: "... I started learning DBP while I was a Satellite Network Controller for the US Army Space Command ... "