PVector rootNoise = new PVector(random(123456), random(123456));
float radius = 180, bott = 600;
float mouseDist, targetMouseDist;
PVector targetSpeed = new PVector(0, 0);
center = new PVector(width/2, height/2);
weeds = new SeaWeed[nbWeeds];
for (int i = 0; i < nbWeeds; i++) {
weeds[i] = new SeaWeed(i*TWO_PI/nbWeeds, 1*radius);
rect(0, 0, width, height);
rootNoise.add(new PVector(.01, .01));
float d = dist(mouseX, mouseY, pmouseX, pmouseY);
mouseDist = min(mouseDist + d/10, 50);
mouseDist = max(mouseDist - 1, 0);
mouse = new PVector(mouseX, mouseY);
targetCenter = mouse.get();
targetSpeed = targetCenter.get();
int tmpTouchCount = constrain(touchCount, 0, 20);
tmpa = a + (bott-a) * map(tmpTouchCount, 0, 20, 1, 0);
targetSpeed.y += (tmpa - center.y) * .001;
for (int i = 0; i < nbWeeds; i++) {
float R, G, B, Rspeed, Gspeed, Bspeed;
final static float minSpeed = .6;
final static float maxSpeed = 1.8;
final static float minR = 20;
final static float maxR = 85;
final static float minG = 198;
final static float maxG = 255;
final static float minB = 200;
final static float maxB = 212;
Rspeed = (random(1) > .5 ? 1 : -1) * random(minSpeed, maxSpeed);
Gspeed = (random(1) > .5 ? 1 : -1) * random(minSpeed, maxSpeed);
Bspeed = (random(1) > .5 ? 1 : -1) * random(minSpeed, maxSpeed);
Rspeed = ((R += Rspeed) > maxR || (R < minR)) ? -Rspeed : Rspeed;
Gspeed = ((G += Gspeed) > maxG || (G < minG)) ? -Gspeed : Gspeed;
Bspeed = ((B += Bspeed) > maxB || (B < minB)) ? -Bspeed : Bspeed;
final static float DIST_MAX = 3;
final static float FLOTATION = -7.5;
MyColor myCol = new MyColor();
SeaWeed(float p_rad, float p_length){
nbSegments = (int)(p_length/DIST_MAX);
pos = new PVector[nbSegments];
cols = new color[nbSegments];
thetas = new float[nbSegments];
float cosi = cos(baseTheta);
float sinu = sin(baseTheta);
pos[0] = new PVector(x, y);
for (int i = 1; i < nbSegments; i++){
pos[i] = new PVector(pos[i-1].x - DIST_MAX*cosi, pos[i-1].y - DIST_MAX*sinu);
cols[i] = myCol.getColor();
float qqq = noise(pos[i].x/22, pos[i].y/22);
qqq = map(qqq, 0, 1, -PI/3, PI/3) * map(i, 0, nbSegments-1, 0, 1);
for (int i = 1; i < nbSegments; i++){
float n = noise(rootNoise.x + .002 * pos[i].x, rootNoise.y + .002 * pos[i].y);
float noiseForce = (.5 - n) * 7;
PVector pv = new PVector(cos(baseTheta+thetas[i]), sin(baseTheta+thetas[i]));
pv.mult(map(i, 1, nbSegments, FLOTATION, .6*FLOTATION));
float d = PVector.dist(mouse, pos[i]);
PVector tmpPV = mouse.get();
tmpPV = PVector.sub(mouse, tmpPV);
PVector tmp = PVector.sub(pos[i-1], pos[i]);
pos[i] = PVector.sub(pos[i-1], tmp);
for (int i = 0; i < nbSegments; i++){
vertex(pos[i].x, pos[i].y);
cols[0] = myCol.getColor();
for (int i = nbSegments-1; i > 0; i--){