The Sparkfun Guide to Processing by Derek Runberg

The Sparkfun Guide to Processing by Derek Runberg

Author:Derek Runberg
Language: eng
Format: epub, mobi
Publisher: No Starch Press, Inc.
Published: 2015-09-03T04:00:00+00:00


Driving Shapes

Making something move on the screen in response to the keyboard or mouse is a basic building block of video game development. Let’s start simple and use the arrow keys to send an ellipse zooming around the sketch window.

Since you want to move the ellipse, you need to be able to change its x- and y-coordinates. First, in the code window, create global variables for those values:

int x = 300;

int y = 300;

Start your ellipse in the middle of the sketch window. In my example, the center is (300,300). Yours may be different, if you change the size of your sketch window.

Now write the setup() and draw() calls:

void setup()

{

size(600,600);

}

void draw()

{

background(150);

fill(255,0,0);

noStroke();

ellipse(x,y,50,50);

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.