Help would be greatly appreciated! (Parabolic Reflection)

Hi, I'm new to the forum!

I haven't been using Processing for very long, so naturally I am stuck :P I am looking to animate a small project of mine, but I am at a loss of what to do. I am using Java. I have the image that I am trying to animate uploaded here: http://tinypic.com/r/spahhj/8 or [IMG]http://i57.tinypic.com/spahhj.png[/IMG]. All I'm trying to do is to get the straight lines going down to move down slowly, then to hit the curve and then end up at the circle, as in the diagram. I'm able to get a few of the straight lines to appear only, and to get them to go diagonally but that's about it. I don't know how to create the circle or the curved line.

Here's my code so far:

int moveLine = 20;
float lineAngleX = 20;
float lineAngleY = 380;

void setup() {
  size(400, 400);
}

void draw() {
  line(20,20,20,moveLine);
  if(moveLine<=380){
  moveLine++;
  } {
     line(50,20,50,moveLine);
  if(moveLine<=385) {
    moveLine++;
  }

  if(moveLine>=380){
  line(20,380,lineAngleX,lineAngleY);

  lineAngleX++;
  lineAngleY--;}
  }
}

Not much... If anyone could help me by sending me code of a full working model if they'd be so kind, and I could look through it to see what you did to learn about it, that would be great. I know it's a lot to ask but I'm desperate! Thanks.

Tagged:

Answers

  • My code is formatted correctly but for some reason when I pressed 'Post' it changed it down to this weird format.

  • int moveLine = 20; 
    float lineAngleX = 20; 
    float lineAngleY = 380;
    
    void setup() { 
      size(400, 400);
    }
    
    void draw() { 
      line(20, 20, 20, moveLine); 
      if (moveLine<=380) { 
        moveLine++;
      } 
      { 
        line(50, 20, 50, moveLine); 
        if (moveLine<=385) { 
          moveLine++;
        }
    
        if (moveLine>=380) { 
          line(20, 380, lineAngleX, lineAngleY);
    
          lineAngleX++; 
          lineAngleY--;
        }
      }
    }
    
  • modified

    int moveLine = 20; 
    float lineAngleX = 20; 
    float lineAngleY = 380;
    
    void setup() { 
      size(400, 400);
      background(111);
    }
    
    void draw() { 
      background(111); 
    
      noFill();
      ellipse (220, 222, 39, 39);
    
      // https: // www.processing.org/reference/arc_.html
      arc(50, 50, 
      80, 80, 
      0, PI, OPEN); 
    
      line(20, 20, 20, moveLine); 
      if (moveLine<=380) { 
        moveLine++;
      } 
      { 
        line(50, 20, 50, moveLine); 
        if (moveLine<=385) { 
          moveLine++;
        }
    
        if (moveLine>=380) { 
          line(20, 380, lineAngleX, lineAngleY);
    
          lineAngleX++; 
          lineAngleY--;
        }
      }
    }
    
  • edited March 2015

    probably you need 2 empty lines before and after the code when posting

    look into the reference for details on ellipse (for circle) and arc (for the curve) pls

    https://www.processing.org/reference/

  • Answer ✓

    the actual reflection is not easy I guess

    but I made a curve for you using curve(). look into curvePoint() to move on from here.

    tasks:

    • detect when line is hitting the curve (easy)

    • calculate the new angle for the line from here (hard)

    • keep drawing the line in the new direction

    ;-)

    int moveLine = 20; 
    float lineAngleX = 20; 
    float lineAngleY = 380;
    
    void setup() { 
      size(400, 400);
      background(111);
    }
    
    void draw() { 
      background(111); 
    
      noFill();
      ellipse (220, 222, 39, 39);
    
      // https: // www.processing.org/reference/arc_.html
      arc(50, 50, 
      80, 80, 
      0, PI, OPEN); 
    
      // advanced curve -----------------
    
      // look into curvePoint() to move on from here
    
      stroke(0);
      // position (left corner) 
      float commonX = 73;
      float commonY = 230;
    
      // width of curve 
      float widthCurve = 299;
    
      // calc the control points from here
      float xoffset = 200; 
      float yoffset = 300;
    
      curve(
      commonX-xoffset, commonY-yoffset, // control point 1 
      commonX, commonY, // 1st point 
      commonX+widthCurve, commonY, // 2nd point  
      commonX+widthCurve+xoffset, commonY-yoffset // control point 2
      ); 
    
      // end of advanced curve -----------------
    
    
      line(20, 20, 20, moveLine); 
      if (moveLine<=380) { 
        moveLine++;
      } 
      { 
        line(50, 20, 50, moveLine); 
        if (moveLine<=385) { 
          moveLine++;
        }
    
        if (moveLine>=380) { 
          line(20, 380, lineAngleX, lineAngleY);
    
          lineAngleX++; 
          lineAngleY--;
        }
      }
    }
    
  • Aahhhh! Thank you very much for all your help!

Sign In or Register to comment.