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

The following examples show how to use processing.core.PShape#texture() . 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: Icosahedron.java    From haxademic with MIT License 6 votes vote down vote up
public static PShape createIcosahedron(PGraphics pg, int level, PImage img) {
	// the icosahedron is created with positions, normals and texture coordinates in the above class
	Icosahedron ico = new Icosahedron(level);
	pg.textureMode(P.NORMAL); // set textureMode to normalized (range 0 to 1);
	PShape mesh = pg.createShape(); // create the initial PShape
	mesh.beginShape(P.TRIANGLES); // define the PShape type: TRIANGLES
	mesh.noStroke();
	if(img != null) mesh.texture(img);

	// put all the vertices, uv texture coordinates and normals into the PShape
	for (int i=0; i<ico.positions.size(); i++) {
		PVector pos = ico.positions.get(i);
		PVector t = ico.texCoords.get(i);
		PVector n = ico.normals.get(i);
		mesh.normal(n.x, n.y, n.z);
		mesh.vertex(pos.x, pos.y, pos.z, t.x, t.y);
	}
	mesh.endShape();
	return mesh;
}
 
Example 2
Source File: DwSoftGrid2D.java    From PixelFlow with MIT License 6 votes vote down vote up
private void displayGridXY(PShape pg, PGraphics2D tex){
  pg.beginShape(PConstants.TRIANGLE_STRIP);
  pg.textureMode(PConstants.NORMAL);
  pg.texture(tex);
  pg.fill(material_color);
  pg.noStroke();
  int ix, iy;
  for(iy = 0; iy < nodes_y-1; iy++){
    for(ix = 0; ix < nodes_x; ix++){
      vertex(pg, getNode(ix, iy+0), ix * tx_inv, (iy+0) * ty_inv);
      vertex(pg, getNode(ix, iy+1), ix * tx_inv, (iy+1) * ty_inv);
    }
    ix -= 1; vertex(pg, getNode(ix, iy+1), 0, 0);
    ix  = 0; vertex(pg, getNode(ix, iy+1), 0, 0);
  }
  pg.endShape();
}
 
Example 3
Source File: DwSoftGrid3D.java    From PixelFlow with MIT License 6 votes vote down vote up
private void displayGridXY(PShape pg, float[][] normals, int iz, PGraphics2D tex){
  pg.beginShape(PConstants.TRIANGLE_STRIP);
  pg.textureMode(PConstants.NORMAL);
  pg.texture(tex);
  pg.fill(material_color);
  int ix, iy;
  for(iy = 0; iy < nodes_y-1; iy++){
    for(ix = 0; ix < nodes_x; ix++){
      vertex(pg, getNode3D(ix, iy+0, iz), normals[(iy+0)*nodes_x+ix], ix * tx_inv, (iy+0) * ty_inv);
      vertex(pg, getNode3D(ix, iy+1, iz), normals[(iy+1)*nodes_x+ix], ix * tx_inv, (iy+1) * ty_inv);
    }
    ix -= 1; vertex(pg, getNode3D(ix, iy+1, iz), normals[(iy+1)*nodes_x+ix], 0, 0);
    ix  = 0; vertex(pg, getNode3D(ix, iy+1, iz), normals[(iy+1)*nodes_x+ix], 0, 0);
  }
  pg.endShape();
}
 
Example 4
Source File: DwSoftGrid3D.java    From PixelFlow with MIT License 6 votes vote down vote up
private void displayGridYZ(PShape pg, float[][] normals, int ix, PGraphics2D tex){
  pg.beginShape(PConstants.TRIANGLE_STRIP);
  pg.textureMode(PConstants.NORMAL);
  pg.texture(tex);
  pg.fill(material_color);
  int iz, iy;
  for(iz = 0; iz < nodes_z-1; iz++){
    for(iy = 0; iy < nodes_y; iy++){
      vertex(pg, getNode3D(ix, iy, iz+0), normals[(iz+0)*nodes_y+iy], iy * ty_inv, (iz+0) * tz_inv);
      vertex(pg, getNode3D(ix, iy, iz+1), normals[(iz+1)*nodes_y+iy], iy * ty_inv, (iz+1) * tz_inv);
    }
    iy -= 1; vertex(pg, getNode3D(ix, iy, iz+1), normals[(iz+1)*nodes_y+iy], 0, 0);
    iy  = 0; vertex(pg, getNode3D(ix, iy, iz+1), normals[(iz+1)*nodes_y+iy], 0, 0);
  }
  pg.endShape();
}
 
Example 5
Source File: DwSoftGrid3D.java    From PixelFlow with MIT License 6 votes vote down vote up
private void displayGridXZ(PShape pg, float[][] normals, int iy, PGraphics2D tex){
  pg.beginShape(PConstants.TRIANGLE_STRIP);
  pg.textureMode(PConstants.NORMAL);
  pg.texture(tex);
  pg.fill(material_color);
  int iz, ix;
  for(iz = 0; iz < nodes_z-1; iz++){
    for(ix = 0; ix < nodes_x; ix++){
      vertex(pg, getNode3D(ix, iy, iz+0), normals[(iz+0)*nodes_x+ix], ix * tx_inv, (iz+0) * tz_inv);
      vertex(pg, getNode3D(ix, iy, iz+1), normals[(iz+1)*nodes_x+ix], ix * tx_inv, (iz+1) * tz_inv);
    }
    ix -= 1; vertex(pg, getNode3D(ix, iy, iz+1), normals[(iz+1)*nodes_x+ix], 0, 0);
    ix  = 0; vertex(pg, getNode3D(ix, iy, iz+1), normals[(iz+1)*nodes_x+ix], 0, 0);
  }
  pg.endShape();
}
 
Example 6
Source File: TextureSphere.java    From haxademic with MIT License 6 votes vote down vote up
PShape createIcosahedron(int level, String imagePath) {
	// the icosahedron is created with positions, normals and texture coordinates in the above class
	Icosahedron ico = new Icosahedron(level);

	textureMode(NORMAL); // set textureMode to normalized (range 0 to 1);
	PImage tex = loadImage(imagePath); // load the texture

	PShape mesh = createShape(); // create the initial PShape
	mesh.beginShape(TRIANGLES); // define the PShape type: TRIANGLES
	mesh.noStroke();
	mesh.texture(tex); // set the texture
	// put all the vertices, uv texture coordinates and normals into the PShape
	for (int i=0; i<ico.positions.size(); i++) {
		PVector p = ico.positions.get(i);
		PVector t = ico.texCoords.get(i);
		PVector n = ico.normals.get(i);
		mesh.normal(n.x, n.y, n.z);
		mesh.vertex(p.x, p.y, p.z, t.x, t.y);
	}
	mesh.endShape();

	return mesh; // our work is done here, return DA MESH! ;-)
}
 
Example 7
Source File: ShaderVertexTrigDeform.java    From haxademic with MIT License 6 votes vote down vote up
PShape createCylinder(float r, float h, int detail, PImage tex) {
	textureMode(NORMAL);
	PShape sh = createShape();
	sh.beginShape(QUAD_STRIP);
	sh.noStroke();
	sh.texture(tex);
	for (int i = 0; i <= detail; i++) {
		float angle = TWO_PI / detail;
		float x = sin(i * angle);
		float z = cos(i * angle);
		float u = (float)i / detail;
		sh.normal(x, 0, z);
		sh.vertex(x * r, -h/2, z * r, u, 0);
		sh.vertex(x * r, +h/2, z * r, u, 1);    
	}
	sh.endShape(); 
	return sh;
}
 
Example 8
Source File: DwFoldingTile.java    From PixelFlow with MIT License 5 votes vote down vote up
public void displayMesh(PShape pg, DwParticle3D[] particles){
//  pg.beginShape(PConstants.TRIANGLES);
  pg.textureMode(PConstants.NORMAL);
  pg.texture(DEF.style.texture);
  pg.noStroke();
  int          s0,s1,s2;
  int          i0,i1,i2;
  float[]      t0,t1,t2;
  DwParticle3D v0,v1,v2;
  for(int i = 0; i < DEF.FACES_COUNT; i++){
    i0 = faces[i][0];  v0 = particles[i0];  if(v0.all_springs_deactivated) continue;
    i1 = faces[i][1];  v1 = particles[i1];  if(v1.all_springs_deactivated) continue;
    i2 = faces[i][2];  v2 = particles[i2];  if(v2.all_springs_deactivated) continue;
    
    i0 = DEF.FACES[i][0]; s0 = DEF.HILO[i0];  t0 = DEF.TEX_COORDS[i0];
    i1 = DEF.FACES[i][1]; s1 = DEF.HILO[i1];  t1 = DEF.TEX_COORDS[i1];
    i2 = DEF.FACES[i][2]; s2 = DEF.HILO[i2];  t2 = DEF.TEX_COORDS[i2];
    
    int ci = DEF.FACES_COL[i];
    
    if(DEF.style.texture != null){
      DwDisplayUtils.vertex(pg, v0, t0); 
      DwDisplayUtils.vertex(pg, v1, t1); 
      DwDisplayUtils.vertex(pg, v2, t2); 
    } else {
//      pg.fill(DEF.style.COL[s0]); DwDisplayUtils.vertex(pg, v0);
//      pg.fill(DEF.style.COL[s1]); DwDisplayUtils.vertex(pg, v1);
//      pg.fill(DEF.style.COL[s2]); DwDisplayUtils.vertex(pg, v2);

      pg.fill(DEF.style.RGBS[ci][s0]); DwDisplayUtils.vertex(pg, v0);
      pg.fill(DEF.style.RGBS[ci][s1]); DwDisplayUtils.vertex(pg, v1);
      pg.fill(DEF.style.RGBS[ci][s2]); DwDisplayUtils.vertex(pg, v2);
    }
  }
//  pg.endShape();
}
 
Example 9
Source File: Icosahedron.java    From haxademic with MIT License 5 votes vote down vote up
public static PShape createIcosahedronGrouped(PApplet p, int level, PImage img, int fillColor, int strokeColor, float strokeWeight) {
	// the icosahedron is created with positions, normals and texture coordinates in the above class
	Icosahedron ico = new Icosahedron(level);
	p.textureMode(P.NORMAL); // set textureMode to normalized (range 0 to 1);
	PShape mesh = p.createShape(P.GROUP); // create the initial PShape
	
	
	// put all the vertices, uv texture coordinates and normals into the PShape
	PShape triangle = null;
	for (int i=0; i<ico.positions.size(); i++) {
		if(i % 3 == 0) {
			triangle = p.createShape();
			triangle.beginShape(P.TRIANGLE); // define the PShape type: TRIANGLES
			if(fillColor != -1) {
				triangle.strokeWeight(strokeWeight);
				triangle.stroke(strokeColor);
				triangle.fill(fillColor);
			}
			if(img != null) mesh.texture(img);
		}
		PVector pos = ico.positions.get(i);
		PVector t = ico.texCoords.get(i);
		PVector n = ico.normals.get(i);
		triangle.normal(n.x, n.y, n.z);
		triangle.vertex(pos.x, pos.y, pos.z, t.x, t.y);
		
		if(i % 3 == 2) {
			triangle.endShape();
			mesh.addChild(triangle);
		}
	}
	
	return mesh;
}
 
Example 10
Source File: Shapes.java    From haxademic with MIT License 5 votes vote down vote up
public static PShape createSheet(int detail, PImage tex) {
	P.p.textureMode(P.NORMAL); 
	// P.println("Shapes.createSheet() setting textureMode is weird to do here... Maybe should be PAppletHax default?");
	PShape sh = P.p.createShape();
	sh.beginShape(P.QUADS);
	sh.noStroke();
	sh.texture(tex);
	float cellW = tex.width / detail;
	float cellH = tex.height / detail;
	// int numVertices = 0;
	for (int col = 0; col < detail; col++) {
		for (int row = 0; row < detail; row++) {
			float xU = col * cellW;
			float yV = row * cellH;
			float x = -tex.width/2f + col * cellW;
			float y = -tex.height/2f + row * cellH;
			float z = 0;
			sh.normal(x, y, z);
			sh.vertex(x, y, z, P.map(xU, 0, tex.width, 0, 1), P.map(yV, 0, tex.height, 0, 1));
			sh.vertex(x, y + cellH, z, P.map(xU, 0, tex.width, 0, 1), P.map(yV + cellH, 0, tex.height, 0, 1));    
			sh.vertex(x + cellW, y + cellH, z, P.map(xU + cellW, 0, tex.width, 0, 1), P.map(yV + cellH, 0, tex.height, 0, 1));    
			sh.vertex(x + cellW, y, z, P.map(xU + cellW, 0, tex.width, 0, 1), P.map(yV, 0, tex.height, 0, 1));
			// numVertices++;
		}
	}
	// P.println("createSheet() vertices:", numVertices);
	sh.endShape(); 
	P.p.textureMode(P.IMAGE); 	// reset 
	return sh;
}
 
Example 11
Source File: Shapes.java    From haxademic with MIT License 5 votes vote down vote up
public static PShape createSheet(int cols, int rows, PImage tex) {
	P.p.textureMode(P.NORMAL); 
	// P.println("Shapes.createSheet() setting textureMode is weird to do here... Maybe should be PAppletHax default?");
	PShape sh = P.p.createShape();
	sh.beginShape(P.QUADS);
	sh.noStroke();
	sh.texture(tex);
	float cellW = (float) tex.width / (float) cols;
	float cellH = (float) tex.height / (float) rows;
	// int numVertices = 0;
	for (int col = 0; col < cols; col++) {
		for (int row = 0; row < rows; row++) {
			float xU = col * cellW;
			float yV = row * cellH;
			float x = -tex.width/2f + col * cellW;
			float y = -tex.height/2f + row * cellH;
			float z = 0;
			sh.normal(x, y, z);
			sh.vertex(x, y, z, 					P.map(xU, 0, tex.width, 0, 1), 			P.map(yV, 0, tex.height, 0, 1));
			sh.vertex(x, y + cellH, z, 			P.map(xU, 0, tex.width, 0, 1), 			P.map(yV + cellH, 0, tex.height, 0, 1));    
			sh.vertex(x + cellW, y + cellH, z, 	P.map(xU + cellW, 0, tex.width, 0, 1), 	P.map(yV + cellH, 0, tex.height, 0, 1));    
			sh.vertex(x + cellW, y, z, 			P.map(xU + cellW, 0, tex.width, 0, 1), 	P.map(yV, 0, tex.height, 0, 1));
			// numVertices++;
		}
	}
	// P.println("createSheet() vertices:", numVertices);
	sh.endShape(); 
	P.p.textureMode(P.IMAGE); 	// reset 
	return sh;
}
 
Example 12
Source File: KinectShaderVertexDeform.java    From haxademic with MIT License 5 votes vote down vote up
PShape createSheet(int detail, PImage tex) {
	p.textureMode(NORMAL);
	PShape sh = p.createShape();
	sh.beginShape(QUADS);
	sh.noStroke();
	sh.noFill();
	sh.texture(tex);
	float cellW = tex.width / detail;
	float cellH = tex.height / detail;
	int numVertices = 0;
	for (int col = 0; col < tex.width; col += cellW) {
		for (int row = 0; row < tex.height; row += cellH) {
			float xU = col;
			float yV = row;
			float x = -tex.width/2f + xU;
			float y = -tex.height/2f + yV;
			float z = 0;
			sh.normal(x, y, z);
			sh.vertex(x, y, z, 					P.map(xU, 0, tex.width, 0, 1f), P.map(yV, 0, tex.height, 0, 1f));
			sh.vertex(x, y + cellH, z, 			P.map(xU, 0, tex.width, 0, 1f), P.map(yV + cellH, 0, tex.height, 0, 1f));    
			sh.vertex(x + cellW, y + cellH, z,	P.map(xU + cellW, 0, tex.width, 0, 1f), P.map(yV + cellH, 0, tex.height, 0, 1f));    
			sh.vertex(x + cellW, y, z, 			P.map(xU + cellW, 0, tex.width, 0, 1f), P.map(yV, 0, tex.height, 0, 1f));
			numVertices++;
		}
	}
	P.println(numVertices, "vertices");
	sh.endShape(); 
	return sh;
}
 
Example 13
Source File: DwFoldingTile.java    From PixelFlow with MIT License 5 votes vote down vote up
public void displayMesh(PShape pg, DwIndexedFaceSet ifs){
//  pg.beginShape(PConstants.TRIANGLES);
  pg.textureMode(PConstants.NORMAL);
  pg.texture(DEF.style.texture);
  pg.noStroke();
  int     s0,s1,s2;
  int     i0,i1,i2;
  float[] t0,t1,t2;
  float[] v0,v1,v2;
  for(int i = 0; i < DEF.FACES_COUNT; i++){
    i0 = faces[i][0];  v0 = ifs.verts[i0];
    i1 = faces[i][1];  v1 = ifs.verts[i1];
    i2 = faces[i][2];  v2 = ifs.verts[i2];
    
    i0 = DEF.FACES[i][0]; s0 = DEF.HILO[i0];  t0 = DEF.TEX_COORDS[i0];
    i1 = DEF.FACES[i][1]; s1 = DEF.HILO[i1];  t1 = DEF.TEX_COORDS[i1];
    i2 = DEF.FACES[i][2]; s2 = DEF.HILO[i2];  t2 = DEF.TEX_COORDS[i2];
    
    int ci = DEF.FACES_COL[i];
    
    if(DEF.style.texture != null){
      DwDisplayUtils.vertex(pg, v0, t0); 
      DwDisplayUtils.vertex(pg, v1, t1); 
      DwDisplayUtils.vertex(pg, v2, t2); 
    } else {
//      pg.fill(DEF.style.COL[s0]); DwDisplayUtils.vertex(pg, v0);
//      pg.fill(DEF.style.COL[s1]); DwDisplayUtils.vertex(pg, v1);
//      pg.fill(DEF.style.COL[s2]); DwDisplayUtils.vertex(pg, v2);
      pg.fill(DEF.style.RGBS[ci][s0]); DwDisplayUtils.vertex(pg, v0);
      pg.fill(DEF.style.RGBS[ci][s1]); DwDisplayUtils.vertex(pg, v1);
      pg.fill(DEF.style.RGBS[ci][s2]); DwDisplayUtils.vertex(pg, v2);
    }
  }
//  pg.endShape();
}
 
Example 14
Source File: ParticleSystem.java    From PixelFlow with MIT License 5 votes vote down vote up
public PShape createParticleShape(DwParticle2D particle, PImage pimg_sprite){
  
  final float rad = 2;

  PShape shp_sprite = papplet.createShape();
  shp_sprite.beginShape(PConstants.QUADS);
  shp_sprite.noStroke();
  shp_sprite.noFill();
  shp_sprite.tint(255,10,10);
  if(particle.idx == IDX_MOUSE_PARTICLE){
    shp_sprite.tint(200,100,100);
  } else {
    float r = 0 + papplet.random(-30, 30);
    float g = 100;
    float b = 100;
    shp_sprite.tint(r,g,b);
  }
  shp_sprite.textureMode(PConstants.NORMAL);
  shp_sprite.texture(pimg_sprite);
  shp_sprite.normal(0, 0, 1);
  shp_sprite.vertex(-rad, -rad, 0, 0);
  shp_sprite.vertex(+rad, -rad, 1, 0);
  shp_sprite.vertex(+rad, +rad, 1, 1);
  shp_sprite.vertex(-rad, +rad, 0, 1);
  shp_sprite.endShape();
  
  return shp_sprite;
}
 
Example 15
Source File: Shapes.java    From haxademic with MIT License 4 votes vote down vote up
public static PShape createDisc(float radius, int vertices, int rows, PImage tex) {
	P.p.textureMode(P.NORMAL); 
	PShape sh = P.p.createShape();
	sh.beginShape(P.TRIANGLES);
	sh.textureMode(P.NORMAL);
	if(tex != null) sh.texture(tex);
	sh.noStroke();
	
	float radiusTwo = radius * 2f;
	float rowSize = radius / (float) rows;
	float segmentRads = P.TWO_PI / vertices;
	for( int v = 0; v < vertices; v++ ) {
		for( int r = 0; r < rows; r++ ) {
			float curRads = v * segmentRads;
			float nextRads = (v+1) * segmentRads;
			float curRadius = r * rowSize; 
			float nextRadius = (r+1) * rowSize; 
			
			float x1 = P.cos(curRads) * curRadius;
			float y1 = P.sin(curRads) * curRadius;
			float u1 = (x1 + radius) / radiusTwo;	// normalize within texture - move from being centered
			float v1 = (y1 + radius) / radiusTwo;
			
			float x2 = P.cos(curRads) * nextRadius;
			float y2 = P.sin(curRads) * nextRadius;
			float u2 = (x2 + radius) / radiusTwo;	// normalize within texture - move from being centered
			float v2 = (y2 + radius) / radiusTwo;

			float x3 = P.cos(nextRads) * nextRadius;
			float y3 = P.sin(nextRads) * nextRadius;
			float u3 = (x3 + radius) / radiusTwo;	// normalize within texture - move from being centered
			float v3 = (y3 + radius) / radiusTwo;

			float x4 = P.cos(nextRads) * curRadius;
			float y4 = P.sin(nextRads) * curRadius;
			float u4 = (x4 + radius) / radiusTwo;	// normalize within texture - move from being centered
			float v4 = (y4 + radius) / radiusTwo;
			
			sh.vertex( x1, y1, 0, u1, v1 );
			sh.vertex( x2, y2, 0, u2, v2 );
			sh.vertex( x3, y3, 0, u3, v3 );
			
			sh.vertex( x1, y1, 0, u1, v1 );
			sh.vertex( x4, y4, 0, u4, v4 );
			sh.vertex( x3, y3, 0, u3, v3 );
		}
	}

	sh.endShape();
	return sh;
}
 
Example 16
Source File: ParticleSystem.java    From PixelFlow with MIT License 4 votes vote down vote up
public PShape createParticleShape(DwParticle2D particle, PImage sprite_img){
    
    final float rad = particle.rad;

    PShape shp_particle = papplet.createShape(PShape.GROUP);
    
    if( PARTICLE_SHAPE_IDX >= 0 && PARTICLE_SHAPE_IDX < 4){
      
      PShape sprite = papplet.createShape(PShape.GEOMETRY);
      sprite.beginShape(PConstants.QUAD);
      sprite.noStroke();
      sprite.noFill();
      sprite.textureMode(PConstants.NORMAL);
      sprite.texture(sprite_img);
      sprite.normal(0, 0, 1);
      sprite.vertex(-rad, -rad, 0, 0);
      sprite.vertex(+rad, -rad, 1, 0);
      sprite.vertex(+rad, +rad, 1, 1);
      sprite.vertex(-rad, +rad, 0, 1);
      sprite.endShape();
      
      shp_particle.addChild(sprite);
    }
    else if( PARTICLE_SHAPE_IDX == 4){   
      
      float threshold1 = 1;   // radius shortening for arc segments
      float threshold2 = 140; // arc between segments
      
      double arc1 = Math.acos(Math.max((rad-threshold1), 0) / rad);
      double arc2 = (180 - threshold2) * Math.PI / 180;
      double arc = Math.min(arc1, arc2);
      
      int num_vtx = (int)Math.ceil(2*Math.PI/arc);
      
//      System.out.println(num_vtx);

      PShape circle = papplet.createShape(PShape.GEOMETRY);
      circle.beginShape();
      circle.noStroke();
      circle.fill(200,100);
      for(int i = 0; i < num_vtx; i++){
        float vx = (float) Math.cos(i * 2*Math.PI/num_vtx) * rad;
        float vy = (float) Math.sin(i * 2*Math.PI/num_vtx) * rad;
        circle.vertex(vx, vy);
      }
      circle.endShape(PConstants.CLOSE);

      PShape line = papplet.createShape(PShape.GEOMETRY);
      line.beginShape(PConstants.LINES);
      line.stroke(0, 100);
      line.strokeWeight(1);
      line.vertex(0, 0);
      line.vertex(-(rad-1), 0);
      line.endShape();
      
//      PShape circle = papplet.createShape(PConstants.ELLIPSE, 0, 0, rad*2, rad*2);
//      circle.setStroke(false);
//      circle.setFill(papplet.color(200,100));
//
//      PShape line = papplet.createShape(PConstants.LINE, 0, 0, -(rad-1), 0);
//      line.setStroke(papplet.color(0,200));
//      line.setStrokeWeight(1); 
      
      shp_particle.addChild(circle);
      shp_particle.addChild(line);
    }
    
    return shp_particle;
    
  }
 
Example 17
Source File: ParticleSystem.java    From PixelFlow with MIT License 4 votes vote down vote up
public PShape createParticleShape(DwParticle2D particle, PImage sprite_img){
    
    final float rad = particle.rad;

    PShape shp_particle = papplet.createShape(PShape.GROUP);
    
    if( PARTICLE_SHAPE_IDX >= 0 && PARTICLE_SHAPE_IDX < 4){
      
      PShape sprite = papplet.createShape(PShape.GEOMETRY);
      sprite.beginShape(PConstants.QUAD);
      sprite.noStroke();
      sprite.noFill();
      sprite.textureMode(PConstants.NORMAL);
      sprite.texture(sprite_img);
      sprite.normal(0, 0, 1);
      sprite.vertex(-rad, -rad, 0, 0);
      sprite.vertex(+rad, -rad, 1, 0);
      sprite.vertex(+rad, +rad, 1, 1);
      sprite.vertex(-rad, +rad, 0, 1);
      sprite.endShape();
      
      shp_particle.addChild(sprite);
    }
    else if( PARTICLE_SHAPE_IDX == 4){   
      
      float threshold1 = 1;   // radius shortening for arc segments
      float threshold2 = 140; // arc between segments
      
      double arc1 = Math.acos(Math.max((rad-threshold1), 0) / rad);
      double arc2 = (180 - threshold2) * Math.PI / 180;
      double arc = Math.min(arc1, arc2);
      
      int num_vtx = (int)Math.ceil(2*Math.PI/arc);
      
//      System.out.println(num_vtx);

      PShape circle = papplet.createShape(PShape.GEOMETRY);
      circle.beginShape();
      circle.noStroke();
      circle.fill(200,100);
      for(int i = 0; i < num_vtx; i++){
        float vx = (float) Math.cos(i * 2*Math.PI/num_vtx) * rad;
        float vy = (float) Math.sin(i * 2*Math.PI/num_vtx) * rad;
        circle.vertex(vx, vy);
      }
      circle.endShape(PConstants.CLOSE);

      PShape line = papplet.createShape(PShape.GEOMETRY);
      line.beginShape(PConstants.LINES);
      line.stroke(0, 100);
      line.strokeWeight(1);
      line.vertex(0, 0);
      line.vertex(-(rad-1), 0);
      line.endShape();
      
//      PShape circle = papplet.createShape(PConstants.ELLIPSE, 0, 0, rad*2, rad*2);
//      circle.setStroke(false);
//      circle.setFill(papplet.color(200,100));
//
//      PShape line = papplet.createShape(PConstants.LINE, 0, 0, -(rad-1), 0);
//      line.setStroke(papplet.color(0,200));
//      line.setStrokeWeight(1); 
      
      shp_particle.addChild(circle);
      shp_particle.addChild(line);
    }
    
    return shp_particle;
    
  }