# Confine the wind in the screen without changing speed or degree

**URL:** <https://discourse.processing.org/t/confine-the-wind-in-the-screen-without-changing-speed-or-degree/32124>\
**Category:** Coding Questions\
**Created:** [September 6, 2021, 8:27pm UTC](https://discourse.processing.org/t/confine-the-wind-in-the-screen-without-changing-speed-or-degree/32124 "2021-09-06T20:27:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arabesque0210](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@Arabesque0210](https://discourse.processing.org/u/Arabesque0210)\
**Post date:** [September 6, 2021, 8:27pm UTC](https://discourse.processing.org/t/confine-the-wind-in-the-screen-without-changing-speed-or-degree/32124/1 "2021-09-06T20:27:42Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [September 6, 2021, 9:18pm UTC](https://discourse.processing.org/t/confine-the-wind-in-the-screen-without-changing-speed-or-degree/32124/2 "2021-09-06T21:18:47Z")

</div>

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

```auto
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

```auto

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
}

```

---

<div class="post-metadata">

**Author:** ![Arabesque0210](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@Arabesque0210](https://discourse.processing.org/u/Arabesque0210)\
**Post date:** [September 7, 2021, 8:55pm UTC](https://discourse.processing.org/t/confine-the-wind-in-the-screen-without-changing-speed-or-degree/32124/3 "2021-09-07T20:55:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [September 7, 2021, 8:56pm UTC](https://discourse.processing.org/t/confine-the-wind-in-the-screen-without-changing-speed-or-degree/32124/4 "2021-09-07T20:56:28Z")

</div>

Thank you for your reply!

😉
