// grid arrangement // n*n numbers in square grid format // mod from Jer Thorp intro course on data visualizaiton (online) // // there is no draw() function defined as there is no interaction, neither animation, just a single output // we made own function for drawing grids // int[] nums = new int[400]; int n = 10; int maxn = n*n; void setup() { size(n*70+100, n*70+100); background(0); smooth(); for (int i = 0; i < nums.length; i++) nums[i] = (int) random(1, maxn); //Draw the grid once colorGrid(nums, 50, 50, 70); // we call the function with concrete values } void colorGrid(int[] wnums, float x, float y, float s) { // own function for drawing the grids for wnums at location x, and y, size is s //Make a list of number counts int[] counts = new int[maxn]; //Fill it with zeros for (int i = 0; i < maxn; i++) { counts[i] = 0; } //Tally the counts for (int i = 0; i < wnums.length; i++) { counts[wnums[i]] ++; } //Move the drawing coordinates to the x,y position specified in the parameters pushMatrix(); translate(x, y); //Draw the grid for (int i = 0; i < counts.length; i++) { colorMode(HSB); fill(counts[i] * 30, 255, 255, counts[i] * 30); rect((i % n) * s, floor(i/n) * s, s, s); // here we define the grid where the i-th item should come } popMatrix(); }