/* built with Studio Sketchpad: * https://sketchpad.cc * * observe the evolution of this sketch: * https://studio.sketchpad.cc/sp/pad/view/ro.T3SkMbJNewQ/rev.14 * * authors: * GoToLoop * license (unless otherwise specified): * creative commons attribution-share alike 3.0 license. * https://creativecommons.org/licenses/by-sa/3.0/ */ // http://forum.processing.org/topic/put-x-y-coordinates-into-2d-array // by phildar & tfguy44 (2013/Apr) // http://studio.processingtogether.com/sp/pad/export/ro.9WgKFjA6WFscW/latest final static float FPS = 40; final static color BG = -1, FG = 0; final static short DIM = 60, D_DIM = DIM << 1; final static short NUM = 10, D_NUM = NUM << 1; final static PVector[][] squares = new PVector[NUM][NUM]; final static PVector[][] coords = new PVector[NUM][NUM]; void setup() { size(800, 800); frameRate(FPS); smooth(); noLoop(); noCursor(); stroke(FG); rectMode(CORNER); ellipseMode(CENTER); int wdNum = width/NUM, wdDNum = width/D_NUM; int hgNum = height/NUM, hgDNum = height/D_NUM; for (int x = 0; x != NUM; x++) for (int y = 0; y != NUM; y++) { squares[x][y] = new PVector(x*wdNum, y*hgNum, BG); coords[x][y] = new PVector( wdDNum + x*wdNum, hgDNum + y*hgNum, (color) random(#000000) ); } } void mouseMoved() { redraw(); } void mousePressed() { redraw(); for (int y = 0, x = 0; x != NUM; x += (y = (y+1) % NUM) == 0 ? 1:0) coords[x][y].z = (color) random(#000000); } void draw() { background(BG); drawCoords(); drawLines(); } void drawCoords() { for (int x = 0; x != NUM; x++) for (int y = 0; y != NUM; y++) { fill(BG); rect(squares[x][y].x, squares[x][y].y, D_DIM, D_DIM); fill( (color) coords[x][y].z ); ellipse(coords[x][y].x, coords[x][y].y, DIM, DIM); } line(width - 1, 0, width - 1, height - 1); line(0, height - 1, width - 1, height - 1); } void drawLines() { for (int y = 0, x = 0; x != NUM; x += (y = (y+1) % NUM) == 0 ? 1:0) line(mouseX, mouseY, coords[x][y].x, coords[x][y].y); }