// Applet size variables int xSize = 400; int ySize = 300; int xMid = xSize/2; int yMid = ySize/2; // Tentacle variables Tentacle[] tentacle; int tMax = 100; float myAngle; float my2Angle; float mouseAngle; float H,S,B,A; // Meander variables Meander meander; // Booleans boolean wire = false; boolean points = false; boolean lines = false; // Extras int counter = 0; // global counter float radius = 50; // size of tube float xm, ym; // x and y mouse positions void setup() { size(xSize,ySize); colorMode(HSB,360); ellipseMode(CENTER_RADIUS); noStroke(); // Construct Meander(xpos, ypos, speed) meander = new Meander(xMid, yMid, 2); // Construct Tentacle Array tentacle = new Tentacle[tMax]; for (int i=0; i 100 && myAngle < 150){ A += (25 - abs(125 - myAngle)) * 5.0; } if (wire){ stroke(H,S,B * 1.25,A/2.0); noFill(); } if (points){ stroke(H,S,B * 1.25,A); noFill(); point(tentacle[t].x[n], tentacle[t].y[n]); } if (!wire && !points){ noStroke(); fill(H,S,B * 1.25,A); } vertex(tentacle[t-1].x[n], tentacle[t-1].y[n]); vertex(tentacle[t].x[n], tentacle[t].y[n]); } endShape(); } } void keyPressed(){ if (key == 'w' || key == 'W'){ if (wire){ wire = false; } else { wire = true; } } else if (key == 'p' || key == 'P'){ if (points){ points = false; } else { points = true; } } else if (key == 'l' || key == 'L'){ if (lines){ lines = false; } else { lines = true; } } else if (key == '-'){ if (meander.noiseScale > 0.002){ meander.noiseScale -= 0.001; } } else if (key == '+'){ if (meander.noiseScale < 0.1){ meander.noiseScale += 0.001; } } } class Meander { boolean outOfBounds; float[] x; float[] y; float v; float xv; float yv; float theta; float angle; float angleDelta; float noiseVal; float noiseCount; float noiseScale = 0.02; Meander (int xSent, int ySent, int vSent){ x = new float[2]; y = new float[2]; for (int i=0; i<=1; i++){ x[i] = xSent; y[i] = ySent; } v = vSent; } void exist(){ findVelocity(); move(); } void findVelocity(){ noiseCount += noiseScale; noiseVal = noise((x[0] + noiseCount) * noiseScale, (y[0] + noiseCount) * noiseScale, noiseCount); angle -= (angle - noiseVal * 1440.0f) * .45f; theta = -radians(angle); xv = cos(theta) * v; yv = sin(theta) * v; } void move(){ x[1] = x[0]; y[1] = y[0]; if (mousePressed){ x[0] -= (x[0] - xm) * .1; y[0] -= (y[0] - ym) * .1; } else { x[0] -= xv; y[0] -= yv; } x[0] = constrain(x[0], -50, xSize + 50); y[0] = constrain(y[0], -50, ySize + 50); if (x[0] < 50 || x[0] > xSize - 50 || y[0] < 50 || y[0] > ySize - 50){ //outOfBounds = true; } noFill(); stroke(0, 0, 360, 250); ellipse(x[0], y[0], radius, radius); } } class Tentacle { int index; int numNodes = 100; int head = 1; float girth = 2; float muscleRange = 45; float muscleFreq = .3; float theta; float thetaMuscle; float count = 0; float[] x; float[] y; float tv; float angle; float xOffset = xMid; float yOffset = yMid; boolean visible = true; Tentacle (int sentIndex) { index = sentIndex; x = new float[numNodes]; y = new float[numNodes]; } void exist(){ if (count == 0){ init(); } move(); } void init(){ x[0] = meander.x[0]; y[0] = meander.y[0]; angle = atan2((meander.y[0] - meander.y[1]), (meander.x[0] - meander.x[1])) + HALF_PI; for (int i=1; i