# How to move an object one pixel at a time up and down the screen and how to change the shape according to aspect ratio

**URL:** https://discourse.processing.org/t/how-to-move-an-object-one-pixel-at-a-time-up-and-down-the-screen-and-how-to-change-the-shape-according-to-aspect-ratio/19502
**Category:** Coding Questions
**Created:** [April 7, 2020, 12:50pm UTC](https://discourse.processing.org/t/how-to-move-an-object-one-pixel-at-a-time-up-and-down-the-screen-and-how-to-change-the-shape-according-to-aspect-ratio/19502 "2020-04-07T12:50:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![s6277](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@s6277](https://discourse.processing.org/u/s6277)
#### Post date: [April 7, 2020, 12:50pm UTC](https://discourse.processing.org/t/how-to-move-an-object-one-pixel-at-a-time-up-and-down-the-screen-and-how-to-change-the-shape-according-to-aspect-ratio/19502/1 "2020-04-07T12:50:46Z")

</div>

Hey, i’m new to processing and I’ve tried and researched so much on this but i can’t find a solution.  
My goal is to basically move a shape up and down one pixel at a time from the left of the screen (without using frame rate) and when space bar is pressed it stops the movement of the object, but when space bar is pressed again the object runs as usual. Also in the results, when you pull the screen horizontally and vertically, the object should be able to change as well and modify to the screen size while still moving at one pixel at a time.

Thank you

---

<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: [April 7, 2020, 2:40pm UTC](https://discourse.processing.org/t/how-to-move-an-object-one-pixel-at-a-time-up-and-down-the-screen-and-how-to-change-the-shape-according-to-aspect-ratio/19502/2 "2020-04-07T14:40:12Z")

</div>

Hello!

and welcome to the forum!

Great to have you here.

you can start from the code below.

what do you have to do to get movement up and down?

Chrisir

```auto

int xpos; 
boolean moving=true; 

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

void draw() {
  background(255);
  if (moving) {
    xpos++;
  }//if
  ellipse(xpos, 200, 
    11, 11);
}

void keyPressed() {
  moving = 
    ! moving;
}
//

```

---

<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: [April 8, 2020, 8:42am UTC](https://discourse.processing.org/t/how-to-move-an-object-one-pixel-at-a-time-up-and-down-the-screen-and-how-to-change-the-shape-according-to-aspect-ratio/19502/3 "2020-04-08T08:42:56Z")

</div>

> [@s6277](#):
>
> i’m new to processing and I’ve tried and researched so much on this but i can’t find a solution.

Hello,

There are lots of resources at the Processing website:

> **[Welcome to Processing!](https://processing.org/)**
>
> Processing is a flexible software sketchbook and a language for learning how to code. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology…

Check out the tutorials, references and so on!

The Coding Train:

> **[The Coding Train](https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw)**
>
> All aboard! The Coding Train is on its way with creative coding video tutorials on subjects ranging from the basics of programming languages like JavaScript to algorithmic art, machine learning, simulation, generative poetry, and more. Choo choo!

Check out the examples that come with the Processing IDE and work through them:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f8cbb0282cffb007ee816e16e47e1e96b8b35505.png)

There are input (mouse is one) examples in there ^ that may help.

I wrote my own code to do this just looking at what was available in references and then I looked at other examples and compared; that comes from experience.

If you are new you will have to work through tutorials, references and examples and start writing code.

If you do find an example try understanding it and write it from scratch to reinforce concepts.

You have to start somewhere.

`:)`
