# Mystify Version 2.5

While trying to get the bounce feature to work properly in the mystify sketch I was writing, I realized while working on the orbiting sketch that I could use sine waves as an alternative to having boolean switches that ticked on and off when the x or y coordinates increased past the canvas boundaries. What resulted is a more fluid dynamic that pretty mesmerizing. I also added the function of adding points when left-clicking and removing points when right-clicking.

```let xC = [];
let yC = [];

let fC;
let xS = [];
let yS = [];

let n = 2;

let i;
let s = 4;

let neg = [-1, 1];

function setup() {
createCanvas(400, 400);
background(255);
for (i = 0; i < n; i += 1) {
xS[i] = random(-s, s);
yS[i] = random(-s, s);
}
}

function draw() {
background(255, 2);
fC = (frameCount) * 0.01;

for (i = 0; i < n; i += 1) {
xC[i] = width / 2 + width / 2 * sin(fC * xS[i]);
yC[i] = height/2 + height / 2 * sin((fC) * yS[i]);
}

for (i = 0; i < n; i += 1) {
stroke(255);
strokeWeight(1.05*log(sqrt(pow(xC[i] - xC[(i + 1) % n], 2) + pow(yC[i] - yC[(i + 1) % n], 2))) * 4-2);
line(xC[i], yC[i], xC[(i + 1) % n], yC[(i + 1) % n]);
}

for (i = 0; i < n; i += 1) {
stroke(25 + 60 * cos(fC), 25 + 5 * sin(fC), 20 + 60 * sin(fC));
strokeWeight(log(sqrt(pow(xC[i] - xC[(i + 1) % n], 2) + pow(yC[i] - yC[(i + 1) % n], 2))) * 4-2);
line(xC[i], yC[i], xC[(i + 1) % n], yC[(i + 1) % n]);
}

}

function mousePressed() {
if (mouseButton == LEFT) {
n += 1;
xS[n - 1] = random(-s, s);
yS[n - 1] = random(-s, s);
} else {
n -= 1;
if (n < 0) {
n = 0
}
}
}
```