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

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

1 Like


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?


int xpos; 
boolean moving=true; 

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

void draw() {
  if (moving) {
  ellipse(xpos, 200, 
    11, 11);

void keyPressed() {
  moving = 
    ! moving;


There are lots of resources at the Processing website:

Check out the tutorials, references and so on!

The Coding Train:

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

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.