xxxxxxxxxx
198
let IXD1= 10; //1 : American
let ID1=20;
let ARC1=11;
let IXD2 =30; //2: Asian
let ID2=50;
let ARC2=61;
let m = 0;
let IXD3=30; //3: European
let ID3=40;
let ARC3= 20;
let students = []; // all the sutdents
//countries
let Americans =[];
let Asians=[];
let Europeans=[]
let majorNum=0;
//Majors
let IXD=[];
let ID=[];
let ARC=[];
function setup() {
createCanvas(400, 400);
input = createInput();
input.position(20, 65);
input2 = createInput();
input2.position(20, 105);
button = createButton('submit');
button.position(30, 165);
button.mousePressed(greet);
greeting = createElement('h2', 'where are you from?');
greeting.position(20, 5);
greeting2 = createElement('h2', 'What is your major?');
greeting2.position(20, 60);
textAlign(CENTER);
textSize(50);
//Here are Americans
for(i = 0; i<IXD1; i++){
append(students, 'American.IXD');
append(Americans,'American.IXD');
append(IXD,'American.IXD');
}
for(i = 0; i<ID1; i++){
append(students, 'American.ID');
append(Americans,'American.ID');
append(ID,'American.ID');
}
for(i = 0; i<ARC1; i++){
append(students, 'American.ARC');
append(Americans,'American.IXD');
append(ARC,'American.IXD');
}
//Here are Asians
for(i = 0; i<IXD2; i++){
append(students, 'Asian.IXD');
append(IXD,'Asian.IXD');
append(Asians, 'Asian.IXD');
}
for(i = 0; i<ID2; i++){
append(students, 'Asian.ID');
append(Asians, 'Asian.ID');
append(ID, 'Asian.ID');
}
for(i = 0; i<ARC2; i++){
append(students, 'Asian.ARC');
append(Asians, 'Asian.ARC');
append(ARC, 'Asian.ARC');
}
//Here are Europeans
for(i = 0; i<IXD3; i++){
append(students, 'European.IXD');
append(IXD,'European.IXD');
append(Europeans, 'European.IXD');
}
for(i = 0; i<ID3; i++){
append(students, 'European.ID');
append(Europeans, 'European.ID');
append(ID, 'European.ID');
}
for(i = 0; i<ARC3; i++){
append(students, 'European.ARC');
append(Europeans, 'European.ARC');
append(ARC, 'European.ARC');
}
// print(Asians);
for(var i =0; i<Asians.length;i++){
// print("here");
let str = "Asians.ID";
// if(Asians[i] == "Asian.IXD"){
// print("Match");
// }
}
//print out Asian array in differet major
// for(i=0; i<Asians.length; i++)
// {
// let m= match(Asians[i], "IXD")
// print(m);
// }
function greet() {
let countryNum = 0;
majorNum=0;
let student;
const major = input2.value();
const country = input.value();
// greeting.html('hello ' + country + '!');
input.value('');
input2.value('');
if (country == "American" || country == "american"){
countryNum = Americans.length;
print(Americans.length);
majorNum=1;
}else if (country == "Asian" || country == "asian"){
countryNum = Asians.length;
print(Asians.length);
majorNum=2;
}
else if (country == "European" || country == "european"){
countryNum = Europeans.length;
print(Europeans.length);
majorNum=3;
}
if (major == "ID" ){
if(majorNum == 1){
student = ID1;
}else if (majorNum == 2){
student = ID2;
}
else if (majorNum == 3){
student = ID3;
}
print(student);
}else if (major == "IXD" ){
if(majorNum == 1){
student = IXD1;
}else if (majorNum == 2){
student = IXD2;
}
else if (majorNum == 3){
student = IXD3;
}
print(student);
}
let per = student/ countryNum*100;
print(per)
fill (200,0,0, per);
ellipse(150,150, 50,50);
// for (let i = 0; i < 200; i++) {
// push();
// fill(random(255), 255, 255);
// translate(random(width), random(height));
// rotate(random(2 * PI));
// text(name, 0, 0);
// pop();
// }
}
}