class Country {
int troopsPerCountry;
ArrayList troopArray;
PImage flag;
String countryName;
int budget;
int originalAmounts;
float w, h;
float frame = 0;
float nameX;
Country(float x, String name, int _troopsPerCountry, int _originalAmounts) {
flag = loadImage(name+".png");
troopsPerCountry = _troopsPerCountry;
countryName = name;
originalAmounts = _originalAmounts;
budget = originalAmounts;
troopArray = new ArrayList();
// Building arraylist of troop objects for each country
for (int i = 0; i < troopsPerCountry; i++) {
if (i == 0) troopArray.add(new Troops(soldiers, x+width+i*100, height/1.32, 150, 75));
if (i == 1) troopArray.add(new Troops(tanks, x+width+i*100, height/1.32-5, 160, 80));
if (i == 2) troopArray.add(new Troops(tanks, x+width+i*100, height/1.32-5, 160, 80));
if (i == 3) troopArray.add(new Troops(tanks, x+width+i*100, height/1.32-5, 160, 80));
if (i == 67) troopArray.add(new Troops(mario, x+width+i*100+300, height/1.38, 120, 100));
else if (i > 3 ) troopArray.add(new Troops(tanks, x+width+i*100, height/1.32-5, 160, 80));
}
}
void CountryCreate() {
Troops firstTroop = (Troops) troopArray.get(0);
firstTroop.displayFlag(flag);
firstTroop.planeFly();
firstTroop.bannerFly();
// firstTroop.displayName(countryName, budget, still);
Troops lastTroop = (Troops) troopArray.get(troopsPerCountry-1);
// if (firstTroop.x 0 && lastTroop.x > width) {
firstTroop.displayName(countryName, budget, nameX);
for (int i = troopArray.size()-1; i >= 0; i--) {
Troops troops = (Troops) troopArray.get(i);
troops.display();
troops.move();
}
}
}
class Troops {
float x, y;
float xPlane, speedPlane;
float speed;
float w, h;
float frame = 0;
PImage[] images;
int counter = 0;
int ticker = 0;
Troops(PImage[] tempImages, float tempX, float tempY, float tempW, float tempH) {
images = tempImages;
x = tempX;
y = tempY;
w = tempW;
h = tempH;
speed = -17;
}
void display() {
image(images[counter], x, y + 10, w, h);
counter = (counter + 1) % images.length;
}
void displayFlag(PImage flag) {
image(flag, x - 47, y - 35, 45, 100);
// frame = (frame +1) % flag.length;
}
void planeFly() {
image(plane, x - 175, y - 385, 153, 50);
}
void displayName(String countryName, int budget, float nameX) {
// if (still = true) {
nameX = x;
text(countryName + " : $" + budget +" billion", nameX -75, 85);
// }
// else {
// nameX = 300;
}
void bannerFly() {
image(banner[counter], x + 100, y - 380, 830, 55);
ticker = (ticker + 1) % banner.length;
}
void move() {
x = x + speed;
}
}
import ddf.minim.*;
AudioPlayer player;
Minim minim;
String[] countries;
int[] amounts;
int[] originalAmounts;
PImage[] tanks = new PImage[1];
PImage[] trucks = new PImage[1];
PImage[] soldiers = new PImage[5];
PImage[] mario = new PImage[8];
PImage[] banner = new PImage[12];
PImage plane;
PFont font;
//boolean restart = false;
int frameRate = 7;
int totalTanks;
int totalCountries = 0;
int indexGlobal =0;
float lastTroopX;
ArrayList countryArray;
boolean still = false;
PImage background;
PImage background_overlay;
void setup() {
size(1080, 600);
smooth();
frameRate(frameRate);
font = loadFont("CarnivaleeFreakshow-50.vlw");
textFont(font);
background = loadImage("background.jpg");
background_overlay = loadImage("background_overlay.png");
minim = new Minim(this);
player = minim.loadFile("sample.mp3", 2048);
player.play();
imageMode (CENTER);
tanks[0] = loadImage("tanks.png");
plane = loadImage("plane.png");
for (int i = 0; i<soldiers.length; i++) {
soldiers[i] = loadImage("soldiers"+i+".png");
}
for (int i = 0; i<mario.length; i++) {
mario[i] = loadImage("l"+i+".png");
}
for (int i = 0; i<banner.length; i++) {
banner[i] = loadImage("banner"+i+".png");
}
countryArray = new ArrayList();
String[] lines = loadStrings("countries.csv"); //PARSING CSV
countries = new String[lines.length];
originalAmounts = new int[lines.length];
amounts = new int[lines.length];
totalCountries = totalCountries + countries.length;
// Loop through the number of entries in the CSV -- 4 times
totalTanks = 0;
for (int i = 0; i < lines.length; i++) {
String[] values = split(lines[i], ",");
// the array values[0] is my list of countries. values [1] is an array of amounts
countries[i] = values[0];
// Numbers of tanks to display for each country
originalAmounts[i] = int(values[1]);
amounts[i] = (originalAmounts[i]/10);
// Offset figure is the rolling total of troops as they hit the for loop with an offset of 500
countryArray.add(new Country((totalTanks*100+i*500), countries[i], amounts[i], originalAmounts[i]));
totalTanks = totalTanks + amounts[i];
}
}
void draw() {
image (background, width/2, height/2);
for (int i = countryArray.size()-1; i >= 0; i--) {
Country countries = (Country) countryArray.get(i);
countries.CountryCreate();
textSize(40);
fill(0);
// countries.xLocation(countries);
// if (i == 0) setup();
}
image (background_overlay, width/2, height/2);
// if (restart = true)
// setup();
}
void keyPressed() {
if (key == 'a') {
player.close();
setup();
}
}
A visualization of national military expenditure by the top 10 spenders