Loading...
Logo
Processing Forum
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

Copy code
  1. import com.onformative.yahooweather.*;

  2. YahooWeather weather;
  3. YahooWeather weather2;

  4. int updateIntervallMillis = 90000; 

  5. PVector[] windParticles = new PVector[200];
  6. PVector[] windParticles2 = new PVector[200];

  7. void setup() {
  8.   size(400, 400);
  9.   // BERLIJN weather = new YahooWeather(this, 638242, "c", updateIntervallMillis);

  10.   // AMSTERDAM
  11.   weather = new YahooWeather(this, 727232, "c", updateIntervallMillis);

  12.   weather2 = new YahooWeather(this, 638242, "c", updateIntervallMillis);

  13.   for (int i=0; i<windParticles.length; i++) {
  14.     windParticles[i] = new PVector(random(0, width/2), random(height));
  15.   }

  16.   for (int i=0; i<windParticles2.length; i++) {
  17.     windParticles2[i] = new PVector(random(width/2, width), random(height));
  18.   }

  19.   noStroke();
  20. }

  21. void draw() {
  22.   weather.update();
  23.   background(0);
  24.   fill(255, 0, 0);
  25.   drawWind();

  26.   text("Stad: "+weather.getCityName(), 10, 20);
  27.   text("Weertype: "+weather.getWeatherCondition(), 10, 40);
  28.   text("Windrichting: "+weather.getWindDirection(), 10, 60);
  29.   text("Windsnelheid: "+weather.getWindSpeed()+"km/h", 10, 80);

  30.   text("Windtemperatuur: "+weather.getWindTemperature(), 10, 100); 
  31.   text("Temperatuur: "+weather.getTemperature(), 10, 120); 

  32.   fill(0, 255, 0);

  33.   drawWind2();

  34.   translate(0, 150);

  35.   text("Stad: "+weather2.getCityName(), 10, 20);
  36.   text("Weertype: "+weather2.getWeatherCondition(), 10, 40);
  37.   text("Windrichting: "+weather2.getWindDirection(), 10, 60);
  38.   text("Windsnelheid: "+weather2.getWindSpeed()+"km/h", 10, 80);
  39.   text("Temperatuur: "+weather2.getTemperature(), 10, 120); 
  40.   text("Windtemperatuur: "+weather2.getWindTemperature(), 10, 100);
  41. }

  42. void drawWind() {
  43.   
  44.   
  45.   float windtemp = int(weather2.getWindTemperature());
  46.   println(windtemp);
  47.   float size = windtemp/2;
  48.   for (int i=0; i<windParticles.length; i++) {
  49.     windParticles[i].add(getNormalizedPVector(weather.getWindDirection()));
  50.     if (windParticles[i].x<0)windParticles[i].x=width/2;
  51.     if (windParticles[i].x>width/2)windParticles[i].x=0;
  52.     if (windParticles[i].y<0)windParticles[i].y=height;
  53.     if (windParticles[i].y>height)windParticles[i].y=0;
  54.     ellipse(windParticles[i].x, windParticles[i].y, size, size);
  55.   }
  56. }


  57. void drawWind2() {

  58.   float windtemp = int(weather.getWindTemperature());
  59.   println(windtemp);
  60.   float size = windtemp/2;
  61.   for (int i=0; i<windParticles2.length; i++) {
  62.     windParticles2[i].add(getNormalizedPVector(weather2.getWindDirection()));
  63.     if (windParticles2[i].x<width/2)windParticles2[i].x=width;
  64.     if (windParticles2[i].x>width)windParticles2[i].x=width/2;
  65.     if (windParticles2[i].y<0)windParticles2[i].y=height;
  66.     if (windParticles2[i].y>height)windParticles2[i].y=0;


  67.     ellipse(windParticles2[i].x, windParticles2[i].y, size, size);
  68.   }
  69. }

  70. /**
  71.  * transforming the wind direction of yahoo into a normalizes vector 
  72.  */
  73. PVector getNormalizedPVector(int direction) {
  74.   int numPoints = 360;
  75.   float angle = TWO_PI/(float)numPoints;
  76.   direction = 360-direction;
  77.   direction += 180;
  78.   return new PVector(sin(angle*direction), cos(angle*direction));
  79. }




I hope someone can help me with this. I'm new with using vectors.


Thanks in advance,


Joshua




Replies(4)


in theory in line 67 multiply the vector with the windspeed
When, for instance, I use the next code:

    windParticles[i].add(getNormalizedPVector(weather.getWindDirection()*mouseX/90));


It doesn't change speed. It only changes direction, because this line only controls the direction. 


    PVector speed1 = new PVector (weather.getWindDirection());
    speed1.mult(mouseX);
    windParticles[i].add(speed1);





Thanks for the response. Still not working though. I'm really stuck with this. Can you please explain me how to implement your code to mine?

Thanks in advance
 


void drawWind2() {
  
    float windtemp = int(weather.getWindTemperature());
println(windtemp);
  float size = windtemp/2;
  for (int i=0; i<windParticles2.length; i++) {
        windParticles2[i].mult(mouseX/10);

    windParticles2[i].add(getNormalizedPVector(weather2.getWindDirection()));
  
  
   // PVector speed1 = new PVector (weather.getWindDirection());
  //  windParticles2[i].add(speed1);

    
    
    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);
  }
}