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

The following examples show how to use processing.core.PShape#translate() . 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: ParticleSystem.java    From PixelFlow with MIT License 6 votes vote down vote up
public PShape createParticleShape(DwParticle3D particle){
   
    PShape shp_particle = papplet.createShape(PShape.GEOMETRY);
    
    shp_particle.resetMatrix();
    shp_particle.translate(particle.cx, particle.cy, particle.cz);
    shp_particle.rotateX(papplet.random(PConstants.TWO_PI));
    shp_particle.rotateY(papplet.random(PConstants.TWO_PI));
    shp_particle.rotateZ(papplet.random(PConstants.TWO_PI));
    shp_particle.setStroke(false);
//    shp_particle.setFill(papplet.color(160));
    
    if(ifs == null) ifs = new DwIcosahedron(1);
//    if(ifs == null) ifs = new DwCube(1);
    DwMeshUtils.createPolyhedronShape(shp_particle, ifs, 1, 3, true);

    return shp_particle;
  }
 
Example 2
Source File: Sampling_Poisson3D.java    From PixelFlow with MIT License 5 votes vote down vote up
void addShape(MyPoissonSample sample){
    PShape shp_point = createShape(POINT, sample.x(), sample.y(), sample.z());
    shp_point.setStroke(color(255));
    shp_point.setStrokeWeight(3);
    shp_samples_points.addChild(shp_point);
    

    if(ifs == null){
      ifs = new DwIcosahedron(2); verts_per_face = 3;
//      ifs = new DwCube(2); verts_per_face = 4;
    }
    PShape shp_sphere = createShape(PShape.GEOMETRY);
    shp_sphere.setStroke(false);
    shp_sphere.setFill(color(255));
    shp_sphere.resetMatrix();
    shp_sphere.translate(sample.x(), sample.y(), sample.z());
   
    DwMeshUtils.createPolyhedronShape(shp_sphere, ifs, sample.rad(), verts_per_face, true);
    
    shp_samples_spheres.addChild(shp_sphere);
    
    
//    PShape shp_sphere_normals = createShape(PShape.GEOMETRY);
//    shp_sphere_normals.setStroke(false);
//    shp_sphere_normals.setFill(color(255));
//    shp_sphere_normals.resetMatrix();
//    shp_sphere_normals.translate(sample.x(), sample.y(), sample.z());
//   
//    DwMeshUtils.createPolyhedronShapeNormals(shp_sphere_normals, ifs, sample.rad(), 10);
//    
//    shp_samples_spheres.addChild(shp_sphere_normals);
  }
 
Example 3
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 4
Source File: Skylight_PoissonSphereSamples.java    From PixelFlow with MIT License 5 votes vote down vote up
void addShape(MyPoissonSample sample){
    PShape shp_point = createShape(POINT, sample.x(), sample.y(), sample.z());
    shp_point.setStroke(color(255));
    shp_point.setStrokeWeight(3);
    shp_samples_points.addChild(shp_point);
    

    if(ifs == null){
      ifs = new DwIcosahedron(2); verts_per_face = 3;
//      ifs = new DwCube(3); verts_per_face = 4;
    }
    PShape shp_sphere = createShape(PShape.GEOMETRY);
    shp_sphere.setStroke(false);
    shp_sphere.setFill(color(255));
    
    colorMode(HSB, 360, 1, 1);
    float hsb_h = 15 + (float)(Math.random() - 0.5f) * 45 ;
    float hsb_s = (float) Math.random() * 0.99f + 0.01f;
    float hsb_b = hsb_s*3;
    
    shp_sphere.setFill(color(hsb_h, hsb_s, hsb_b));
    colorMode(RGB);
    
    shp_sphere.resetMatrix();
    shp_sphere.translate(sample.x(), sample.y(), sample.z());
    
    boolean flat_shading = random(1) > 0.5f;
   
    DwMeshUtils.createPolyhedronShape(shp_sphere, ifs, sample.rad(), verts_per_face, flat_shading);
    
    shp_samples_spheres.addChild(shp_sphere);
  }
 
Example 5
Source File: Demo_GroupOfBoxesOrthoUVTexture.java    From haxademic with MIT License 5 votes vote down vote up
protected void firstFrame() {
		// make texture
		texture = PG.newPG(p.width * 2, p.height * 2);
//		PG.drawGrid(texture, 0xff000000, 0xffffffff, p.width / 21, p.height / 15);
		PG.drawGrid(texture, 0xff000000, 0xffffffff, p.width / 16, p.height / 12, 3);
		
		// build boxes
		shape = p.createShape(P.GROUP);
		for (int y = 0; y < 220; y++) {
			PShape subShape = Shapes.createBox(MathUtil.randRangeDecimal(40, 150));
			subShape.translate(
							MathUtil.randRangeDecimal(-p.width/1.5f, p.width/1.5f),
							MathUtil.randRangeDecimal(-p.height/1.5f, p.height/1.5f),	
							MathUtil.randRangeDecimal(-150, 150)
							);
			subShape.rotateX(MathUtil.randRangeDecimal(-P.PI, P.PI));
			subShape.rotateY(MathUtil.randRangeDecimal(-P.PI, P.PI));
			shape.addChild(subShape);
		}

		// normalize & prep mesh texture
		shape = shape.getTessellation();
		PShapeUtil.centerShape(shape);
		PShapeUtil.addTextureUVToShape(shape, texture);
		shape.setTexture(texture);
		DebugView.setValue("shape.getVertexCount();", PShapeUtil.vertexCount(shape));
	}
 
Example 6
Source File: DeepFlat.java    From haxademic with MIT License 5 votes vote down vote up
protected void firstFrame() {
		// make texture
		texture = PG.newPG(p.width * 2, p.height * 2);
//		PG.drawGrid(texture, 0xff000000, 0xffffffff, p.width / 21, p.height / 15);
		PG.drawGrid(texture, 0xff000000, 0xffffffff, p.width / 16, p.height / 12, 3);
		
		// build boxes
		shape = p.createShape(P.GROUP);
		for (int y = 0; y < 220; y++) {
			PShape subShape = Shapes.createBox(MathUtil.randRangeDecimal(40, 150));
			subShape.translate(
							MathUtil.randRangeDecimal(-p.width/1.5f, p.width/1.5f),
							MathUtil.randRangeDecimal(-p.height/1.5f, p.height/1.5f),	
							MathUtil.randRangeDecimal(-150, 150)
							);
			subShape.rotateX(MathUtil.randRangeDecimal(-P.PI, P.PI));
			subShape.rotateY(MathUtil.randRangeDecimal(-P.PI, P.PI));
			shape.addChild(subShape);
		}

		// normalize & prep mesh texture
		shape = shape.getTessellation();
		PShapeUtil.centerShape(shape);
		PShapeUtil.addTextureUVToShape(shape, texture);
		shape.setTexture(texture);
		DebugView.setValue("shape.getVertexCount();", PShapeUtil.vertexCount(shape));
	}
 
Example 7
Source File: TextureAudioBlocksDeform.java    From haxademic with MIT License 5 votes vote down vote up
protected void buildGrid() {
		// build the parent group
		gridShape = P.p.createShape(P.GROUP);

		// build the blocks
		int cols = 20;
		int rows = 10;
		float blockSize = 20f;
		float blockSpacing = blockSize * 2f;
		float halfW = cols/2 * blockSpacing;
		float halfH = rows/2 * blockSpacing;
		blocks = new PShape[cols * rows];
		int buildIndex = 0;
		for (int x = 0; x < cols; x++) {
			for (int y = 0; y < rows; y++) {
				float u = P.map(x, 0, cols - 1, 0.005f, 0.995f);
				float v = P.map(y, 0, rows - 1, 0.005f, 0.995f);
				PShape boxx = Shapes.createBoxSingleUV(blockSize, u, v);
//				PShape boxx = Shapes.createRectSingleUV(blockSize, u, v);
				boxx.setStroke(false);
//				boxx.setFill(gradient.getColorAtProgress(MathUtil.randRangeDecimal(0, 1)));
				boxx.setTexture(audioTexture.texture());
				boxx.translate(x * blockSpacing - halfW, y * blockSpacing - halfH, 0);
				blocks[buildIndex] = boxx;
				buildIndex++;
			}
		}
		
		// normalize group shape
		PShapeUtil.centerShape(gridShape);
		PShapeUtil.scaleShapeToHeight(gridShape, height * 5f);
	}
 
Example 8
Source File: Skylight_Cubes.java    From PixelFlow with MIT License 4 votes vote down vote up
public void createScene(){
    
//    int res = 4;
    
    num_x = 100;
    num_y = 100;
    
    
    if(group_cubes == null){
      group_cubes = createShape(GROUP);
      shp_cubes = new PShape[num_x * num_y];
    }
    

    
    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 dims = 1;
    
    for(int y = 0; y < num_y; y++){
      for(int x = 0; x < num_x; x++){
        int idx = y * num_x + x;
//        float dim_z = random(scene_dimz/4, scene_dimz);
        float nval = noise(3*x/(float)num_x, 2*y/(float)num_y);
        float dim_z = scene_dimz * nval*nval;
        PShape shp_cube = createShape(BOX, dim*dims, dim*dims, dim*dims*1);
        shp_cube.setStroke(false);
        shp_cube.setStroke(color(0));
        shp_cube.setFill(true);
        shp_cube.setFill(color(255, 255*nval,255*nval*nval));
        shp_cube.translate(tx + x * dim, ty + y * dim, dim_z);
        group_cubes.addChild(shp_cube);
        shp_cubes[idx] = shp_cube;
      }
    }
    

//    int cubes_dimz = 100;
  }
 
Example 9
Source File: Skylight_Cubes.java    From PixelFlow with MIT License 4 votes vote down vote up
public void updateAnim(){
    
    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;
    
    anim_counter += 0.003f;
    
    float anim_frequency = 2;
    
    for(int y = 0; y < num_y; y++){
      for(int x = 0; x < num_x; x++){
        int idx = y * num_x + x;
        PShape shp_cube = shp_cubes[idx];
        
        float nval = noise(anim_counter + anim_frequency*x/(float)num_x, anim_counter + anim_frequency*y/(float)num_y);
        float dim_z = scene_dimz * nval * nval;
        
        float rgb_r = 255;
        float rgb_g = 255*nval;
        float rgb_b = 255*nval*nval;
        
        
        shp_cube.setFill(color(rgb_r, rgb_g, rgb_b));

        shp_cube.resetMatrix();
//        shp_cube.rotateY(nval*PI);
//        shp_cube.rotateX(nval*PI);
//        shp_cube.rotateZ(nval*PI);
        shp_cube.translate(tx + x * dim, ty + y * dim, dim_z);
//        shp_cube.rotateY(nval*PI/4f);
//        shp_cube.rotateX(nval*PI);
//        shp_cube.rotateZ(nval*PI);
        shp_cube.rotateZ(cos(nval*10));
//        shp_cube.rotateY(nval*PI/4f);
//        shp_cube.rotateZ(nval*PI);
//        shp_cube.rotateX(nval*PI);
//        shp_cube.rotateY(nval*PI);
      }
    }
  }
 
Example 10
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 11
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 12
Source File: Skylight_Movie1.java    From PixelFlow with MIT License 4 votes vote down vote up
public void updateAnim(){
    
    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;
    
    anim_counter += 0.003f;
    
    float anim_frequency = 2;
    
    for(int y = 0; y < num_y; y++){
      for(int x = 0; x < num_x; x++){
        int idx = y * num_x + x;
        PShape shp_cube = shp_cubes[idx];
        
        float nval = noise(anim_counter + anim_frequency*x/(float)num_x, anim_counter + anim_frequency*y/(float)num_y);
        float dim_z = scene_dimz * nval * nval;
        
//        float rgb_r = 255;
//        float rgb_g = 255*nval;
//        float rgb_b = 255*nval*nval;
        
        
//        shp_cube.setFill(color(rgb_r, rgb_g, rgb_b));

        shp_cube.resetMatrix();
//        shp_cube.rotateY(nval*PI);
//        shp_cube.rotateX(nval*PI);
//        shp_cube.rotateZ(nval*PI);
        shp_cube.translate(tx + x * dim, ty + y * dim, dim_z);
//        shp_cube.rotateY(nval*PI/4f);
//        shp_cube.rotateX(nval*PI);
//        shp_cube.rotateZ(nval*PI);
//        shp_cube.rotateZ(cos(nval*10));
//        shp_cube.rotateY(nval*PI/4f);
//        shp_cube.rotateZ(nval*PI);
//        shp_cube.rotateX(nval*PI);
//        shp_cube.rotateY(nval*PI);
      }
    }
  }
 
Example 13
Source File: PShapeUtil.java    From haxademic with MIT License 4 votes vote down vote up
public static PShape translateShape(PShape shape, float x, float y, float z) {
	if(x != 0 || y != 0 || z != 0) {
		shape.translate(x, y, z);
	}
	return shape;
}
 
Example 14
Source File: TextureBlocksSheet.java    From haxademic with MIT License 4 votes vote down vote up
protected void buildGrid() {
		// build the parent group
		gridShape = P.p.createShape(P.GROUP);

		// build the blocks
		int cols = 20;
		int rows = 10;
		float blockSize = 15f;
		float blockSpacing = blockSize * 2f;
		float halfW = cols/2 * blockSpacing;
		float halfH = rows/2 * blockSpacing;
		blocks = new PShape[cols * rows];
		int buildIndex = 0;
		for (int x = 0; x < cols; x++) {
			for (int y = 0; y < rows; y++) {
//				PShape box = P.p.createShape(P.BOX, 10);
//				box.setFill(gradient.getColorAtProgress(MathUtil.randRangeDecimal(0, 1)));
//				box.translate(x, y, -MathUtil.randRangeDecimal(0, 1));
//				gridShape.addChild(box);
				
				float u = P.map(x, 0, cols - 1, 0.005f, 0.995f);
				float v = P.map(y, 0, rows - 1, 0.005f, 0.995f);
				PShape boxx = Shapes.createBoxSingleUV(blockSize, u, v);
//				PShape boxx = Shapes.createRectSingleUV(blockSize, u, v);
				boxx.setStroke(false);
//				boxx.setFill(gradient.getColorAtProgress(MathUtil.randRangeDecimal(0, 1)));
				boxx.setTexture(audioTexture.texture());
				boxx.translate(x * blockSpacing - halfW, y * blockSpacing - halfH, 0);
				blocks[buildIndex] = boxx;
				buildIndex++;
				
//				gridShape.addChild(boxx);
			}
		}
		
//		gridShape = Shapes.createSheet(40, audioTexture.texture());
//		gridShape = gridShape.getTessellation();
//		gridShape.setTexture(audioTexture.texture());
		
		// normalize group shape
		PShapeUtil.centerShape(gridShape);
		PShapeUtil.scaleShapeToHeight(gridShape, height * 5f);
		
//		for (int i = 0; i < blocks.length; i++) {
//			PShapeUtil.scaleShapeToHeight(blocks[i], height * 0.2f);
//		}
		
		// debug
//		DebugView.setValue("grid cubes", cols * rows);
//		DebugView.setValue("grid vertices", PShapeUtil.vertexCount(gridShape));
//		DebugView.setValue("grid max extent", PShapeUtil.getMaxExtent(gridShape));
	}
 
Example 15
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);
    }
  }
}
 
Example 16
Source File: Skylight_Movie1.java    From PixelFlow with MIT License 2 votes vote down vote up
public void createScene(){
    
    
    PImage img = loadImage("Skylight_Movie/data/owdmn516.bmp");
//    img.loadPixels();
    

    
    System.out.println(img.width+", "+img.height);
    
//    int res = 4;
    
    int scale = 25;
    
    num_x = img.width/scale;
    num_y = img.height/scale;
    
//    img.resize(num_x, num_y);
    
    PGraphics2D pga = (PGraphics2D) createGraphics(num_x, num_y, P2D);
    PGraphics2D pgb = (PGraphics2D) createGraphics(num_x, num_y, P2D);
    
    pga.beginDraw();
    pga.image(img, 0, 0, num_x, num_y);
    pga.endDraw();
    
    DwFilter.get(context).gaussblur.apply(pga, pga, pgb, 1);
    pga.loadPixels();
    
    
    
//    if(group_cubes == null)
    {
      group_cubes = createShape(GROUP);
      shp_cubes = new PShape[num_x * num_y];
    }
    

    
    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 dims = 1;
    
    for(int y = 0; y < num_y; y++){
      for(int x = 0; x < num_x; x++){
        int idx = y * num_x + x;


        int rgb = pga.pixels[idx];
        int r = (rgb >> 16) & 0xFF;
        int g = (rgb >>  8) & 0xFF;
        int b = (rgb >>  0) & 0xFF;
        
        float gray = (r + g + b) / (3f * 255f);
        
//        float dim_z = random(scene_dimz/4, scene_dimz);
        float nval = noise(3*x/(float)num_x, 2*y/(float)num_y);
        float dim_z = scene_dimz * gray * 0.35f;
        PShape shp_cube = createShape(BOX, dim*dims, dim*dims, dim*dims*1);
        shp_cube.setStroke(false);
        shp_cube.setStroke(color(0));
        shp_cube.setFill(true);
        shp_cube.setFill(rgb);
        shp_cube.translate(tx + x * dim, ty + y * dim, dim_z);
        group_cubes.addChild(shp_cube);
        shp_cubes[idx] = shp_cube;
      }
    }
    

//    int cubes_dimz = 100;
  }