Algoan
Documentation
Quick Start
API Reference
Welcome to the Algoan developer hub
</>
<
<
>
class Tentacle {
constructor(x, y, segmentNum, baseLength, baseDirection) {
this.base
=
[x, y]
;
this.position
=
[x, y]
;
this.target
=
[x, y]
;
this.segmentNum
=
segmentNum
;
this.baseLength
=
baseLength
;
this.baseDirection
=
baseDirection
;
this.segmentProps
=
["x1", "y1", "x2", "y2", "l", "d", "h"]
;
this.segments
=
new PropsArray
(segmentNum, this.segmentProps);
this.follow
=
false
;
let i
=
this.segments.length - this.segmentProps.length
;
let x1, y1, x2, y2, l, d, h
;
l
=
this.baseLength
;
d
=
this.baseDirection
;
for (; i >= 0; i -= this.segmentProps.length) {
x1 =
x2
|| this.position[0];
y1 =
y2
|| this.position[1];
x2 =
x1 - l * cos(d)
;
y2 =
y1 - l * sin(d)
;
d +=
0.309
;
l *=
0.98
;
h =
baseHue + fadeIn(i, this.segments.length) * rangeHue
;
this.segments.set([x1, y1, x2, y2, l, d, h], i);
}
}
setCtx(ctx) {
this.ctx
=
ctx
;
}
setTarget(target) {
this.target
=
target
;
}
updateBase() {
let t
=
simplex.noise3D(this.base[0] * 0.005, this.base[1] * 0.005, tick * 0.005) * TAU
;
}
function setup() {
tick
=
0
;
simplex
=
new SimplexNoise()
;
mouse
= [0, 0];
createCanvas();
resize();
tentacles
= [];
let i, d, t, tentacle;
for (i = 0; i < tentacleCount; i++) {
d =
randRange(colonyRadius)
;
t =
i / tentacleCount * TAU
;
tentacle
=
new Tentacle(
center[0] + d * cos(t),
center[1] + d * sin(t),
round(randIn(segmentCountMin, segmentCountMax)),
round(randIn(segmentLengthMin, segmentLengthMax)),
t
);
tentacle.setCtx(ctx.a);
tentacles.push(tentacle);
}
loop();
}
function createCanvas() {
canvas =
{
a: document.createElement("canvas"),
b: document.createElement("canvas")
};
canvas.b.style = `
position: absolute;
top: 0;
left: 0;
width: 100%;
Documentation
API Reference