Trying to make a square out of moving ellipses.
in
Programming Questions
•
11 months ago
What I'm trying to do:
-I'm trying to create a square out of ellipses
-I'd like each side of the square to be almost entirely made up of ellipses
-I want the ellipses to be in constant movement around the box in one directions
-I'd like to create this without having to call 28 separate ellipses for each side of the box
My problem:
-I can't seem to get a handle on getting multiple ellipses to move from one point to another with a single function.
-I've tried for, while and if loops. I've tried creating a seperate function, and even putting it all into a class. No technique I could figure out worked well.
I've narrowed down what I want to do to two very simple examples that I've been trying to merge together with no success.
Example one:
//This shows my ultimate goal: the box with the moving circles around it.
//This doesn't have the second part of my goal, a wall of ellipses.
- int flow;
- int steady = 150;
- int offset = 200;
- int flowRate = 1;
- void setup () {
- size(500,500);
- frameRate(30);
- }
- void draw () {
- background(255);
- flow+=flowRate;
- if (flow > 200) {
- flow = 0;
- }
- ellipse(150+offset-flow, steady+random(-5, 5), 3, 3);
- ellipse(steady+random(-5, 5), 150+flow, 3, 3);
- ellipse(150+flow, steady+offset+random(-5, 5), 3, 3);
- ellipse(steady+offset+random(-5, 5), 150+offset-flow, 3, 3);
- }
Example two:
//This shows off my goal of a wall of moving ellipses
//however, I can't seem to keep the starting and ending x and y positions constant
- int flow;
- int steady = 250;
- int flowRate = 1;
- void setup () {
- size(500,500);
- }
- void draw () {
- background(255);
- flow+=flowRate;
- if (flow > 200) {
- flow = 0;
- }
- for (int i = 0; i < 200; i = i+7){
- ellipse(150+flow+i, steady+random(-5, 5), 3, 3);
- }
- }
Any help is greatly appreciated. I've been coming back to this over and over for a couple of days now, and I just can't seem to get a handle on it.
1