Skip to content

Instantly share code, notes, and snippets.

@axiomsofchoice
Created September 3, 2011 14:32
Show Gist options
  • Save axiomsofchoice/1191270 to your computer and use it in GitHub Desktop.
Save axiomsofchoice/1191270 to your computer and use it in GitHub Desktop.
Processing Tutorial #solo11
/*
#myrandomnumber Tutorial
blprnt@blprnt.com
April, 2010
*/
//This is the Google spreadsheet manager and the id of the spreadsheet that we want to populate, along with our Google username & password
SimpleSpreadsheetManager sm;
String sUrl = "t6mq_WLV5c5uj6mUNSryBIA";
String googleUser = "MY_USER";
String googlePass = "MY_PASSWORD";
float ellipseSize = 16;
P5Properties props;
// Based on http://wiki.processing.org/w/External_configuration_files
class P5Properties extends Properties {
boolean getBooleanProperty(String id, boolean defState) {
return boolean(getProperty(id,""+defState));
}
int getIntProperty(String id, int defVal) {
return int(getProperty(id,""+defVal));
}
float getFloatProperty(String id, float defVal) {
return float(getProperty(id,""+defVal));
}
String getStringProperty(String id, String defVal) {
return getProperty(id,""+defVal);
}
}
void barGraph(int[] nums, float y) {
//Make a list of number counts
int[] counts = new int[100];
//Fill it with zeros
for (int i = 1; i < 100; 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 = 0; i < counts.length; i++) {
colorMode(HSB);
fill(counts[i] * 30, 255, 255);
//fill(255, counts[i] * 30, 0);
rect(i * 8, y, 8, -counts[i] * 10);
};
};
void setup() {
try {
props=new P5Properties();
props.load(openStream("proc.properties"));
googleUser=props.getStringProperty("user","");
googlePass=props.getStringProperty("password","");
}
catch(IOException e) {
println("Couldn't read config file proc.properties");
}
//This code happens once, right when our sketch is launched
size(800,800);
background(0);
smooth();
//Ask for the list of numbers
int[] numbers = getNumbers();
//Draw the graph
//barGraph(numbers, 400);
for (int i = 1; i < 7; i++) {
int[] randoms = getRandomNumbers(225);
barGraph(randoms, 100 + (i * 130));
};
/*fill(255,40);
noStroke();
for (int i = 0; i < numbers.length; i++) {
ellipse(numbers[i] * 8, width/2, ellipseSize, ellipseSize);
};
//A line of random numbers
for (int i = 0; i < numbers.length; i++) {
ellipse(ceil(random(0,99)) * 8, height/2 + 20, ellipseSize, ellipseSize);
};*/
};
void draw() {
//This code happens once every frame.
};
user=my_username
password=my_password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment