mirror of
https://github.com/Astatin3/Code.org-Final-Projects.git
synced 2026-06-09 00:18:02 -06:00
Add code
This commit is contained in:
@@ -0,0 +1,85 @@
|
|||||||
|
import org.code.neighborhood.*;
|
||||||
|
|
||||||
|
public class ConwayRunner {
|
||||||
|
|
||||||
|
public int mod(int n) {
|
||||||
|
int o = n % 8;
|
||||||
|
if(o < 0){
|
||||||
|
return 8+o;
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int isAlive(String color) {
|
||||||
|
boolean isAlive = (color == "White" || color == "1");
|
||||||
|
if(isAlive){
|
||||||
|
return 1;
|
||||||
|
}else{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(Renderer r, String[][] state) {
|
||||||
|
for(String[] line : state){
|
||||||
|
System.out.println(String.join("",line));
|
||||||
|
}
|
||||||
|
|
||||||
|
r.render(state);
|
||||||
|
this.iterate(r, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void iterate(Renderer r, String[][] initState) {
|
||||||
|
int index1 = 0;
|
||||||
|
String[][] newState = new String[8][8];
|
||||||
|
for(String[] line : initState) {
|
||||||
|
int index2 = 0;
|
||||||
|
for(String cell : line) {
|
||||||
|
|
||||||
|
String cell1 = initState[this.mod(index1-1)][this.mod(index2-1)];
|
||||||
|
String cell2 = initState[this.mod(index1-1)][this.mod(index2)];
|
||||||
|
String cell3 = initState[this.mod(index1-1)][this.mod(index2+1)];
|
||||||
|
String cell4 = initState[this.mod(index1)][this.mod(index2-1)];
|
||||||
|
String cell5 = initState[this.mod(index1)][this.mod(index2+1)];
|
||||||
|
String cell6 = initState[this.mod(index1+1)][this.mod(index2-1)];
|
||||||
|
String cell7 = initState[this.mod(index1+1)][this.mod(index2)];
|
||||||
|
String cell8 = initState[this.mod(index1+1)][this.mod(index2+1)];
|
||||||
|
|
||||||
|
boolean isAlive = (cell == "White");
|
||||||
|
int count = this.isAlive(cell1)+
|
||||||
|
this.isAlive(cell2)+
|
||||||
|
this.isAlive(cell3)+
|
||||||
|
this.isAlive(cell4)+
|
||||||
|
this.isAlive(cell5)+
|
||||||
|
this.isAlive(cell6)+
|
||||||
|
this.isAlive(cell7)+
|
||||||
|
this.isAlive(cell8);
|
||||||
|
|
||||||
|
|
||||||
|
String newColor = new String();
|
||||||
|
if(isAlive && count < 2){
|
||||||
|
newColor = "Black";
|
||||||
|
}else if(isAlive && count == 2 || count == 3){
|
||||||
|
newColor = "White";
|
||||||
|
}else if(isAlive && count > 3){
|
||||||
|
newColor = "Black";
|
||||||
|
}else if(!isAlive && count == 3){
|
||||||
|
newColor = "White";
|
||||||
|
}else if(!isAlive){
|
||||||
|
newColor = "Black";
|
||||||
|
}
|
||||||
|
|
||||||
|
// System.out.println(count);
|
||||||
|
|
||||||
|
// newLine.set(index2, newColor);
|
||||||
|
newState[index1][index2] = (newColor);
|
||||||
|
|
||||||
|
|
||||||
|
index2++;
|
||||||
|
}
|
||||||
|
index1++;
|
||||||
|
// newState.set(index1, newLine);
|
||||||
|
}
|
||||||
|
this.run(r, newState);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import org.code.neighborhood.*;
|
||||||
|
|
||||||
|
public class NeighborhoodRunner {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
String I = "White";
|
||||||
|
String O = "Black";
|
||||||
|
|
||||||
|
String[][] initState = new String[][] {
|
||||||
|
new String[] {O,O,O,O,O,O,O,O},
|
||||||
|
new String[] {O,I,I,O,O,O,O,O},
|
||||||
|
new String[] {O,I,O,I,O,O,O,O},
|
||||||
|
new String[] {O,I,O,O,O,O,O,O},
|
||||||
|
new String[] {O,O,O,O,O,O,O,O},
|
||||||
|
new String[] {O,O,O,O,O,I,I,O},
|
||||||
|
new String[] {O,O,O,O,I,O,I,O},
|
||||||
|
new String[] {O,O,O,O,O,O,I,O}};
|
||||||
|
|
||||||
|
ConwayRunner cw = new ConwayRunner();
|
||||||
|
Renderer r = new Renderer();
|
||||||
|
cw.run(r, initState);
|
||||||
|
cw.run(r, initState);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import org.code.neighborhood.*;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MuralPainter is a PainterPlus that paints
|
||||||
|
* murals in The Neighborhood
|
||||||
|
*/
|
||||||
|
public class Renderer extends Painter {
|
||||||
|
|
||||||
|
|
||||||
|
public void render(String[][] mural) {
|
||||||
|
|
||||||
|
this.setPaint((8*8));
|
||||||
|
int index1 = 0;
|
||||||
|
for(String[] line : mural){
|
||||||
|
// System.out.println(line[0].toString());
|
||||||
|
int index2 = 0;
|
||||||
|
for(String color : line){
|
||||||
|
|
||||||
|
// System.out.println(color);
|
||||||
|
|
||||||
|
if(!this.isOnPaint()){
|
||||||
|
this.paint(color);
|
||||||
|
}else if(this.isOnPaint() && this.getColor() != color){
|
||||||
|
this.scrapePaint();
|
||||||
|
this.paint(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(index2 != line.length-1){
|
||||||
|
this.move();
|
||||||
|
}
|
||||||
|
index2++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(index1 != mural.length-1){
|
||||||
|
this.turnLeft();
|
||||||
|
this.turnLeft();
|
||||||
|
this.turnLeft();
|
||||||
|
this.move();
|
||||||
|
this.turnLeft();
|
||||||
|
this.turnLeft();
|
||||||
|
this.turnLeft();
|
||||||
|
|
||||||
|
for(int i=0;i<line.length-1;i++){
|
||||||
|
this.move();
|
||||||
|
}
|
||||||
|
this.turnLeft();
|
||||||
|
this.turnLeft();
|
||||||
|
}else{
|
||||||
|
this.turnLeft();
|
||||||
|
for(int i=0;i<mural.length-1;i++){
|
||||||
|
this.move();
|
||||||
|
}
|
||||||
|
this.turnLeft();
|
||||||
|
for(int i=0;i<line.length-1;i++){
|
||||||
|
this.move();
|
||||||
|
}
|
||||||
|
this.turnLeft();
|
||||||
|
this.turnLeft();
|
||||||
|
}
|
||||||
|
index1++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class donut {
|
||||||
|
private int height;
|
||||||
|
private int width;
|
||||||
|
|
||||||
|
private double A = 0;
|
||||||
|
private double B = 0;
|
||||||
|
private char[] buffer;
|
||||||
|
private double[] z;
|
||||||
|
|
||||||
|
final static String newLine = "\n";
|
||||||
|
final static double phi_step = 0.07;
|
||||||
|
final static double theta_step = 0.02;
|
||||||
|
final static char[] shade_chars = {'.',',','-','~',':',';','=','!','*','#','$','@'};
|
||||||
|
|
||||||
|
final static double TWO_PI = 6.28;
|
||||||
|
|
||||||
|
public donut(int height, int width) {
|
||||||
|
this.buffer = new char[height * width];
|
||||||
|
this.z = new double[height * width];
|
||||||
|
this.height = height;
|
||||||
|
this.width = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String render(double zoom, double thickness){
|
||||||
|
double outer_size = this.width/thickness;
|
||||||
|
int buffer_size = this.height * this.width;
|
||||||
|
Arrays.fill(this.buffer,0,buffer_size,' ');
|
||||||
|
Arrays.fill(z,0,buffer_size,0);
|
||||||
|
for(double phi = 0; phi < TWO_PI; phi += phi_step){
|
||||||
|
for(double theta = 0; theta < TWO_PI; theta += theta_step){
|
||||||
|
double sin_theta = Math.sin(theta);
|
||||||
|
double cos_phi = Math.cos(phi);
|
||||||
|
double sin_A = Math.sin(A);
|
||||||
|
double sin_phi = Math.sin(phi);
|
||||||
|
double cos_A = Math.cos(A);
|
||||||
|
double h = cos_phi + outer_size;
|
||||||
|
double D = (1 / (sin_theta*h*sin_A*sin_phi*cos_A + 5)) * zoom;
|
||||||
|
double cos_theta = Math.cos(theta);
|
||||||
|
double cos_B = Math.cos(B);
|
||||||
|
double sin_B = Math.sin(B);
|
||||||
|
double t = sin_theta * h * cos_A - sin_phi * sin_A;
|
||||||
|
int x = (int) ((this.width / 2) + 30 * D * (cos_theta * h * cos_B - t * sin_B));
|
||||||
|
int y = (int) ((this.height / 2 + 1) + 15 * D * (cos_theta * h * sin_B + t * cos_B));
|
||||||
|
int o = x + this.width * y;
|
||||||
|
int N = (int) (8 * ((sin_phi * sin_A - sin_theta * cos_phi * cos_A) * cos_B - sin_theta * cos_phi * sin_A - sin_phi * cos_A - cos_theta * cos_phi * sin_B));
|
||||||
|
|
||||||
|
if(this.height > y && y > 0 && x > 0 && this.width > x && D > z[o]){
|
||||||
|
z[o] = D;
|
||||||
|
int num = Math.max(N, 0);
|
||||||
|
this.buffer[o] = shade_chars[num];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
A += 0.04;
|
||||||
|
B += 0.02;
|
||||||
|
String str = "";
|
||||||
|
for(int k=0; buffer_size >= k; k++){
|
||||||
|
if(k % this.width > 0){
|
||||||
|
str += (this.buffer[k]);
|
||||||
|
}else{
|
||||||
|
str += (newLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
public class main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
regularDonut d = new regularDonut();
|
||||||
|
|
||||||
|
d.setZoom(2);
|
||||||
|
d.setThickness(40);
|
||||||
|
|
||||||
|
while(true){
|
||||||
|
System.out.print(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
public class regularDonut extends donut {
|
||||||
|
private int width;
|
||||||
|
private int height;
|
||||||
|
private double zoom;
|
||||||
|
private double thickness;
|
||||||
|
|
||||||
|
public regularDonut() {
|
||||||
|
this(22,80,1,40);
|
||||||
|
}
|
||||||
|
|
||||||
|
public regularDonut(int height, int width, double zoom, double thickness) {
|
||||||
|
super(height, width);
|
||||||
|
this.height = height;
|
||||||
|
this.width = width;
|
||||||
|
this.zoom = zoom;
|
||||||
|
this.thickness = thickness;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setZoom(double zoom) {
|
||||||
|
this.zoom = zoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getZoom() {
|
||||||
|
return this.zoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThickness(double thickness) {
|
||||||
|
this.thickness = thickness;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getThickness() {
|
||||||
|
return this.thickness;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return this.render(zoom, thickness);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
Afghanistan
|
||||||
|
Albania
|
||||||
|
Algeria
|
||||||
|
American Samoa
|
||||||
|
Andorra
|
||||||
|
Angola
|
||||||
|
Antigua and Barbuda
|
||||||
|
Argentina
|
||||||
|
Armenia
|
||||||
|
Aruba
|
||||||
|
Australia
|
||||||
|
Austria
|
||||||
|
Azerbaijan
|
||||||
|
Bahamas, The
|
||||||
|
Bahrain
|
||||||
|
Bangladesh
|
||||||
|
Barbados
|
||||||
|
Belarus
|
||||||
|
Belgium
|
||||||
|
Belize
|
||||||
|
Benin
|
||||||
|
Bermuda
|
||||||
|
Bhutan
|
||||||
|
Bolivia
|
||||||
|
Bosnia and Herzegovina
|
||||||
|
Botswana
|
||||||
|
Brazil
|
||||||
|
British Virgin Islands
|
||||||
|
Brunei Darussalam
|
||||||
|
Bulgaria
|
||||||
|
Burkina Faso
|
||||||
|
Burundi
|
||||||
|
Cabo Verde
|
||||||
|
Cambodia
|
||||||
|
Cameroon
|
||||||
|
Canada
|
||||||
|
Cayman Islands
|
||||||
|
Central African Republic
|
||||||
|
Chad
|
||||||
|
Chile
|
||||||
|
China
|
||||||
|
Colombia
|
||||||
|
Comoros
|
||||||
|
Congo, Dem. Rep.
|
||||||
|
Congo, Rep.
|
||||||
|
Costa Rica
|
||||||
|
Cote d'Ivoire
|
||||||
|
Croatia
|
||||||
|
Cuba
|
||||||
|
Curacao
|
||||||
|
Cyprus
|
||||||
|
Czech Republic
|
||||||
|
Denmark
|
||||||
|
Djibouti
|
||||||
|
Dominica
|
||||||
|
Dominican Republic
|
||||||
|
Ecuador
|
||||||
|
Egypt, Arab Rep.
|
||||||
|
El Salvador
|
||||||
|
Equatorial Guinea
|
||||||
|
Eritrea
|
||||||
|
Estonia
|
||||||
|
Eswatini
|
||||||
|
Ethiopia
|
||||||
|
Faroe Islands
|
||||||
|
Fiji
|
||||||
|
Finland
|
||||||
|
France
|
||||||
|
French Polynesia
|
||||||
|
Gabon
|
||||||
|
Gambia, The
|
||||||
|
Georgia
|
||||||
|
Germany
|
||||||
|
Ghana
|
||||||
|
Gibraltar
|
||||||
|
Greece
|
||||||
|
Greenland
|
||||||
|
Grenada
|
||||||
|
Guam
|
||||||
|
Guatemala
|
||||||
|
Guinea
|
||||||
|
Guinea-Bissau
|
||||||
|
Guyana
|
||||||
|
Haiti
|
||||||
|
Honduras
|
||||||
|
Hong Kong SAR, China
|
||||||
|
Hungary
|
||||||
|
Iceland
|
||||||
|
India
|
||||||
|
Indonesia
|
||||||
|
Iran, Islamic Rep.
|
||||||
|
Iraq
|
||||||
|
Ireland
|
||||||
|
Isle of Man
|
||||||
|
Israel
|
||||||
|
Italy
|
||||||
|
Jamaica
|
||||||
|
Japan
|
||||||
|
Jordan
|
||||||
|
Kazakhstan
|
||||||
|
Kenya
|
||||||
|
Kiribati
|
||||||
|
Korea, Dem. People's Rep.
|
||||||
|
Korea, Rep.
|
||||||
|
Kuwait
|
||||||
|
Kyrgyz Republic
|
||||||
|
Lao PDR
|
||||||
|
Latvia
|
||||||
|
Lebanon
|
||||||
|
Lesotho
|
||||||
|
Liberia
|
||||||
|
Libya
|
||||||
|
Liechtenstein
|
||||||
|
Lithuania
|
||||||
|
Luxembourg
|
||||||
|
Macao SAR, China
|
||||||
|
Madagascar
|
||||||
|
Malawi
|
||||||
|
Malaysia
|
||||||
|
Maldives
|
||||||
|
Mali
|
||||||
|
Malta
|
||||||
|
Marshall Islands
|
||||||
|
Mauritania
|
||||||
|
Mauritius
|
||||||
|
Mexico
|
||||||
|
Micronesia, Fed. Sts.
|
||||||
|
Moldova
|
||||||
|
Monaco
|
||||||
|
Mongolia
|
||||||
|
Montenegro
|
||||||
|
Morocco
|
||||||
|
Mozambique
|
||||||
|
Myanmar
|
||||||
|
Namibia
|
||||||
|
Nauru
|
||||||
|
Nepal
|
||||||
|
Netherlands
|
||||||
|
New Caledonia
|
||||||
|
New Zealand
|
||||||
|
Nicaragua
|
||||||
|
Niger
|
||||||
|
Nigeria
|
||||||
|
North Macedonia
|
||||||
|
Northern Mariana Islands
|
||||||
|
Norway
|
||||||
|
Oman
|
||||||
|
Pakistan
|
||||||
|
Palau
|
||||||
|
Panama
|
||||||
|
Papua New Guinea
|
||||||
|
Paraguay
|
||||||
|
Peru
|
||||||
|
Philippines
|
||||||
|
Poland
|
||||||
|
Portugal
|
||||||
|
Puerto Rico
|
||||||
|
Qatar
|
||||||
|
Romania
|
||||||
|
Russian Federation
|
||||||
|
Rwanda
|
||||||
|
Samoa
|
||||||
|
San Marino
|
||||||
|
Sao Tome and Principe
|
||||||
|
Saudi Arabia
|
||||||
|
Senegal
|
||||||
|
Serbia
|
||||||
|
Seychelles
|
||||||
|
Sierra Leone
|
||||||
|
Singapore
|
||||||
|
Sint Maarten (Dutch part)
|
||||||
|
Slovak Republic
|
||||||
|
Slovenia
|
||||||
|
Solomon Islands
|
||||||
|
Somalia
|
||||||
|
South Africa
|
||||||
|
South Sudan
|
||||||
|
Spain
|
||||||
|
Sri Lanka
|
||||||
|
St. Kitts and Nevis
|
||||||
|
St. Lucia
|
||||||
|
St. Martin (French part)
|
||||||
|
St. Vincent and the Grenadines
|
||||||
|
Sudan
|
||||||
|
Suriname
|
||||||
|
Sweden
|
||||||
|
Switzerland
|
||||||
|
Syrian Arab Republic
|
||||||
|
Tajikistan
|
||||||
|
Tanzania
|
||||||
|
Thailand
|
||||||
|
Timor-Leste
|
||||||
|
Togo
|
||||||
|
Tonga
|
||||||
|
Trinidad and Tobago
|
||||||
|
Tunisia
|
||||||
|
Turkey
|
||||||
|
Turkmenistan
|
||||||
|
Turks and Caicos Islands
|
||||||
|
Tuvalu
|
||||||
|
Uganda
|
||||||
|
Ukraine
|
||||||
|
United Arab Emirates
|
||||||
|
United Kingdom
|
||||||
|
United States
|
||||||
|
Uruguay
|
||||||
|
Uzbekistan
|
||||||
|
Vanuatu
|
||||||
|
Venezuela, RB
|
||||||
|
Vietnam
|
||||||
|
Virgin Islands (U.S.)
|
||||||
|
West Bank and Gaza
|
||||||
|
Yemen, Rep.
|
||||||
|
Zambia
|
||||||
|
Zimbabwe
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class DataRunner {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Statistics plotter thing!
|
||||||
|
// Options:
|
||||||
|
// Option 0 - population
|
||||||
|
// Option 1 - unemployment %
|
||||||
|
// Option 2 - internet %
|
||||||
|
|
||||||
|
int opt1 = 0;
|
||||||
|
int opt2 = 2;
|
||||||
|
|
||||||
|
int width = 50;
|
||||||
|
int height = 100;
|
||||||
|
|
||||||
|
UserStory us = new UserStory(opt1, opt2, width, height);
|
||||||
|
System.out.print(us);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
Low Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
Low Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
Low Income
|
||||||
|
Low Income
|
||||||
|
Lower Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Low Income
|
||||||
|
Low Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
Low Income
|
||||||
|
Lower Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Low Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
Low Income
|
||||||
|
High Income
|
||||||
|
upper Middle Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
Low Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
Low Income
|
||||||
|
Low Income
|
||||||
|
Upper Middle Income
|
||||||
|
Low Income
|
||||||
|
Lower Middle Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
Low Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
Low Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Low income
|
||||||
|
Low Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Low Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
Low Income
|
||||||
|
Lower Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Low Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
Low Income
|
||||||
|
Lower Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Low Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
Low Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
Low Income
|
||||||
|
Upper Middle Income
|
||||||
|
Low Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Low Income
|
||||||
|
Low Income
|
||||||
|
Low Income
|
||||||
|
Upper Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
Low Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
High Income
|
||||||
|
Upper Middle Income
|
||||||
|
Low Income
|
||||||
|
Lower Middle Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
Upper Middle Income
|
||||||
|
Lower Middle Income
|
||||||
|
High Income
|
||||||
|
Lower Middle Income
|
||||||
|
Low Income
|
||||||
|
Lower Middle Income
|
||||||
|
Lower Middle Income
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
13.5
|
||||||
|
71.85
|
||||||
|
49.04
|
||||||
|
-1
|
||||||
|
91.57
|
||||||
|
14.34
|
||||||
|
76
|
||||||
|
74.29
|
||||||
|
64.74
|
||||||
|
97.17
|
||||||
|
86.55
|
||||||
|
87.48
|
||||||
|
79.8
|
||||||
|
85
|
||||||
|
98.64
|
||||||
|
15
|
||||||
|
81.76
|
||||||
|
79.13
|
||||||
|
88.66
|
||||||
|
47.08
|
||||||
|
20
|
||||||
|
98.37
|
||||||
|
48.11
|
||||||
|
44.29
|
||||||
|
70.12
|
||||||
|
47
|
||||||
|
70.43
|
||||||
|
77.7
|
||||||
|
94.87
|
||||||
|
64.78
|
||||||
|
16
|
||||||
|
2.66
|
||||||
|
57.16
|
||||||
|
40
|
||||||
|
23.2
|
||||||
|
91
|
||||||
|
81.07
|
||||||
|
4.34
|
||||||
|
6.5
|
||||||
|
82.33
|
||||||
|
54.3
|
||||||
|
64.13
|
||||||
|
8.48
|
||||||
|
8.62
|
||||||
|
8.65
|
||||||
|
74.09
|
||||||
|
46.82
|
||||||
|
75.29
|
||||||
|
57.15
|
||||||
|
68.13
|
||||||
|
84.43
|
||||||
|
80.69
|
||||||
|
97.32
|
||||||
|
55.68
|
||||||
|
69.62
|
||||||
|
74.82
|
||||||
|
57.27
|
||||||
|
46.92
|
||||||
|
33.82
|
||||||
|
26.24
|
||||||
|
1.31
|
||||||
|
89.36
|
||||||
|
47
|
||||||
|
18.62
|
||||||
|
97.58
|
||||||
|
49.97
|
||||||
|
88.89
|
||||||
|
82.04
|
||||||
|
72.7
|
||||||
|
62
|
||||||
|
19.84
|
||||||
|
62.72
|
||||||
|
89.74
|
||||||
|
39
|
||||||
|
94.44
|
||||||
|
72.95
|
||||||
|
69.48
|
||||||
|
59.07
|
||||||
|
80.51
|
||||||
|
65
|
||||||
|
18
|
||||||
|
3.93
|
||||||
|
37.33
|
||||||
|
32.47
|
||||||
|
31.7
|
||||||
|
90.51
|
||||||
|
76.07
|
||||||
|
99.01
|
||||||
|
34.45
|
||||||
|
39.9
|
||||||
|
70
|
||||||
|
75
|
||||||
|
84.52
|
||||||
|
-1
|
||||||
|
83.73
|
||||||
|
74.39
|
||||||
|
55.07
|
||||||
|
91.28
|
||||||
|
66.79
|
||||||
|
78.9
|
||||||
|
17.83
|
||||||
|
14.58
|
||||||
|
-1
|
||||||
|
96.02
|
||||||
|
99.6
|
||||||
|
38
|
||||||
|
25.51
|
||||||
|
83.58
|
||||||
|
78.18
|
||||||
|
29
|
||||||
|
7.98
|
||||||
|
21.76
|
||||||
|
98.1
|
||||||
|
79.72
|
||||||
|
97.06
|
||||||
|
83.79
|
||||||
|
9.8
|
||||||
|
13.78
|
||||||
|
81.2
|
||||||
|
63.19
|
||||||
|
13
|
||||||
|
81.66
|
||||||
|
38.7
|
||||||
|
20.8
|
||||||
|
58.6
|
||||||
|
65.77
|
||||||
|
35.3
|
||||||
|
76.12
|
||||||
|
97.05
|
||||||
|
47.16
|
||||||
|
71.52
|
||||||
|
64.8
|
||||||
|
10
|
||||||
|
30.68
|
||||||
|
51
|
||||||
|
57
|
||||||
|
34
|
||||||
|
94.71
|
||||||
|
82.01
|
||||||
|
90.81
|
||||||
|
27.86
|
||||||
|
5.25
|
||||||
|
42
|
||||||
|
79.17
|
||||||
|
-1
|
||||||
|
96.49
|
||||||
|
80.19
|
||||||
|
15.51
|
||||||
|
-1
|
||||||
|
57.87
|
||||||
|
11.21
|
||||||
|
64.99
|
||||||
|
52.54
|
||||||
|
60.05
|
||||||
|
77.54
|
||||||
|
74.66
|
||||||
|
70.6
|
||||||
|
99.65
|
||||||
|
70.68
|
||||||
|
80.86
|
||||||
|
21.77
|
||||||
|
33.61
|
||||||
|
60.18
|
||||||
|
29.93
|
||||||
|
93.31
|
||||||
|
46
|
||||||
|
73.36
|
||||||
|
58.77
|
||||||
|
9
|
||||||
|
88.17
|
||||||
|
-1
|
||||||
|
80.66
|
||||||
|
79.75
|
||||||
|
11.92
|
||||||
|
2
|
||||||
|
56.17
|
||||||
|
7.98
|
||||||
|
86.11
|
||||||
|
34.11
|
||||||
|
80.71
|
||||||
|
50.82
|
||||||
|
-1
|
||||||
|
22.39
|
||||||
|
30.87
|
||||||
|
48.95
|
||||||
|
92.14
|
||||||
|
89.69
|
||||||
|
34.25
|
||||||
|
21.96
|
||||||
|
25
|
||||||
|
56.82
|
||||||
|
27.49
|
||||||
|
12.36
|
||||||
|
41.25
|
||||||
|
77.33
|
||||||
|
64.19
|
||||||
|
71.04
|
||||||
|
21.25
|
||||||
|
-1
|
||||||
|
49.32
|
||||||
|
23.71
|
||||||
|
62.55
|
||||||
|
98.45
|
||||||
|
94.9
|
||||||
|
87.27
|
||||||
|
74.77
|
||||||
|
55.2
|
||||||
|
25.72
|
||||||
|
72
|
||||||
|
70.35
|
||||||
|
64.38
|
||||||
|
64.4
|
||||||
|
26.72
|
||||||
|
14.3
|
||||||
|
27.06
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
37172386
|
||||||
|
2866376
|
||||||
|
42228429
|
||||||
|
55465
|
||||||
|
77006
|
||||||
|
30809762
|
||||||
|
96286
|
||||||
|
44494502
|
||||||
|
2951776
|
||||||
|
105845
|
||||||
|
24982688
|
||||||
|
8840521
|
||||||
|
9939800
|
||||||
|
385640
|
||||||
|
1569439
|
||||||
|
161356039
|
||||||
|
286641
|
||||||
|
9483499
|
||||||
|
11433256
|
||||||
|
383071
|
||||||
|
11485048
|
||||||
|
63973
|
||||||
|
754394
|
||||||
|
11353142
|
||||||
|
3323929
|
||||||
|
2254126
|
||||||
|
209469333
|
||||||
|
29802
|
||||||
|
428962
|
||||||
|
7025037
|
||||||
|
19751535
|
||||||
|
11175378
|
||||||
|
543767
|
||||||
|
16249798
|
||||||
|
25216237
|
||||||
|
37057765
|
||||||
|
64174
|
||||||
|
4666377
|
||||||
|
15477751
|
||||||
|
18729160
|
||||||
|
1392730000
|
||||||
|
49648685
|
||||||
|
832322
|
||||||
|
84068091
|
||||||
|
5244363
|
||||||
|
4999441
|
||||||
|
25069229
|
||||||
|
4087843
|
||||||
|
11338138
|
||||||
|
159800
|
||||||
|
1189265
|
||||||
|
10629928
|
||||||
|
5793636
|
||||||
|
958920
|
||||||
|
71625
|
||||||
|
10627165
|
||||||
|
17084357
|
||||||
|
98423595
|
||||||
|
6420744
|
||||||
|
1308974
|
||||||
|
3213972
|
||||||
|
1321977
|
||||||
|
1136191
|
||||||
|
109224559
|
||||||
|
48497
|
||||||
|
883483
|
||||||
|
5515525
|
||||||
|
66977107
|
||||||
|
277679
|
||||||
|
2119275
|
||||||
|
2280102
|
||||||
|
3726549
|
||||||
|
82905782
|
||||||
|
29767108
|
||||||
|
33718
|
||||||
|
10731726
|
||||||
|
56025
|
||||||
|
111454
|
||||||
|
165768
|
||||||
|
17247807
|
||||||
|
12414318
|
||||||
|
1874309
|
||||||
|
779004
|
||||||
|
11123176
|
||||||
|
9587522
|
||||||
|
7451000
|
||||||
|
9775564
|
||||||
|
352721
|
||||||
|
1352617328
|
||||||
|
267663435
|
||||||
|
81800269
|
||||||
|
38433600
|
||||||
|
4867309
|
||||||
|
84077
|
||||||
|
8882800
|
||||||
|
60421760
|
||||||
|
2934855
|
||||||
|
126529100
|
||||||
|
9956011
|
||||||
|
18272430
|
||||||
|
51393010
|
||||||
|
115847
|
||||||
|
25549819
|
||||||
|
51606633
|
||||||
|
4137309
|
||||||
|
6322800
|
||||||
|
7061507
|
||||||
|
1927174
|
||||||
|
6848925
|
||||||
|
2108132
|
||||||
|
4818977
|
||||||
|
6678567
|
||||||
|
37910
|
||||||
|
2801543
|
||||||
|
607950
|
||||||
|
631636
|
||||||
|
26262368
|
||||||
|
18143315
|
||||||
|
31528585
|
||||||
|
515696
|
||||||
|
19077690
|
||||||
|
484630
|
||||||
|
58413
|
||||||
|
4403319
|
||||||
|
1265303
|
||||||
|
126190788
|
||||||
|
112640
|
||||||
|
2706049
|
||||||
|
38682
|
||||||
|
3170208
|
||||||
|
622227
|
||||||
|
36029138
|
||||||
|
29495962
|
||||||
|
53708395
|
||||||
|
2448255
|
||||||
|
12704
|
||||||
|
28087871
|
||||||
|
17231624
|
||||||
|
284060
|
||||||
|
4841000
|
||||||
|
6465513
|
||||||
|
22442948
|
||||||
|
195874740
|
||||||
|
2082958
|
||||||
|
56882
|
||||||
|
5311916
|
||||||
|
4829483
|
||||||
|
212215030
|
||||||
|
17907
|
||||||
|
4176873
|
||||||
|
8606316
|
||||||
|
6956071
|
||||||
|
31989256
|
||||||
|
106651922
|
||||||
|
37974750
|
||||||
|
10283822
|
||||||
|
3195153
|
||||||
|
2781677
|
||||||
|
19466145
|
||||||
|
144478050
|
||||||
|
12301939
|
||||||
|
196130
|
||||||
|
33785
|
||||||
|
211028
|
||||||
|
33699947
|
||||||
|
15854360
|
||||||
|
6982604
|
||||||
|
96762
|
||||||
|
7650154
|
||||||
|
5638676
|
||||||
|
40654
|
||||||
|
5446771
|
||||||
|
2073894
|
||||||
|
652858
|
||||||
|
15008154
|
||||||
|
57779622
|
||||||
|
10975920
|
||||||
|
46796540
|
||||||
|
21670000
|
||||||
|
52441
|
||||||
|
181889
|
||||||
|
37264
|
||||||
|
110210
|
||||||
|
41801533
|
||||||
|
575991
|
||||||
|
10175214
|
||||||
|
8513227
|
||||||
|
16906283
|
||||||
|
9100837
|
||||||
|
56318348
|
||||||
|
69428524
|
||||||
|
1267972
|
||||||
|
7889094
|
||||||
|
103197
|
||||||
|
1389858
|
||||||
|
11565204
|
||||||
|
82319724
|
||||||
|
5850908
|
||||||
|
37665
|
||||||
|
11508
|
||||||
|
42723139
|
||||||
|
44622516
|
||||||
|
9630959
|
||||||
|
66460344
|
||||||
|
326687501
|
||||||
|
3449299
|
||||||
|
32955400
|
||||||
|
292680
|
||||||
|
28870195
|
||||||
|
95540395
|
||||||
|
106977
|
||||||
|
4569087
|
||||||
|
28498687
|
||||||
|
17351822
|
||||||
|
14439018
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
11.18
|
||||||
|
13.75
|
||||||
|
13.57
|
||||||
|
9.2
|
||||||
|
3.7
|
||||||
|
7.36
|
||||||
|
8.42
|
||||||
|
9.22
|
||||||
|
17.7
|
||||||
|
8.9
|
||||||
|
5.16
|
||||||
|
4.85
|
||||||
|
4.9
|
||||||
|
12.7
|
||||||
|
1.2
|
||||||
|
4.37
|
||||||
|
9.72
|
||||||
|
4.76
|
||||||
|
5.95
|
||||||
|
6.6
|
||||||
|
2.65
|
||||||
|
8.94
|
||||||
|
2.45
|
||||||
|
3.52
|
||||||
|
15.69
|
||||||
|
17.86
|
||||||
|
11.93
|
||||||
|
2.9
|
||||||
|
8.7
|
||||||
|
5.21
|
||||||
|
6.48
|
||||||
|
1.57
|
||||||
|
12.17
|
||||||
|
0.72
|
||||||
|
3.53
|
||||||
|
5.66
|
||||||
|
4.24
|
||||||
|
5.6
|
||||||
|
5.9
|
||||||
|
7.23
|
||||||
|
3.8
|
||||||
|
9.11
|
||||||
|
8.14
|
||||||
|
4.49
|
||||||
|
10
|
||||||
|
11.49
|
||||||
|
3.27
|
||||||
|
8.43
|
||||||
|
2.4
|
||||||
|
13.43
|
||||||
|
8.37
|
||||||
|
2.24
|
||||||
|
4.97
|
||||||
|
5.8
|
||||||
|
10.96
|
||||||
|
5.86
|
||||||
|
3.81
|
||||||
|
11.74
|
||||||
|
4.01
|
||||||
|
8.1
|
||||||
|
5.1
|
||||||
|
5.37
|
||||||
|
22.72
|
||||||
|
2.25
|
||||||
|
3.7
|
||||||
|
4.32
|
||||||
|
7.36
|
||||||
|
9.06
|
||||||
|
11.74
|
||||||
|
20.39
|
||||||
|
9.42
|
||||||
|
12.67
|
||||||
|
3.38
|
||||||
|
4.22
|
||||||
|
1
|
||||||
|
19.29
|
||||||
|
9.1
|
||||||
|
22.9
|
||||||
|
5.4
|
||||||
|
2.46
|
||||||
|
4.55
|
||||||
|
6
|
||||||
|
14.02
|
||||||
|
14.1
|
||||||
|
5.65
|
||||||
|
3.09
|
||||||
|
3.71
|
||||||
|
2.7
|
||||||
|
5.33
|
||||||
|
4.4
|
||||||
|
12.06
|
||||||
|
13.02
|
||||||
|
5.74
|
||||||
|
2.67
|
||||||
|
4
|
||||||
|
10.61
|
||||||
|
7.72
|
||||||
|
2.4
|
||||||
|
15.27
|
||||||
|
4.9
|
||||||
|
2.76
|
||||||
|
9.33
|
||||||
|
4.7
|
||||||
|
3.82
|
||||||
|
2.16
|
||||||
|
4.54
|
||||||
|
9.41
|
||||||
|
7.41
|
||||||
|
6.35
|
||||||
|
24.58
|
||||||
|
3.08
|
||||||
|
19.03
|
||||||
|
2.01
|
||||||
|
6.15
|
||||||
|
5.59
|
||||||
|
2
|
||||||
|
1.79
|
||||||
|
28.67
|
||||||
|
3.3
|
||||||
|
6.12
|
||||||
|
1.62
|
||||||
|
3.66
|
||||||
|
4.74
|
||||||
|
10.34
|
||||||
|
6.43
|
||||||
|
3.48
|
||||||
|
8.86
|
||||||
|
2.98
|
||||||
|
6.33
|
||||||
|
5.38
|
||||||
|
15.17
|
||||||
|
9.3
|
||||||
|
3.43
|
||||||
|
0.87
|
||||||
|
19.88
|
||||||
|
13.28
|
||||||
|
11.36
|
||||||
|
3.83
|
||||||
|
14.59
|
||||||
|
4.3
|
||||||
|
4.52
|
||||||
|
7.77
|
||||||
|
8.39
|
||||||
|
20.74
|
||||||
|
11.17
|
||||||
|
3.8
|
||||||
|
1.8
|
||||||
|
4.08
|
||||||
|
1.36
|
||||||
|
3.89
|
||||||
|
2.62
|
||||||
|
6.22
|
||||||
|
6.43
|
||||||
|
2.34
|
||||||
|
3.85
|
||||||
|
6.99
|
||||||
|
8.27
|
||||||
|
0.11
|
||||||
|
4.19
|
||||||
|
4.85
|
||||||
|
15.11
|
||||||
|
14.47
|
||||||
|
6.45
|
||||||
|
13.59
|
||||||
|
6.04
|
||||||
|
6.76
|
||||||
|
12.73
|
||||||
|
3.53
|
||||||
|
4.68
|
||||||
|
4.2
|
||||||
|
9.9
|
||||||
|
6.54
|
||||||
|
5.11
|
||||||
|
0.69
|
||||||
|
5.9
|
||||||
|
28.47
|
||||||
|
12.15
|
||||||
|
15.25
|
||||||
|
4.05
|
||||||
|
5.12
|
||||||
|
21.26
|
||||||
|
12
|
||||||
|
18.79
|
||||||
|
17.44
|
||||||
|
7.22
|
||||||
|
6.35
|
||||||
|
4.71
|
||||||
|
8.61
|
||||||
|
6.9
|
||||||
|
2.12
|
||||||
|
0.77
|
||||||
|
4.66
|
||||||
|
3.74
|
||||||
|
3.07
|
||||||
|
3.21
|
||||||
|
15.46
|
||||||
|
10.89
|
||||||
|
4
|
||||||
|
8.3
|
||||||
|
8.49
|
||||||
|
9.44
|
||||||
|
8.8
|
||||||
|
2.23
|
||||||
|
4
|
||||||
|
3.9
|
||||||
|
8.34
|
||||||
|
9.3
|
||||||
|
1.85
|
||||||
|
6.6
|
||||||
|
2
|
||||||
|
7
|
||||||
|
26.26
|
||||||
|
13.47
|
||||||
|
11.63
|
||||||
|
4.77
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class UserStory {
|
||||||
|
|
||||||
|
private String[] countries = FileReader.toStringArray("countries.txt");
|
||||||
|
|
||||||
|
private double[] populations = FileReader.toDoubleArray("populations.txt");
|
||||||
|
private double[] unemployment = FileReader.toDoubleArray("unemployment.txt");
|
||||||
|
private double[] internetpercent = FileReader.toDoubleArray("internetpercent.txt");
|
||||||
|
|
||||||
|
private int opt1;
|
||||||
|
private int opt2;
|
||||||
|
|
||||||
|
private int width;
|
||||||
|
private int height;
|
||||||
|
|
||||||
|
public UserStory() {
|
||||||
|
this(0, 2, 50, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserStory(int opt1, int opt2, int width, int height){
|
||||||
|
this.opt1 = opt1;
|
||||||
|
this.opt2 = opt2;
|
||||||
|
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double[] getArrayFromOpt(int i) {
|
||||||
|
switch(i) {
|
||||||
|
case 0:
|
||||||
|
return this.populations;
|
||||||
|
case 1:
|
||||||
|
return this.unemployment;
|
||||||
|
case 2:
|
||||||
|
return this.internetpercent;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameFromOpt(int i) {
|
||||||
|
switch(i) {
|
||||||
|
case 0:
|
||||||
|
return "populations";
|
||||||
|
case 1:
|
||||||
|
return "unemployment";
|
||||||
|
case 2:
|
||||||
|
return "internetpercent";
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to find maximum in an array
|
||||||
|
public double max(double[] arr){
|
||||||
|
double max = arr[0];
|
||||||
|
for (int i = 0; i < arr.length; i++)
|
||||||
|
if (arr[i] > max){
|
||||||
|
max = arr[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the corrosponding country name, of largest value of array
|
||||||
|
public String maxStr(double[] arr){
|
||||||
|
double max = arr[0];
|
||||||
|
String maxName = "";
|
||||||
|
for (int i = 0; i < arr.length; i++)
|
||||||
|
if (arr[i] > max){
|
||||||
|
max = arr[i];
|
||||||
|
maxName = this.countries[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxName;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to find minimum in an array
|
||||||
|
public double min(double[] arr){
|
||||||
|
double min = arr[0];
|
||||||
|
for (int i = 0; i < arr.length; i++)
|
||||||
|
if (arr[i] < min){
|
||||||
|
min = arr[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the corrosponding country name, of smallest value of array
|
||||||
|
public String minStr(double[] arr){
|
||||||
|
double min = arr[0];
|
||||||
|
String minName = "";
|
||||||
|
for (int i = 0; i < arr.length; i++)
|
||||||
|
if (arr[i] < min){
|
||||||
|
min = arr[i];
|
||||||
|
minName = this.countries[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return minName;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A method to find at which x and y choords are there points.
|
||||||
|
public boolean[][] pointAtChoord(double[] arr1, double[] arr2, double maxX, double maxY) {
|
||||||
|
|
||||||
|
// Create a 2d boolean array that is all false
|
||||||
|
boolean[][] result = new boolean[this.width][this.height];
|
||||||
|
for(int a = 0; a < this.width; a++){
|
||||||
|
for(int b = 0; b < this.height; b++){
|
||||||
|
result[a][b] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0;i<arr1.length;i++){
|
||||||
|
double x = arr1[i];
|
||||||
|
double y = arr2[i];
|
||||||
|
|
||||||
|
// Map the numbers onto points in the output
|
||||||
|
x = width-Math.round((x/maxX)*(this.width))-2;
|
||||||
|
y = Math.round((y/maxY)*(this.height))-1;
|
||||||
|
|
||||||
|
// Make all values < 0, = 0
|
||||||
|
x = Math.max(x, 0);
|
||||||
|
y = Math.max(y, 0);
|
||||||
|
|
||||||
|
// Make the output point true
|
||||||
|
result[(int)x][(int)y] = true;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output the scatter plot, and some other numbers, as a string.
|
||||||
|
public String plotter() {
|
||||||
|
|
||||||
|
// Get arrays from options
|
||||||
|
String arr1Name = getNameFromOpt(this.opt1);
|
||||||
|
String arr2Name = getNameFromOpt(this.opt2);
|
||||||
|
double[] arr1 = getArrayFromOpt(this.opt1);
|
||||||
|
double[] arr2 = getArrayFromOpt(this.opt2);
|
||||||
|
|
||||||
|
// Calc maximum x and y vars
|
||||||
|
double maxX = max(arr1);
|
||||||
|
double maxY = max(arr2);
|
||||||
|
|
||||||
|
|
||||||
|
// Calc points
|
||||||
|
boolean[][] plot = pointAtChoord(arr1, arr2, maxX, maxY);
|
||||||
|
|
||||||
|
String out = "";
|
||||||
|
|
||||||
|
// Format scatter plot
|
||||||
|
out += "\n";
|
||||||
|
out += arr1Name + " As (x) vs. " + arr2Name + " As (y)";
|
||||||
|
out += "\n";
|
||||||
|
out += "0" + (" ".repeat(this.height)) + maxX + "\n";
|
||||||
|
out += "/" + ("-".repeat(this.height)) + "\\ " + maxY + "\n";
|
||||||
|
for(int a=0;a<this.width;a++){
|
||||||
|
out += "|";
|
||||||
|
for(int b=0;b<height;b++){
|
||||||
|
if(plot[a][b]){
|
||||||
|
out += "#";
|
||||||
|
}else{
|
||||||
|
out += " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out += "|\n";
|
||||||
|
}
|
||||||
|
out += "\\" + ("-".repeat(this.height)) + "/ 0";
|
||||||
|
out += "\n\n";
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get stats about the arrays passed
|
||||||
|
public String metaStats() {
|
||||||
|
// Get arrays from options
|
||||||
|
String arr1Name = getNameFromOpt(this.opt1);
|
||||||
|
String arr2Name = getNameFromOpt(this.opt2);
|
||||||
|
double[] arr1 = getArrayFromOpt(this.opt1);
|
||||||
|
double[] arr2 = getArrayFromOpt(this.opt2);
|
||||||
|
|
||||||
|
String out = "";
|
||||||
|
|
||||||
|
// Calc the values and countries of min and max stats
|
||||||
|
out += arr1Name + " Maximum: \n";
|
||||||
|
out += max(arr1) + " - " + maxStr(arr1) + "\n";
|
||||||
|
out += arr1Name + " Minimum: \n";
|
||||||
|
out += min(arr1) + " - " + minStr(arr1) + "\n";
|
||||||
|
|
||||||
|
out += arr2Name + " Maximum: \n";
|
||||||
|
out += max(arr2) + " - " + maxStr(arr2) + "\n";
|
||||||
|
out += arr2Name + " Minimum: \n";
|
||||||
|
out += min(arr2) + " - " + minStr(arr2) + "\n";
|
||||||
|
|
||||||
|
out += "\n\n";
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return plotter() + metaStats();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// This code is from https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/Complex.java
|
||||||
|
// I did not write this.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Compilation: javac Complex.java
|
||||||
|
* Execution: java Complex
|
||||||
|
*
|
||||||
|
* Data type for complex numbers.
|
||||||
|
*
|
||||||
|
* The data type is "immutable" so once you create and initialize
|
||||||
|
* a Complex object, you cannot change it. The "final" keyword
|
||||||
|
* when declaring re and im enforces this rule, making it a
|
||||||
|
* compile-time error to change the .re or .im instance variables after
|
||||||
|
* they've been initialized.
|
||||||
|
*
|
||||||
|
* % java Complex
|
||||||
|
* a = 5.0 + 6.0i
|
||||||
|
* b = -3.0 + 4.0i
|
||||||
|
* Re(a) = 5.0
|
||||||
|
* Im(a) = 6.0
|
||||||
|
* b + a = 2.0 + 10.0i
|
||||||
|
* a - b = 8.0 + 2.0i
|
||||||
|
* a * b = -39.0 + 2.0i
|
||||||
|
* b * a = -39.0 + 2.0i
|
||||||
|
* a / b = 0.36 - 1.52i
|
||||||
|
* (a / b) * b = 5.0 + 6.0i
|
||||||
|
* conj(a) = 5.0 - 6.0i
|
||||||
|
* |a| = 7.810249675906654
|
||||||
|
* tan(a) = -6.685231390246571E-6 + 1.0000103108981198i
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
public class Complex {
|
||||||
|
private final double re; // the real part
|
||||||
|
private final double im; // the imaginary part
|
||||||
|
|
||||||
|
// create a new object with the given real and imaginary parts
|
||||||
|
public Complex(double real, double imag) {
|
||||||
|
re = real;
|
||||||
|
im = imag;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return a string representation of the invoking Complex object
|
||||||
|
public String toString() {
|
||||||
|
if (im == 0) return re + "";
|
||||||
|
if (re == 0) return im + "i";
|
||||||
|
if (im < 0) return re + " - " + (-im) + "i";
|
||||||
|
return re + " + " + im + "i";
|
||||||
|
}
|
||||||
|
|
||||||
|
// return abs/modulus/magnitude
|
||||||
|
public double abs() {
|
||||||
|
return Math.hypot(re, im);
|
||||||
|
}
|
||||||
|
|
||||||
|
// return angle/phase/argument, normalized to be between -pi and pi
|
||||||
|
public double phase() {
|
||||||
|
return Math.atan2(im, re);
|
||||||
|
}
|
||||||
|
|
||||||
|
// return a new Complex object whose value is (this + b)
|
||||||
|
public Complex plus(Complex b) {
|
||||||
|
Complex a = this; // invoking object
|
||||||
|
double real = a.re + b.re;
|
||||||
|
double imag = a.im + b.im;
|
||||||
|
return new Complex(real, imag);
|
||||||
|
}
|
||||||
|
|
||||||
|
// return a new Complex object whose value is (this - b)
|
||||||
|
public Complex minus(Complex b) {
|
||||||
|
Complex a = this;
|
||||||
|
double real = a.re - b.re;
|
||||||
|
double imag = a.im - b.im;
|
||||||
|
return new Complex(real, imag);
|
||||||
|
}
|
||||||
|
|
||||||
|
// return a new Complex object whose value is (this * b)
|
||||||
|
public Complex times(Complex b) {
|
||||||
|
Complex a = this;
|
||||||
|
double real = a.re * b.re - a.im * b.im;
|
||||||
|
double imag = a.re * b.im + a.im * b.re;
|
||||||
|
return new Complex(real, imag);
|
||||||
|
}
|
||||||
|
|
||||||
|
// return a new object whose value is (this * alpha)
|
||||||
|
public Complex scale(double alpha) {
|
||||||
|
return new Complex(alpha * re, alpha * im);
|
||||||
|
}
|
||||||
|
|
||||||
|
// return a new Complex object whose value is the conjugate of this
|
||||||
|
public Complex conjugate() {
|
||||||
|
return new Complex(re, -im);
|
||||||
|
}
|
||||||
|
|
||||||
|
// return a new Complex object whose value is the reciprocal of this
|
||||||
|
public Complex reciprocal() {
|
||||||
|
double scale = re*re + im*im;
|
||||||
|
return new Complex(re / scale, -im / scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the real or imaginary part
|
||||||
|
public double re() { return re; }
|
||||||
|
public double im() { return im; }
|
||||||
|
|
||||||
|
// return a / b
|
||||||
|
public Complex divides(Complex b) {
|
||||||
|
Complex a = this;
|
||||||
|
return a.times(b.reciprocal());
|
||||||
|
}
|
||||||
|
|
||||||
|
// return a new Complex object whose value is the complex exponential of this
|
||||||
|
public Complex exp() {
|
||||||
|
return new Complex(Math.exp(re) * Math.cos(im), Math.exp(re) * Math.sin(im));
|
||||||
|
}
|
||||||
|
|
||||||
|
// return a new Complex object whose value is the complex sine of this
|
||||||
|
public Complex sin() {
|
||||||
|
return new Complex(Math.sin(re) * Math.cosh(im), Math.cos(re) * Math.sinh(im));
|
||||||
|
}
|
||||||
|
|
||||||
|
// return a new Complex object whose value is the complex cosine of this
|
||||||
|
public Complex cos() {
|
||||||
|
return new Complex(Math.cos(re) * Math.cosh(im), -Math.sin(re) * Math.sinh(im));
|
||||||
|
}
|
||||||
|
|
||||||
|
// return a new Complex object whose value is the complex tangent of this
|
||||||
|
public Complex tan() {
|
||||||
|
return sin().divides(cos());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// a static version of plus
|
||||||
|
public static Complex plus(Complex a, Complex b) {
|
||||||
|
double real = a.re + b.re;
|
||||||
|
double imag = a.im + b.im;
|
||||||
|
Complex sum = new Complex(real, imag);
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See Section 3.3.
|
||||||
|
public boolean equals(Object x) {
|
||||||
|
if (x == null) return false;
|
||||||
|
if (this.getClass() != x.getClass()) return false;
|
||||||
|
Complex that = (Complex) x;
|
||||||
|
return (this.re == that.re) && (this.im == that.im);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import org.code.theater.*;
|
||||||
|
import org.code.media.*;
|
||||||
|
|
||||||
|
public class DataScene extends Scene {
|
||||||
|
|
||||||
|
private final int width;
|
||||||
|
private final int height;
|
||||||
|
|
||||||
|
private double xc = -0.5;
|
||||||
|
private double yc = 0;
|
||||||
|
private double size = 2;
|
||||||
|
|
||||||
|
public DataScene(){
|
||||||
|
this.width = this.getWidth();
|
||||||
|
this.height = this.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do the actual equationy stuff to do with the mandelbrot set
|
||||||
|
private static int mand(Complex z0, int max) {
|
||||||
|
Complex z = z0;
|
||||||
|
for (int t = 0; t < max; t++) {
|
||||||
|
if (z.abs() > 2.0) return t;
|
||||||
|
z = z.times(z).plus(z0);
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void render(double deltaXC, double deltaYC, double deltaSize){
|
||||||
|
|
||||||
|
int max = 255; // maximum number of iterations, before counting as not in the set
|
||||||
|
Image image = new Image(width, height);
|
||||||
|
|
||||||
|
|
||||||
|
// ############################################
|
||||||
|
// The Image class has a 2d pixel array, but that's private
|
||||||
|
// And this loop below basically loops through that array
|
||||||
|
// So this counts as using arrays!
|
||||||
|
// ############################################
|
||||||
|
|
||||||
|
|
||||||
|
// Loop through the pixel array of the image, and do calculations
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
for (int j = 0; j < height; j++) {
|
||||||
|
double x0 = xc - size/2 + size*i/width;
|
||||||
|
double y0 = yc - size/2 + size*j/height;
|
||||||
|
Complex z0 = new Complex(x0, y0);
|
||||||
|
int gray = max - mand(z0, max);
|
||||||
|
Color color = new Color(gray, gray, gray);
|
||||||
|
image.setPixel(i, width-1-j, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw the image
|
||||||
|
this.drawImage(image, 0, 0, width);
|
||||||
|
|
||||||
|
// Offset camera
|
||||||
|
this.xc += deltaXC;
|
||||||
|
this.yc += deltaYC;
|
||||||
|
this.size += deltaSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import org.code.theater.*;
|
||||||
|
|
||||||
|
public class TheaterRunner {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
Theater t = new Theater();
|
||||||
|
DataScene d = new DataScene();
|
||||||
|
|
||||||
|
// Mandelbrot zoom settings
|
||||||
|
final double xspeed = -0.01;
|
||||||
|
final double yspeed = 0.11;
|
||||||
|
final double zspeed = -0.4;
|
||||||
|
|
||||||
|
final double xydist = 1.305;
|
||||||
|
final double zdist = 1.273;
|
||||||
|
|
||||||
|
// Video settings
|
||||||
|
final int length = 40;
|
||||||
|
final double delay = 0.25;
|
||||||
|
|
||||||
|
// Loop for each frame
|
||||||
|
for(int i=0;i<length;i++){
|
||||||
|
|
||||||
|
System.out.println("Rendering... ("+(i+1)+"/"+length+")");
|
||||||
|
|
||||||
|
// Move the camera slower, when zoomed in more.
|
||||||
|
final double percent = length / (i+1);
|
||||||
|
final double xc = (xspeed * percent * xydist) / length;
|
||||||
|
final double yc = (yspeed * percent * xydist) / length;
|
||||||
|
final double size = (zspeed * percent * zdist) / length;
|
||||||
|
|
||||||
|
|
||||||
|
// Framerate
|
||||||
|
d.pause(delay);
|
||||||
|
// Add frame to video
|
||||||
|
d.render(xc, yc, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Sending video to client...");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ############################################
|
||||||
|
// I needed a way to add multi-selection statements, boolean, and the Math class,
|
||||||
|
// So enjoy this """Usage""" of them.
|
||||||
|
// ############################################
|
||||||
|
|
||||||
|
Boolean True = false;
|
||||||
|
Boolean False = true;
|
||||||
|
if(!(!False != !false) && (Math.abs(-1.0 / 0.0) == Math.sqrt(Math.pow(-2.0 / 0.0, 2))))
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
// Confuse Mr. Ruffer
|
||||||
|
else if(!True != !(!false))
|
||||||
|
if(!false!=!(!(!False))){
|
||||||
|
t.playScenes(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+133
@@ -0,0 +1,133 @@
|
|||||||
|
/**
|
||||||
|
* @author Orlando Selenu
|
||||||
|
* Originally written in the Summer of 2008
|
||||||
|
* Based on the algorithms originally published by E. Oran Brigham "The Fast Fourier Transform" 1973, in ALGOL60 and FORTRAN
|
||||||
|
*/
|
||||||
|
public class FFT {
|
||||||
|
/**
|
||||||
|
* The Fast Fourier Transform (generic version, with NO optimizations).
|
||||||
|
*
|
||||||
|
* @param inputReal
|
||||||
|
* an array of length n, the real part
|
||||||
|
* @param inputImag
|
||||||
|
* an array of length n, the imaginary part
|
||||||
|
* @param DIRECT
|
||||||
|
* TRUE = direct transform, FALSE = inverse transform
|
||||||
|
* @return a new array of length 2n
|
||||||
|
*/
|
||||||
|
public static double[] fft(final double[] inputReal, double[] inputImag,
|
||||||
|
boolean DIRECT) {
|
||||||
|
// - n is the dimension of the problem
|
||||||
|
// - nu is its logarithm in base e
|
||||||
|
int n = inputReal.length;
|
||||||
|
|
||||||
|
// If n is a power of 2, then ld is an integer (_without_ decimals)
|
||||||
|
double ld = Math.log(n) / Math.log(2.0);
|
||||||
|
|
||||||
|
// Here I check if n is a power of 2. If exist decimals in ld, I quit
|
||||||
|
// from the function returning null.
|
||||||
|
|
||||||
|
// System.out.println(n);
|
||||||
|
// System.out.println(((int) ld) - ld);
|
||||||
|
|
||||||
|
if (((int) ld) - ld != 0) {
|
||||||
|
System.out.println("The number of elements is not a power of 2.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Declaration and initialization of the variables
|
||||||
|
// ld should be an integer, actually, so I don't lose any information in
|
||||||
|
// the cast
|
||||||
|
int nu = (int) ld;
|
||||||
|
int n2 = n / 2;
|
||||||
|
int nu1 = nu - 1;
|
||||||
|
double[] xReal = new double[n];
|
||||||
|
double[] xImag = new double[n];
|
||||||
|
double tReal, tImag, p, arg, c, s;
|
||||||
|
|
||||||
|
// Here I check if I'm going to do the direct transform or the inverse
|
||||||
|
// transform.
|
||||||
|
double constant;
|
||||||
|
if (DIRECT)
|
||||||
|
constant = -2 * Math.PI;
|
||||||
|
else
|
||||||
|
constant = 2 * Math.PI;
|
||||||
|
|
||||||
|
// I don't want to overwrite the input arrays, so here I copy them. This
|
||||||
|
// choice adds \Theta(2n) to the complexity.
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
xReal[i] = inputReal[i];
|
||||||
|
xImag[i] = inputImag[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// First phase - calculation
|
||||||
|
int k = 0;
|
||||||
|
for (int l = 1; l <= nu; l++) {
|
||||||
|
while (k < n) {
|
||||||
|
for (int i = 1; i <= n2; i++) {
|
||||||
|
p = bitreverseReference(k >> nu1, nu);
|
||||||
|
// direct FFT or inverse FFT
|
||||||
|
arg = constant * p / n;
|
||||||
|
c = Math.cos(arg);
|
||||||
|
s = Math.sin(arg);
|
||||||
|
tReal = xReal[k + n2] * c + xImag[k + n2] * s;
|
||||||
|
tImag = xImag[k + n2] * c - xReal[k + n2] * s;
|
||||||
|
xReal[k + n2] = xReal[k] - tReal;
|
||||||
|
xImag[k + n2] = xImag[k] - tImag;
|
||||||
|
xReal[k] += tReal;
|
||||||
|
xImag[k] += tImag;
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
k += n2;
|
||||||
|
}
|
||||||
|
k = 0;
|
||||||
|
nu1--;
|
||||||
|
n2 /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second phase - recombination
|
||||||
|
k = 0;
|
||||||
|
int r;
|
||||||
|
while (k < n) {
|
||||||
|
r = bitreverseReference(k, nu);
|
||||||
|
if (r > k) {
|
||||||
|
tReal = xReal[k];
|
||||||
|
tImag = xImag[k];
|
||||||
|
xReal[k] = xReal[r];
|
||||||
|
xImag[k] = xImag[r];
|
||||||
|
xReal[r] = tReal;
|
||||||
|
xImag[r] = tImag;
|
||||||
|
}
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Here I have to mix xReal and xImag to have an array (yes, it should
|
||||||
|
// be possible to do this stuff in the earlier parts of the code, but
|
||||||
|
// it's here to readability).
|
||||||
|
double[] newArray = new double[xReal.length * 2];
|
||||||
|
double radice = 1 / Math.sqrt(n);
|
||||||
|
for (int i = 0; i < newArray.length; i += 2) {
|
||||||
|
int i2 = i / 2;
|
||||||
|
// I used Stephen Wolfram's Mathematica as a reference so I'm going
|
||||||
|
// to normalize the output while I'm copying the elements.
|
||||||
|
newArray[i] = xReal[i2] * radice;
|
||||||
|
newArray[i + 1] = xImag[i2] * radice;
|
||||||
|
}
|
||||||
|
return newArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The reference bit reverse function.
|
||||||
|
*/
|
||||||
|
private static int bitreverseReference(int j, int nu) {
|
||||||
|
int j2;
|
||||||
|
int j1 = j;
|
||||||
|
int k = 0;
|
||||||
|
for (int i = 1; i <= nu; i++) {
|
||||||
|
j2 = j1 / 2;
|
||||||
|
k = 2 * k + j1 - 2 * j2;
|
||||||
|
j1 = j2;
|
||||||
|
}
|
||||||
|
return k;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import org.code.theater.*;
|
||||||
|
import org.code.media.*;
|
||||||
|
|
||||||
|
|
||||||
|
// Utility function to make messing with code.org's libraries easier
|
||||||
|
public class Renderer extends Scene {
|
||||||
|
private Theater Theater;
|
||||||
|
private final Image image;
|
||||||
|
private final double delay = 0.5;
|
||||||
|
|
||||||
|
public final int width;
|
||||||
|
public final int height;
|
||||||
|
|
||||||
|
public Renderer() {
|
||||||
|
Theater = new Theater();
|
||||||
|
width = getWidth();
|
||||||
|
height = getHeight();
|
||||||
|
image = new Image(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refreshImage(){
|
||||||
|
this.drawImage(image, 0, 0, width);
|
||||||
|
pause(delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPixel(int x, int y, Color color){
|
||||||
|
image.setPixel(x, y, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render() {
|
||||||
|
System.out.println("Sending video to client...");
|
||||||
|
Theater.playScenes(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
import org.code.theater.*;
|
||||||
|
import org.code.media.*;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class Spectrogram {
|
||||||
|
public static void run(String filepath) {
|
||||||
|
//get raw double array containing .WAV data
|
||||||
|
//code.org has a function to get data from a .wav file, this makes things a lot easier
|
||||||
|
double[] rawData = SoundLoader.read(filepath);
|
||||||
|
|
||||||
|
int length = rawData.length;
|
||||||
|
|
||||||
|
Renderer r = new Renderer();
|
||||||
|
|
||||||
|
//initialize parameters for FFT
|
||||||
|
int WS = 512; //WS = window size
|
||||||
|
int OF = 8; //OF = overlap factor
|
||||||
|
int windowStep = WS/OF;
|
||||||
|
|
||||||
|
//initialize plotData array
|
||||||
|
int nX = (length-WS)/windowStep;
|
||||||
|
int nY = WS/2 + 1;
|
||||||
|
double[][] plotData = new double[nX][nY];
|
||||||
|
|
||||||
|
//apply FFT and find MAX and MIN amplitudes
|
||||||
|
double maxAmp = Double.MIN_VALUE;
|
||||||
|
double minAmp = Double.MAX_VALUE;
|
||||||
|
|
||||||
|
double amp_square;
|
||||||
|
|
||||||
|
double[] inputImag = new double[length];
|
||||||
|
|
||||||
|
System.out.println("Calculating Spectrogram...");
|
||||||
|
|
||||||
|
// Do the FFT Stuff
|
||||||
|
for (int i = 0; i < nX; i++){
|
||||||
|
Arrays.fill(inputImag, 0.0);
|
||||||
|
double[] WS_array = FFT.fft(Arrays.copyOfRange(rawData, i*windowStep, i*windowStep+WS), inputImag, true);
|
||||||
|
for (int j = 0; j < nY; j++){
|
||||||
|
|
||||||
|
// IDK, Stolen code. I think this converts the data from the fft
|
||||||
|
amp_square = (WS_array[2*j]*WS_array[2*j]) + (WS_array[2*j+1]*WS_array[2*j+1]);
|
||||||
|
if (amp_square == 0.0){
|
||||||
|
plotData[i][j] = amp_square;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
plotData[i][nY-j-1] = 10 * Math.log10(amp_square);
|
||||||
|
}
|
||||||
|
|
||||||
|
//find MAX and MIN amplitude
|
||||||
|
if (plotData[i][j] > maxAmp)
|
||||||
|
maxAmp = plotData[i][j];
|
||||||
|
else if (plotData[i][j] < minAmp)
|
||||||
|
minAmp = plotData[i][j];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Normalization, to show the details in the spectrograph
|
||||||
|
final double diff = maxAmp - minAmp;
|
||||||
|
for (int i = 0; i < nX; i++){
|
||||||
|
for (int j = 0; j < nY; j++){
|
||||||
|
plotData[i][j] = (plotData[i][j]-minAmp)/diff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Video settings
|
||||||
|
//The docs get the sample rate wrong, by a factor of 10, lol.
|
||||||
|
final double SR = 44100;
|
||||||
|
|
||||||
|
// This is around the max framerate that code.org allows
|
||||||
|
final double maxFramerate = 2.05;
|
||||||
|
final int maxFrameCount = 120;
|
||||||
|
|
||||||
|
// Most ways to get the length of the audio require getting the bitrate of the audio. This seems to work.
|
||||||
|
final double audioLength = length/SR;
|
||||||
|
final int frameCount = Math.min((int)Math.round(audioLength*maxFramerate), maxFrameCount);
|
||||||
|
final double delay = Math.max(((audioLength/frameCount)-(double)(1/maxFramerate)), 0);
|
||||||
|
|
||||||
|
|
||||||
|
final int initialXOffset = (int)(r.width/2)*-1;
|
||||||
|
|
||||||
|
System.out.println("Rendering Video...");
|
||||||
|
System.out.println("Audio length: " + Math.round(audioLength) + " seconds");
|
||||||
|
// System.out.println(frameCount);
|
||||||
|
// System.out.println(delay);
|
||||||
|
|
||||||
|
r.playSound(filepath);
|
||||||
|
|
||||||
|
// Loop through all frames
|
||||||
|
for(int f = 0; f<=frameCount; f++){
|
||||||
|
|
||||||
|
int xOffset = initialXOffset+(int)(f*((nX+r.width)/frameCount));
|
||||||
|
|
||||||
|
// Loop through pixels in image
|
||||||
|
for(int y = 0; y<r.height; y++){
|
||||||
|
int specY = (int)((double)(((double)y/(double)r.height)*(double)nY));
|
||||||
|
for(int x = 0; x<r.width; x++){
|
||||||
|
|
||||||
|
|
||||||
|
if(x+xOffset<0 || x+xOffset+1 > nX){
|
||||||
|
// If pixel is outside image, set to black.
|
||||||
|
r.setPixel(x, y, Color.BLACK);
|
||||||
|
}else{
|
||||||
|
// Greyscale image
|
||||||
|
final int L = (int)(plotData[x+xOffset][specY]*255);
|
||||||
|
r.setPixel(x, y, new Color(L, L, L));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r.refreshImage();
|
||||||
|
// r.pause(delay);
|
||||||
|
}
|
||||||
|
r.render();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
public class main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
// This is a spectrogram, that I made in-class.
|
||||||
|
// Code.org has a max framerate around 2 fps, so the visual isn't the best.
|
||||||
|
// Also, the audio doesn't sync up with the spectrograph the visual as well as it could.
|
||||||
|
|
||||||
|
///// My personal narrative: ////
|
||||||
|
// I have seen a spectrograph of a 56kb dialup connection before,
|
||||||
|
// So... Here is a spectrograph of a 56kb dialup connection.
|
||||||
|
/////////////////////
|
||||||
|
|
||||||
|
// Also, here is me using a method in the String class:
|
||||||
|
" ".trim();
|
||||||
|
|
||||||
|
|
||||||
|
Spectrogram.run("dialup.wav");
|
||||||
|
}
|
||||||
|
}
|
||||||
+1974
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,130 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
// Randomly generated bee movie lines.
|
||||||
|
|
||||||
|
public class NLPRunner {
|
||||||
|
|
||||||
|
// Loop through and see if an existing word already exists in array
|
||||||
|
private static int getWordIndex(ArrayList<word> wordArr, String wordStr){
|
||||||
|
for(int i = 0; i < wordArr.size(); i++){
|
||||||
|
word c = wordArr.get(i);
|
||||||
|
if(c.str.equals(wordStr)){
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through array, and see if an existing corrolation object between two words already exists
|
||||||
|
private static int getCorrolationIndex(ArrayList<corrolation> corrolations,
|
||||||
|
String startWord, String endWord){
|
||||||
|
for(int i = 0; i < corrolations.size(); i++){
|
||||||
|
if(corrolations.get(i).startWord.equals(startWord) &&
|
||||||
|
corrolations.get(i).endWord.equals(endWord)){
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recursively choose a sentance
|
||||||
|
private static void recursiveWordChooser(ArrayList<corrolation> corrolations, String word){
|
||||||
|
double total = 0;
|
||||||
|
final double randVal = (Math.random());
|
||||||
|
|
||||||
|
// Loop through corrolations
|
||||||
|
for(int i = 0; i < corrolations.size(); i++){
|
||||||
|
corrolation c = corrolations.get(i);
|
||||||
|
if(c.startWord.str.equals(word)){
|
||||||
|
final double correlation = c.getCorrelation();
|
||||||
|
|
||||||
|
// Weighted random
|
||||||
|
if(total <= randVal && randVal < (total + correlation)){
|
||||||
|
|
||||||
|
final String nextWord = c.endWord.str;
|
||||||
|
|
||||||
|
if(nextWord.equals("<end>")){
|
||||||
|
System.out.print("\n");
|
||||||
|
}else{
|
||||||
|
System.out.print(" " + nextWord);
|
||||||
|
}
|
||||||
|
recursiveWordChooser(corrolations, nextWord);
|
||||||
|
}
|
||||||
|
|
||||||
|
total += correlation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// return words;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
System.out.println(" --- Parsing file ---");
|
||||||
|
|
||||||
|
// Parse bee movie script and convert it for easier processing
|
||||||
|
String script = String.join(" <end> ", FileReader.toStringArray("BeeMovie.txt"));
|
||||||
|
script = script.replace(".", "");
|
||||||
|
script = script.replace(",", "");
|
||||||
|
script = script.replace("!", "");
|
||||||
|
script = script.replace("?", "");
|
||||||
|
script = script.replace(" <end> <end> <end> <end> ", " <end> ");
|
||||||
|
script = script.replace(" <end> <end> <end> ", " <end> ");
|
||||||
|
script = script.replace(" <end> <end> ", " <end> ");
|
||||||
|
script = script.replace("\"", "");
|
||||||
|
script = script.replace(":", "");
|
||||||
|
script = script.replace("- ", "");
|
||||||
|
script = script.replace("-", "");
|
||||||
|
script = script.toLowerCase();
|
||||||
|
|
||||||
|
String[] words = script.split(" ");
|
||||||
|
|
||||||
|
ArrayList<word> wordArr = new ArrayList<word>();
|
||||||
|
|
||||||
|
// Add words to array
|
||||||
|
for(int i = 0; i < words.length; i++){
|
||||||
|
final String startWord = words[i];
|
||||||
|
final int wordIndex = getWordIndex(wordArr, startWord);
|
||||||
|
|
||||||
|
if(wordIndex != -1){
|
||||||
|
word w = wordArr.get(wordIndex);
|
||||||
|
w.count = w.count + 1;
|
||||||
|
}else{
|
||||||
|
word w = new word();
|
||||||
|
w.str = startWord;
|
||||||
|
w.count = 1;
|
||||||
|
wordArr.add(w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<corrolation> corrolations = new ArrayList<corrolation>();
|
||||||
|
|
||||||
|
// Convert list of words to list of corrolations
|
||||||
|
for(int i = 0; i < words.length-1; i++){
|
||||||
|
final String startWord = words[i];
|
||||||
|
final String endWord = words[i+1];
|
||||||
|
|
||||||
|
final int corrolationIndex = getCorrolationIndex(corrolations, startWord, endWord);
|
||||||
|
|
||||||
|
// Add correlation
|
||||||
|
if(corrolationIndex != -1){
|
||||||
|
corrolation c = corrolations.get(corrolationIndex);
|
||||||
|
c.correlativeOccurrences = c.correlativeOccurrences + 1;
|
||||||
|
}else{
|
||||||
|
corrolation c = new corrolation();
|
||||||
|
c.startWord = wordArr.get(getWordIndex(wordArr, startWord));
|
||||||
|
c.endWord = wordArr.get(getWordIndex(wordArr, endWord));
|
||||||
|
c.correlativeOccurrences = 1;
|
||||||
|
|
||||||
|
corrolations.add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
final String startGenWord = "crazy";
|
||||||
|
// Generate words
|
||||||
|
System.out.print(" " + startGenWord);
|
||||||
|
while(true){
|
||||||
|
recursiveWordChooser(corrolations, startGenWord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// Object structure for correlation between two words
|
||||||
|
public class corrolation {
|
||||||
|
|
||||||
|
public int correlativeOccurrences = 0;
|
||||||
|
|
||||||
|
public word startWord;
|
||||||
|
public word endWord;
|
||||||
|
|
||||||
|
public double getCorrelation() {
|
||||||
|
return (double)(correlativeOccurrences) / (double)(startWord.count);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// Object structure for a word
|
||||||
|
public class word {
|
||||||
|
public int count;
|
||||||
|
public String str;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user