Confine the wind in the screen without changing speed or degree

Hi there,

I am new to processing and trying to create a floating text following wind data for my art project.

I want to make sure this string is always in the screen like bouncing ball, however maybe cuz I use the real-time data, I can’t really use if statement to change the speed to make it turn around.

But if I confine the wind in the screen, probably its data must be revised then.

Anyone got any solutions?

Thanks

float x;
float y;
float wd;
float ws;
float tw;
JSONObject json;

void setup(){
  size(1920,1080);
  fill(0);
  x = width/2;
  y = 1;
    
}


void draw(){
  
  background(255);
  
  String url = "https://api.openweathermap.org/data/2.5/weather?q=Longyearbyen&appid=b6ec4043ea9954f70e3885f2ac8e9d2c"; 
  json = loadJSONObject(url);
  JSONObject wind = json.getJSONObject("wind");
  
  wd = wind.getInt("deg");
  ws = wind.getFloat("speed");
  
  
  x += cos(radians(wd))*ws;
  y += sin(radians(wd))*ws;
  
  translate(x, y);
  rotate(radians(wd));
  
  textSize(ws*5);
  String q = "Hello";
  
  tw = textWidth(q);
  
  text(q, -200, -50, tw+1, 800);
  
  
  
}
1 Like

Yeah, once it’s leaving the screen let it re-appear on the other side

when x < 0 say x=width
when x > width say x=0

same for y

remark

say String q = "Windy"; before setup()

use text() with only 3 parameters

  • the word could rotate around its center with the speed of the wind
  • the word could change with the speed of the wind (slow, windy, tornado)
  • how often does the data change? Not much change at the moment

Warm Regards,

Chrisir


final String url = "https://api.openweathermap.org/data/2.5/weather?q=Longyearbyen&appid=b6ec4043ea9954f70e3885f2ac8e9d2c"; 
final String q = "Windy";

JSONObject wind;

float x;
float y;
float wd;
float ws;
float tw;

JSONObject json;

void setup() {
  size(1920, 1080);
  fill(0);
  x = width/2;
  y = 1;
}

void draw() {
  background(255);

  json = loadJSONObject(url);
  wind = json.getJSONObject("wind");

  wd = wind.getInt("deg");
  ws = wind.getFloat("speed");

  // print(wd, "   ");

  x += cos(radians(wd))*ws;
  y += sin(radians(wd))*ws;

  translate(x, y);
  rotate(radians(wd));

  textSize(ws*5);

  //tw = textWidth(q);
  text(q, 0, 0);  // , tw+1, 800
}

2 Likes

Aha thanks for your advice Chrisir, this method is so effective yet easy to apply.

I use the data from openweathermap, I think it changes every ten minutes.

I use tw+1 cuz I have an extra design for this string, I want to make it reconfigurable in another interface, then input it to processing as data, the text would change and the length of it may be different. Yet this is still a conception, I’m not sure, maybe I should create several strings to achieve this.

1 Like

Thank you for your reply!

:wink:

1 Like