how to detect when when ball touches left or right side of the rectangle?
in
Programming Questions
•
9 months ago
how can i activate strokeWeight(random(10));
only when ball touches left or right side of the rectangle?
only when ball touches left or right side of the rectangle?
- float diam=100;
float a=0;
void setup(){
size(500,400);
background(0);
noFill();
}
void draw(){
background(0);
float x=sin(a)*width/2;
float y=height/2;
float x1=width/2;
float y1=height/2;
float d=dist(x,y,x1, y1);
strokeWeight(1);
stroke(255,255,0);
//line(width/2,0,width/2+x,y);
fill(255);
ellipse(width/2+x,height/2,20,20);
noFill();
if (d<50){
strokeWeight(random(10));
}
else {
strokeWeight(1);
}
stroke(0,255,0);
rectMode(CENTER);
rect(x1,y1,50,50);
a+=0.05;
}
1