Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How do I fill a 3D PShape Cube with color?

$
0
0

I was able to create the PShape Cube with a stroke the color that I want, but I am having trouble adding color to my cube. I have also tried moving "cube.setFill(color(100,200,0));" after "PShape cube = createShape();". Any help is greatly appreciated.

import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;

PeasyCam cam;

void setup(){
  size(600,600, P3D);
  cam = new PeasyCam(this, 600);
}
void draw(){
  background(255);

  PVector p1 = new PVector(0, 0, 0);
  PVector p2 = new PVector(0, -100, 0);
  PVector p3 = new PVector(-100, -100, 0);
  PVector p4 = new PVector(-100, 0, 0);
  PVector p5 = new PVector(0, 0, -100); 
  PVector p6 = new PVector(0, -100, -100);
  PVector p7 = new PVector(-100, -100, -100);
  PVector p8 = new PVector(-100, 0, -100);

  PShape cube = createShape();
  cube.beginShape();
  cube.vertex(p1.x, p1.y, p1.z);
  cube.vertex(p2.x, p2.y, p2.z);
  cube.vertex(p3.x, p3.y, p3.z);
  cube.vertex(p4.x, p4.y, p4.z);

  cube.vertex(p1.x, p1.y, p1.z);
  cube.vertex(p5.x, p5.y, p5.z);
  cube.vertex(p6.x, p6.y, p6.z);
  cube.vertex(p2.x, p2.y, p2.z);

  cube.vertex(p3.x, p3.y, p3.z);
  cube.vertex(p7.x, p7.y, p7.z);
  cube.vertex(p8.x, p8.y, p8.z);
  cube.vertex(p4.x, p4.y, p4.z);

  cube.vertex(p8.x, p8.y, p8.z);
  cube.vertex(p5.x, p5.y, p5.z);
  cube.vertex(p6.x, p6.y, p6.z);
  cube.vertex(p7.x, p7.y, p7.z);

  cube.vertex(p8.x, p8.y, p8.z);
  cube.vertex(p4.x, p4.y, p4.z);

  cube.endShape(CLOSE);

  cube.setFill(color(100,200,0));
  stroke(100,200,0);
  shape(cube);
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles