/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.M1jUuR9HRUy/rev.1146
*
* authors:
* Troy
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
int numOptions = 6;
int[][] originalNodePositions = new int[numOptions][2];
int[][] nodePositions = new int[numOptions][2];
int nodeRadius = 50;
String[] nodeNames = {
"Home",
"Test"
};
int[][][] iconLines = {
{
{-10, 10, 18, 0},
{-10, 8, 0, -13},
{10, 8, 0, -13},
{-10, -5, 10, -10},
{10, -5, -10, -10},
{-10, -5, 18, 0}
},
{
{-10, -10, 18, 0},
{-10, -10, 10, 15},
{10, -10, -10, 15}
}
};
//do, pos
float[][] anim = new float[iconLines.length][2];
for (float[] animInfo : anim) {
animInfo = {0,0};
}
void setup() {
size(300, 300);
smooth();
frameRate(30);
originalNodePositions[0][0] = width/2;
originalNodePositions[0][1] = height/2;
for (int i=0; i < numOptions-1; i++) {
int xPos = cos(2*PI*i/(numOptions-1) - PI/2) * 100 + width/2;
int yPos = sin(2*PI*i/(numOptions-1) - PI/2) * 100 + height/2;
originalNodePositions[i+1][0] = xPos;
originalNodePositions[i+1][1] = yPos;
}
}
void mousePressed() {
for (int i=0; i < numOptions; i++) {
int[] pos = nodePositions[i];
if (pow(mouseX-pos[0], 2) + pow(mouseY-pos[1], 2) < pow(nodeRadius/2, 2)) {
if (i < nodeNames.length){
alert(nodeNames[i]+" node was pressed");
}else{
alert("Unnamed node was pressed");
}
}
}
}
void draw() {
background(255);
for (float[] animInfo : anim){
if (animInfo[0] > 0) {
if (animInfo[1] < 1) {
animInfo[1] = min(animInfo[1] + 0.2, 1);
}
else {
animInfo[1] = 1;
animInfo[0] = 0;
}
}
else if (animInfo[0] < 0) {
if (animInfo[1] > 0) {
animInfo[1] = max(animInfo[1] - 0.2, 0);
}
else {
animInfo[1] = 0;
animInfo[0] = 0;
}
}
animInfo[0] = -1;
}
stroke(215, 232, 239);
fill(92, 173, 194);
for (int i=0; i < numOptions; i++) {
int[] pos = originalNodePositions[i];
float xOff = mouseX-pos[0];
float yOff = mouseY-pos[1];
float dist = sqrt(pow(xOff, 2) + pow(yOff, 2));
nodePositions[i][0] = pos[0] + xOff*min(10/dist, 1);
nodePositions[i][1] = pos[1] + yOff*min(10/dist, 1);
}
strokeWeight(5);
for (int i=0; i < numOptions; i++) {
for (int j=i+1; j < numOptions; j++) {
line(nodePositions[i][0], nodePositions[i][1], nodePositions[j][0], nodePositions[j][1]);
}
}
for (int i=0; i < numOptions; i++) {
int[] pos = nodePositions[i];
if (pow(mouseX-pos[0], 2) + pow(mouseY-pos[1], 2) < pow(nodeRadius/2, 2)) {
strokeWeight(8);
if (i < anim.length) {
anim[i][0] = 1;
}
}
else {
strokeWeight(5);
}
fill(92, 173, 194);
ellipse(pos[0], pos[1], nodeRadius, nodeRadius);
}
for (int i=0; i < iconLines.length; i++) {
for (int[] pos : iconLines[i]) {
stroke(215, 232, 239);
strokeWeight(2);
line(pos[0] + nodePositions[i][0], pos[1] + nodePositions[i][1], pos[0] + nodePositions[i][0] + pos[2], pos[1] + nodePositions[i][1] + pos[3]);
if (anim[i][1] > 0) {
stroke(0,0,0);
strokeWeight(2);
line(pos[0] + nodePositions[i][0], pos[1] + nodePositions[i][1], pos[0] + nodePositions[i][0] + pos[2]*anim[i][1], pos[1] + nodePositions[i][1] + pos[3]*anim[i][1]);
}
}
}
fill(0,0,0);
textSize(18);
for (int i=0; i < numOptions; i++) {
int[] pos = nodePositions[i];
if (pow(mouseX-pos[0], 2) + pow(mouseY-pos[1], 2) < pow(nodeRadius/2, 2)) {
if (i < nodeNames.length){
text(nodeNames[i], pos[0]-textWidth(nodeNames[i])/2, pos[1]+nodeRadius/2+16);
}else{
text("Unnamed", pos[0]-textWidth("Unnamed")/2, pos[1]+nodeRadius/2+16);
}
}
}
textSize(14);
//text(anim, 0, 10);
}