Editing
P4P2010-05-27
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Programming for Poets, class 5/27 We went through varibles and functions again, and introduced conditionals ("if") statements. We updated our pongball program to bounce! int ballx = 0; // start at left int bally = 200; // and halfway down int pballx = 0; int pbally = 200; int speed = 5; // the ball moves this number of pixels between frames int deltax = speed; // start with positive x speed (right) int deltay = speed; // start with positive y speed (down) void setup() { // size of our drawing window size(400, 400); // set the background color to gray background(128); } void draw() { // draw over the previous ball location stroke(128); // gray fill(128); drawball(pballx,pbally); // update the ball location ballx = ballx + deltax; bally = bally + deltay; // check that ball is on the screen if(ballx>400) { println("right bounce x"); deltax = -speed; // move left } if(bally>400) { println("bottom bounce y"); deltay = -speed; // now move up } if(ballx<1) { println("left bounce x"); deltax = speed; // now move right } if(bally<1) { println("top bounce y"); deltay = speed; } // now draw ball in new location stroke(255); fill(255); //white drawball(ballx,bally); // save the new location for next time pballx = ballx; pbally = bally; } // draw a paddle-shaped box at the given coordinates void drawbox(int x, int y) { rect(30,y,10,40); } // draw a ball at the given coordinates void drawball(int foo, int bar) { ellipse(foo,bar,10,10); } int myadd(int A, int B) { return (A+B); }
Summary:
Please note that all contributions to Noisebridge are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Noisebridge:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Request account
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Dig in!
Noisebridge
- Status: MOVED
- Donate
- ABOUT
- Accessibility
- Vision
- Blog
Manual
MANUAL
Visitors
Participation
Community Standards
Channels
Operations
Events
EVENTS
Guilds
GUILDS
- Meta
- Electronics
- Fabrication
- Games
- Music
- Library
- Neuro
- Philosophy
- Funding
- Art
- Crypto
- Documentation/Wiki
Wiki
Recent Changes
Random Page
Help
Categories
(Edit)
Tools
What links here
Related changes
Special pages
Page information