// barchart of a lot of integers between 1 and maxn-1 // HSB color scheme is used to emphasize count // mod from Jer Thorp intro course on data visualizaiton (online) // int[] nums = new int[300]; int maxn = 100; // numbers will be between 1 and maxn-1 int[] counts = new int[maxn]; void setup () { size(12*(maxn+1), maxn*3); for (int i = 0; i < nums.length; i++) nums[i] = (int) random(1, maxn); // numbers are generated randomly be between 1 and maxn-1 background(0); colorMode(HSB); smooth(); noLoop(); // at once the entire picture is produced } void draw() { //Make a list of number counts int[] counts = new int[maxn]; //Fill it with zeros for (int i = 1; i < maxn; i++) counts[i] = 0; //Tally the counts for (int i = 0; i < nums.length; i++) counts[nums[i]] ++; //Draw the bar graph for (int i = 1; i < maxn; i++) { fill(counts[i] * 30, 255, 255); // hue is changed according to count rect(i * 12, height-10, 12, -counts[i] * 10); }; };