secret
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
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();
}
}
}
gistfile2.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
//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 );
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.