r/processing • u/Jimmyboy142 • May 02 '21
I seek help
I have to write a program in processing (java) that starts a line in the middle and has a lenght of random(0, 39); and a random direction west, east, north and south random(0, 3); and stops when the accumulated lenght goes over 1500. I've been trying hard but can't wrap my head around the directions part and accumulation tracking. Thanks for the help.

2
u/ChuckEye May 02 '21 edited May 02 '21
Off the top of my head I’m thinking an array of PVectors storing the X, Y coordinates of all the points and a conditional to stop adding to the array when the array length is greater than 1500.
Then each frame of draw you use point(x,y) to in a for loop with the current array length as the max?
1
u/Jimmyboy142 May 02 '21
Thank you, but I'm not allowed to use arrays, nor methods. I have to do it with a while loop. 😕 Also I checked and there's no Pvector methid in the documentation for processing and it does not work
1
u/ChuckEye May 02 '21
You can get away with not using an array if you’re not using a setup/draw structure.
1
u/x-seronis-x May 02 '21 edited May 02 '21
its length not lenght. There is no hard 't' sound at the end so dont spell it with one.
Also you mentioned in a comment some weird stipulations that you failed to put in the OP. Not everyone is going to read comments before replying. To avoid wasting the time of people who are willing to help you should always put any requirements in the OP. Its quite rude not to
4
u/Wootai May 02 '21 edited May 02 '21
So, we need to break down this problem into a few smaller problems. There are a lot of approaches to this, and you’ve stated you cannot use arrays or methods. So let’s look at the problem and break it down:
Start in the center. (Easy enough)
Choose a random length for our line segment. (Again easy enough)
Choose a random direction (Got that)
Draw a line segment from our current position, to the next position that is our random length, and our random direction. (Hmm)
if all of our line segments are 1500 pixels long, stop, otherwise go back to step to
Ok. So let’s look at some pseudo code: