#include "Particle.h"

Particle::Particle(){
	particle_radius = 10;
	
	pos = ofxPoint2f(ofGetWidth()/2,ofGetHeight()/2);
	next_pos = ofxPoint2f(ofGetWidth()/2,ofGetHeight()/2);
	prev_pos = ofxPoint2f(ofGetWidth()/2,ofGetHeight()/2);
	pct_moved = 0;
	
	size_pct = 0;
	size = ofxPoint2f(10,10);
	prev_size = ofxPoint2f(0,0);
	next_size = ofxPoint2f(200,200);
	
	origin = ofxPoint2f(ofGetWidth()/2,ofGetHeight()/2);
	radius_of_movement = 50;
	angle = 0;
	angle_of_step = .01;
	
	c = colors();
}

void Particle::update(){ //takes care of edge issues..
	if(pos.x > ofGetWidth()+size.x/2){
		pos.x = 0 - size.x/2;
	} else if(pos.x < 0-size.x/2){
		pos.x = ofGetWidth() + size.x/2;
	}
	if(pos.y > ofGetHeight()+size.y/2){
		pos.y = 0 - size.y/2;
	} else if(pos.y < 0-size.y/2){
		pos.y = ofGetHeight() + size.y/2;
	}
}

void Particle::move(float x, float y){
	pos.x += x;
	pos.y += y;
	update();
}

void Particle::tween(float speed=.01,float shaper=1){
	if(pct_moved < 1){
		pct_moved += speed;
	}
	float pct = powf(pct_moved,shaper);
	pos.x = ((1-pct)*prev_pos.x)+(pct * next_pos.x);
	pos.y = ((1-pct)*prev_pos.y)+(pct * next_pos.y);	
}

void Particle::tweenXeno(float speed){
	pos.x = (speed*next_pos.x)+(1-speed)*pos.x;
	pos.y = (speed*next_pos.y)+(1-speed)*pos.y;
}

void Particle::move_around_circle(){
	pos.x = origin.x + radius_of_movement * cos(angle);
	pos.y = origin.y + radius_of_movement * sin(angle);
	angle += angle_of_step;
}

void Particle::tweenSize(float speed, float shaper){
	if(size_pct >= 1){
		size_pct = 0;
		size = next_size;
		next_size = prev_size;
		prev_size = size;
	} else {
		size_pct += speed;
	}
	float pct = powf(size_pct,shaper);
	size.x = ((1-pct)*prev_size.x)+(pct*next_size.x);
	size.y = ((1-pct)*prev_size.x)+(pct*next_size.x);
}

void Particle::setDestination(float x,float y){
		prev_pos = pos;
		next_pos.x = x;
		next_pos.y = y;
		pct_moved = 0;
}

void Particle::draw(){
	//ofNoFill();
	ofCircle(pos.x,pos.y,particle_radius);
	//ofFill();
}