Using "if" to set variable
in
Programming Questions
•
11 months ago
I want to use "if" to set variables according to the position of the mouse.
However, it seems to limit the accessability of the variable and I don't know what to do!
Please help me
I am trying to draw a shape that deforms randomly with the "random" function. But I want to deform the shape more as the mouse approaches the right hand side of the sketch by setting zones on the sketch.
Here is my code..
int [] [] points = {{1, 2}, {2, 0}, {3, 2}, {4, 0}, {5, 2}, {6, 0}, {7,2}, {8, 0}, {9, 2}, {8, 4}, {7, 2}, {6, 4}, {5, 2}, {4, 4}, {3,2}, {2, 4}, {1, 2}, {0, 4}, {1, 6}, {2, 4}, {3, 6}, {4, 4}, {5, 6}, {6, 4}, {7,6}, {8, 4}};
float [] rx = new float [points.length] ;
float [] ry = new float [points.length] ;
float scalelength = 40;
void setup() {
size (500, 300);
noFill ();
stroke(255);
strokeWeight(.5);
smooth ();
}
void draw() {
background (150);
if (mouseX < width/7) {
float rrange_x1 = -40;
}
float rrange_x1 = -0;
float rrange_x2 = -1*rrange_x1;
float rrange_y1 = -20;
float rrange_y2 = -1*rrange_y1;
for (int i = 0; i < 26 ; i++) {
rx [i] = random(rrange_x1, rrange_x2);
ry [i] = random(rrange_y1, rrange_y2);
}
beginShape(TRIANGLE_STRIP);
for (int i = 0 ; i < 9; i++) {
vertex (points [i] [0]*scalelength + rx[i], points [i] [1]*scalelength + ry[i]);
}
endShape();
}
void mousePressed() {
redraw ();
}
1