several random objects per random object
in
Programming Questions
•
1 year ago
Hi all!
3rd day into Processing (and OOP coding at all), and pretty excited about it. I ran into an issue that a bunch of searching hasn't helped. I currently have a bunch of ellipses being drawn randomly, and I'm trying to attach a random number of randomly sized arc segments to each ellipse. I was able to get one arc per circle, but I'd like to get more (all arcs per ellipse should be the same stroke thickness, but random start and stop points). What's the best way to do this?
Here's what I have so far. Thanks in advance for any insight :)
- //declare variables globally
- int circNum = (int) random(10, 30); //Declare the number of Circles globally
- //declare arrays globally
- int[]ArrayCirSiz = new int[circNum]; //Array for random size of Circs
- int[]ArrayCirStr = new int[circNum]; //Array for random stroke weight of Circs
- int[]ArrayArcNum = new int[circNum]; //Array for random ArcSegs per Circ
- int[]ArrayArcBeg = new int[circNum]; //Array for when each ArcSeg starts --- May have to be 2D
- int[]ArrayArcEnd = new int[circNum]; //Array for when each ArcSeg ends --- May have to be 2D
- int[]ArrayArcStr = new int[circNum]; //Array for ranom stroke weight of all ArcSegs per Circ
- //everything in setup runs once, so randoms are all generated here, otherwise they loop.
- void setup() {
- size (500, 500); //set the canvas size
- // circNum = (int) random(15, 30); //set the number of circles to a random number, once.
- //loop that populates all the random numbers
- for (int i = 0; i < circNum; i++) {
- ArrayCirSiz[i] = (int) random(width/3, width);
- ArrayCirStr[i] = (int) random(1, 2);
- ArrayArcNum[i] = (int) random(1, 3);
- ArrayArcBeg[i] = (int) random(1, 360);
- ArrayArcEnd[i] = (int) random(5, 360);
- ArrayArcStr[i] = (int) random(2, 4);
- }
- }
- void draw() {
- //constant values that affect everything in the scene
- background(52);
- smooth();
- stroke(255);
- strokeCap(SQUARE);
- noFill();
- //variable values for this loop
- for (int i = 0; i < circNum; i++) {
- strokeWeight(ArrayCirStr[i]);
- ellipse(width/2, height/2, ArrayCirSiz[i], ArrayCirSiz[i]);
- strokeWeight(ArrayArcStr[i] + ArrayCirStr[i]);
- arc(width/2, height/2, ArrayCirSiz[i], ArrayCirSiz[i], radians(ArrayArcBeg[i]), radians(ArrayArcBeg[i] + ArrayArcEnd[i]));
- }
- }
1