I think its a rare combination having a penchant for both art and programming. Not that they dont mix, its just that theyre quite different.
As for vector randomization, you do unfortunately probably need math to do things proper. Nothing more complicated than highschool geometry and trigonometry, but its still math xD.
A quick and dirty solution of the top of my head (with minimal math since i havent brushed up on it yet myself):
- generate a random vector (with the z coordinate locked)
2a. The tricky part that needs math; run the new vector through an “angle check algorithm” to see if its generating a valid angle.
2b. If the angle is invalid, change it until it is. Two methods i can think of off the top of my head;
Simply restarting the process from step 1 until you generate a valid angle
-OR-
Randomly generate an angle within the valid range and then use the power of math to calculate where the vector should be placed to make the appropriate angle.
3a Do a raycast from the old vector to the new one, with the trace distance randomly generated (with a min/max value to keep the polygon dimensions reasonable)
3b. And then set the new vectors location to the end of the linetrace. - Loop this process as many times as you want to produce a shape with as many sides as you want.
- Connect the first and last vectors to close the polygon.
Some notes about the above algorithm:
*-You WILL need to review the math that figures out the sum of all the inner (or outer if thats the way you roll) angle for a given n-sided polygon and make it so that your angle checker takes that into account when check for a valid angle.
-How you setup step 2 will determine if your script will produce shapes with concave angles or not.
-Its step 3 that you need to tweak to “normalize” the size of the generated polygon. Off the top of my head you can use either a second rescaling factor with the random number clamped to a narrower range of values (maybe even integer values) OR use the lerp node.
-You probably want to start with a line of random lenght before running this algorithm so step 2 actually produces an angle you can check straight after you generate the first vector.
-You probably want an additional step after the last vector is generated that checks to make sure you didnt just generate a zigzagging line with a long and straight connection between then first and last vectors (something like needing a minimum lenght between them).
-Making a polygon with too many sides will probably lead to poor aesthetic outcome for the polygon unless you build in a failsafe of some
sort.
*