-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
59 lines (48 loc) · 1.22 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
Developed by https://github.com/mzaidikhlas
*/
var weather;
var api = 'http://api.openweathermap.org/data/2.5/weather?q=';
var apiKey = '&APPID=ca4d95a5190d960961997673c70a62ea';
var input;
var position = Array();
function setup() {
createCanvas(windowWidth, windowHeight-100);
var button = select('#submit');
button.mousePressed(weatherAsk);
for(i=0; i<400; i++){
position[i] = createVector(random(0,width), random(0,height));
}
wind = createVector();
input = select('#city');
}
function weatherAsk() {
var url = api + input.value() + apiKey;
loadJSON(url, gotData);
}
function gotData(data) {
weather = data;
}
function draw() {
background(255);
if (weather) {
var speed = weather.wind.speed;
var degree = radians(weather.wind.deg);
wind = p5.Vector.fromAngle(degree);
console.log(speed);
for(i=0; i<400; i++){
position[i].add(wind);
noStroke();
fill(50,205,50,200);
ellipse(position[i].x*speed, position[i].y*speed, 16, 16);
if (position[i].x > width)
position[i].x = 0;
if (position[i].x < 0)
position[i].x = width;
if (position[i].y > height)
position[i].y = 0;
if (position[i].y < 0)
position[i].y = height;
}
}
}