/* built with Studio Sketchpad: * https://sketchpad.cc * * observe the evolution of this sketch: * https://studio.sketchpad.cc/sp/pad/view/ro.MqT6GnQ4l7a/rev.25 * * authors: * GoToLoop * license (unless otherwise specified): * creative commons attribution-share alike 3.0 license. * https://creativecommons.org/licenses/by-sa/3.0/ */ /** * Circle Matrix Groups (v2.5) * by Polk (2015/May/27) * mod GoToLoop * * forum.Processing.org/two/discussion/11034/problem-with-positioning-object-on-grid * studio.ProcessingTogether.com/sp/pad/export/ro.9Ix4oqMF4OK6g/latest */ static final int QTY = 3, GAP = 40; static final int DIAM_W = CircleMatrix.DIAM * CircleMatrix.COLS + GAP; static final int DIAM_H = CircleMatrix.DIAM * CircleMatrix.ROWS; final CircleMatrix[] groups = new CircleMatrix[QTY]; void setup() { size(600, 250, JAVA2D); smooth(4); noLoop(); frameRate(60); fill(Circle.INK); stroke(Circle.OUTLINE); strokeWeight(Circle.WEIGHT); ellipseMode(Circle.MODE); int x = width - DIAM_W*QTY + GAP >> 1, y = height - DIAM_H >> 1; for (int col = 0; col != QTY; ++col) groups[col] = new CircleMatrix(x + col*DIAM_W, y); } void draw() { background(0100); for (CircleMatrix c : groups) c.display(); } class Circle { static final color INK = #FFFF00, OUTLINE = 0; static final float WEIGHT = 1.5; static final short MODE = CENTER; static final short DIAM = 28, RAD = DIAM>>1; final short x, y; Circle(int xx, int yy) { x = (short) (xx + RAD); y = (short) (yy + RAD); } void display() { ellipse(x, y, DIAM, DIAM); } } class CircleMatrix { static final int ROWS = 4, COLS = 5, QTY = ROWS*COLS; static final int GAP = 4, DIAM = Circle.DIAM + GAP, RAD = DIAM>>1; final Circle[] circles = new Circle[QTY]; CircleMatrix(int x, int y) { for (int row = 0; row != ROWS; ++row) for (int col = 0; col != COLS; ++col) circles[col + row*COLS] = new Circle(x + col*DIAM, y + row*DIAM); } void display() { for (Circle c : circles) c.display(); } }