File: one-galaxy.gravitspawn

package info (click to toggle)
gravit 0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,420 kB
  • ctags: 942
  • sloc: ansic: 6,841; makefile: 63; sh: 43
file content (27 lines) | stat: -rw-r--r-- 907 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-- vim:syntax=lua tabstop=4

load("functions.lua")

function describe()
	log("One spiral galaxy")
end

function spawn()
	particlemassmin = randomfloat(1,1000)
	particlemassmax = randomfloat(1,1000)
	estmass = (particlemassmin + particlemassmax) / 2 * spawnparticles
	galaxyradius = randomfloat(10,1000)
	speedbase = .0000001
	thickness = randomfloat(0.001, 10)
	verticalvelocity = randomfloat(0, 1)
	for i=0,spawnparticles-1 do
		radius = randomfloat(0,galaxyradius)
		speed = speedbase * radius * math.sqrt(estmass) 
		angle = randomfloat(0,2*math.pi)
		pos = v(math.cos(angle)*radius, math.sin(angle)*radius, randomfloat(-thickness,thickness))
		vel = v(math.cos(angle+math.pi/2)*speed*radius, math.sin(angle+math.pi/2)*speed*radius, randomfloat(-verticalvelocity, verticalvelocity))
		mass = randomfloat(particlemassmin,particlemassmax)
		particle(i, pos, vel, mass)
	end
end