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

The following examples show how to use processing.core.PShape#setStroke() . 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: PShapeUtil.java    From haxademic with MIT License 6 votes vote down vote up
public static void addTextureUVSpherical(PShape shape, PImage img) {
	shape.setStroke(false);
	// shape.setFill(255);	// This seems to jack up vertex shaders
	shape.setTextureMode(P.NORMAL);
	
	for (int i = 0; i < shape.getVertexCount(); i++) {
		PVector p = shape.getVertex(i);
		// map spherical coordinate to uv coordinate :: https://stackoverflow.com/questions/19357290/convert-3d-point-on-sphere-to-uv-coordinate
		util.set(p.normalize()); 
		float u = P.atan2(util.x, util.z) / P.TWO_PI + 0.5f; 
		float v = P.asin(util.y) / P.PI + .5f;
		shape.setTextureUV(i, u, v);
	}
		
	for (int j = 0; j < shape.getChildCount(); j++) {
		PShape subShape = shape.getChild(j);
		addTextureUVToShape(subShape, img);
	}
	
	if(img != null) shape.setTexture(img);
}
 
Example 2
Source File: DwSoftBody3D.java    From PixelFlow with MIT License 6 votes vote down vote up
private PShape createShape(PApplet papplet, float radius, boolean icosahedron){
    PShape shape;
    
    if(!icosahedron){
      shape = papplet.createShape(PConstants.POINT, 0, 0);
      shape.setStroke(true);
      shape.setStrokeWeight(1);
    } else {
      if(ifs == null){
        ifs = new DwIcosahedron(1);
//        ifs = new DwCube(1);
      }
      shape = papplet.createShape(PShape.GEOMETRY);
      shape.setStroke(false);
      shape.setFill(true);
      DwMeshUtils.createPolyhedronShape(shape, ifs, radius, 3, true);
    }

    return shape;
  }
 
Example 3
Source File: PShapeUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static void setMaterialColor(PShape shape, int newColor) {
	for (int i = 0; i < shape.getVertexCount(); i++) {
		shape.setFill(i, newColor);
		shape.setStroke(false);
	}
	for (int j = 0; j < shape.getChildCount(); j++) {
		setMaterialColor(shape.getChild(j), newColor);
	}
}
 
Example 4
Source File: Skylight_BulletPhysics_Breakable_VideoExport.java    From PixelFlow with MIT License 5 votes vote down vote up
public void toggleDisplayWireFrame(){
  DISPLAY_WIREFRAME = !DISPLAY_WIREFRAME;
  for (BObject body : physics.rigidBodies) {
    PShape shp = body.displayShape;
    String name = shp.getName();
    if(name != null && name.contains("[wire]")){
      shp.setFill(!DISPLAY_WIREFRAME);
      shp.setStroke(DISPLAY_WIREFRAME);
    }
  }
  skylight.reset();
}
 
Example 5
Source File: Skylight_BulletPhysics_Breakable.java    From PixelFlow with MIT License 5 votes vote down vote up
public PShape createBoxShape(Vector3f dim){
  PShape shp = createShape(BOX, dim.x, dim.y, dim.z);
  shp.setStroke(false);
  shp.setFill(true);
  shp.setFill(color(16));
  shp.setStrokeWeight(1);
  shp.setStroke(color(0));
  return shp;
}
 
Example 6
Source File: Skylight_BulletPhysics_Breakable.java    From PixelFlow with MIT License 5 votes vote down vote up
public void toggleDisplayWireFrame(){
  DISPLAY_WIREFRAME = !DISPLAY_WIREFRAME;
  for (BObject body : physics.rigidBodies) {
    PShape shp = body.displayShape;
    String name = shp.getName();
    if(name != null && name.contains("[wire]")){
      shp.setFill(!DISPLAY_WIREFRAME);
      shp.setStroke(DISPLAY_WIREFRAME);
    }
  }
  skylight.reset();
}
 
Example 7
Source File: Skylight_BulletPhysics_Breakable3.java    From PixelFlow with MIT License 5 votes vote down vote up
public void toggleDisplayWireFrame(){
  DISPLAY_WIREFRAME = !DISPLAY_WIREFRAME;
  for (BObject body : physics.rigidBodies) {
    PShape shp = body.displayShape;
    String name = shp.getName();
    if(name != null && name.contains("[wire]")){
      shp.setFill(!DISPLAY_WIREFRAME);
      shp.setStroke(DISPLAY_WIREFRAME);
    }
  }
  skylight.reset();
}
 
Example 8
Source File: Skylight_Movie2.java    From PixelFlow with MIT License 5 votes vote down vote up
public void createScene(){
  
  int scale = 10;
  
  int src_w = pg_src.width;
  int src_h = pg_src.height;
  
  int num_x = src_w/scale;
  int num_y = src_h/scale;

  pg_src_small     = (PGraphics2D) createGraphics(num_x, num_y, P2D);
  pg_src_small_tmp = (PGraphics2D) createGraphics(num_x, num_y, P2D);
  
  opticalflow.resize(src_w, src_h);
  
  pg_src_tmp = (PGraphics2D) createGraphics(src_w, src_h, P2D);
  
  tex_vel_small.resize(context, opticalflow.frameCurr.velocity);
  tex_vel_small.resize(context, num_x, num_y);
  
  pg_oflow = (PGraphics2D) createGraphics(src_w, src_h, P2D);

  group_cubes = createShape(GROUP);
  shp_cubes = new PShape[num_x * num_y];
  
  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 = createShape(BOX, 1, 1, 1);
      shp_cube.setStroke(false);
      shp_cube.setStroke(color(0));
      shp_cube.setFill(true);
      shp_cubes[idx] = shp_cube;
      group_cubes.addChild(shp_cube);
    }
  }
}
 
Example 9
Source File: Skylight_BulletPhysics_Breakable3.java    From PixelFlow with MIT License 5 votes vote down vote up
public PShape createBoxShape(Vector3f dim){
  PShape shp = createShape(BOX, dim.x, dim.y, dim.z);
  shp.setStroke(false);
  shp.setFill(true);
  shp.setFill(color(16));
  shp.setStrokeWeight(1);
  shp.setStroke(color(0));
  return shp;
}
 
Example 10
Source File: Skylight_BulletPhysics_CellFracture.java    From PixelFlow with MIT License 5 votes vote down vote up
public void toggleDisplayWireFrame(){
  DISPLAY_WIREFRAME = !DISPLAY_WIREFRAME;
  for (BObject body : physics.rigidBodies) {
    PShape shp = body.displayShape;
    String name = shp.getName();
    if(name != null && name.contains("[wire]")){
      shp.setFill(!DISPLAY_WIREFRAME);
      shp.setStroke(DISPLAY_WIREFRAME);
    }
  }
  skylight.reset();
}
 
Example 11
Source File: DwSoftBall2D.java    From PixelFlow with MIT License 5 votes vote down vote up
@Override
public void createShapeWireframe(PGraphics pg, DwStrokeStyle style){
  PShape shp = createShape(pg);
  
  shp.setTexture(null);
  shp.setFill(false);
  shp.setStroke(true);
  shp.setStroke(style.stroke_color);
  shp.setStrokeWeight(style.stroke_weight);
  setShapeWireframe(pg.parent, shp);
}
 
Example 12
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 13
Source File: Sampling_Halton.java    From PixelFlow with MIT License 5 votes vote down vote up
void addShape(float[] position, float scale){
  PVector pos = new PVector().set(position).mult(scale);
  PShape shp_point = createShape(POINT, pos.x, pos.y, pos.z);
  shp_point.setStroke(color(255));
  shp_point.setStrokeWeight(3);
  shp_samples.addChild(shp_point);
}
 
Example 14
Source File: Sampling_Fibonacci.java    From PixelFlow with MIT License 5 votes vote down vote up
void addShape(float[] position, float scale){
  PVector pos = new PVector().set(position).mult(scale);
  PShape shp_point = createShape(POINT, pos.x, pos.y);
  shp_point.setStroke(color(255));
  shp_point.setStrokeWeight(3);
  shp_samples.addChild(shp_point);
}
 
Example 15
Source File: DwSoftBall2D.java    From PixelFlow with MIT License 4 votes vote down vote up
@Override
public void createShapeMesh(PGraphics pg) {
  PShape shp = createShape(pg);
  shp.setStroke(false);
  setShapeMesh(pg.parent, shp);
}
 
Example 16
Source File: Skylight_Movie3.java    From PixelFlow with MIT License 4 votes vote down vote up
public void resize(){
    
    if(!movie.available()){
      return;
    }
    
    int src_w = movie.width;
    int src_h = movie.height;
    
    if(src_w == 0 || src_h == 0){
      return;
    }
    
    if(pg_src != null){
      if(pg_src.width  == src_w && 
         pg_src.height == src_h) return;
    }
    
    movie.jump(80);
    
    // 1) x * y = count_limit
    // 2) x / y = ratio
    // x = ratio * y;
    // y * y * ratio = count_limit
    // y = sqrt(count_limit / ratio);

    int num_limit = 10000;
    float wh_ratio = src_w / (float) src_h;

    int num_y = (int) (Math.sqrt(num_limit / wh_ratio) + 0.5f);
    int num_x = (int) (num_y * wh_ratio + 0.5f);
    
    
    opticalflow.resize(src_w, src_h);
    tex_vel_small.resize(context, num_x, num_y);
    
    // render target
    pg_oflow = (PGraphics2D) createGraphics(src_w, src_h, P2D);
    pg_oflow.smooth(8);

    // drawing canvas, used as input for the optical flow
    pg_src = (PGraphics2D) createGraphics(src_w, src_h, P2D);
    pg_src.smooth(0);
    
    pg_src_tmp = (PGraphics2D) createGraphics(src_w, src_h, P2D);
    pg_src_tmp.smooth(0);

    
    pg_src_small = (PGraphics2D) createGraphics(num_x, num_y, P2D);
    pg_src_small.smooth(0);
    
    pg_src_small_tmp = (PGraphics2D) createGraphics(num_x, num_y, P2D);
    pg_src_small_tmp.smooth(0);
    
//    pg_src_small.loadPixels();
    

    group_cubes = createShape(GROUP);
    shp_cubes = new PShape[num_x * num_y];
    
    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 = createShape(BOX, 1, 1, 1);
        shp_cube.setStroke(false);
        shp_cube.setStroke(color(0));
        shp_cube.setFill(true);
        shp_cubes[idx] = shp_cube;
        group_cubes.addChild(shp_cube);
      }
    }
  }
 
Example 17
Source File: DwSoftBall3D.java    From PixelFlow with MIT License 4 votes vote down vote up
@Override
public void createShapeMesh(PGraphics pg){
  PShape shp = createShape(pg);
  shp.setStroke(false);
  setShapeMesh(pg.parent, shp);
}
 
Example 18
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 19
Source File: DwSoftGrid3D.java    From PixelFlow with MIT License 4 votes vote down vote up
@Override
public void createShapeMesh(PGraphics pg){
  PShape shp = createShape(pg);
  shp.setStroke(false);
  setShapeMesh(pg.parent, shp);
}
 
Example 20
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;
  }