Loading...
Logo
Processing Forum
druckaa's Profile
1 Posts
1 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    Hi,

    I'm trying to figure out how to consolidate drawing these lines into a for-loop in the draw() function.  Basically, I'm trying to animate a bar graph, eg trying to draw each bar from 0 to it's Y value, and then it draws the next bar and so on.  I can manually add each block below, and it works fine to create each line, but it seems better to automate it.  Each line creates a bar/column.

    1. float yPos = map(actions[1].presses, minVal, maxVal, height/2, 50);
    2. line(lineXpos, actions[1].a, endLineXpos, actions[1].a);
    3. actions[1].a = actions[1].a - 2;
    4. if (actions[1].a < yPos) { 
    5.   actions[1].a = height/2; 
    6. }

    7. float yPos2 = map(actions[2].presses, minVal, maxVal, height/2, 50);
    8. line(lineXpos+10, actions[2].a, endLineXpos+10, actions[2].a);
    9. actions[2].a = actions[2].a - 2;
    10. if (actions[2].a < yPos2) { 
    11.   actions[2].a = height/2; 
    12. }

    13. float yPos3 = map(actions[3].presses, minVal, maxVal, height/2, 50);
    14. ...
    15. ...
    16. and so on...


    It seems like I could consolidate the above into something like this below, but when I run it, it runs endlessly and creates a slope.

    1. void draw() {
    2.   
    3.   for( int j = 1; j < actions.length; j++) {
    4.     
    5.     actions[j].yPos = map(actions[j].presses, minVal, maxVal, height/2, 50);
    6.     
    7.     line(actions[j].lineXpos, actions[j].a, actions[j].endLineXpos, actions[j].a);
    8.     actions[j].a = actions[j].a - 2; 
    9.        
    10.     if (actions[j].a < actions[j].yPos) { 
    11.       actions[j].a = height/2;
    12.       actions[j].lineXpos = actions[j].lineXpos + 10;
    13.       actions[j].endLineXpos = actions[j].endLineXpos + 10;
    14.     }
    15.     
    16.   }

    17. }

    I think the actions[j].yPos gets overwritten each time.  Any ideas what I'm doing wrong?

    Thanks!