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

Activity Trend

Last 30 days
Show:
Private Message
    I'm trying to write a simple program which draws a line from the centre of the screen to a randomised point within the window. Then, I want to (for now) draw an ellipse somewhere along that line, using the y-intercept formula y=mx+b to track the line's slope. So far, so good.

    However, now I want to ensure that this ellipse isn't drawn too close to the centre. I used a while loop to check the distance between the ellipse's centre coordinates and the centre of the screen, but it's quite regularly, though not always, getting stuck in an infinite loop. It seems x and y are fairly often being assigned / calculated to 100.0 (i.e. the centre of the screen). Code below (beware of infinite looping if you decide to run it):

    1. size(200, 200);
    2. background(#13212C);
    3. smooth();
    4. stroke(255);

    5. float x1 = width / 2;
    6. float y1 = height / 2;
    7. float x2 = random(0, width);
    8. float y2 = random(0, height);

    9. while(x2 > (width / 4) && x2 < ((width / 4) * 3) && x2 > (height / 4) &&  x2 <((height / 4) * 3))
    10. {
    11.       x2 = random(0, width);
    12.       y2 = random(0, height);
    13. }
    14. line(x1, y1, x2, y2);
    15. float m = (y2 - y1) / (x2 - x1);
    16. float b = y1 - (m * x1);

    17. float x = random(x1, x2);
    18. float y = (m * x) + b;
    19. float nodeProx = dist(x, y, x1, y1);

    20. println("nodeProx" + nodeProx);
    21. println("x" + x + ", y" + y);
    22. while(nodeProx <= 20.0)
    23. {
    24.       x = random(x1, x2);
    25.       y = (m * x) + b;
    26.       nodeProx = dist(x, y, x1, y1);
    27.       println("x" + x + ", y" + y);
    28.       println(nodeProx);
    29. }
    30. println("m = " + m);
    31. println("b = " + b);

    32. noStroke();
    33. fill(255);
    34. ellipse((width / 2), (height / 2), 20, 20); // central ellipse
    35. fill(255, 0, 0);
    36. ellipse(x, y, 5, 5); // 'node' ellipse

    I thought I'd allowed for the infinite loop by randomising x within the while loop, re-calculating y, then reassigning nodeProx to the new distance, however, it spits out 0.0 for nodeProx and can't change despite the reassignment within the while loop.

    I'm relatively new to Processing and my maths is extremely rusty. I suspect it's a maths problem over a programming problem, but after managing to get to this point, I'm a little stuck.

    Can anyone see the error of my ways? Is there a simpler solution for drawing a random point along a randomly-generated line?

    Many thanks in advance!
    The processing.exe shortcut can be pinned to the taskbar in Windows 7 like most programs. However, when the program's actually opened, it opens a second instance of the icon which doesn't have the option to 'pin to taskbar' when right clicked

    After a bit of research, it seems the application processing.exe opens the process javaw.exe.

    I imagine the issue is similar to this forum post about an identical Eclipse issue (specifically, comment 21 and below). I imagine Processing's .ini file equivalent is processing.txt (Users>[username]AppData>Roaming>Processing) but can't see any options to edit to try to reproduce the steps in the Eclipse forum post.

    Anyone have any suggestions or workarounds to pin the open Processing program to the taskbar?