# Ribbons in Jinx!Script
# (c) 2015 Bob Kojima
# bob.k.kojima@gmail.com


# initialize
:init
	config particle_count = 10
	config particle_distance = 50
	config fadeout = 8
	config pause = 1

	w = matrix_x
	h = matrix_y

	time = 0
	
	for i = 0 to particle_count step 1
		gosub setup
	next
	
end

# render frame
:render

	fade fadeout
	
	for i = 0 to particle_count step 1	
			
		#basically created a set of particles moving in random direction
		for j = 0 to particle_count step 1
		
			#calculating distance of particle with all other particles
			yd = y[j] - y[i]
			xd = x[j] - x[i]
			distance = sqr(xd*xd + yd*yd)
			
			#draw a line between both particles if they are in range
			if distance < particle_distance
				hsv2rgb hue[i], 255, 255, r, g, b
				line x[i], y[i], x[j], y[j], r, g, b
			endif
		next
		
		if time = pause
			#Lets move the particles
			x[i] = x[i] + speed[i]*cos(angle[i]*pi/180)
			y[i] = y[i] + speed[i]*sin(angle[i]*pi/180)
			hue[i] = hue[i] + .5
		endif
		
		if x[i] < 0 
			x[i] = w
		endif
		if x[i] > w 
			x[i] = 0
		endif
		if y[i] < 0
			y[i] = h
		endif
		if y[i] > h 
			y[i] = 0
		endif
		if hue[i] = 360
			hue[i] = 0
		endif
			
	next
	
	if time = pause				
		time = 0
 	else
 		time = time + 1
  endif
	
end


:setup

		x[i] = rnd(w)
		y[i] = rnd(h)
		r[i] = 0
		speed[i] = 3
		angle[i] = rnd(360)
		hue[i] = rnd(360)

return
end