/* @pjs preload="circle.svg, circleWhiteDot.svg, link.svg, linkWhite.svg"; */ float scaleFactor = 0.33333; int distBetweenPoints = int(scaleFactor * 53); int numRows, numCols; ArrayList points; float linkDensity = 0.5; PShape circle; PShape link; PShape linkWhite; PShape circleWhiteDot; color redColor = color(179, 43, 44); color greenColor = color(77, 153, 54); String word = "peace"; boolean noDraw = false; void setup() { size(500,700); if(navigator.userAgent.indexOf("Chrome") == -1 && navigator.userAgent.indexOf("Safari") == -1) { noDraw = true; return; } smooth(); noLoop(); points = new ArrayList(); circle = loadShape("circle.svg"); link = loadShape("link.svg"); linkWhite = loadShape("linkWhite.svg"); circleWhiteDot = loadShape("circleWhiteDot.svg"); circle.disableStyle(); link.disableStyle(); linkWhite.disableStyle(); circleWhiteDot.disableStyle(); setupPoints(); setupLinks(); } void setupPoints() { points.clear(); numRows = floor(height / distBetweenPoints); numCols = floor(width / distBetweenPoints); //println(numCols + " " + numRows); for (int y = 0; y < numRows; y++) { for (int x = 0; x < numCols; x++) { float xPos = (x +.25) * distBetweenPoints; float yPos = (y +.10) * distBetweenPoints; LinkPoint lp = new LinkPoint(); lp.x = xPos; lp.y = yPos; points.add(lp); } } } void setupLinks() { for (LinkPoint lp : points) { lp.resetLinks(); } int numLinks = (numRows - 1) * numCols + (numCols - 1) * numRows; int linksToDraw =round(linkDensity * numLinks); for (int i = 0; i < linksToDraw; i++) { int randomPoint = floor(random(points.size())); LinkPoint lp = points.get(randomPoint); while (lp.linkLeft && lp.linkUp && lp.linkRight && lp.linkDown) { lp = points.get(floor(random(points.size()))); } int direction = floor(random(4)); boolean linkMade = false; while (!linkMade) { switch(direction) { case 0: if (!lp.linkLeft) { lp.linkLeft = true; linkMade = true; } break; case 1: if (!lp.linkUp) { lp.linkUp = true; linkMade = true; } break; case 2: if (!lp.linkRight) { lp.linkRight = true; linkMade = true; } break; case 3: if (!lp.linkDown) { lp.linkDown = true; linkMade = true; } break; } direction = (direction + 1) % 4; } } removeSideLinks(); if(random(1) > 0.5) { // if(word.equals("joy")) { textJoy(); } else { textPeace(); } } void clearLinks(int startRow, int startCol, int numColsToClear, int numRowsToClear) { for (int i = startRow; i < startRow + numRowsToClear; i++) { for (int j = startCol; j < startCol + numColsToClear; j++) { LinkPoint lp = points.get(i * numCols + j); if (i == startRow) { lp.linkDown = false; } else if (i == startRow + numRowsToClear - 1) { lp.linkUp = false; } else if (j == startCol) { lp.linkLeft = false; } else if (j == startCol + numColsToClear -1) { lp.linkRight = false; } else { lp.resetLinks(); } } } } void textJoy() { int startRow = 7; int startCol = 9; // int startCol = 6; int numColsToClear = 11; int numRowsToClear = 7; clearLinks(startRow, startCol, numColsToClear, numRowsToClear); //J points.get((startRow + 4) * numCols + startCol+1).linkDown = true; points.get((startRow + 5) * numCols + startCol+1).linkLeft = true; points.get((startRow + 5) * numCols + startCol+2).linkLeft = true; points.get((startRow + 4) * numCols + startCol+3).linkDown = true; points.get((startRow + 3) * numCols + startCol+3).linkDown = true; points.get((startRow + 2) * numCols + startCol+3).linkDown = true; points.get((startRow + 1) * numCols + startCol+3).linkDown = true; //O points.get((startRow + 1) * numCols + startCol+4).linkDown = true; points.get((startRow + 1) * numCols + startCol+4).linkLeft = true; points.get((startRow + 1) * numCols + startCol+5).linkLeft = true; points.get((startRow + 1) * numCols + startCol+6).linkDown = true; points.get((startRow + 2) * numCols + startCol+4).linkDown = true; points.get((startRow + 2) * numCols + startCol+6).linkDown = true; points.get((startRow + 3) * numCols + startCol+4).linkDown = true; points.get((startRow + 3) * numCols + startCol+6).linkDown = true; points.get((startRow + 4) * numCols + startCol+4).linkDown = true; points.get((startRow + 4) * numCols + startCol+6).linkDown = true; points.get((startRow + 5) * numCols + startCol+4).linkLeft = true; points.get((startRow + 5) * numCols + startCol+5).linkLeft = true; //Y points.get((startRow + 1) * numCols + startCol + 7).linkDown = true; points.get((startRow + 1) * numCols + startCol + 9).linkDown = true; points.get((startRow + 2) * numCols + startCol + 7).linkDown = true; points.get((startRow + 2) * numCols + startCol + 9).linkDown = true; points.get((startRow + 3) * numCols + startCol + 7).linkLeft = true; points.get((startRow + 3) * numCols + startCol + 8).linkLeft = true; points.get((startRow + 3) * numCols + startCol + 8).linkDown = true; points.get((startRow + 4) * numCols + startCol + 8).linkDown = true; } void textPeace() { int startRow = 7; int startCol = 6; // int startCol = 3; int numColsToClear = 17; int numRowsToClear = 7; clearLinks(startRow, startCol, numColsToClear, numRowsToClear); //P points.get((startRow+1) * numCols + startCol+1).linkLeft = true; points.get((startRow+1) * numCols + startCol+1).linkDown = true; points.get((startRow+2) * numCols + startCol+1).linkDown = true; points.get((startRow+3) * numCols + startCol+1).linkLeft = true; points.get((startRow+3) * numCols + startCol+2).linkLeft = true; points.get((startRow+1) * numCols + startCol+2).linkLeft = true; points.get((startRow+1) * numCols + startCol+3).linkDown = true; points.get((startRow+2) * numCols + startCol+3).linkDown = true; points.get((startRow+3) * numCols + startCol+1).linkDown = true; points.get((startRow+4) * numCols + startCol+1).linkDown = true; //E points.get((startRow+1) * numCols + startCol + 4).linkLeft = true; points.get((startRow+1) * numCols + startCol + 4).linkDown = true; points.get((startRow+2) * numCols + startCol + 4).linkDown = true; points.get((startRow+1) * numCols + startCol + 5).linkLeft = true; points.get((startRow+3) * numCols + startCol + 4).linkLeft = true; points.get((startRow+3) * numCols + startCol + 4).linkDown = true; points.get((startRow+4) * numCols + startCol + 4).linkDown = true; points.get((startRow+5) * numCols + startCol + 4).linkLeft = true; points.get((startRow+5) * numCols + startCol + 5).linkLeft = true; //A points.get((startRow + 1) * numCols + startCol + 7).linkLeft = true; points.get((startRow + 1) * numCols + startCol + 8).linkLeft = true; points.get((startRow + 1) * numCols + startCol + 7).linkDown = true; points.get((startRow + 3) * numCols + startCol + 7).linkLeft = true; points.get((startRow + 3) * numCols + startCol + 8).linkLeft = true; points.get((startRow + 2) * numCols + startCol + 7).linkDown = true; points.get((startRow + 3) * numCols + startCol + 7).linkDown = true; points.get((startRow + 4) * numCols + startCol + 7).linkDown = true; points.get((startRow + 1) * numCols + startCol + 9).linkDown = true; points.get((startRow + 2) * numCols + startCol + 9).linkDown = true; points.get((startRow + 3) * numCols + startCol + 9).linkDown = true; points.get((startRow + 4) * numCols + startCol + 9).linkDown = true; //C points.get((startRow + 1) * numCols + startCol + 10).linkLeft = true; points.get((startRow + 1) * numCols + startCol + 11).linkLeft = true; points.get((startRow + 1) * numCols + startCol + 10).linkDown = true; points.get((startRow + 2) * numCols + startCol + 10).linkDown = true; points.get((startRow + 3) * numCols + startCol + 10).linkDown = true; points.get((startRow + 4) * numCols + startCol + 10).linkDown = true; points.get((startRow + 5) * numCols + startCol + 10).linkLeft = true; points.get((startRow + 5) * numCols + startCol + 11).linkLeft = true; //E points.get((startRow+1) * numCols + startCol + 13).linkLeft = true; points.get((startRow+1) * numCols + startCol + 13).linkDown = true; points.get((startRow+2) * numCols + startCol + 13).linkDown = true; points.get((startRow+1) * numCols + startCol + 14).linkLeft = true; points.get((startRow+3) * numCols + startCol + 13).linkLeft = true; points.get((startRow+3) * numCols + startCol + 13).linkDown = true; points.get((startRow+4) * numCols + startCol + 13).linkDown = true; points.get((startRow+5) * numCols + startCol + 13).linkLeft = true; points.get((startRow+5) * numCols + startCol + 14).linkLeft = true; } void removeSideLinks() { int bottomRow = (numRows - 1) * numCols; int rightCol = numCols - 1; for (int i = 0; i < numCols; i++) { points.get(i).linkUp = false; points.get(i + bottomRow).linkDown = false; } for (int i = 0; i < numRows; i++) { points.get(i * numCols).linkRight = false; points.get(i * numCols + rightCol).linkLeft = false; } } void draw() { if(noDraw) { return; } background(255); noStroke(); for (LinkPoint lp : points) { lp.draw(); } for (LinkPoint lp : points) { lp.drawLinks(); } } class LinkPoint { color c; float x, y, radius; boolean linkLeft = false; boolean linkRight = false; boolean linkUp = false; boolean linkDown = false; void setFill() { colorMode(HSB); fill(lerpColor(greenColor, redColor, map(y, 0, height, 0, 1))); //green to red } void draw() { noStroke(); setFill(); shape(circle, x, y, circle.width*scaleFactor, circle.height*scaleFactor); fill(255); shape(circleWhiteDot, x, y, circleWhiteDot.width*scaleFactor, circleWhiteDot.height*scaleFactor); } void drawLinks() { noStroke(); setFill(); if (linkLeft) { fill(lerpColor(greenColor, redColor, map(y, 0, height, 0, 1))); //green to red shape(link, x, y, link.width*scaleFactor, link.height*scaleFactor); fill(255); shape(linkWhite, x, y, linkWhite.width*scaleFactor, linkWhite.height*scaleFactor); } if (linkUp) { pushMatrix(); translate(x, y); rotate(-PI/2.0); fill(lerpColor(greenColor, redColor, map(y, 0, height, 0, 1))); //green to red shape(link, -47.5*scaleFactor, 0, link.width*scaleFactor, link.height*scaleFactor); fill(255); shape(linkWhite, -47.5*scaleFactor, 0, linkWhite.width*scaleFactor, linkWhite.height*scaleFactor); popMatrix(); } if (linkRight) { fill(lerpColor(greenColor, redColor, map(y, 0, height, 0, 1))); //green to red shape(link, x-distBetweenPoints, y, link.width*scaleFactor, link.height*scaleFactor); fill(255); shape(linkWhite, x-distBetweenPoints, y, linkWhite.width*scaleFactor, linkWhite.height*scaleFactor); } if (linkDown) { pushMatrix(); translate(x, y); rotate(PI/2.0); fill(lerpColor(greenColor, redColor, map(y, 0, height, 0, 1))); //green to red shape(link, 0-0, 0-47.5*scaleFactor, link.width*scaleFactor, link.height*scaleFactor); fill(255); shape(linkWhite, 0, -47.5*scaleFactor, linkWhite.width*scaleFactor, linkWhite.height*scaleFactor); popMatrix(); } } void resetLinks() { linkLeft = false; linkRight = false; linkUp = false; linkDown = false; } }