Created
November 10, 2016 21:33
-
-
Save wxs/757aa2b4c7cce635c8175c973330802a to your computer and use it in GitHub Desktop.
How I made this blog post image: https://github.com/wxs/keras-mnist-tutorial/blob/master/figure.png
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.pdf.*; | |
int gridW = 5; | |
int gridH = 5; | |
int cellW = 30; | |
int cellH = 30; | |
int nodeR = 10; | |
int rowY0 = 100; | |
int spacingY = 50; | |
int[] rows = {10, 20, 20}; | |
int[] spacingX = {20, 15, 15}; | |
float gridCenterX; | |
float gridCenterY; | |
void setup() { | |
size(400,400, PDF, "output.pdf"); | |
ellipseMode(CENTER); | |
noLoop(); | |
gridCenterX = width/2; | |
gridCenterY = height-100; | |
} | |
float[] nodeCenter(int rowI, int i) { | |
float cY = rowY0 + spacingY*rowI; | |
float cX = width/2 + spacingX[rowI] * (i + 0.5 - rows[rowI]/2.0) ; | |
float[] r = new float[2]; | |
r[0] = cX; | |
r[1] = cY; | |
return r; | |
} | |
void draw() { | |
background(255,255,255,0); | |
for (int rowI = 0; rowI < rows.length; rowI++) { | |
int N = rows[rowI]; | |
for (int i = 0; i < N; i++) { | |
float[] center = nodeCenter(rowI, i); | |
stroke(0,0,0,255); | |
ellipse(center[0], center[1], nodeR, nodeR); | |
if (rowI == rows.length-1) { | |
for (int gridX = 0; gridX < gridW; gridX++) { | |
for (int gridY = 0; gridY < gridH; gridY++) { | |
float gX = gridCenterX + cellW * (gridX + 0.5 - gridW/2.0); | |
float gY = gridCenterY + cellH * (gridY + 0.5 - gridH/2.0); | |
stroke(0,0,0,100); | |
line(center[0], center[1], gX, gY); | |
} | |
} | |
} else { | |
for (int j = 0; j < rows[rowI+1]; j++) { | |
float[] nextCenter = nodeCenter(rowI+1, j); | |
stroke(0,0,0,100); | |
line(center[0], center[1], nextCenter[0], nextCenter[1]); | |
} | |
} | |
} | |
} | |
exit(); | |
//save("output.png"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment