class Cell { final PShape myshape ; final PImage myimage ; final int width, height ; final int defaultWidth = 200, defaultHeight = 200 ; Cell(PShape theshape) { myshape = theshape ; myimage = null ; width = round((myshape.width > 0) ? myshape.width : defaultWidth) ; height = round((myshape.height > 0) ? myshape.height : defaultHeight) ; } Cell(PShape theshape, int theWidth, int theHeight) { myshape = theshape ; myimage = null ; width = (theWidth > 0) ? theWidth : defaultWidth ; height = (theHeight > 0) ? theHeight : defaultHeight ; // println("DEBUG CELL w = " + width + " h = " + height); } Cell(PImage theimage) { myshape = null ; myimage = theimage ; width = (myimage.width > 0) ? myimage.width : defaultWidth ; height = (myimage.height > 0) ? myimage.height : defaultHeight ; } Cell(PImage theimage, int theWidth, int theHeight) { myshape = null ; myimage = theimage ; width = (theWidth > 0) ? theWidth : defaultWidth ; height = (theHeight > 0) ? theHeight : defaultHeight ; } void display(int x, int y) { display(x, y, width, height); } void display(int x, int y, int w, int h) { shapeMode(CENTER); imageMode(CENTER); pushMatrix(); if (myshape != null) { shape(myshape, x, y, w, h); if (nestLevel > 1) { float shrinkage = (1.0 / nestLevel) ; for (int i = 1 ; i < nestLevel ; i++) { shape(myshape, x, y, w - w * (shrinkage * i), h - h * (shrinkage * i)); } } } else { if (tintsIndex == 0) { noTint(); } else { tint(tints[tintsIndex][tintsOffset]); tintsOffset = (tintsOffset+1) % tints[tintsIndex].length; } image(myimage, x, y, w, h); if (nestLevel > 1) { float shrinkage = (1.0 / nestLevel) ; for (int i = 1 ; i < nestLevel ; i++) { image(myimage, x, y, w - w * (shrinkage * i), h - h * (shrinkage * i)); } } } popMatrix(); } } /** * Cell Illustration 3.1 from * *Designing Tesselations* by Jinney Beyer, D. Parson, Fenruary 2019. **/ PShape shape_3_1 = null ; PShape make_3_1() { int sw = 1 ; PShape right, upperleft, lowerleft, diagonal ; if (shape_3_1 != null) { return shape_3_1 ; } right = createShape(); right.beginShape(); right.stroke(0); right.strokeWeight(sw); right.fill(0,0,255); // right.fill(100); right.vertex(100, -100); right.vertex(100, 100); right.vertex(0,0); right.vertex(0, -100); right.vertex(100, -100); right.endShape(); diagonal = createShape(); diagonal.beginShape(); diagonal.stroke(0); diagonal.strokeWeight(sw); diagonal.fill(0, 255, 255); // diagonal.fill(200); diagonal.vertex(100, 100); diagonal.vertex(-100, -100); diagonal.vertex(-100,0); diagonal.vertex(0, 100); diagonal.vertex(100, 100); diagonal.endShape(); upperleft = createShape(); upperleft.beginShape(); upperleft.stroke(0); upperleft.strokeWeight(sw); upperleft.fill(255, 0, 255) ; // upperleft.fill(255); upperleft.vertex(-100, -100); upperleft.vertex(0, 0); upperleft.vertex(0, -100); upperleft.vertex(-100, -100); upperleft.endShape(); lowerleft = createShape(); lowerleft.beginShape(); lowerleft.stroke(0); lowerleft.strokeWeight(sw); lowerleft.fill(255, 0, 255); // lowerleft.fill(255); lowerleft.vertex(-100, 0); lowerleft.vertex(-100, 100); lowerleft.vertex(0, 100); lowerleft.vertex(-100, 0); lowerleft.endShape(); PShape R = loadShape("r.svg"); R.translate(-50, -85); shape_3_1 = createShape(GROUP); shape_3_1.addChild(right); shape_3_1.addChild(diagonal); shape_3_1.addChild(upperleft); shape_3_1.addChild(lowerleft); shape_3_1.addChild(R); PShape outer = createShape(); outer.beginShape(); outer.stroke(0); outer.strokeWeight(sw); outer.noFill(); outer.vertex(-100, -100); outer.vertex(100, -100); outer.vertex(100, 100); outer.vertex(-100, 100); outer.vertex(-100, -100); outer.endShape(); shape_3_1.addChild(outer); shape_3_1.translate(100.5, 100.5); int shape_3_1_size = 201 ; shape_3_1.width = shape_3_1_size ; // It defaults to 0, but this works. shape_3_1.height = shape_3_1_size ; // println("shape_3_1 width = " + shape_3_1.width + ", height = " + shape_3_1.height); /* PGraphics pg = createGraphics(shape_3_1_size, shape_3_1_size); pg.beginDraw(); pg.shapeMode(CENTER); pg.shape(shape_3_1, shape_3_1_size/2, shape_3_1_size/2, shape_3_1_size, shape_3_1_size); pg.endDraw(); pg.save("shape_3_1_xxxxx.png"); */ return shape_3_1 ; }