package net.beadsproject.touch.examples;

import java.awt.Color;

import net.beadsproject.touch.HVLayout;
import net.beadsproject.touch.ParticleSimulator;
import net.beadsproject.touch.perform.PerformNode;
import processing.core.PApplet;

/**
 * Demonstrates the use of a particle simulation after an initial layout by HVLayout.
 * 
 * @author ben
 *
 */
public class ParticleSimulatorTest extends PApplet {	
	
	static final int DEPTH = 5;
	static final int NARY = 3;
	static int NUM_PARTICLES = 1;
	
	static PerformNode pt = null;
	ParticleSimulator simulator = null;
	
	boolean isSimulating = false; 
	
	public void setup()
	{		
		size(900,900);
		ellipseMode(CENTER);
		simulator = new ParticleSimulator();		
		
		println("Building tree");
		pt = Example.example1();
		pt.computeUniqueValue(0, 1);
				
		println("Laying out and initialising simulator.");
		simulator.addHVPoints(HVLayout.layout(pt));
		simulator.computeTreeDistance();
		
		println("Done");
	}	
		
	public void draw()
	{		
		background(255);
		pushMatrix();
		scale(width,height);
		noStroke();
		for(ParticleSimulator.Particle p: simulator.getParticles())
		{
			Color c = new Color(Color.HSBtoRGB(p.pn.uniqueValue(),.8f,1f));			
			fill(c.getRed(),c.getGreen(),c.getBlue(),150);
			ellipse((float)p.x,(float)p.y,(float)(p.radius*2),(float)(p.radius*2));
			
			fill(0);
			ellipse((float)p.x,(float)p.y,4.f/width,4.f/height);
		}
		popMatrix();
		
		// now simulate by some amount
		if (isSimulating)
		{
			simulator.step(0.001f);
			
			/*
			for(ParticleSimulator.Particle p: simulator.getParticles())
			{
				p.radius += 0.0001;
			}
			*/
		}
	}		
	
	public void mouseClicked()
	{
		isSimulating = !isSimulating;
	}
}
