# Random position ellipse smear/freeze

**URL:** <https://discourse.processing.org/t/random-position-ellipse-smear-freeze/38300>\
**Category:** Beginners\
**Created:** [August 10, 2022, 8:06pm UTC](https://discourse.processing.org/t/random-position-ellipse-smear-freeze/38300 "2022-08-10T20:06:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tilman](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@Tilman](https://discourse.processing.org/u/Tilman)\
**Post date:** [August 10, 2022, 8:06pm UTC](https://discourse.processing.org/t/random-position-ellipse-smear-freeze/38300/1 "2022-08-10T20:06:36Z")

</div>

Hi I am doing chapter 7-10 in learning processing. And want to do a jiggeling UFO. Somehow in my code it makes the graphic not update correctly. It smears freezes (paints over one an other) Hope someone can help me what I am doing wrong here?

My Code:

float x = 200;  
float y = 200;  
float theSize = 200;  
float offset = theSize/4;

void setup() {  
size (400, 400);

}

void draw() {  
jiggleUFO(2);

// Draw Main UFO Body  
ellipseMode(CENTER);  
fill(0);

ellipse(x, y, theSize, theSize/3);  
ellipse(x, y-(offset/2), theSize/3, theSize/3);  
fill(255);

ellipse(x-offset, y, theSize/8, theSize/8);  
ellipse(x, y, theSize/8, theSize/8);  
ellipse(x+offset, y, theSize/8, theSize/8);

}

void jiggleUFO(float speed) {

x = x + random(-1, 1)\*speed;  
y = y + random(-1, 1)\*speed;  
// Constrain UFO to window  
x = constrain(x, 0, width);  
y = constrain(y, 0, height);  
}

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 10, 2022, 11:10pm UTC](https://discourse.processing.org/t/random-position-ellipse-smear-freeze/38300/2 "2022-08-10T23:10:03Z")

</div>

Hi  
I think you need background

```auto

float x = 200;
float y = 200;
float theSize = 200;
float offset = theSize/4;
float speed= 200;
void setup() {
size (400, 400);

}

void draw() {
background (255);
jiggleUFO(2);

// Draw Main UFO Body
ellipseMode(CENTER);
fill(0);

ellipse(x, y, theSize, theSize/3);
ellipse(x, y-(offset/2), theSize/3, theSize/3);
fill(255);

ellipse(x-offset, y, theSize/8, theSize/8);
ellipse(x, y, theSize/8, theSize/8);
ellipse(x+offset, y, theSize/8, theSize/8);

}

void jiggleUFO(float speed) {

x = x + random(-1, 1)*speed;
y = y + random(-1, 1)*speed;
// Constrain UFO to window
x = constrain(x, 0, width);
y = constrain(y, 0, height);
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 11, 2022, 2:30am UTC](https://discourse.processing.org/t/random-position-ellipse-smear-freeze/38300/3 "2022-08-11T02:30:21Z")

</div>

Hello @Tilman,

These should help you to understand what is happening:

- [https://processing.org/tutorials/overview](https://processing.org/tutorials/overview)
- [https://processing.org/reference/draw\_.html](https://processing.org/reference/draw_.html)
- [https://processing.org/reference/background\_.html](https://processing.org/reference/background_.html)

`:)`

---

<div class="post-metadata">

**Author:** ![Tilman](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@Tilman](https://discourse.processing.org/u/Tilman)\
**Post date:** [August 11, 2022, 7:48am UTC](https://discourse.processing.org/t/random-position-ellipse-smear-freeze/38300/4 "2022-08-11T07:48:24Z")

</div>

perfect! Thank you @jafal ] @glv

🔎 👓  
\*

> “It is common to call **background()** near the beginning of the **draw()** loop to clear the contents of the window, as shown in the first example above. Since pixels drawn to the window are cumulative, omitting**background()** may result in unintended results.”

-

---

<div class="post-metadata">

**Author:** ![Tilman](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@Tilman](https://discourse.processing.org/u/Tilman)\
**Post date:** [August 11, 2022, 8:14am UTC](https://discourse.processing.org/t/random-position-ellipse-smear-freeze/38300/5 "2022-08-11T08:14:54Z")

</div>

Thanks again. Maybe you can help me further 🙂  
Now I run into another problem with completing the exercise. I want to make these UFOs Jiggle in a patch where I call several instances. So as you see above I get it to work for one instance now.

it seems the void jiggleUFO(float speed) “function?” here does have no effect. I try to understand why. I have not yet learned about dbugging.

// code goes here

```auto
float x = 100;
float y = 100;
float theSize = 200;
float offset = theSize/4;
float speed= 200;

void setup() {
  size(640, 360);
}

void draw() {
background(255);
jiggleUFO(2);
spaceship (482, 159, 223);
spaceship (126, 89, 93);
spaceship (422, 286, 84);
spaceship (294, 49, 48);
spaceship (162, 220, 151);

}
void spaceship (float x, float y, float size) {
// Draw Main UFO Body  
ellipseMode(CENTER);
fill(0);
ellipse(x, y, theSize, theSize/3);
ellipse(x, y-(offset/2), theSize/3, theSize/3);
fill(255);
// Draw Main UFO Windows
ellipse(x-offset, y, theSize/8, theSize/8);
ellipse(x, y, theSize/8, theSize/8);
ellipse(x+offset, y, theSize/8, theSize/8);
}
  
void jiggleUFO(float speed) {
x = x + random(-1, 1)*speed;
y = y + random(-1, 1)*speed;
// Constrain UFO to window
x = constrain(x, 0, width);
y = constrain(y, 0, height);
}

```

// code ends here

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 12, 2022, 2:24am UTC](https://discourse.processing.org/t/random-position-ellipse-smear-freeze/38300/6 "2022-08-12T02:24:44Z")

</div>

@Tilman,

I fixed the link to the “Processing Overview” tutorial.

`:)`
