Hello, I’m getting a “NullPointerException” trying to draw a PShape from an array of the same type.
This is the code snippet:
PShape s10, s15, s20, s25, s30, s35, s40, s45, s50;
PShape[][] grid = {
{s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50},
{s50, s45, s45, s45, s45, s45, s45, s45, s45, s45, s45, s45, s45, s45, s45, s45, s45, s50},
{s50, s45, s40, s40, s40, s40, s40, s40, s40, s40, s40, s40, s40, s40, s40, s40, s45, s50},
{s50, s45, s40, s35, s35, s35, s35, s35, s35, s35, s35, s35, s35, s35, s35, s40, s45, s50},
{s50, s45, s40, s35, s30, s30, s30, s30, s30, s30, s30, s30, s30, s30, s30, s40, s45, s50},
{s50, s45, s40, s35, s30, s25, s25, s25, s25, s25, s25, s25, s25, s30, s30, s40, s45, s50},
{s50, s45, s40, s35, s30, s25, s20, s20, s20, s20, s20, s20, s25, s30, s30, s40, s45, s50},
{s50, s45, s40, s35, s30, s25, s20, s15, s15, s15, s15, s20, s25, s30, s35, s40, s45, s50},
{s50, s45, s40, s35, s30, s25, s20, s15, s10, s10, s15, s20, s25, s30, s35, s40, s45, s50},
{s50, s45, s40, s35, s30, s25, s20, s15, s10, s10, s15, s20, s25, s30, s35, s40, s45, s50},
{s50, s45, s40, s35, s30, s25, s20, s15, s15, s15, s15, s20, s25, s30, s35, s40, s45, s50},
{s50, s45, s40, s35, s30, s25, s20, s20, s20, s20, s20, s20, s25, s30, s35, s40, s45, s50},
{s50, s45, s40, s35, s30, s25, s25, s25, s25, s25, s25, s25, s25, s30, s35, s40, s45, s50},
{s50, s45, s40, s35, s30, s30, s30, s30, s30, s30, s30, s30, s30, s30, s35, s40, s45, s50},
{s50, s45, s35, s35, s35, s35, s35, s35, s35, s35, s35, s35, s35, s35, s35, s40, s45, s50},
{s50, s45, s40, s40, s40, s40, s40, s40, s40, s40, s40, s40, s40, s40, s40, s40, s45, s50},
{s50, s45, s45, s45, s45, s45, s45, s45, s45, s45, s45, s45, s45, s45, s45, s45, s45, s50},
{s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50, s50},
};
setup() {
s10 = createSegment(torusRadius, radius, radians(10), cylinderHeight, sides);
s15 = createSegment(torusRadius, radius, radians(15), cylinderHeight, sides);
s20 = createSegment(torusRadius, radius, radians(20), cylinderHeight, sides);
s25 = createSegment(torusRadius, radius, radians(25), cylinderHeight, sides);
s30 = createSegment(torusRadius, radius, radians(30), cylinderHeight, sides);
s35 = createSegment(torusRadius, radius, radians(35), cylinderHeight, sides);
s40 = createSegment(torusRadius, radius, radians(40), cylinderHeight, sides);
s45 = createSegment(torusRadius, radius, radians(45), cylinderHeight, sides);
s50 = createSegment(torusRadius, radius, radians(50), cylinderHeight, sides);
} //setup
void draw() {
for (int x = 0; x < tilesX; x++) {
for (int y = 0; y < tilesX; y++) {
pushMatrix();
translate(tilesW * x, tilesH * y);
rotateX(HALF_PI);
rotateY(rotation[x][y]);
// NullPointerException
shape(grid[x][y]);
popMatrix();
} //for x
} //for y
} //draw
For a visual reference, this is what I’m trying to recreate in Processing:
I’ve been able to create all the segments as PShapes, but I’m having trouble drawing them, since the ones on the outside have a different inclination from the ones on the inside, hence the matrix that defines which one to draw.