We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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);
}
Answers
This after line 24
cube.setFill(color(100,200,0));
This seems to give me the same output as before.
https://processing.org/reference/beginShape_.html
Two ways illustrated below. Check the link above for options. Not clear if the documentation list the requirements to set a fill on a PShape. Notice you do not need to CLOSE the shape if you specify a parameter.
Kf
I appreciate the reference and explanation, thank you!