package com.haxademic.sketch.render;

import com.haxademic.core.app.P;
import com.haxademic.core.app.PAppletHax;
import com.haxademic.core.constants.AppSettings;
import com.haxademic.core.draw.context.DrawUtil;
import com.haxademic.core.draw.context.OpenGLUtil;

public class ConcentricCubes
extends PAppletHax {
	public static void main(String args[]) { PAppletHax.main(Thread.currentThread().getStackTrace()[1].getClassName()); }

	//	protected ControlP5 _cp5;

	protected int _x = 0;
	protected int _y = 0;

	protected int _frames = 40;

	protected void overridePropsFile() {
		p.appConfig.setProperty( AppSettings.WIDTH, "800" );
		p.appConfig.setProperty( AppSettings.HEIGHT, "800" );

		p.appConfig.setProperty( AppSettings.RENDERING_MOVIE, "false" );
		p.appConfig.setProperty( AppSettings.RENDERING_GIF, "false" );
		p.appConfig.setProperty( AppSettings.RENDERING_GIF_FRAMERATE, "40" );
		p.appConfig.setProperty( AppSettings.RENDERING_GIF_QUALITY, "15" );
		p.appConfig.setProperty( AppSettings.RENDERING_GIF_START_FRAME, "2" );
		p.appConfig.setProperty( AppSettings.RENDERING_GIF_STOP_FRAME, ""+Math.round(_frames+1) );

	}

	public void setup() {
		super.setup();	
		p.smooth( OpenGLUtil.SMOOTH_HIGH );

		//		_cp5 = new ControlP5(this);
		//		_cp5.addSlider("_x").setPosition(20,60).setWidth(200).setRange(0,p.displayWidth - p.width);
		//		_cp5.addSlider("_y").setPosition(20,100).setWidth(200).setRange(0,p.displayHeight - p.height);
	}

	public void drawApp() {
		background(20);
		DrawUtil.setDrawCenter(p);
		p.noFill();
		p.translate(p.width/2, p.height/2, -1200);

		float percentComplete = ((float)(p.frameCount%_frames)/_frames);

		p.sphereDetail(4);

		//				p.blendMode(P.SCREEN);
//		p.blendMode(P.MULTIPLY);
//		p.blendMode(P.ADD);

		float cubeSize = p.width/1f;
		float cubScaleDown = 300f + 270 * P.sin(P.TWO_PI * percentComplete);
		int i=0;
		while(cubeSize > 10) {
			p.pushMatrix();
			p.stroke(127 + 127f * P.sin(i/20f), 127 + 127f * P.sin(i/30f), 127 + 127f * P.sin(i/10f));
			p.strokeWeight(2.2f);
			//			p.rotateY(0.5f * P.sin(P.TWO_PI * percentComplete + i/numCubes));
			p.rotateY(1.1f * P.sin(P.TWO_PI * percentComplete + i * 0.03f));
			p.rotateZ(2.1f * P.sin(P.TWO_PI * percentComplete + i * 0.03f));
			p.rotateX(1.1f * P.sin(P.TWO_PI * percentComplete + i * 0.03f));
//			p.box(cubeSize);
			p.sphere(cubeSize);
			p.popMatrix();
			cubeSize -= p.width / cubScaleDown;
			i++;
		}

		//		p.filter(P.BLUR);

		if( p.frameCount == _frames * 2 + 2 ) {
			if(p.appConfig.getBoolean("rendering", false) ==  true) {				
				movieRenderer.stop();
				P.println("render done!");
			}
		}

	}

}




@@ -529,17 +529,18 @@
 rames = 
-4
+10
 0;%0A%0A%09pro
@@ -619,21 +619,19 @@
 .WIDTH, 
-%22
 800
-%22
  );%0A%09%09p.
@@ -677,18 +677,15 @@
 HT, 
-%22
 800
-%22
  );%0A
-%0A
 %09%09p.
@@ -740,709 +740,17 @@
 IE, 
-%22
 false
-%22
  );%0A
-%09%09p.appConfig.setProperty( AppSettings.RENDERING_GIF, %22false%22 );%0A%09%09p.appConfig.setProperty( AppSettings.RENDERING_GIF_FRAMERATE, %2240%22 );%0A%09%09p.appConfig.setProperty( AppSettings.RENDERING_GIF_QUALITY, %2215%22 );%0A%09%09p.appConfig.setProperty( AppSettings.RENDERING_GIF_START_FRAME, %222%22 );%0A%09%09p.appConfig.setProperty( AppSettings.RENDERING_GIF_STOP_FRAME, %22%22+Math.round(_frames+1) );%0A%0A%09%7D%0A%0A%09public void setup() %7B%0A%09%09super.setup();%09%0A%09%09p.smooth( OpenGLUtil.SMOOTH_HIGH );%0A%0A%09%09//%09%09_cp5 = new ControlP5(this);%0A%09%09//%09%09_cp5.addSlider(%22_x%22).setPosition(20,60).setWidth(200).setRange(0,p.displayWidth - p.width);%0A%09%09//%09%09_cp5.addSlider(%22_y%22).setPosition(20,100).setWidth(200).setRange(0,p.displayHeight - p.height);
 %0A%09%7D%0A
@@ -1337,13 +1337,13 @@
 f);%0A
+//
 %09%09%09
-//
 %09%09%09p
@@ -1398,17 +1398,8 @@
  + i
-/numCubes
 ));%0A
@@ -1720,211 +1720,10 @@
 %09%09%7D%0A
-%0A%09%09//%09%09p.filter(P.BLUR);%0A%0A%09%09if( p.frameCount == _frames * 2 + 2 ) %7B%0A%09%09%09if(p.appConfig.getBoolean(%22rendering%22, false) ==  true) %7B%09%09%09%09%0A%09%09%09%09movieRenderer.stop();%0A%09%09%09%09P.println(%22render done!%22);%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%7D%0A
+%09%7D
 %0A%7D%0A%0A

Clean up