Summary
Immerse yourself in a mesmerizing cosmic simulation where thousands of particles dance like spinning galaxies and stars.
(I've also made a Picotron version)
Controls
- Use the arrow keys to move around.
- Use Z and X to zoom in and out.
Hold both Z and X together then...
- Use Left and Right to adjust the speed of the animation.
- Press Down to pause and resume the animation
- Press Up to reset everything
Based on an algorithm by yuruyurau
Hi! Nice job, it is fun to look at! I re-worked the code a bit to remove redundancy, un-capped the curve count to get more particles. Hooked the Update() to 60 hz for a smoother result! Finally, you can hold "Z" + left/right to change the current particle count, and hold "Z" + up/down to zoom.
-- bubble universe (optimized)
-- by movie vertigo
-- consts
init_scale = 32
init_speed = 0.004
speed_change = 0.0001
scale_mul = 1.01
curve_step = 4
init_curve_count = 252
two_pi = 6.283185307179586
inv_two_pi = 0.1591549430918953
ang1_inc = curve_step * two_pi / 235 * inv_two_pi
ang2_inc = curve_step * inv_two_pi
-- vars
x_offset = 0
y_offset = 0
anim_time = 0
scale = init_scale
speed = init_speed
curve_count = init_curve_count
old_btn3 = false
old_speed = 0
function set_palette()
local p = {129,1,140,12, 133,131,139,138, 128,130,2,136, 8,9,10}
for i = 1, 15 do pal(i, p[i], 1) end
end
function _init()
set_palette()
camera(-64, -64)
end
function _update60()
local o_held = btn(4)
local x_held = btn(5)
if o_held and x_held then
if btn(0) then speed += speed_change end
if btn(1) then speed -= speed_change end
if btn(2) then
x_offset = 0 y_offset = 0 anim_time = 0
scale = init_scale speed = init_speed
curve_count = init_curve_count
end
if btn(3) and not old_btn3 then
if speed != 0 then
old_speed = speed
speed = 0
else
speed = old_speed
end
end
elseif o_held then
if btn(2) then scale *= scale_mul x_offset *= scale_mul y_offset *= scale_mul end
if btn(3) then scale /= scale_mul x_offset /= scale_mul y_offset /= scale_mul end
if btn(0) then curve_count = max(0, curve_count - curve_step) end
if btn(1) then curve_count += curve_step end
else
if btn(0) then x_offset += 1 end
if btn(1) then x_offset -= 1 end
if btn(2) then y_offset += 1 end
if btn(3) then y_offset -= 1 end
end
old_btn3 = btn(3)
anim_time += speed
end
function _draw()
local cstep = curve_step
local ccount = curve_count
local a1inc = ang1_inc
local a2inc = ang2_inc
local inv2 = inv_two_pi
local xoff = x_offset
local yoff = y_offset
local sc = scale
local a1_base = anim_time * inv2
local a2_base = a1_base
local _sin = sin
local _cos = cos
local _pset = pset
local _color = color
cls()
for i = 0, ccount, cstep do
local c = 1 + ((i >> 6) % 4) * 4
local a1s = a1_base
local a2s = a2_base
local x = _sin(a1s) + _sin(a2s)
local y = _cos(a1s) + _cos(a2s)
-- color 1
_color(c)
_pset(y*sc+xoff, x*sc+yoff)
for j = 2, 8 do
local a1 = a1s + x * inv2
local a2 = a2s + y * inv2
x = _sin(a1) + _sin(a2)
y = _cos(a1) + _cos(a2)
_pset(y*sc+xoff, x*sc+yoff)
end
-- color 2
_color(c+1)
for j = 1, 8 do
local a1 = a1s + x * inv2
local a2 = a2s + y * inv2
x = _sin(a1) + _sin(a2)
y = _cos(a1) + _cos(a2)
_pset(y*sc+xoff, x*sc+yoff)
end
-- color 3
_color(c+2)
for j = 1, 8 do
local a1 = a1s + x * inv2
local a2 = a2s + y * inv2
x = _sin(a1) + _sin(a2)
y = _cos(a1) + _cos(a2)
_pset(y*sc+xoff, x*sc+yoff)
end
-- color 4
_color(c+3)
for j = 1, 8 do
local a1 = a1s + x * inv2
local a2 = a2s + y * inv2
x = _sin(a1) + _sin(a2)
y = _cos(a1) + _cos(a2)
_pset(y*sc+xoff, x*sc+yoff)
end
a1_base += a1inc
a2_base += a2inc
end
end |
[Please log in to post a comment]




