Hi, I would greatly appreciate any help anyone can offer.
Here is my code so far.
- // This is a list of my circles / nodes from the class Node
- ArrayList nodes;
- void setup() {
- // runs only once
- size(1000, 1000);
- // Create an empty ArrayList
- nodes = new ArrayList();
- // set radius of the main circle
- int radius = 400;
- int p = 380;
- // init nodes here in a for loop
- for (int deg = 0; deg < 360; deg += 36) {
- float angle = radians (deg);
- // x and y = Position of small cirlces on the big circle
- float x = 100 + (cos(angle) * radius);
- float y = 100 + (sin(angle) * radius);
- // A new node object (small circle) is added to the ArrayList (by default to the end)
- nodes.add(new Node(x, y));
- } // for
- for (int deg = 0; deg < 360; deg += 10) {
- float angle = radians (deg);
- // x and y = Position of small cirlces on the big circle
- float x = (100 + (cos(angle) * p));
- float y = (100 + (sin(angle) * p));
- // A new node object (small circle) is added to the ArrayList (by default to the end)
- nodes.add(new Node(x, y));
- } // for
- // message to show how many elements we have in the list (e.g. 10)
- println (nodes.size());
- // get one element and display its coordinates
- Node node = (Node) nodes.get(1);
- println (node.xpos + 400);
- println (node.ypos + 400);
- //
- } // func
- void draw() {
- // runs in a loop again and again
- background(255);
- // set up the variable node from Class Node
- Node node;
- // display nodes here etc.
- for (int i = nodes.size()-1; i >= 0; i--) {
- // get the node named "node" at position i in the list
- node = (Node) nodes.get(i);
- // display this individual node
- node.display();
- } // for
- if (mouseX > 890 && mouseX < 910 && mouseY > 490 && mouseY < 510) {
- String[] lines = loadStrings("node_connect.txt");
- for ( int i = 0; i< lines.length; i++) {
- String[] pieces = split(lines[i], '\t');
- if (pieces.length ==8) { //number of items in each row of .txt file
- int a = int(pieces[0]);
- int b = int(pieces[1]);
- int c = int(pieces[2]);
- int d = int(pieces[3]);
- int e = int(pieces[4]);
- int f = int(pieces[5]);
- int g = int(pieces[6]);
- int h = int(pieces[7]);
- smooth();
- stroke(255, 0, 0);
- strokeWeight(.25);
- noFill();
- bezier (a, b, c, d, e, f, g, h);
- //end of code for drawing bezier splines between nodes
- }//for
- }
- } else if (mouseX > 814 && mouseX < 834 && mouseY > 725 && mouseY < 745) {
- String[] lines = loadStrings("node_connect_2.txt");
- for ( int i = 0; i< lines.length; i++) {
- String[] pieces = split(lines[i], '\t');
- if (pieces.length ==8) { //number of items in each row of .txt file
- int a = int(pieces[0]);
- int b = int(pieces[1]);
- int c = int(pieces[2]);
- int d = int(pieces[3]);
- int e = int(pieces[4]);
- int f = int(pieces[5]);
- int g = int(pieces[6]);
- int h = int(pieces[7]);
- smooth();
- stroke(255, 0, 0);
- strokeWeight(.25);
- noFill();
- bezier (a, b, c, d, e, f, g, h);
- //end of code for drawing bezier splines between nodes
- }//for
- }
- } else if (mouseX > 614 && mouseX < 634 && mouseY > 870 && mouseY < 890) {
- String[] lines = loadStrings("node_connect_3.txt");
- for ( int i = 0; i< lines.length; i++) {
- String[] pieces = split(lines[i], '\t');
- if (pieces.length ==8) { //number of items in each row of .txt file
- int a = int(pieces[0]);
- int b = int(pieces[1]);
- int c = int(pieces[2]);
- int d = int(pieces[3]);
- int e = int(pieces[4]);
- int f = int(pieces[5]);
- int g = int(pieces[6]);
- int h = int(pieces[7]);
- smooth();
- stroke(255, 0, 0);
- strokeWeight(.25);
- noFill();
- bezier (a, b, c, d, e, f, g, h);
- //end of code for drawing bezier splines between nodes
- }//for
- }
- } else if (mouseX > 366 && mouseX < 386 && mouseY > 870 && mouseY < 890) {
- String[] lines = loadStrings("node_connect_3.txt");
- for ( int i = 0; i< lines.length; i++) {
- String[] pieces = split(lines[i], '\t');
- if (pieces.length ==8) { //number of items in each row of .txt file
- int a = int(pieces[0]);
- int b = int(pieces[1]);
- int c = int(pieces[2]);
- int d = int(pieces[3]);
- int e = int(pieces[4]);
- int f = int(pieces[5]);
- int g = int(pieces[6]);
- int h = int(pieces[7]);
- smooth();
- stroke(255, 0, 0);
- strokeWeight(.25);
- noFill();
- bezier (a, b, c, d, e, f, g, h);
- //end of code for drawing bezier splines between nodes
- }//for
- }
- } else if (mouseX > 166 && mouseX < 186 && mouseY > 725 && mouseY < 745) {
- String[] lines = loadStrings("node_connect_3.txt");
- for ( int i = 0; i< lines.length; i++) {
- String[] pieces = split(lines[i], '\t');
- if (pieces.length ==8) { //number of items in each row of .txt file
- int a = int(pieces[0]);
- int b = int(pieces[1]);
- int c = int(pieces[2]);
- int d = int(pieces[3]);
- int e = int(pieces[4]);
- int f = int(pieces[5]);
- int g = int(pieces[6]);
- int h = int(pieces[7]);
- smooth();
- stroke(255, 0, 0);
- strokeWeight(.25);
- noFill();
- bezier (a, b, c, d, e, f, g, h);
- //end of code for drawing bezier splines between nodes
- }//for
- }
- } else if (mouseX > 90 && mouseX < 110 && mouseY > 490 && mouseY < 510) {
- String[] lines = loadStrings("node_connect_3.txt");
- for ( int i = 0; i< lines.length; i++) {
- String[] pieces = split(lines[i], '\t');
- if (pieces.length ==8) { //number of items in each row of .txt file
- int a = int(pieces[0]);
- int b = int(pieces[1]);
- int c = int(pieces[2]);
- int d = int(pieces[3]);
- int e = int(pieces[4]);
- int f = int(pieces[5]);
- int g = int(pieces[6]);
- int h = int(pieces[7]);
- smooth();
- stroke(255, 0, 0);
- strokeWeight(.25);
- noFill();
- bezier (a, b, c, d, e, f, g, h);
- //end of code for drawing bezier splines between nodes
- }//for
- }
- } else if (mouseX > 166 && mouseX < 186 && mouseY > 255 && mouseY < 275) {
- String[] lines = loadStrings("node_connect_3.txt");
- for ( int i = 0; i< lines.length; i++) {
- String[] pieces = split(lines[i], '\t');
- if (pieces.length ==8) { //number of items in each row of .txt file
- int a = int(pieces[0]);
- int b = int(pieces[1]);
- int c = int(pieces[2]);
- int d = int(pieces[3]);
- int e = int(pieces[4]);
- int f = int(pieces[5]);
- int g = int(pieces[6]);
- int h = int(pieces[7]);
- smooth();
- stroke(255, 0, 0);
- strokeWeight(.25);
- noFill();
- bezier (a, b, c, d, e, f, g, h);
- //end of code for drawing bezier splines between nodes
- }//for
- }
- } else if (mouseX > 366 && mouseX < 386 && mouseY > 110 && mouseY < 130) {
- String[] lines = loadStrings("node_connect_3.txt");
- for ( int i = 0; i< lines.length; i++) {
- String[] pieces = split(lines[i], '\t');
- if (pieces.length ==8) { //number of items in each row of .txt file
- int a = int(pieces[0]);
- int b = int(pieces[1]);
- int c = int(pieces[2]);
- int d = int(pieces[3]);
- int e = int(pieces[4]);
- int f = int(pieces[5]);
- int g = int(pieces[6]);
- int h = int(pieces[7]);
- smooth();
- stroke(255, 0, 0);
- strokeWeight(.25);
- noFill();
- bezier (a, b, c, d, e, f, g, h);
- //end of code for drawing bezier splines between nodes
- }//for
- }
- } else if (mouseX > 614 && mouseX < 634 && mouseY > 110 && mouseY < 130) {
- String[] lines = loadStrings("node_connect_3.txt");
- for ( int i = 0; i< lines.length; i++) {
- String[] pieces = split(lines[i], '\t');
- if (pieces.length ==8) { //number of items in each row of .txt file
- int a = int(pieces[0]);
- int b = int(pieces[1]);
- int c = int(pieces[2]);
- int d = int(pieces[3]);
- int e = int(pieces[4]);
- int f = int(pieces[5]);
- int g = int(pieces[6]);
- int h = int(pieces[7]);
- smooth();
- stroke(255, 0, 0);
- strokeWeight(.25);
- noFill();
- bezier (a, b, c, d, e, f, g, h);
- //end of code for drawing bezier splines between nodes
- }//for
- }
- } else if (mouseX > 814 && mouseX < 834 && mouseY > 255 && mouseY < 275) {
- String[] lines = loadStrings("node_connect_3.txt");
- for ( int i = 0; i< lines.length; i++) {
- String[] pieces = split(lines[i], '\t');
- if (pieces.length ==8) { //number of items in each row of .txt file
- int a = int(pieces[0]);
- int b = int(pieces[1]);
- int c = int(pieces[2]);
- int d = int(pieces[3]);
- int e = int(pieces[4]);
- int f = int(pieces[5]);
- int g = int(pieces[6]);
- int h = int(pieces[7]);
- smooth();
- stroke(255, 0, 0);
- strokeWeight(.25);
- noFill();
- bezier (a, b, c, d, e, f, g, h);
- //end of code for drawing bezier splines between nodes
- }//for
- }
- }
- } // func
- // ==========================================================
- class Node {
- float xpos; // each node has its properties
- float ypos;
- Node(float tempX, float tempY) {
- // each node gets its properties here in the Constructor
- xpos = tempX;
- ypos = tempY;
- } // Constructor
- //
- void display () {
- stroke(255, 0, 0);
- fill(70);
- smooth();
- int radius = (400);
- // use the individual properties to draw one node
- ellipse (xpos + radius, ypos + radius, 8, 8);
- //links to .txt file to draw bezier splines between nodes
- //if
- } // func
- //
- } // class
What I am essentially trying to do is create an inner and outer circle comprised of points (and the number of points need to be able to change) and then connect certain points using a bezier when I rollover those points.
I am trying to create a class and then reference objects from that class.
I've created a class called nodes (the points).
I've made a large inner and outer circle out of these nodes.
I can find the x and y position of each individual node using this part of the code.
- Node node = (Node) nodes.get(1);
- println (node.xpos + 400);
- println (node.ypos + 400);
Then I can individually input each of these coordinates and create a bezier spline to connect certain nodes to each other using a string to read information from a .txt file where I have manually input all of the node locations. The biggest problem with doing it this way is that if the number of nodes changes, then I have to go back and find the x and y position of each node again and then manually input all of the information again.
Here is an image of what it should look like:
It seems that there should be a way to say draw a bezier between one node and another node without having to go through all of this manually input.
If anyone can help, thanks! If you need more information of if you need the .txt files, I can send them to you but I can't find a way to attach them on this forum.
1