Skip to content

Instantly share code, notes, and snippets.

Created May 10, 2013 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5d381824e66e58f9a340 to your computer and use it in GitHub Desktop.
Save anonymous/5d381824e66e58f9a340 to your computer and use it in GitHub Desktop.
Cell[][]grid;
//call x y position
int rowQty;
int x = 10;
int y = 550;
int cols = 0;
int rows = 200;
float r = random(0, 300);
//spacing of colums
int spacing = 19;
//declare Y position spacing
int newSpacing = 5;
int newY = 24;
//Type of font used
PFont myFont;
void setup() {
//Ensures the size of the canvas fits the size of the csv data file
size(screen.width, screen.height);
//set size and font type
background(255);
//display Image
PImage Key = loadImage("Key.png");
//Size of key image
Key.resize(400, 0);
//This positions the key image
image(Key, 600, 40);
//This loads the books image
PImage bookworm = loadImage("bookworm.png");
bookworm.resize(400, 0);
//This tints the books image
tint(255, 50);
image(bookworm, 1500, 105);
//Display font type and font size
myFont = createFont("Times", 14, true);
textFont(myFont);
textAlign(RIGHT);
//Display csv file data
String dataLines[] = loadStrings("Book.csv");
//declare rows
rowQty = dataLines.length;
//Show the data within the csv file
//States that book name is text
String[] Book;
//States that number is string
int[] Amount;
//declare the data types
Book = new String [rowQty];
Amount = new int [rowQty];
for (int i = 0; i < rowQty; i++) {
String[]temp= split(dataLines[i], ',');
Book[i] = (temp[0]);
Amount[i] = int(temp[1]);
}
for (int n= 0; n <rowQty; n++) {
// graph colour
fill(3, 255, 232);
rect(x, y, 20, -Amount [n]/.5);
x = x + spacing;
rotate(PI/-2);
//Book names colour
fill(#FF0000);
text(Book[n], -630, newY);
//Number text colour
fill (0);
text(Amount[n], -580, newY);
newY += newSpacing +14;
rotate(PI/2);
text("Top 100 selling books Worldwide", 900, 50);
}
}
void draw() {
grid = new Cell[cols][rows];
for (int i = 0; i <cols; i ++) {
for (int j = 0; j < rows; j ++) {
grid[i][j] = new Cell(i*10, j*10, 10, 10, i+j);
}
}
// values for columns and Rows
for (int i = 0; i <cols; i ++) {
for (int j = 0; j < rows; j ++) {
//oscilate and display each object
grid[i][j].oscillate();
grid[i][j].display();
}
}
}
//declare cell object and class
class Cell{
float x=0,y=0;// x position y position
float w=0,h=0;// declaring width and height
float angle;// oscillation
Cell(float tempX,float tempY,float tempW,float tempH,float tempAngle){
x = tempX;
y = tempY;
w = tempW;
h = tempH;
angle = tempAngle;
}
//oscillate
void oscillate(){
angle +=0.1;
}
// display the rect's
void display(){
stroke(0);
// rect position / colour / sine
fill(700+700*sin(angle));
rect(x,y,w,h);
}
}
boolean between( int target, int bound1, int bound2 ){
if( target >= bound1 && target <= bound2 ){ return( true ); }
if( target <= bound1 && target >= bound2 ){ return( true ); }
return( false );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment