Imperial Japanese Nishikigoi
Traditional Nishikigoi carp simulation displaying realistic S-curve carangiform swimming mechanics, Kohaku cinnabar red and Sumi-e black markings on pearlescent ivory scales, sensory barbels, and tranquil pond water ripples.
60 FPS • Canvas 2D
Click + Drag to interact with field
</>
Full Executable Algorithm Code
222 lines
8299 chars
// 076 - Imperial Japanese Nishikigoi (creatures)
// 1:1 Original algorithm engine source
function createJapaneseKoi() {
return {
setup() {
},
render(context, timeState, params) {
const { ctx, width, height } = context;
const swimRate = Number(params.swimSpeed ?? 0.75);
const rippleLuster = Number(params.pondRipples ?? 1);
const patternColor = Number(params.kohakuHue ?? 12);
const t = timeState.time * swimRate;
ctx.fillStyle = "#03080d";
ctx.fillRect(0, 0, width, height);
const cx = width * 0.5;
const cy = height * 0.5;
const maxR = Math.min(width, height) * 0.44;
ctx.save();
ctx.translate(cx, cy);
if (rippleLuster > 0.1) {
for (let r = 1; r <= 4; r++) {
const rRadius = maxR * (0.4 + 0.22 * r) * (1 + 0.05 * Math.sin(t * 1.5 + r));
ctx.beginPath();
ctx.ellipse(0, 0, rRadius, rRadius * 0.7, 0.4, 0, Math.PI * 2);
ctx.strokeStyle = hsla(190, 80, 65, (0.12 - r * 0.02) * rippleLuster);
ctx.lineWidth = 1;
ctx.stroke();
}
}
const spineJoints = 22;
const spinePoints = [];
const bodyLen = maxR * 1.1;
for (let j = 0; j <= spineJoints; j++) {
const frac = j / spineJoints;
const amp = Math.pow(frac, 1.4) * (maxR * 0.18);
const wave = Math.sin(t * 3 - frac * Math.PI * 2.4);
const sx = -bodyLen * 0.48 + frac * bodyLen * 0.9;
const sy = wave * amp;
let bWidth = 0;
if (frac < 0.3) {
bWidth = Math.sin(frac / 0.3 * (Math.PI * 0.5)) * (maxR * 0.16);
} else {
bWidth = Math.cos((frac - 0.3) / 0.7 * (Math.PI * 0.5)) * (maxR * 0.16);
}
spinePoints.push({ x: sx, y: sy, angle: 0, width: Math.max(2, bWidth) });
}
for (let j = 0; j <= spineJoints; j++) {
const next = spinePoints[Math.min(spineJoints, j + 1)];
const prev = spinePoints[Math.max(0, j - 1)];
spinePoints[j].angle = Math.atan2(next.y - prev.y, next.x - prev.x);
}
const tailPt = spinePoints[spineJoints];
const tailRays = 18;
const tailLen = maxR * 0.48;
for (let r = 0; r < tailRays; r++) {
const rFrac = r / (tailRays - 1);
const fanAng = tailPt.angle + (rFrac - 0.5) * Math.PI * 0.65;
const rWave = Math.sin(t * 3.5 - rFrac * 2) * 12;
const tipX = tailPt.x + Math.cos(fanAng) * tailLen + rWave;
const tipY = tailPt.y + Math.sin(fanAng) * tailLen + rWave * 0.5;
ctx.beginPath();
ctx.moveTo(tailPt.x, tailPt.y);
ctx.quadraticCurveTo(tailPt.x + Math.cos(fanAng) * (tailLen * 0.5), tailPt.y + Math.sin(fanAng) * (tailLen * 0.5), tipX, tipY);
ctx.strokeStyle = hsla(40, 90, 85, 0.4);
ctx.lineWidth = 1.4;
ctx.stroke();
}
const pectPt = spinePoints[3];
for (const pSide of [-1, 1]) {
const pPhase = Math.sin(t * 3.2 + (pSide === 1 ? 0 : Math.PI * 0.2)) * 0.3;
const pBaseAngle = pectPt.angle + pSide * (Math.PI * 0.55 + pPhase);
const pLen = maxR * 0.38;
ctx.save();
const startX = pectPt.x - Math.sin(pectPt.angle) * (pSide * pectPt.width * 0.8);
const startY = pectPt.y + Math.cos(pectPt.angle) * (pSide * pectPt.width * 0.8);
ctx.translate(startX, startY);
ctx.rotate(pBaseAngle);
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.bezierCurveTo(pLen * 0.6, -pLen * 0.3, pLen, -pLen * 0.1, pLen, 0);
ctx.bezierCurveTo(pLen * 0.8, pLen * 0.3, pLen * 0.4, pLen * 0.2, 0, 0);
ctx.fillStyle = "rgba(254, 243, 199, 0.3)";
ctx.fill();
ctx.strokeStyle = hsla(45, 95, 80, 0.85);
ctx.lineWidth = 1.2;
ctx.stroke();
for (let ray = 1; ray <= 5; ray++) {
const rayF = ray / 6;
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(pLen * 0.85 * rayF, (rayF - 0.5) * pLen * 0.3);
ctx.strokeStyle = hsla(40, 90, 85, 0.35);
ctx.lineWidth = 0.8;
ctx.stroke();
}
ctx.restore();
}
ctx.beginPath();
const headPt = spinePoints[0];
ctx.moveTo(headPt.x, headPt.y);
for (let j = 1; j <= spineJoints; j++) {
const pt = spinePoints[j];
const normX = -Math.sin(pt.angle);
const normY = Math.cos(pt.angle);
ctx.lineTo(pt.x + normX * pt.width, pt.y + normY * pt.width);
}
for (let j = spineJoints; j >= 0; j--) {
const pt = spinePoints[j];
const normX = -Math.sin(pt.angle);
const normY = Math.cos(pt.angle);
ctx.lineTo(pt.x - normX * pt.width, pt.y - normY * pt.width);
}
ctx.closePath();
const koiSkin = ctx.createLinearGradient(spinePoints[0].x, 0, spinePoints[spineJoints].x, 0);
koiSkin.addColorStop(0, "#fef9c3");
koiSkin.addColorStop(0.5, "#fffbeb");
koiSkin.addColorStop(1, "#fef08a");
ctx.fillStyle = koiSkin;
ctx.fill();
ctx.strokeStyle = "#f59e0b";
ctx.lineWidth = 1.5;
ctx.stroke();
const crownPt = spinePoints[2];
ctx.beginPath();
ctx.ellipse(crownPt.x, crownPt.y, maxR * 0.11, maxR * 0.08, crownPt.angle, 0, Math.PI * 2);
ctx.fillStyle = hsla(patternColor, 95, 52, 0.95);
ctx.fill();
const saddlePt = spinePoints[7];
ctx.beginPath();
ctx.ellipse(saddlePt.x, saddlePt.y - 2, maxR * 0.15, maxR * 0.11, saddlePt.angle, 0, Math.PI * 2);
ctx.fillStyle = hsla(patternColor + 4, 92, 48, 0.95);
ctx.fill();
const sumiPt = spinePoints[13];
ctx.beginPath();
ctx.ellipse(sumiPt.x, sumiPt.y + 4, maxR * 0.08, maxR * 0.06, sumiPt.angle, 0, Math.PI * 2);
ctx.fillStyle = "#090a0f";
ctx.fill();
const hiPt = spinePoints[16];
ctx.beginPath();
ctx.ellipse(hiPt.x, hiPt.y, maxR * 0.09, maxR * 0.05, hiPt.angle, 0, Math.PI * 2);
ctx.fillStyle = hsla(patternColor - 3, 95, 50, 0.95);
ctx.fill();
for (const bSide of [-1, 1]) {
const bSway = Math.sin(t * 4 + bSide) * 4;
ctx.beginPath();
ctx.moveTo(headPt.x + 2, headPt.y + bSide * 5);
ctx.quadraticCurveTo(headPt.x - 12, headPt.y + bSide * 16 + bSway, headPt.x - 22, headPt.y + bSide * 20 + bSway);
ctx.strokeStyle = "#fef08a";
ctx.lineWidth = 1.3;
ctx.stroke();
}
for (const eSide of [-1, 1]) {
const eyeX = headPt.x + 8;
const eyeY = headPt.y + eSide * (headPt.width * 0.75);
ctx.beginPath();
ctx.arc(eyeX, eyeY, 3.2, 0, Math.PI * 2);
ctx.fillStyle = "#0f172a";
ctx.fill();
ctx.strokeStyle = "#f59e0b";
ctx.lineWidth = 1;
ctx.stroke();
ctx.fillStyle = "#ffffff";
ctx.beginPath();
ctx.arc(eyeX - 0.7, eyeY - 0.7, 0.8, 0, Math.PI * 2);
ctx.fill();
}
ctx.restore();
}
};
}
// Default parameters from content metadata
const defaultParams = [
{
"key": "swimSpeed",
"label": "Carp Swimming Rate",
"type": "range",
"min": 0.3,
"max": 1.6,
"step": 0.05,
"defaultValue": 0.75,
"description": "S-curve spinal propulsion frequency"
},
{
"key": "pondRipples",
"label": "Pond Water Caustics",
"type": "range",
"min": 0,
"max": 1.6,
"step": 0.1,
"defaultValue": 1,
"description": "Concentric water surface wave intensity"
},
{
"key": "kohakuHue",
"label": "Kohaku Vermilion Hue",
"type": "range",
"min": 0,
"max": 45,
"step": 2,
"defaultValue": 12,
"description": "Hue of traditional cinnabar red carp patches"
}
];
if (!window.__art_instances) window.__art_instances = {};
if (!window.__art_instances['japanese-koi']) {
const inst = typeof createJapaneseKoi === 'function' ? createJapaneseKoi() : null;
if (inst && inst.setup) {
inst.setup({ ctx, width, height, dpr: 1, aspectRatio: width / height }, defaultParams);
}
window.__art_instances['japanese-koi'] = inst;
}
const instance = window.__art_instances['japanese-koi'];
if (instance && instance.render) {
instance.render(
{ ctx, width, height, dpr: 1, aspectRatio: width / height },
{ time, deltaTime: dt, frameCount: Math.floor(time * 60), fps: 60 },
defaultParams
);
} Edit in Interactive Playground
Zero Dependencies • Standalone Canvas 2D
ƒ
Mathematical Formulation
high
Analytical Equation
rkoi(s,t)=[xsA(s)sin(ks−ωt)],ppectoral(θ)=pgirdle+L[cosθpsinθp]
Click to expand
∑
Imperial Japanese Nishikigoi
Full Mathematical System • creatures
100%
Complete System of Equations
[Governing Law][Discrete Progression][Domain & Space][Parameter State]rkoi(s,t)=[xsA(s)sin(ks−ωt)],ppectoral(θ)=pgirdle+L[cosθpsinθp]spine=sin(3t−s⋅2.4)⋅amp(s),skin=ivory+kohakupatches(s)x∈R2,t∈R+,ω∈[0,2π]λswimSpeed=0.75(Carp Swimming Rate),λpondRipples=1(Pond Water Caustics),λkohakuHue=12(Kohaku Vermilion Hue)
rkoi(s,t)=[xsA(s)sin(ks−ωt)],ppectoral(θ)=pgirdle+L[cosθpsinθp]
Computational Implementation (JavaScript Engine Equivalent)
spine = sin(3t - s*2.4)*amp(s), skin = ivory + kohaku_patches(s) Compact Formula
spine = sin(3t - s*2.4)*amp(s), skin = ivory + kohaku_patches(s) Mathematical Tags
#koi
#fish
#nishikigoi
#japanese
#kohaku
#creatures
#pond
#water
Author: Math Art Core Target: 60 FPS
Press ESC or F to exit