Help needed to place three rectangles on the screen
in
Programming Questions
•
11 months ago
I am a complete novice at processing and have been trying to place three rectangles on the screen for most of the day and seem to be getting no where fast... any help would be gratefully appreciated.
- //variables
float ballX, ballY, xVel, yVel, ballDiam=30;
//set up
void setup() {
//set up size of screen
size(500, 500);
//set the stroke weight
strokeWeight(1);
}
//start drawing stuff
void draw() {
//background
background(0);
//if the mouse is pressed...
if (mousePressed) {
//set ball x,y position to the same as the mouse position
ballX=mouseX;
ballY=mouseY;
}
//otherwise
else {
//place it to wherever it is according to the last throw
ballX += xVel;
ballY += yVel;
}
// draw the ball:
ellipse(ballX, ballY, ballDiam, ballDiam);
// any edge of the window, reverse its X or Y velocity
if ((ballX<ballDiam/2) || (ballX>width-ballDiam/2)) xVel = -xVel;
if ((ballY<ballDiam/2) || (ballY>height-ballDiam/2)) yVel = -yVel;
}
//adding another draw function for the bricks
void draw()
{
for(int i = bricklist.size () -1; i>0; i--)
{
Bricks singleBrick = (Bricks) bricklist.get(i);
if (singleBrick.collide(ball.ballX, ball.ballY, ball.radiusBall)) {
ball.yVel = ball.yVel * -1;
bricklist.remove(i);
println("hit");
}
}
class Bricks
{
float h;
float w;
float x;
float y;
Bricks(float tempx, float tempy, float tempw, float temph)
{
h = temph;
w = tempw;
x = tempx;
y = tempy;
}
void display()
{
noStroke();
fill(255);
rectMode(CENTER);
rect(x, y, w, h);
}
}
//when the mouse is released
void mouseReleased() {
//throw the ball and set its volicity
xVel = mouseX-pmouseX;
yVel = mouseY-pmouseY;
}
1