Hey There peeps.
I’m trying stuff out on the file from the Codingtrain’s SuperShape and i’m trying to add a texture(image) on the object instead of giving it a color. I tried to load in an image and set it up as a texture but i doesn’t work. Anybody an idea what is wrong with it, or can point out what i need to do!
Thanks for the help already!!
import peasy.*;
PeasyCam cam;
PVector[][] globe;
// RESOLUTIE -- < ++
int total = 25;
float offset = 0;
float m = 0;
float mchange = 0;
PImage img;
void setup() {
size(600, 600, P3D);
img = loadImage("test.jpg");
//CAMERA ZOOM
cam = new PeasyCam(this, 200);
colorMode(HSB);
globe = new PVector[total+1][total+1];
}
float a = 1;
float b = 1;
float supershape(float theta, float m, float n1, float n2, float n3) {
float t1 = abs((1/a)*cos(m * theta / 4));
t1 = pow(t1, n2);
float t2 = abs((1/b)*sin(m * theta/4));
t2 = pow(t2, n3);
float t3 = t1 + t2;
float r = pow(t3, - 1 / n1);
return r;
}
void draw() {
m = map(sin(mchange), -1, 1, 0, 7);
mchange += 0.02;
background(0);
noStroke();
lights();
float r = 50;
for (int i = 0; i < total+1; i++) {
float lat = map(i, 0, total, -HALF_PI, HALF_PI);
float r2 = supershape(lat, 5, 8, 5.344, 2);
//float r2 = supershape(lat, 2, 10, 10, 10);
for (int j = 0; j < total+1; j++) {
float lon = map(j, 0, total, -PI, PI);
float r1 = supershape(lon, m, 14, 30.2539, 0.5);
//float r1 = supershape(lon, 8, 60, 100, 30);
float x = r * r1 * cos(lon) * r2 * cos(lat);
float y = r * r1 * sin(lon) * r2 * cos(lat);
float z = r * r2 * sin(lat);
globe[i][j] = new PVector(x, y, z);
}
}
stroke(255);
//fill(255);
noFill();
//image(img, 0, 0);
offset += 1;
for (int i = 0; i < total; i++) {
//float hu = map(i, 0, total, 0, 255*6);
//fill((hu + offset) % 255, 255, 255);
beginShape(TRIANGLE_STRIP);
texture(img);
for (int j = 0; j < total+1; j++) {
PVector v1 = globe[i][j];
vertex(v1.x, v1.y, v1.z);
PVector v2 = globe[i+1][j];
vertex(v2.x, v2.y, v2.z);
}
endShape();
}
}