lonestar108 commited on
Commit
08f9588
·
verified ·
1 Parent(s): 2182d72

CREATE AN Entropic Creature lagoon -

Browse files

<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>Multi-Resonance Simulation</title>
<style>body,html{margin:0;overflow:hidden;background:#000}canvas{display:block}#controls{position:fixed;top:10px;left:10px;color:#fff;font-family:sans-serif;font-size:12px;max-height:95vh;overflow-y:auto;}input[type=range]{vertical-align:middle;width:100px}button{margin:5px 0}#stats,.control-group{margin-top:5px;padding:8px;background:rgba(255,255,255,0.1);border-radius:3px;width:200px}.control-group h3{margin:0 0 5px;font-weight:bold;color:#a78bfa;}</style>
</head>
<body>
<canvas id='c'></canvas>
<div id="controls">
<div id="stats">
Avg KE: <span id="keVal">0.00</span><br>
Current Drag: <span id="dragVal">0.00</span>
</div>
<div><button id="refresh">Refresh</button> <button id="randomize">Randomize</button></div>
</div>
<script>
(() => {
const M = Math;
const D = document;
const c = D.getElementById('c');
const x = c.getContext('2d');
let W = c.width = innerWidth;
let H = c.height = innerHeight;
window.onresize = () => { W = c.width = innerWidth; H = c.height = innerHeight; };

const ctrlDiv = D.getElementById('controls');
const P = {
minDist: 80, maxDist: 300, minDrag: 0.2, maxDrag: 0.9, count: 250, centerF: 0.005,
modulus: 12, phaseForce: 0.25,
bondDist: 90, bondStrength: 0.1,
coherenceThreshold: 0.75, coherenceForce: 0.2,
useDigitalRoot: true, useLogProximity: true
};
const ctrlConfig = {
count: { name:"Particles", min:50, max:300, step:1, needsInit:true, group: 'Global' },
phaseForce: { name:"Phase Force", min:0, max:1, step:0.01, f:v=>v.toFixed(2), group: 'Phase Dynamics' },
minDist: { name:"Min Dist", min:0, max:200, group: 'Phase Dynamics' },
maxDrag: { name:"Max Drag", min:0.1, max:0.99, step:0.01, f:v=>v.toFixed(2), group: 'Phase Dynamics' },
minDrag: { name:"Min Drag", min:0.01, max:0.5, step:0.01, f:v=>v.toFixed(2), group: 'Phase Dynamics' },
bondDist: { name:"Bond Distance", min:20, max:200, group: 'Crystallization' },
bondStrength: { name:"Bond Strength", min:0.01, max:0.5, step:0.01, f:v=>v.toFixed(2), group: 'Crystallization' },
coherenceThreshold: { name: "Threshold", min: 0, max: 1, step: 0.01, f:v=>v.toFixed(2), group: 'Coherence' },
coherenceForce: { name: "Force", min: 0, max: 1, step: 0.01, f:v=>v.toFixed(2), group: 'Coherence' },
modulus: { name:"Modulus", min:2, max:30, step:1, needsInit:true, group: 'Coherence' },
};

let particles = [];
let avgKE = 0;
let currentDrag = P.minDrag;

// --- UI Generation ---
const groups = {};
Object.keys(ctrlConfig).forEach(key => {
const conf = ctrlConfig[key];
if (!groups[conf.group]) groups[conf.group] = '';
const val = P[key];
groups[conf.group] += `<div>${conf.name}: <span id="${key}Val">${conf.f?conf.f(val):val}</span><br><input type="range" id="${key}" min="${conf.min}" max="${conf.max}" value="${val}" step="${conf.step||'any'}"></div>`;
});
groups['Coherence'] += `<div style="margin-top:10px;"><label><input type="checkbox" id="useDigitalRoot" ${P.useDigitalRoot ? 'checked' : ''}> Digital Root</label><br><label><input type="checkbox" id="useLogProximity" ${P.useLogProximity ? 'checked' : ''}> Log Proximity</label></div>`;
for (const groupName in groups) {
const groupDiv = D.createElement('div');
groupDiv.className = 'control-group';
groupDiv.innerHTML = `<h3>${groupName}</h3>${groups[groupName]}`;
ctrlDiv.appendChild(groupDiv);
}

Object.keys(ctrlConfig).forEach(key => {
D.getElementById(key).oninput = e => {
P[key] = +e.target.value;
D.getElementById(`${key}Val`).textContent = ctrlConfig[key].f ? ctrlConfig[key].f(P[key]) : P[key];
if(ctrlConfig[key].needsInit) init();
};
});

D.getElementById('useDigitalRoot').onchange = e => P.useDigitalRoot = e.target.checked;
D.getElementById('useLogProximity').onchange = e => P.useLogProximity = e.target.checked;

D.getElementById('refresh').onclick = init;
D.getElementById('randomize').onclick = () => {
Object.keys(ctrlConfig).forEach(key => {
const conf = ctrlConfig[key];
let val = conf.min + M.random() * (conf.max - conf.min);
if (conf.step) val = M.round(val / conf.step) * conf.step;
P[key] = +val.toFixed(4);
D.getElementById(key).value = P[key];
D.getElementById(`${key}Val`).textContent = conf.f ? conf.f(P[key]) : P[key];
});
P.useDigitalRoot = M.random() > 0.5;
D.getElementById('useDigitalRoot').checked = P.useDigitalRoot;
P.useLogProximity = M.random() > 0.5;
D.getElementById('useLogProximity').checked = P.useLogProximity;
init();
};

// --- HELPER FUNCTIONS & PARTICLE CLASS ---
const digitalRoot = n => 1 + ((n - 1) % 9);

function calculateCoherence(p1, p2) {
let features = [], weights = [];
const resDelta = M.abs(p1.residue - p2.residue), circDelta = M.min(resDelta, P.modulus - resDelta);
features.push(circDelta / (P.modulus / 2));
weights.push(1.0);
if (P.useDigitalRoot) {
const drDelta = M.abs(p1.digitalRoot - p2.digitalRoot);
features.push(drDelta / 8);
weights.push(0.8);
}
if (P.useLogProximity) {
const logDelta = M.abs(M.log(p1.value) - M.log(p2.value));
features.push(M.min(1, logDelta / M.log(P.count * 0.5)));
weights.push(0.6);
}
let weightedSum = 0, totalWeight = 0;
for (let i = 0; i < features.length; i++) {
weightedSum += features[i] * weights[i];
totalWeight += weights[i];
}
return 1 - (weightedSum / totalWeight);
}

class Particle {
constructor(i){
this.id = i;
this.value = i + 1;
this.residue = this.value % P.modulus;
this.digitalRoot = digitalRoot(this.value);
this.color = `hsl(${(this.residue / P.modulus) * 360}, 100%, 75%)`;
this.x = W/2 + (M.random()-0.5) * W*0.8;
this.y = H/2 + (M.random()-0.5) * H*0.8;
this.vx = M.random()*2-1;
this.vy = M.random()*2-1;
this.size = 2 + M.random();
this.phase = 180 + (M.random() * 20 - 10);
this.density = this.ax = this.ay = this.phaseInfluence = this.influenceCount = 0;
this.isLocked = false;
}

update(){
const lockKE = 1.0, unlockKE = 1.5, lockDensity = 3.5;
if (avgKE < lockKE && this.density < lockDensity && this.density > 0.5) {
this.isLocked = true;
} else if (avgKE > unlockKE) {
this.isLocked = false;
}

if (!this.isLocked) {
const densityTarget = 90 + (this.density - 5) * 15;
this.phase += (densityTarget - this.phase) * 0.01;
if (this.influenceCount > 0) this.phase += (this.phaseInfluence / this.influenceCount) * 0.02;
this.phase += (M.random() - 0.05);
this.phase = (this.phase % 360 + 360) % 360;
} else {
this.phase += (180 - this.phase) * 0.05;
}

this.vx=(this.vx+this.ax)*(1-currentDrag);
this.vy=(this.vy+this.ay)*(1-currentDrag);
this.x+=this.vx;
this.y+=this.vy;

const dC=M.hypot(W/2-this.x,H/2-this.y);
if(dC>0){
this.ax+=(W/2-this.x)/dC*P.centerF;
this.ay+=(H/2-this.y)/dC*P.centerF;
}

if(this.x<0||this.x>W){this.vx*=-1;this.x=M.max(0,M.min(W,this.x));}
if(this.y<0||this.y>H){this.vy*=-1;this.y=M.max(0,M.min(H,this.y));}
}

draw(){
x.globalCompositeOperation = 'source-over';
const coreColor = this.isLocked ? '#ffffff' : this.color;
x.fillStyle = coreColor;
x.beginPath();
x.arc(this.x,this.y,this.size,0,2*M.PI);
x.fill();
if (this.isLocked) {
x.strokeStyle = this.color;
x.lineWidth = .5;
x.stroke();
}
}
}

function init(){
if(!P.count||P.count<0)return;
particles=Array.from({length:M.floor(P.count)},(_,i)=>new Particle(i));
particles.forEach(p => {
p.residue = p.value % P.modulus;
p.color = `hsl(${(p.residue / P.modulus) * 360}, 100%, 75%)`;
});
}

function animate(){
x.fillStyle='rgba(0,0,0,0.2)'; x.fillRect(0,0,W,H);
if(!particles.length){requestAnimationFrame(animate);return;}

let totalKE = 0;
particles.forEach(p => {
p.ax=p.ay=p.density=p.phaseInfluence=p.influenceCount=0;
totalKE += 0.5 * (p.vx*p.vx + p.vy*p.vy);
});
avgKE = totalKE / P.count;
const energyRatio = M.max(0, M.min(1, (avgKE - 0.5) / 5));
currentDrag = P.maxDrag - energyRatio * (P.maxDrag - P.minDrag);

D.getElementById('keVal').textContent = avgKE.toFixed(2);
D.getElementById('dragVal').textContent = currentDrag.toFixed(2);

const grid = new Map(), cellSize = 200;
for (const p of particles) { const key = `${M.floor(p.x/cellSize)},${M.floor(p.y/cellSize)}`; if (!grid.has(key)) grid.set(key, []); grid.get(key).push(p); }

for (const p1 of particles) {
const gX=M.floor(p1.x/cellSize), gY=M.floor(p1.y/cellSize);
for(let dx=-1;dx<=1;dx++){
for(let dy=-1;dy<=1;dy++){
const neighbors=grid.get(`${gX+dx},${gY+dy}`);
if(!neighbors) continue;
for(const p2 of neighbors){
if(p1.id>=p2.id) continue;
const dX=p1.x-p2.x, dY=p1.y-p2.y, distSq=dX*dX+dY*dY;
if(distSq > cellSize*cellSi

Files changed (2) hide show
  1. README.md +6 -4
  2. index.html +439 -18
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Entropic Creatures
3
- emoji: 🐨
4
  colorFrom: yellow
5
- colorTo: green
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: entropic-creatures
3
+ emoji: 🐳
4
  colorFrom: yellow
5
+ colorTo: blue
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,440 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Entropic Creature Lagoon</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://unpkg.com/feather-icons"></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
10
+ <style>
11
+ body, html {
12
+ margin: 0;
13
+ padding: 0;
14
+ overflow: hidden;
15
+ background: #000;
16
+ font-family: 'Inter', sans-serif;
17
+ }
18
+ canvas {
19
+ display: block;
20
+ }
21
+ #controls {
22
+ position: fixed;
23
+ top: 20px;
24
+ left: 20px;
25
+ color: #fff;
26
+ background: rgba(0, 0, 0, 0.7);
27
+ backdrop-filter: blur(10px);
28
+ border-radius: 12px;
29
+ padding: 16px;
30
+ max-height: 90vh;
31
+ overflow-y: auto;
32
+ box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
33
+ border: 1px solid rgba(255, 255, 255, 0.1);
34
+ z-index: 100;
35
+ width: 280px;
36
+ }
37
+ .control-group {
38
+ margin-bottom: 16px;
39
+ padding-bottom: 16px;
40
+ border-bottom: 1px solid rgba(255, 255, 255, 0.1);
41
+ }
42
+ .control-group:last-child {
43
+ border-bottom: none;
44
+ margin-bottom: 0;
45
+ padding-bottom: 0;
46
+ }
47
+ .control-group h3 {
48
+ margin: 0 0 12px;
49
+ font-weight: 600;
50
+ color: #a78bfa;
51
+ font-size: 14px;
52
+ text-transform: uppercase;
53
+ letter-spacing: 0.5px;
54
+ }
55
+ .control-row {
56
+ margin-bottom: 10px;
57
+ }
58
+ .control-row label {
59
+ display: block;
60
+ font-size: 12px;
61
+ margin-bottom: 4px;
62
+ color: rgba(255, 255, 255, 0.8);
63
+ }
64
+ input[type="range"] {
65
+ width: 100%;
66
+ height: 4px;
67
+ background: rgba(255, 255, 255, 0.1);
68
+ border-radius: 2px;
69
+ -webkit-appearance: none;
70
+ }
71
+ input[type="range"]::-webkit-slider-thumb {
72
+ -webkit-appearance: none;
73
+ width: 14px;
74
+ height: 14px;
75
+ border-radius: 50%;
76
+ background: #a78bfa;
77
+ cursor: pointer;
78
+ }
79
+ .value-display {
80
+ font-size: 12px;
81
+ color: #fff;
82
+ margin-top: 4px;
83
+ }
84
+ #stats {
85
+ background: rgba(255, 255, 255, 0.1);
86
+ padding: 12px;
87
+ border-radius: 8px;
88
+ margin-bottom: 16px;
89
+ }
90
+ #stats p {
91
+ margin: 0;
92
+ font-size: 12px;
93
+ display: flex;
94
+ justify-content: space-between;
95
+ }
96
+ button {
97
+ background: rgba(167, 139, 250, 0.2);
98
+ color: #a78bfa;
99
+ border: 1px solid rgba(167, 139, 250, 0.3);
100
+ border-radius: 6px;
101
+ padding: 8px 12px;
102
+ font-size: 12px;
103
+ cursor: pointer;
104
+ transition: all 0.2s;
105
+ margin-right: 8px;
106
+ margin-bottom: 8px;
107
+ }
108
+ button:hover {
109
+ background: rgba(167, 139, 250, 0.3);
110
+ }
111
+ .checkbox-container {
112
+ display: flex;
113
+ align-items: center;
114
+ margin-top: 8px;
115
+ }
116
+ .checkbox-container input {
117
+ margin-right: 8px;
118
+ }
119
+ .checkbox-container label {
120
+ margin: 0;
121
+ font-size: 12px;
122
+ }
123
+ #title {
124
+ position: fixed;
125
+ bottom: 20px;
126
+ left: 20px;
127
+ color: rgba(255, 255, 255, 0.5);
128
+ font-size: 12px;
129
+ z-index: 100;
130
+ }
131
+ </style>
132
+ </head>
133
+ <body class="bg-black">
134
+ <canvas id="c"></canvas>
135
+
136
+ <div id="controls">
137
+ <div id="stats">
138
+ <p>Avg KE: <span id="keVal" class="font-mono">0.00</span></p>
139
+ <p>Current Drag: <span id="dragVal" class="font-mono">0.00</span></p>
140
+ </div>
141
+
142
+ <div class="flex flex-wrap mb-4">
143
+ <button id="refresh" class="flex items-center">
144
+ <i data-feather="refresh-cw" class="w-3 h-3 mr-2"></i> Refresh
145
+ </button>
146
+ <button id="randomize" class="flex items-center">
147
+ <i data-feather="shuffle" class="w-3 h-3 mr-2"></i> Randomize
148
+ </button>
149
+ </div>
150
+
151
+ <div id="control-groups"></div>
152
+ </div>
153
+
154
+ <div id="title">Entropic Creature Lagoon</div>
155
+
156
+ <script>
157
+ feather.replace();
158
+
159
+ (() => {
160
+ const M = Math;
161
+ const D = document;
162
+ const c = D.getElementById('c');
163
+ const x = c.getContext('2d');
164
+ let W = c.width = innerWidth;
165
+ let H = c.height = innerHeight;
166
+ window.onresize = () => { W = c.width = innerWidth; H = c.height = innerHeight; };
167
+
168
+ const ctrlDiv = D.getElementById('control-groups');
169
+ const P = {
170
+ minDist: 80, maxDist: 300, minDrag: 0.2, maxDrag: 0.9, count: 250, centerF: 0.005,
171
+ modulus: 12, phaseForce: 0.25,
172
+ bondDist: 90, bondStrength: 0.1,
173
+ coherenceThreshold: 0.75, coherenceForce: 0.2,
174
+ useDigitalRoot: true, useLogProximity: true
175
+ };
176
+ const ctrlConfig = {
177
+ count: { name:"Particles", min:50, max:300, step:1, needsInit:true, group: 'Global' },
178
+ phaseForce: { name:"Phase Force", min:0, max:1, step:0.01, f:v=>v.toFixed(2), group: 'Phase Dynamics' },
179
+ minDist: { name:"Min Distance", min:0, max:200, group: 'Phase Dynamics' },
180
+ maxDrag: { name:"Max Drag", min:0.1, max:0.99, step:0.01, f:v=>v.toFixed(2), group: 'Phase Dynamics' },
181
+ minDrag: { name:"Min Drag", min:0.01, max:0.5, step:0.01, f:v=>v.toFixed(2), group: 'Phase Dynamics' },
182
+ bondDist: { name:"Bond Distance", min:20, max:200, group: 'Crystallization' },
183
+ bondStrength: { name:"Bond Strength", min:0.01, max:0.5, step:0.01, f:v=>v.toFixed(2), group: 'Crystallization' },
184
+ coherenceThreshold: { name: "Coherence Threshold", min: 0, max: 1, step: 0.01, f:v=>v.toFixed(2), group: 'Coherence' },
185
+ coherenceForce: { name: "Coherence Force", min: 0, max: 1, step: 0.01, f:v=>v.toFixed(2), group: 'Coherence' },
186
+ modulus: { name:"Modulus", min:2, max:30, step:1, needsInit:true, group: 'Coherence' },
187
+ };
188
+
189
+ let particles = [];
190
+ let avgKE = 0;
191
+ let currentDrag = P.minDrag;
192
+
193
+ // --- UI Generation ---
194
+ const groups = {};
195
+ Object.keys(ctrlConfig).forEach(key => {
196
+ const conf = ctrlConfig[key];
197
+ if (!groups[conf.group]) groups[conf.group] = '';
198
+ const val = P[key];
199
+ groups[conf.group] += `
200
+ <div class="control-row">
201
+ <label for="${key}">${conf.name}</label>
202
+ <input type="range" id="${key}" min="${conf.min}" max="${conf.max}" value="${val}" step="${conf.step||'any'}">
203
+ <div class="value-display" id="${key}Val">${conf.f?conf.f(val):val}</div>
204
+ </div>
205
+ `;
206
+ });
207
+
208
+ for (const groupName in groups) {
209
+ const groupDiv = D.createElement('div');
210
+ groupDiv.className = 'control-group';
211
+ groupDiv.innerHTML = `
212
+ <h3>${groupName}</h3>
213
+ ${groups[groupName]}
214
+ ${groupName === 'Coherence' ? `
215
+ <div class="checkbox-container">
216
+ <input type="checkbox" id="useDigitalRoot" ${P.useDigitalRoot ? 'checked' : ''}>
217
+ <label for="useDigitalRoot">Digital Root</label>
218
+ </div>
219
+ <div class="checkbox-container">
220
+ <input type="checkbox" id="useLogProximity" ${P.useLogProximity ? 'checked' : ''}>
221
+ <label for="useLogProximity">Log Proximity</label>
222
+ </div>
223
+ ` : ''}
224
+ `;
225
+ ctrlDiv.appendChild(groupDiv);
226
+ }
227
+
228
+ Object.keys(ctrlConfig).forEach(key => {
229
+ D.getElementById(key).oninput = e => {
230
+ P[key] = +e.target.value;
231
+ D.getElementById(`${key}Val`).textContent = ctrlConfig[key].f ? ctrlConfig[key].f(P[key]) : P[key];
232
+ if(ctrlConfig[key].needsInit) init();
233
+ };
234
+ });
235
+
236
+ D.getElementById('useDigitalRoot').onchange = e => P.useDigitalRoot = e.target.checked;
237
+ D.getElementById('useLogProximity').onchange = e => P.useLogProximity = e.target.checked;
238
+
239
+ D.getElementById('refresh').onclick = init;
240
+ D.getElementById('randomize').onclick = () => {
241
+ Object.keys(ctrlConfig).forEach(key => {
242
+ const conf = ctrlConfig[key];
243
+ let val = conf.min + M.random() * (conf.max - conf.min);
244
+ if (conf.step) val = M.round(val / conf.step) * conf.step;
245
+ P[key] = +val.toFixed(4);
246
+ D.getElementById(key).value = P[key];
247
+ D.getElementById(`${key}Val`).textContent = conf.f ? conf.f(P[key]) : P[key];
248
+ });
249
+ P.useDigitalRoot = M.random() > 0.5;
250
+ D.getElementById('useDigitalRoot').checked = P.useDigitalRoot;
251
+ P.useLogProximity = M.random() > 0.5;
252
+ D.getElementById('useLogProximity').checked = P.useLogProximity;
253
+ init();
254
+ };
255
+
256
+ // --- HELPER FUNCTIONS & PARTICLE CLASS ---
257
+ const digitalRoot = n => 1 + ((n - 1) % 9);
258
+
259
+ function calculateCoherence(p1, p2) {
260
+ let features = [], weights = [];
261
+ const resDelta = M.abs(p1.residue - p2.residue), circDelta = M.min(resDelta, P.modulus - resDelta);
262
+ features.push(circDelta / (P.modulus / 2));
263
+ weights.push(1.0);
264
+ if (P.useDigitalRoot) {
265
+ const drDelta = M.abs(p1.digitalRoot - p2.digitalRoot);
266
+ features.push(drDelta / 8);
267
+ weights.push(0.8);
268
+ }
269
+ if (P.useLogProximity) {
270
+ const logDelta = M.abs(M.log(p1.value) - M.log(p2.value));
271
+ features.push(M.min(1, logDelta / M.log(P.count * 0.5)));
272
+ weights.push(0.6);
273
+ }
274
+ let weightedSum = 0, totalWeight = 0;
275
+ for (let i = 0; i < features.length; i++) {
276
+ weightedSum += features[i] * weights[i];
277
+ totalWeight += weights[i];
278
+ }
279
+ return 1 - (weightedSum / totalWeight);
280
+ }
281
+
282
+ class Particle {
283
+ constructor(i){
284
+ this.id = i;
285
+ this.value = i + 1;
286
+ this.residue = this.value % P.modulus;
287
+ this.digitalRoot = digitalRoot(this.value);
288
+ this.color = `hsl(${(this.residue / P.modulus) * 360}, 100%, 75%)`;
289
+ this.x = W/2 + (M.random()-0.5) * W*0.8;
290
+ this.y = H/2 + (M.random()-0.5) * H*0.8;
291
+ this.vx = M.random()*2-1;
292
+ this.vy = M.random()*2-1;
293
+ this.size = 2 + M.random();
294
+ this.phase = 180 + (M.random() * 20 - 10);
295
+ this.density = this.ax = this.ay = this.phaseInfluence = this.influenceCount = 0;
296
+ this.isLocked = false;
297
+ }
298
+
299
+ update(){
300
+ const lockKE = 1.0, unlockKE = 1.5, lockDensity = 3.5;
301
+ if (avgKE < lockKE && this.density < lockDensity && this.density > 0.5) {
302
+ this.isLocked = true;
303
+ } else if (avgKE > unlockKE) {
304
+ this.isLocked = false;
305
+ }
306
+
307
+ if (!this.isLocked) {
308
+ const densityTarget = 90 + (this.density - 5) * 15;
309
+ this.phase += (densityTarget - this.phase) * 0.01;
310
+ if (this.influenceCount > 0) this.phase += (this.phaseInfluence / this.influenceCount) * 0.02;
311
+ this.phase += (M.random() - 0.05);
312
+ this.phase = (this.phase % 360 + 360) % 360;
313
+ } else {
314
+ this.phase += (180 - this.phase) * 0.05;
315
+ }
316
+
317
+ this.vx=(this.vx+this.ax)*(1-currentDrag);
318
+ this.vy=(this.vy+this.ay)*(1-currentDrag);
319
+ this.x+=this.vx;
320
+ this.y+=this.vy;
321
+
322
+ const dC=M.hypot(W/2-this.x,H/2-this.y);
323
+ if(dC>0){
324
+ this.ax+=(W/2-this.x)/dC*P.centerF;
325
+ this.ay+=(H/2-this.y)/dC*P.centerF;
326
+ }
327
+
328
+ if(this.x<0||this.x>W){this.vx*=-1;this.x=M.max(0,M.min(W,this.x));}
329
+ if(this.y<0||this.y>H){this.vy*=-1;this.y=M.max(0,M.min(H,this.y));}
330
+ }
331
+
332
+ draw(){
333
+ x.globalCompositeOperation = 'source-over';
334
+ const coreColor = this.isLocked ? '#ffffff' : this.color;
335
+ x.fillStyle = coreColor;
336
+ x.beginPath();
337
+ x.arc(this.x,this.y,this.size,0,2*M.PI);
338
+ x.fill();
339
+ if (this.isLocked) {
340
+ x.strokeStyle = this.color;
341
+ x.lineWidth = .5;
342
+ x.stroke();
343
+ }
344
+ }
345
+ }
346
+
347
+ function init(){
348
+ if(!P.count||P.count<0)return;
349
+ particles=Array.from({length:M.floor(P.count)},(_,i)=>new Particle(i));
350
+ particles.forEach(p => {
351
+ p.residue = p.value % P.modulus;
352
+ p.color = `hsl(${(p.residue / P.modulus) * 360}, 100%, 75%)`;
353
+ });
354
+ }
355
+
356
+ function animate(){
357
+ x.fillStyle='rgba(0,0,0,0.2)'; x.fillRect(0,0,W,H);
358
+ if(!particles.length){requestAnimationFrame(animate);return;}
359
+
360
+ let totalKE = 0;
361
+ particles.forEach(p => {
362
+ p.ax=p.ay=p.density=p.phaseInfluence=p.influenceCount=0;
363
+ totalKE += 0.5 * (p.vx*p.vx + p.vy*p.vy);
364
+ });
365
+ avgKE = totalKE / P.count;
366
+ const energyRatio = M.max(0, M.min(1, (avgKE - 0.5) / 5));
367
+ currentDrag = P.maxDrag - energyRatio * (P.maxDrag - P.minDrag);
368
+
369
+ D.getElementById('keVal').textContent = avgKE.toFixed(2);
370
+ D.getElementById('dragVal').textContent = currentDrag.toFixed(2);
371
+
372
+ const grid = new Map(), cellSize = 200;
373
+ for (const p of particles) { const key = `${M.floor(p.x/cellSize)},${M.floor(p.y/cellSize)}`; if (!grid.has(key)) grid.set(key, []); grid.get(key).push(p); }
374
+
375
+ for (const p1 of particles) {
376
+ const gX=M.floor(p1.x/cellSize), gY=M.floor(p1.y/cellSize);
377
+ for(let dx=-1;dx<=1;dx++){
378
+ for(let dy=-1;dy<=1;dy++){
379
+ const neighbors=grid.get(`${gX+dx},${gY+dy}`);
380
+ if(!neighbors) continue;
381
+ for(const p2 of neighbors){
382
+ if(p1.id>=p2.id) continue;
383
+ const dX=p1.x-p2.x, dY=p1.y-p2.y, distSq=dX*dX+dY*dY;
384
+ if(distSq > cellSize*cellSize || distSq === 0) continue;
385
+ const dist=M.sqrt(distSq);
386
+
387
+ const coherenceScore = calculateCoherence(p1, p2);
388
+ if (coherenceScore > P.coherenceThreshold) {
389
+ const forceMag = (coherenceScore - P.coherenceThreshold) / (1 - P.coherenceThreshold);
390
+ const force = forceMag * P.coherenceForce * -1;
391
+ const fX = (dX / dist) * force, fY = (dY / dist) * force;
392
+ p1.ax += fX; p1.ay += fY;
393
+ p2.ax -= fX; p2.ay -= fY;
394
+ }
395
+
396
+ if (p1.isLocked && p2.isLocked && dist < P.bondDist) {
397
+ const restLength = P.minDist * 0.9;
398
+ const displacement = dist - restLength;
399
+ const force = displacement * P.bondStrength;
400
+ const fX = (dX / dist) * force, fY = (dY / dist) * force;
401
+ p1.ax -= fX; p1.ay -= fY;
402
+ p2.ax += fX; p2.ay += fY;
403
+
404
+ const opacity = M.max(0, 1 - M.abs(displacement) / restLength) * 0.09;
405
+ const grad = x.createLinearGradient(p1.x, p1.y, p2.x, p2.y);
406
+ grad.addColorStop(0, p1.color.replace(')', `, ${opacity})`).replace('hsl', 'hsla'));
407
+ grad.addColorStop(1, p2.color.replace(')', `, ${opacity})`).replace('hsl', 'hsla'));
408
+ x.strokeStyle = grad;
409
+ x.lineWidth = 1.5;
410
+ x.beginPath(); x.moveTo(p1.x, p1.y); x.lineTo(p2.x, p2.y); x.stroke();
411
+
412
+ } else {
413
+ if (coherenceScore > P.coherenceThreshold) {
414
+ x.setLineDash([2, 3]);
415
+ const hue = 60 - (coherenceScore - P.coherenceThreshold) * 60;
416
+ const opacity = (coherenceScore - P.coherenceThreshold) * 0.5 * (1 - dist/cellSize);
417
+ x.strokeStyle = `hsla(${hue}, 100%, 70%, ${M.max(0, opacity)})`;
418
+ x.lineWidth = 0.3;
419
+ x.beginPath(); x.moveTo(p1.x, p1.y); x.lineTo(p2.x, p2.y); x.stroke();
420
+ x.setLineDash([]);
421
+ }
422
+ const t1=(p1.phase%360)/180, t2=(p2.phase%360)/180; const attr1=2-t1, rep1=t1, attr2=2-t2, rep2=t2; let f1=0, f2=0; if(dist < P.minDist){ const f = (P.minDist - dist) / P.minDist * P.phaseForce; f1 = f * rep1; f2 = f * rep2; } else if (dist < P.maxDist) { const f = (dist - P.minDist) / P.maxDist * P.phaseForce; const resDelta = M.abs(p1.residue - p2.residue); const circDelta = M.min(resDelta, P.modulus - resDelta); const residueCompat = 1 - (circDelta / (P.modulus / 2)); f1 = f * attr1 * M.max(0, residueCompat) * -1; f2 = f * attr2 * M.max(0, residueCompat) * -1; } const fX1 = (dX / dist) * f1, fY1 = (dY / dist) * f1; p1.ax += fX1; p1.ay += fY1; p2.ax -= fX1; p2.ay -= fY1; const fX2 = (dX / dist) * f2, fY2 = (dY / dist) * f2; p1.ax += fX2; p1.ay += fY2; p2.ax -= fX2; p2.ay -= fY2;
423
+ }
424
+
425
+ if (distSq < P.minDist*P.minDist * 2.25) { const w = 1 - dist / (P.minDist * 1.5); p1.density += w; p2.density += w; }
426
+ if (distSq < P.minDist*P.minDist * 4 && !p1.isLocked && !p2.isLocked) { const w = 1 - dist / (P.minDist * 2); let pD = p2.phase - p1.phase; pD = (pD + 540) % 360 - 180; p1.phaseInfluence += pD * w; p2.phaseInfluence -= pD * w; p1.influenceCount += w; p2.influenceCount += w; }
427
+ }
428
+ }
429
+ }
430
+ }
431
+
432
+ particles.forEach(p=>{p.update();p.draw();});
433
+ requestAnimationFrame(animate);
434
+ }
435
+ init();
436
+ animate();
437
+ })();
438
+ </script>
439
+ </body>
440
  </html>