“HW11_2” by chris pro
https://openprocessing.org/sketch/97170
License CreativeCommons Attribution ShareAlike
https://creativecommons.org/licenses/by-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution ShareAlike
HW11_2
pro
xxxxxxxxxx
//CHRIS PRO HOMEWORK 11.2
//placing my arrays using a new made class
Balls [] ballsX = new Balls[10];
Balls [] ballsY = new Balls[10];
void setup() {
size (500, 500);
//setting my number of arrays and what i decided to edit in my new made class
for (int i = 0; i < ballsX.length; i = i + 1){
ballsX[i] = new Balls( int(random(0,500)), int(random(0,500)), int(random(0,30)));
}
for (int i = 0; i < ballsY.length; i = i +1){
ballsY[i] = new Balls( int(random(0,500)), int(random(0,500)), int(random(0,30)));
}
}
void draw(){
background(31, 255, 3);
//setting my number of arraws and what functions placed in my class i chose to include
for (int i = 0; i < ballsX.length; i = i + 1){
ballsX[i].display();
ballsX[i].moveX();
ballsX[i].bounceX();
}
for (int i = 0; i < ballsY.length; i = i + 1){
ballsY[i].display();
ballsY[i].moveY();
ballsY[i].bounceY();
}
}
// my class name and the data variables
class Balls{
int x;
int y;
int speed;
//Initialize my data variables
Balls(int tempX, int tempY, int tempSpeed) {
x = tempX;
y = tempY;
speed = tempSpeed;
}
//my functions that tell my class what to do
void display(){
fill(135, 8, 152);
ellipse(x, y, 20, 20);
}
void moveX(){
x = x + speed;
}
void moveY(){
y = y + speed;
}
void bounceX(){
if ((x > width) || (x < 0)) {
speed = speed * -1;
}}
void bounceY (){
if ((y > height) || (y < 0)) {
speed = speed * -1;
}}
}
See More Shortcuts