Change speed of particles
in
Contributed Library Questions
•
3 months ago
Dear all interested readers,
I've been working on an example from onformative ( http://www.onformative.com/lab/google-weather-library-for-processing/) to visualise weather data.
Now I want to use the particles, as shown in example, to have the speed based on the getWindSpeed() function. If the windspeed is 20.19, I would like to have to move the particles 20.19/4 in the right direction, already given in the code
I've been working on an example from onformative ( http://www.onformative.com/lab/google-weather-library-for-processing/) to visualise weather data.
Now I want to use the particles, as shown in example, to have the speed based on the getWindSpeed() function. If the windspeed is 20.19, I would like to have to move the particles 20.19/4 in the right direction, already given in the code
- import com.onformative.yahooweather.*;
- YahooWeather weather;
- YahooWeather weather2;
- int updateIntervallMillis = 90000;
- PVector[] windParticles = new PVector[200];
- PVector[] windParticles2 = new PVector[200];
- void setup() {
- size(400, 400);
- // BERLIJN weather = new YahooWeather(this, 638242, "c", updateIntervallMillis);
- // AMSTERDAM
- weather = new YahooWeather(this, 727232, "c", updateIntervallMillis);
- weather2 = new YahooWeather(this, 638242, "c", updateIntervallMillis);
- for (int i=0; i<windParticles.length; i++) {
- windParticles[i] = new PVector(random(0, width/2), random(height));
- }
- for (int i=0; i<windParticles2.length; i++) {
- windParticles2[i] = new PVector(random(width/2, width), random(height));
- }
- noStroke();
- }
- void draw() {
- weather.update();
- background(0);
- fill(255, 0, 0);
- drawWind();
- text("Stad: "+weather.getCityName(), 10, 20);
- text("Weertype: "+weather.getWeatherCondition(), 10, 40);
- text("Windrichting: "+weather.getWindDirection(), 10, 60);
- text("Windsnelheid: "+weather.getWindSpeed()+"km/h", 10, 80);
- text("Windtemperatuur: "+weather.getWindTemperature(), 10, 100);
- text("Temperatuur: "+weather.getTemperature(), 10, 120);
- fill(0, 255, 0);
- drawWind2();
- translate(0, 150);
- text("Stad: "+weather2.getCityName(), 10, 20);
- text("Weertype: "+weather2.getWeatherCondition(), 10, 40);
- text("Windrichting: "+weather2.getWindDirection(), 10, 60);
- text("Windsnelheid: "+weather2.getWindSpeed()+"km/h", 10, 80);
- text("Temperatuur: "+weather2.getTemperature(), 10, 120);
- text("Windtemperatuur: "+weather2.getWindTemperature(), 10, 100);
- }
- void drawWind() {
- float windtemp = int(weather2.getWindTemperature());
- println(windtemp);
- float size = windtemp/2;
- for (int i=0; i<windParticles.length; i++) {
- windParticles[i].add(getNormalizedPVector(weather.getWindDirection()));
- if (windParticles[i].x<0)windParticles[i].x=width/2;
- if (windParticles[i].x>width/2)windParticles[i].x=0;
- if (windParticles[i].y<0)windParticles[i].y=height;
- if (windParticles[i].y>height)windParticles[i].y=0;
- ellipse(windParticles[i].x, windParticles[i].y, size, size);
- }
- }
- void drawWind2() {
- float windtemp = int(weather.getWindTemperature());
- println(windtemp);
- float size = windtemp/2;
- for (int i=0; i<windParticles2.length; i++) {
- windParticles2[i].add(getNormalizedPVector(weather2.getWindDirection()));
- if (windParticles2[i].x<width/2)windParticles2[i].x=width;
- if (windParticles2[i].x>width)windParticles2[i].x=width/2;
- if (windParticles2[i].y<0)windParticles2[i].y=height;
- if (windParticles2[i].y>height)windParticles2[i].y=0;
- ellipse(windParticles2[i].x, windParticles2[i].y, size, size);
- }
- }
- /**
- * transforming the wind direction of yahoo into a normalizes vector
- */
- PVector getNormalizedPVector(int direction) {
- int numPoints = 360;
- float angle = TWO_PI/(float)numPoints;
- direction = 360-direction;
- direction += 180;
- return new PVector(sin(angle*direction), cos(angle*direction));
- }
I hope someone can help me with this. I'm new with using vectors.
Thanks in advance,
Joshua
Thanks in advance,
Joshua
1