beginner code trouble (if statement in draw)
in
Programming Questions
•
2 years ago
So basically this code is meant to draw a vertical and horizontal line and when they intersect draw a diagonal like off of that.
It's nothing fancy, I'm just trying to learn processing and figured it would be a nice little thing to try out.
I have the vertical and horizontal lines working, and the if statement recognizes the collision (but only if I set x1 and y1 to a constant instead of a random).
so...
1) what do I have to do to lines 14 & 17 to get them to recognize in the collision?
2) what do I have to do to get my diagonal line to grow from that collision point?
Any help would be appreciated.
- int w = 450;
- int h = 450;
- void setup(){
- size(w,h);
- background(255);
- stroke(0);
- strokeWeight(1);
- smooth();
- loop();
- }
- float x1 = random(w-1);
- float x2 = x1;
- float y1 = random(h-1);
- float y2 = y1;
- int grow_vert = h;
- int grow_hor = w;
- int speed = -1;
- void draw(){
- grow_vert = grow_vert+speed;
- grow_hor = grow_hor+speed;
- line (x1,h,x2,grow_vert);
- line (w,y1,grow_hor,y2);
- if (x2==grow_hor || grow_vert==y2){
- int grow_dia = 1;
- grow_dia = grow_dia+(speed/2);
- float x3 = x2;
- float y3 = y2;
- line(x3,y3,x3-grow_dia,y3-grow_dia);
- }
- }
1