sketch
var x= 30;
var xPos = 0;
var y = 60
var r = [55, 98, 145, 195] //radius of visualization 1
var angle =10
var cycle = 1; //cycle through the different visualizations
var transparent =100 //used for key
var value = 0
var yr = 1980
//precipitation data
var precip1 = [39.46, 37.5, 32.01, 41.41, 35.32, 38.51, 37.4, 39.2,
27.09, 42.51]
var precip2 = [52.24, 32.02, 36.65, 38.26, 41.34, 28.89, 45.47, 34.21,
36.21, 40.12]
var precip3 = [35.73, 32.33, 41.04, 57.41, 41.23, 34.90,40.70, 39.69, 32.84,
37.85]
var precip4 = [44.24, 41.74, 36.65, 36.84, 40.56, 35.01, 42.15, 57.83, 52.46, 39.33]
//used for text in vizualization 1
precipData = [39.46, 37.5, 32.01, 41.41, 35.32, 38.51, 37.4, 39.2,
27.09, 42.51, 52.24, 32.02, 36.65, 38.26, 41.34, 28.89, 45.47, 34.21,
36.21, 40.12,35.73, 32.33, 41.04, 57.41, 41.23, 34.90,40.70, 39.69, 32.84,
37.85, 44.24, 41.74, 36.65, 36.84, 40.56, 35.01, 42.15, 57.83, 52.46, 39.33]
var precipitation = []
var precipitation2 = []
var precipitation3 = []
var precipitation4 = []
//temperature data
var temp = [49.5, 49.1, 50.4, 50.5, 50.4, 50.6, 51.7, 52.3, 51.0, 50.2, 53.3, 54.2, 50.9,
51.8, 51.6, 51.8, 50.3, 50, 54, 52, 50.8, 52.2, 52.6, 50.3, 51.6, 51.6, 52.3,
52, 50.9, 51, 51.9, 52.8, 54.2, 51.5, 50, 52.5, 54.2, 53.6, 52.3, 52.4, 53.3 ]
//images
var skyline;
var backdrop;
var buildings;
var snow = []
function preload() {
skyline = loadImage("https://i.imgur.com/U7UJvXu.png")
backdrop = loadImage("https://i.imgur.com/vShIEDi.png")
buildings = loadImage("https://i.imgur.com/dfPYkth.png")
}
function setup() {
createCanvas(480, 480);
background(220);
for (var i = 0; i < 10; i++) {
precipitation[i] = new Object();
precipitation[i].x = r[0] * sin(angle);
precipitation[i].y = r[0] * cos(angle);
}
for (var i = 0; i < 10; i++) {
precipitation2[i] = new Object();
precipitation2[i].x = r[1] * sin(angle);
precipitation2[i].y = r[1] * cos(angle);
}
for (var i = 0; i < 10; i++) {
precipitation3[i] = new Object();
precipitation3[i].x = r[2] * sin(angle);
precipitation3[i].y = r[2] * cos(angle);
}
for (var i = 0; i < 10; i++) {
precipitation4[i] = new Object();
precipitation4[i].x = r[3] * sin(angle);
precipitation4[i].y = r[3] * cos(angle);
}
for (var i = 0; i < 500; i++) {
snow[i] = new Object();
snow[i].x = random(30, width-30)
snow[i].y = random(60, 300)
snow[i].dy = 1;
}
}
function draw() { //cycles through the different climate patterns
if (cycle == 1) {
introduction()
} else if (cycle == 2) {
drawPrecipitation()
} else if (cycle ==3) {
drawTemp()
} else if (cycle == 4) {
drawSnowRecord()
} else {
cycle = 1
}
}
function introduction() { //first slide
background(0)
fill(255)
textSize(15)
text("Data Visualizations on Climate Patterns in Pittsburgh", 10, height/2)
textSize(12)
text("Click mouse to change data", 10, height/2+20)
}
function drawPrecipitation() {
background(255, 229, 227)
fill(0)
textSize(15)
text("Average Precipitation in Pittsburgh (1980-2020)", 10, 25)
frameRate(int(1.5))
noStroke()
//bottom left key
fill(214, 132, 84, 100)
rect(10, 420, 30, 10)
fill(214, 132, 84, 100-15)
rect(10, 431, 30, 10)
fill(214, 132, 84, 100-30)
rect(10, 442, 30, 10)
fill(214, 132, 84, 100-45)
rect(10, 453, 30, 10)
textSize(8)
fill(0)
text("1980-1990", 45, 427)
text("1990-2000", 45, 427+11)
text("2000-2010", 45, 427+22)
text("2010-2020", 45, 427+33)
translate(width/2, height/2+15)
fill(214, 132, 84, 60)
noStroke()
circle(0, 0, 150)
circle(0, 0, 240)
circle(0, 0, 337)
circle(0, 0, 440)
fill(214, 132, 84, 50)
circle(0, 0, 70)
//ring of ellipses
for (var i=0; i<precip1.length; i++) {
noStroke()
fill(0, 255-precip1[i]*3, precip1[i]*4)
rotate(radians(360/10))
circle(precipitation[i].x, precipitation[i].y, precip1[i]/1.4)
}
for (var i=0; i<precip2.length; i++) {
var x = r[1] * sin(angle);
var y = r[1] * cos(angle);
noStroke()
fill(0, 255-precip2[i]*3, precip2[i]*4)
rotate(radians(360/10))
circle(precipitation2[i].x, precipitation2[i].y, precip2[i]/1.4) //change to object
}
for (var i=0; i<precip3.length; i++) {
var x = r[2] * sin(angle);
var y = r[2] * cos(angle);
noStroke()
fill(0, 255-precip3[i]*3, precip3[i]*4)
rotate(radians(360/10))
circle(precipitation3[i].x, precipitation3[i].y, precip3[i]/1.4)
}
for (var i=0; i<precip4.length; i++) {
var x = r[3] * sin(angle);
var y = r[3] * cos(angle);
noStroke()
fill(0, 255-precip4[i]*3, precip4[i]*4)
rotate(radians(360/10))
circle(precipitation4[i].x, precipitation4[i].y, precip4[i]/1.4)
}
textSize(10)
text(precipData[value], -10, 10)
value+=1
if (value>40) {
value=0
}
textSize(15)
text(yr, -15, 0)
yr+=1
if (yr >2020) {
yr=1980
}
}
function drawTemp() {
background(235, 88, 52)
textSize(15)
fill(0)
text("Average Temperature in Pittsburgh (1980-2020)", 10, 25)
frameRate(25)
translate(width/2,height/2)
//background circles
fill(255, 255, 255, 70)
circle(0, 0, 400, 400)
fill(235, 88, 52)
circle(0, 0, 150, 150)
//rotating circle data
for (var i =0; i<temp.length; i++) {
rotate(radians(angle))
// xPos=(300/2 * cos(temp[i]))
fill(temp[i]*3,0,0, 80)
circle(xPos, 100, temp[i]/2)
angle+=.01
}
}
function drawSnowRecord() {
background(10,31,50)
fill(255)
text("Greatest Snowfall in One Day in Pittsburgh", 10, 25)
push()
textSize(10)
text("Hover over the snowballs", 10, 40)
pop()
image(backdrop, 20, 92)
circle(420, 290, 60)
image(skyline, 30, 150)
fill(250, 250, 250)
circle(260, 300, 40)
circle(150, 305, 30)
image(buildings, 30, 272)
circle(80, 300, 50)
circle(330, 290, 80)
pop()
//data appears when hovering over snowballs
if ((dist(330, 290, mouseX, mouseY) < 80/2)) {
text("March 13, 1993: 23.6 inches of snow", 130, 400)
}
if ((dist(420, 290, mouseX, mouseY) < 60/2)) {
text("December 17, 1890: 22 inches of snow", 130, 400)
}
if ((dist(80, 300, mouseX, mouseY) < 50/2)) {
text("January 8, 1884: 16.5 inches of snow", 130, 400)
}
if ((dist(260, 300, mouseX, mouseY) < 40/2)) {
text("March 3, 1942: 16.3 inches of snow", 130, 400)
}
if ((dist(150, 305, mouseX, mouseY) < 30/2)) {
text("March 5, 1902: 15 inches of snow", 130, 400)
}
//snow
for (var i=0; i<500; i++) {
noStroke()
fill(255)
circle(snow[i].x, snow[i].y, 2)
}
}
function mousePressed() { //changes visualzation when mouse clicked
cycle += 1;
}