xxxxxxxxxx
452
let n = 0;
let dogs = 0;
let o = 0;
let m = 0;
let u = 0;
let xb = [];
let yb = [];
let xl = [];
let yl = [];
dogs = 0;
function preload() {
// db = ('https://data.cityofnewyork.us/Health/DOHMH-Dog-Bite-Data/rsgh-akpg')
// dogbite = loadJSON('https://data.cityofnewyork.us/resource/rsgh-akpg.json')
// pbfilter = ''
dogbite = loadJSON(
"https://data.cityofnewyork.us/resource/rsgh-akpg.json?$limit=50000&$$app_token=ZSTtmLmzkwS1LEc4H9EzWlKc4"
);
// dbpitbull = ('https://data.cityofnewyork.us/resource/rsgh-akpg.json?breed=Pit%20Bull')
licensedog = loadJSON(
"https://data.cityofnewyork.us/resource/nu7n-tubp.json?$limit=50000&$$app_token=ZSTtmLmzkwS1LEc4H9EzWlKc4"
);
pb = loadImage("assets/pitbull.jpg"); //Photo by Andrew Sterling on Unsplash
sz = loadImage("assets/shihtzu.jpg"); //Photo by Lucia Macedo on Unsplash
ch = loadImage("assets/chihuahua.jpg"); //Photo by Alicia Gauthier on Unsplash
ger = loadImage("assets/german.jpg"); //Photo by Kanashi on Unsplash
yor = loadImage("assets/yorter.jpg"); //Photo by Daria Turchak on Unsplash
fortext = loadFont("assets/SpaceMono-Regular.ttf");
}
function setup() {
createCanvas(600, 600);
pitbulls = createButton("Pitbulls");
pitbulls.position(width / 2 - 270, height - 80);
pitbulls.size(100, 50);
pitbulls.mousePressed(pitbulldata);
pitbulls.addClass("button");
shihtzu = createButton("Shihtzus");
shihtzu.position(width / 2 - 160, height - 80);
shihtzu.size(100, 50);
shihtzu.mousePressed(shihtzudata);
shihtzu.addClass("button");
chihu = createButton("Chihuahuas");
chihu.position(width / 2 - 50, height - 80);
chihu.size(100, 50);
chihu.mousePressed(chihudata);
chihu.addClass("button");
gs = createButton("German Shepherds");
gs.position(width / 2 + 60, height - 80);
gs.size(100, 50);
gs.mousePressed(gsdata);
gs.addClass("button");
yt = createButton("Yorkshire Terriers");
yt.position(width / 2 + 170, height - 80);
yt.size(100, 50);
yt.mousePressed(ytdata);
yt.addClass("button");
home = createButton("⬅︎");
home.position(20, 20);
home.size(40, 40);
home.mousePressed(goback);
home.addClass("buttonhome");
}
function draw() {
textSize(18);
textAlign(CENTER);
textFont(fortext);
switch (dogs) {
case 0:
home.hide();
background(280, 230, 280);
text(
"There are many stereotypes around the breeds of dogs and how aggressive they are. This is a comparison between how many dog bite cases are reported for different breeds and how many dog licenses for those breeds exist in NYC, as a way to see if there is any correlation between them as choice of pets.",
50,
50,
500,
300
);
push();
textSize(22);
text(
"Click on the different dog breeds to see the data for reported dog bites and reported licenses.",
50,
250,
500,
300
);
pop();
push();
textSize(14);
text("Note: This does not collect any personal data.", 50, 400, 500, 300);
pop();
break;
case 1:
background(255, 228, 153);
home.show();
for (let k = 0; k < p; k++) {
b = random(-1, 1);
image(pb, xb[k] + b, yb[k] + b, 100, 100);
}
for (let k = 0; k < q; k++) {
b = random(-1, 1);
image(pb, xl[k] + b, yl[k] + b, 100, 100);
}
// }
text(
"Dog bites by pitbulls: " + p + "%",
width / 2 - 200,
height - 180,
180,
100
);
text(
"Pitbull licenses: " + q + "%",
width / 2 + 50,
height - 180,
180,
100
);
break;
case 2:
background(189, 255, 153);
home.show();
for (let k = 0; k < p; k++) {
b = random(-1, 1);
image(sz, xb[k] + b, yb[k] + b, 100, 100);
}
for (let k = 0; k < q; k++) {
b = random(-1, 1);
image(sz, xl[k] + b, yl[k] + b, 100, 100);
}
// }
text(
"Dog bites by Shihtuzus:" + p + "%",
width / 2 - 200,
height - 180,
180,
100
);
text(
"Shihtuzu licenses: " + q + " %",
width / 2 + 50,
height - 180,
180,
100
);
break;
case 3:
background(191, 255, 238);
home.show();
for (let k = 0; k < p; k++) {
b = random(-1, 1);
image(ch, xb[k] + b, yb[k] + b, 100, 100);
}
for (let k = 0; k < q; k++) {
b = random(-1, 1);
image(ch, xl[k] + b, yl[k] + b, 100, 100);
}
text(
"Dog bites by Chihuahuas: " + p + "%",
width / 2 - 200,
height - 180,
180,
180
);
text(
"Chihuahua licenses: " + q + "%",
width / 2 + 50,
height - 180,
180,
180
);
break;
case 4:
background(171, 214, 255);
home.show();
for (let k = 0; k < p; k++) {
b = random(-1, 1);
image(ger, xb[k] + b, yb[k] + b, 100, 100);
}
for (let k = 0; k < q; k++) {
b = random(-1, 1);
image(ger, xl[k] + b, yl[k] + b, 100, 100);
}
// image(ger, 150, 100, 300, 300);
text(
"Dog bites by German Shepherds: " + p + "%",
width / 2 - 200,
height - 180,
180,
180
);
text(
"German Shepherd licenses: " + q + "%",
width / 2 + 50,
height - 180,
180,
180
);
break;
case 5:
background(230, 212, 255);
home.show();
for (let k = 0; k < p; k++) {
b = random(-1, 1);
image(yor, xb[k] + b, yb[k] + b, 100, 100);
}
for (let k = 0; k < q; k++) {
b = random(-1, 1);
image(yor, xl[k] + b, yl[k] + b, 100, 100);
}
// image(yor, 150, 100, 300, 300);
text(
"Dog bites by Yorkshire Terriers: " + p + "%",
width / 2 - 200,
height - 180,
180,
180
);
text(
"Yorkshire Terrier licenses: " + q + "%",
width / 2 + 50,
height - 180,
180,
180
);
break;
}
}
function pitbulldata() {
for (var i in dogbite) {
if (
dogbite[i].breed == "Pit Bull" ||
dogbite[i].breed == "American Pit Bull Mix / Pit Bull Mix" ||
dogbite[i].breed == "American Pit Bull Terrier/Pit Bull" ||
dogbite[i].breed == "PIT BULL MIXED"
) {
n++;
}
if (!dogbite[i].breed || dogbite[i].breed == "UNKNOWN") {
m++;
}
p = round((n / (i - m)) * 100);
}
for (var a in licensedog) {
if (
licensedog[a].breedname == "American Pit Bull Mix / Pit Bull Mix" ||
licensedog[a].breedname == "American Pit Bull Terrier/Pit Bull"
) {
o++;
}
if (licensedog[a].breedname == "Unknown") {
u++;
}
q = round((o / (a - u)) * 100);
}
for (let k = 0; k < p; k++) {
xb[k] = random(50, width / 2 - 100);
yb[k] = random(20, height / 2);
}
for (let k = 0; k < q; k++) {
xl[k] = random(width / 2 + 50, width - 150);
yl[k] = random(20, height / 2);
}
dogs = 1;
// console.log(n)
n = 0;
o = 0;
u = 0;
m = 0;
}
function shihtzudata() {
for (var i in dogbite) {
if (dogbite[i].breed == "Shih Tzu") {
n++;
}
if (!dogbite[i].breed || dogbite[i].breed == "UNKNOWN") {
m++;
}
p = round((n / (i - m)) * 100);
}
for (var a in licensedog) {
if (
licensedog[a].breedname == "Shih Tzu" ||
licensedog[a].breedname == "Shih Tzu Crossbreed"
) {
o++;
}
if (licensedog[a].breedname == "Unknown") {
u++;
}
q = round((o / (a - u)) * 100);
}
for (let k = 0; k < p; k++) {
xb[k] = random(50, width / 2 - 100);
yb[k] = random(20, height / 2);
}
for (let k = 0; k < q; k++) {
xl[k] = random(width / 2 + 50, width - 150);
yl[k] = random(20, height / 2);
}
dogs = 2;
// console.log(n)
n = 0;
o = 0;
m = 0;
u = 0;
}
function chihudata() {
for (var i in dogbite) {
if (
dogbite[i].breed == "Chihuahua" ||
dogbite[i].breed == "Chihuahua Crossbreed"
) {
n++;
}
if (!dogbite[i].breed || dogbite[i].breed == "UNKNOWN") {
m++;
}
p = round((n / (i - m)) * 100);
}
for (var a in licensedog) {
if (licensedog[a].breedname == "Chihuahua") {
o++;
}
if (licensedog[a].breedname == "Unknown") {
u++;
}
q = round((o / (a - u)) * 100);
}
for (let k = 0; k < p; k++) {
xb[k] = random(50, width / 2 - 100);
yb[k] = random(20, height / 2);
}
for (let k = 0; k < q; k++) {
xl[k] = random(width / 2 + 50, width - 150);
yl[k] = random(20, height / 2);
}
dogs = 3;
// console.log(n)
n = 0;
o = 0;
m = 0;
u = 0;
}
function gsdata() {
for (var i in dogbite) {
if (
dogbite[i].breed == "German Shepherd" ||
dogbite[i].breed == "German Shepherd Crossbreed" ||
dogbite[i].breed == "GERMAN SHEPHERD/RIDGEBACK"
) {
n++;
}
if (!dogbite[i].breed || dogbite[i].breed == "UNKNOWN") {
m++;
}
p = round((n / (i - m)) * 100);
}
for (var a in licensedog) {
if (
licensedog[a].breedname == "German Shepherd Dog" ||
licensedog[a].breedname == "German Shepherd Crossbreed"
) {
o++;
}
if (licensedog[a].breedname == "Unknown") {
u++;
}
q = round((o / (a - u)) * 100);
}
for (let k = 0; k < p; k++) {
xb[k] = random(50, width / 2 - 100);
yb[k] = random(20, height / 2);
}
for (let k = 0; k < q; k++) {
xl[k] = random(width / 2 + 50, width - 150);
yl[k] = random(20, height / 2);
}
dogs = 4;
// console.log(n)
n = 0;
o = 0;
m = 0;
u = 0;
}
function ytdata() {
for (var i in dogbite) {
if (dogbite[i].breed == "Yorkshire Terrier") {
n++;
}
if (!dogbite[i].breed || dogbite[i].breed == "UNKNOWN") {
m++;
}
p = round((n / (i - m)) * 100);
}
for (var a in licensedog) {
if (licensedog[a].breedname == "Yorkshire Terrier") {
o++;
}
if (licensedog[a].breedname == "Unknown") {
u++;
}
if (licensedog[a].breedname == "Unknown") {
u++;
}
q = round((o / (a - u)) * 100);
}
for (let k = 0; k < p; k++) {
xb[k] = random(50, width / 2 - 100);
yb[k] = random(20, height / 2);
}
for (let k = 0; k < q; k++) {
xl[k] = random(width / 2 + 50, width - 150);
yl[k] = random(20, height / 2);
}
dogs = 5;
// console.log(n)
n = 0;
o = 0;
m = 0;
u = 0;
}
function goback() {
dogs = 0;
home.hide();
}