Connect ellipses created in a class with one other
in
Programming Questions
•
10 months ago
Hey guys,
I am trying to make a quick experiment. I created a class that generates a random sized circles every time you click the screen. I want to implement connecting the circles to one other once they're on screen. So far I've managed to connect them to the center one but I want to implement a connection amongst them all or at least the previous one.
I tried doing pmouseX, pmouseY as I thought this location might only get saved on click since I put it inside the mouseReleased function. Now I know that it's always updating!
Any thoughts? Here's my code, thanks and happy thanksgiving!
- ArrayList circleCollection;
- int originX = 400;
- int originY = 250;
- float prevX, prevY;
- void setup(){
- size(800,500);
- smooth();
- frameRate(30);
- //DEFINE ARRAY LIST
- circleCollection = new ArrayList();
- }
- void draw(){
- background(240);
- fill(0);
- for(int i = 0; i < circleCollection.size(); i++){
- Circle myCircle = (Circle) circleCollection.get(i);
- myCircle.display();
- }
- ellipse(originX, originY, 10,10);
- }
- void mouseReleased(){
- Circle myCircle = new Circle(mouseX, mouseY, random(1,10), pmouseX, pmouseY);
- circleCollection.add(myCircle);
- }
- class Circle{
- //CLASS VARIABLES
- float xPos, yPos, diameter, prevX, prevY;
- //CONSTRUCTOR
- Circle(float _xPos, float _yPos, float _diameter, float _prevX, float _prevY){
- xPos = _xPos;
- yPos = _yPos;
- diameter = _diameter;
- prevX = _prevX;
- prevY = _prevY;
- }
- void display(){
- ellipse(xPos, yPos, diameter, diameter);
- line(originX, originY, xPos, yPos);
- line(prevX, prevY, xPos, yPos);
- }
- }
1