We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I have been trying to make this irregular triangle bounce. Now it works on the top but not on the three other boundaries.
Could somebody help? Thank you !
Here is the code: It displays well in this Processing Online editor http://js.do/blog/processing/editor/#!star_painted
boolean xRight, xLeft, yDown; //, yTop;
int xPos, yPos;
int speed = 1;
void setup() {
size(250, 350);
strokeWeight(5);
xRight = true;
yDown = true;
xPos = width/2;
yPos = height/2;
}
void draw() {
background(204);
// Control right
if (xRight) xPos += speed;
else xPos -= speed;
if (xPos +76.67>= width || xPos <= 0) xRight = !xRight;
// Control left
if (xLeft) xPos -= speed;
else xPos += speed;
if (xPos -23.33 >= width || xPos >= 0) xLeft = !xLeft;
// Control down and up
if (yDown) yPos += speed;
else yPos -= speed;
if (yPos >= height || yPos -124.33 <= 0) yDown = !yDown;
driehoek(xPos, yPos);
}
void driehoek(int xLinks, int yLinks) {
int xA = xLinks -53.33;
int yA = yLinks -4.33;
int xB = xLinks -23.33;
int yB = yLinks +95.67;
int xC = xLinks +76.67;
int yC = yLinks -124.33;
triangle(xA, yA, xB, yB, xC, yC);
}
Answers
Please do not create multiple posts.
Format your code. Edit your post (click the gear icon on the right top corner of your post), select your code and hit ctrl+o.
Kf
Hi, Done, thank you
https://forum.Processing.org/two/discussion/19789/irregular-triangle-bounce