Java Code Examples for processing.core.PShape#scale()

The following examples show how to use processing.core.PShape#scale() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Skylight_PoissonSphereSamples.java    From PixelFlow with MIT License 5 votes vote down vote up
public void updateSpheres(){
  PShape[] shp_spheres = shp_samples_spheres.getChildren();
  for(int i = 0; i < shp_spheres.length; i++){
    PShape shp_sphere = shp_spheres[i];
    MyPoissonSample sample = pds.samples.get(i);
    sample.updateAnimation();
    shp_sphere.resetMatrix();
    shp_sphere.scale(sample.anim_rad);
    shp_sphere.translate(sample.x(), sample.y(), sample.z());
  }
}
 
Example 2
Source File: Demo_PShapeUtil_createBasicPShape.java    From haxademic with MIT License 5 votes vote down vote up
protected void firstFrame() {
	// config build shapes
	float shapeSize = 100;
	float spacing = 120;
	float strokeWeight = 3;
	p.sphereDetail(8);
	
	// grid of shapes
	// boxes
	shapes.add(PShapeUtil.createBox(shapeSize, shapeSize, shapeSize, p.color(0, 255, 255)));
	lastShape().scale(1, 1, 0.5f);
	lastShape().translate(spacing*-2.5f, spacing*-1, 0);
	shapes.add(PShapeUtil.createBox(shapeSize, shapeSize, shapeSize, spacing*-1.5f, spacing*-1, 0, 0, p.color(255, 0, 255), strokeWeight));
	shapes.add(PShapeUtil.createBox(shapeSize, shapeSize, shapeSize, spacing*-0.5f, spacing*-1, 0, p.color(255), p.color(1), strokeWeight));
	// spheres
	shapes.add(PShapeUtil.createSphere(shapeSize, p.color(0, 255, 255)));
	lastShape().translate(spacing*0.5f, spacing*-1, 0);
	shapes.add(PShapeUtil.createSphere(shapeSize, spacing*1.5f, spacing*-1, 0, 0, p.color(255, 0, 255), strokeWeight));
	shapes.add(PShapeUtil.createSphere(shapeSize, spacing*2.5f, spacing*-1, 0, p.color(255), p.color(1), strokeWeight));
	// rect
	shapes.add(PShapeUtil.createRect(shapeSize, shapeSize, p.color(0, 255, 255)));
	lastShape().translate(spacing*-2.5f, spacing*1, 0);
	shapes.add(PShapeUtil.createRect(shapeSize, shapeSize, spacing*-1.5f, spacing*1, 0, 0, p.color(255, 0, 255), strokeWeight));
	shapes.add(PShapeUtil.createRect(shapeSize, shapeSize, spacing*-0.5f, spacing*1, 0, p.color(255), p.color(1), strokeWeight));
	// ellipse
	shapes.add(PShapeUtil.createEllipse(shapeSize, shapeSize, p.color(0, 255, 255)));
	lastShape().translate(spacing*0.5f, spacing*1, 0);
	shapes.add(PShapeUtil.createEllipse(shapeSize, shapeSize, spacing*1.5f, spacing*1, 0, 0, p.color(255, 0, 255), strokeWeight));
	shapes.add(PShapeUtil.createEllipse(shapeSize, shapeSize, spacing*2.5f, spacing*1, 0, p.color(255), p.color(1), strokeWeight));

	// outer sphere
	shapes.add(PShapeUtil.createSphere(3000, p.color(180, 180, 0)));
	PShape innerSphere = PShapeCopy.copyShape(lastShape());
	PShapeUtil.setBasicShapeStyles(innerSphere, 0, p.color(0), 10);
	innerSphere.scale(0.6f);
	shapes.add(innerSphere);
}
 
Example 3
Source File: Skylight_Movie2.java    From PixelFlow with MIT License 4 votes vote down vote up
public void updateAnim(){
  
  if(pg_src_small == null){
    return;
  }
  
  int num_x = pg_src_small.width;
  int num_y = pg_src_small.height;
  
  DwFilter.get(context).gaussblur.apply(pg_src, pg_src, pg_src_tmp, 5);
  
  pg_src_small.beginDraw();
  pg_src_small.image(pg_src, 0, 0, num_x, num_y);
  pg_src_small.endDraw();
  
  opticalflow.update(pg_src);
  DwFilter.get(context).copy.apply(opticalflow.frameCurr.velocity, tex_vel_small);
  flow = tex_vel_small.getFloatTextureData(flow);

  DwFilter.get(context).gaussblur.apply(pg_src_small, pg_src_small, pg_src_small_tmp, 3);
  
  pg_src_small.loadPixels();
  



  float scene_dimx = bounds[3] - bounds[0];
  float scene_dimy = bounds[4] - bounds[1];
  float scene_dimz = bounds[5] - bounds[2];
  float bounds_off = 100;

  float dimx = (scene_dimx - bounds_off*2) / num_x;
  float dimy = (scene_dimy - bounds_off*2) / num_y;
  
  float dim = min(dimx, dimy);

  float tx = -dim * num_x * 0.5f;
  float ty = -dim * num_y * 0.5f;
  float tz = 0;

  for(int y = 0; y < num_y; y++){
    for(int x = 0; x < num_x; x++){
      int idx = y * num_x + x;

      int rgb = pg_src_small.pixels[idx];
      int r = (rgb >> 16) & 0xFF;
      int g = (rgb >>  8) & 0xFF;
      int b = (rgb >>  0) & 0xFF;
      
      int flow_idx = (num_y - y - 1) * num_x + x;
      float flows = 5;
      float flowx = flow[flow_idx * 2 + 0] * +flows;
      float flowy = flow[flow_idx * 2 + 1] * -flows;
      

      float gray = (r + g + b) / (3f * 255f);
      
      float px = tx + x * dim + flowx;
      float py = ty + y * dim + flowy;
      float pz = tz + scene_dimz * gray * 0.35f;
      
      PShape cube = shp_cubes[idx];

      cube.resetMatrix();
      cube.scale(dim);
      cube.translate(px, py, pz);
 
      cube.setFill(rgb);
    }
  }
}
 
Example 4
Source File: Skylight_Movie3.java    From PixelFlow with MIT License 4 votes vote down vote up
public void updateAnim(){
    
   
    cube_numx = pg_src_small.width;
    cube_numy = pg_src_small.height;
    
  
    // apply filters (not necessary)
//    if(APPLY_GRAYSCALE){
//      DwFilter.get(context).luminance.apply(pg_movie_a, pg_movie_a);
//    }
//    if(APPLY_BILATERAL)
    DwFilter.get(context).gaussblur.apply(pg_src, pg_src, pg_src_tmp, 5);
    
//    {
//      DwFilter.get(context).bilateral.apply(pg_src, pg_src_tmp, 5, 0.10f, 4);
//      swap();
//    }
    

    
    pg_src_small.beginDraw();
    pg_src_small.image(pg_src, 0, 0, cube_numx, cube_numy);
    pg_src_small.endDraw();
    
    opticalflow.update(pg_src);
    DwFilter.get(context).copy.apply(opticalflow.frameCurr.velocity, tex_vel_small);
    flow = tex_vel_small.getFloatTextureData(flow);

    DwFilter.get(context).gaussblur.apply(pg_src_small, pg_src_small, pg_src_small_tmp, 1);
    
    pg_src_small.loadPixels();
    
    float scene_dimx = bounds[3] - bounds[0];
    float scene_dimy = bounds[4] - bounds[1];
    float scene_dimz = bounds[5] - bounds[2];
    float bounds_off = 100;

    float dimx = (scene_dimx - bounds_off*2) / cube_numx;
    float dimy = (scene_dimy - bounds_off*2) / cube_numy;
    
    cube_size = min(dimx, dimy);

    float tx = -cube_size * cube_numx * 0.5f;
    float ty = -cube_size * cube_numy * 0.5f;
    float tz = 10;

    for(int y = 0; y < cube_numy; y++){
      for(int x = 0; x < cube_numx; x++){
        int idx = y * cube_numx + x;

        int rgb = pg_src_small.pixels[idx];
        int r = (rgb >> 16) & 0xFF;
        int g = (rgb >>  8) & 0xFF;
        int b = (rgb >>  0) & 0xFF;
        
        int flow_idx = (cube_numy - y - 1) * cube_numx + x;
        float flows = 3;
        float flowx = flow[flow_idx * 2 + 0] * +flows;
        float flowy = flow[flow_idx * 2 + 1] * -flows;
        
        float flow_mm = flowx*flowx + flowy*flowy;
        float flow_m = (float) Math.pow(flow_mm, 0.5f) * 0.75f;
        
  
        float gray = (r + g + b) / (3f * 255f);
        
        float px = x * cube_size;
        float py = y * cube_size;
        float pz = scene_dimz * gray * 0.25f;
        
        pz = max(pz, 0);

        
        PShape cube = shp_cubes[idx];

        cube.resetMatrix();
        cube.rotateZ((float) Math.atan2(flowy, flowx));
        cube.scale(cube_size + flow_m);
        cube.translate(tx+px, ty+py, tz+pz);
 
        cube.setFill(rgb);
      }
    }
  }
 
Example 5
Source File: Demo_VertexShader_MoveSpheres.java    From haxademic with MIT License 4 votes vote down vote up
protected void firstFrame() {
		// UI
		UI.addTitle("Spheres config");
		UI.addToggle(CAMERA_ON, true, false);
		UI.addSlider(NOISE_SPEED_X, 0.001f, 0, 0.1f, 0.00001f, false);
		UI.addSlider(NOISE_SPEED_Y, 0.001f, 0, 0.1f, 0.00001f, false);
		UI.addSlider(DISPLACE_AMP, 200, 0, 1000, 1, false);
		UI.addSlider(DISPLACE_OFFSET_X, 0, 0, 1000, 0.01f, false);
		UI.addSlider(DISPLACE_OFFSET_Y, 0, 0, 1000, 0.01f, false);
		UI.addSliderVector(LIGHT_DIR, 1f, -10f, 10f, 0.01f, false);
		UI.addSliderVector(LIGHT_COL, 1f, 0, 1, 0.001f, false);
		UI.addSliderVector(LIGHT_AMBIENT, 1f, 0, 1, 0.001f, false);
		UI.addSlider(LIGHT_SHININESS, 1f, 0, 1000, 0.01f, false);
		
		// config build shapes
		float shapeSize = 12;
		float shapeSpacing = 12;
		p.sphereDetail(10);
		int vertCount = PShapeUtil.vertexCount(PShapeUtil.createSphere(1, 0));

		// create PShapes inside a group
		int startBuildTime = p.millis();
		int cols = 300;
		int rows = 200;
		startBuildTime = p.millis();
		group = p.createShape(P.GROUP);
		for (int x = 0; x < cols; x++) {
			for (int y = 0; y < rows; y++) {
				float gridX = -(shapeSpacing * cols/2) + (x * shapeSpacing);
				float gridY = -(shapeSpacing * rows/2) + (y * shapeSpacing);
//				PShape shape = PShapeUtil.createSphere(shapeSize, gridX, gridY, 0, 127 + 127 * p.color(P.sin(x/10f), 127 + 127 * P.sin(y/10f), 127 + 127 * P.sin(x+y/100f)), 0, 0);
				PShape shape = PShapeUtil.createBox(shapeSize, shapeSize, shapeSize, gridX, gridY, 0, 127 + 127 * p.color(P.sin(x/10f), 127 + 127 * P.sin(y/10f), 127 + 127 * P.sin(x+y/100f)), 0, 0);
				// give the shape attributes for the shader to pick out their UV coord from grid index
				shape.attrib("x", x);
				shape.attrib("y", y);
				group.addChild(shape);
			}
		}
		DebugView.setValue("Group PShape time", p.millis() - startBuildTime + "ms");
		DebugView.setValue("Num shapes", cols * rows);
		DebugView.setValue("Num verts", cols * rows * vertCount);
		
		// outer sphere
		shared.add(PShapeUtil.createSphere(4000, p.color(50, 0)));
		PShape innerSphere = PShapeCopy.copyShape(shared.get(shared.size() - 1));
		PShapeUtil.setBasicShapeStyles(innerSphere, 0, p.color(20), 10);
		innerSphere.scale(0.6f);
		shared.add(innerSphere);
		
		// load shader to move spheres
		polygonShader = new PShaderHotSwap(
				FileUtil.getPath("haxademic/shaders/vertex/mesh-3d-deform-vert.glsl"),
				FileUtil.getPath("haxademic/shaders/vertex/mesh-3d-deform-frag.glsl") 
			);
		noiseTexture = new SimplexNoiseTexture(cols, rows, true);
		displaceTexture = PG.newPG32(cols, rows, false, false);
		DebugView.setTexture("noiseTexture", noiseTexture.texture());
		DebugView.setTexture("displaceTexture", displaceTexture);
	}
 
Example 6
Source File: Skylight_Capture1.java    From PixelFlow with MIT License 2 votes vote down vote up
public void updateAnim(){
  
  if(pg_src_small == null){
    createScene();
  }
  
  int num_x = pg_src_small.width;
  int num_y = pg_src_small.height;
  
  DwFilter.get(context).gaussblur.apply(pg_src, pg_src, pg_src_tmp, 3);
  
  pg_src_small.beginDraw();
  pg_src_small.image(pg_src, 0, 0, num_x, num_y);
  pg_src_small.endDraw();
  
  opticalflow.update(pg_src);
  DwFilter.get(context).copy.apply(opticalflow.frameCurr.velocity, tex_vel_small);
  flow = tex_vel_small.getFloatTextureData(flow);

  DwFilter.get(context).gaussblur.apply(pg_src_small, pg_src_small, pg_src_small_tmp, 3);
  
  pg_src_small.loadPixels();
  



  float scene_dimx = bounds[3] - bounds[0];
  float scene_dimy = bounds[4] - bounds[1];
  float scene_dimz = bounds[5] - bounds[2];
  float bounds_off = 100;

  float dimx = (scene_dimx - bounds_off*2) / num_x;
  float dimy = (scene_dimy - bounds_off*2) / num_y;
  
  float dim = min(dimx, dimy);

  float tx = -dim * num_x * 0.5f;
  float ty = -dim * num_y * 0.5f;
  float tz = 10;

  for(int y = 0; y < num_y; y++){
    for(int x = 0; x < num_x; x++){
      int idx = y * num_x + x;

      int rgb = pg_src_small.pixels[idx];
      int r = (rgb >> 16) & 0xFF;
      int g = (rgb >>  8) & 0xFF;
      int b = (rgb >>  0) & 0xFF;
      
      int flow_idx = (num_y - y - 1) * num_x + x;
      float flows = 3;
      float flowx = flow[flow_idx * 2 + 0] * +flows;
      float flowy = flow[flow_idx * 2 + 1] * -flows;
      
      float flow_mm = flowx*flowx + flowy*flowy;
      float flow_m = (float) Math.pow(flow_mm, 0.5f);
      

      float gray = (r + g + b) / (3f * 255f);
      
      float px = x * dim;
      float py = y * dim;
      float pz = scene_dimz * gray * 0.25f + +flow_m;
      
      pz = max(pz, 0);

      
      PShape cube = shp_cubes[idx];

      cube.resetMatrix();
      cube.scale(dim);
      cube.translate(tx+px, ty+py, tz+pz);
 
      cube.setFill(rgb);
    }
  }
}