LordXido commited on
Commit
a3ea276
·
verified ·
1 Parent(s): 6111ef8

Update main.js

Browse files
Files changed (1) hide show
  1. main.js +100 -55
main.js CHANGED
@@ -1,103 +1,141 @@
1
- // ===============================
2
- // CodexReality3D — Operational Core
3
- // ===============================
4
 
 
5
  const canvas = document.getElementById("viewport");
6
  const ctx = canvas.getContext("2d");
7
 
 
 
 
 
 
 
 
 
8
  const log = document.getElementById("log");
9
  const input = document.getElementById("input");
10
 
11
- canvas.width = window.innerWidth - 360;
12
- canvas.height = window.innerHeight;
13
-
14
- // ---------- Utilities ----------
15
- function print(msg){
16
  log.innerHTML += msg + "<br/>";
17
  log.scrollTop = log.scrollHeight;
18
  }
19
 
20
- // ---------- World Field ----------
21
  const W = 200;
22
  const H = 200;
23
 
 
24
  let field = new Float32Array(W * H);
25
 
26
- // ---------- System Parameters ----------
27
- let Psi = 0.01; // intent injection
28
- let sigma = 0.5; // superposition mixing
29
  let running = true;
30
- let time = 0;
31
 
32
- // ---------- Initialize Field ----------
33
- for(let i=0;i<field.length;i++){
34
- field[i] = Math.random();
 
 
 
 
 
35
  }
 
36
 
37
- // ---------- Evolution Operator Φ ----------
38
- function evolve(){
39
- let next = new Float32Array(field.length);
40
 
41
- for(let y=1;y<H-1;y++){
42
- for(let x=1;x<W-1;x++){
43
- const i = y*W + x;
44
 
45
  const laplace =
46
- field[i-1] + field[i+1] +
47
- field[i-W] + field[i+W] -
48
- 4*field[i];
 
 
49
 
50
  next[i] =
51
- (1-sigma)*field[i] +
52
- sigma*(field[i] + 0.25*laplace) +
53
  Psi;
54
  }
55
  }
56
-
57
  field = next;
58
  }
59
 
60
- // ---------- Rendering ----------
61
- function render(){
62
  const img = ctx.createImageData(W, H);
63
 
64
- for(let i=0;i<field.length;i++){
65
  const v = Math.max(0, Math.min(1, field[i]));
66
  const c = Math.floor(v * 255);
67
 
68
- img.data[i*4+0] = c;
69
- img.data[i*4+1] = c;
70
- img.data[i*4+2] = 255;
71
- img.data[i*4+3] = 255;
72
  }
73
 
74
  ctx.putImageData(img, 0, 0);
75
  ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height);
76
  }
77
 
78
- // ---------- Main Loop ----------
79
- function loop(){
80
- if(running){
81
  evolve();
82
- time++;
83
  }
84
  render();
85
  requestAnimationFrame(loop);
86
  }
87
-
88
  loop();
89
 
90
- // ---------- Command Interface ----------
91
- function handle(cmd){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  const p = cmd.split(" ");
93
- switch(p[0]){
 
94
  case "help":
95
  print("Commands:");
96
- print(" inject <value>");
97
- print(" superposition <value>");
98
- print(" pause");
99
- print(" resume");
100
  print(" reset");
 
 
101
  break;
102
 
103
  case "inject":
@@ -121,25 +159,32 @@ function handle(cmd){
121
  break;
122
 
123
  case "reset":
124
- for(let i=0;i<field.length;i++){
125
- field[i] = Math.random();
126
- }
127
  print("World reset");
128
  break;
129
 
 
 
 
 
 
 
 
 
130
  default:
131
- print("Unknown command");
132
  }
133
  }
134
 
135
- input.addEventListener("keydown", e=>{
136
- if(e.key==="Enter"){
 
137
  print("> " + input.value);
138
  handle(input.value.trim());
139
  input.value = "";
140
  }
141
  });
142
 
143
- // ---------- Boot ----------
144
- print("CodexReality3D Operational");
145
  print("Type `help`");
 
1
+ // =================================================
2
+ // CodexReality3D v4 Field + Branching World Engine
3
+ // =================================================
4
 
5
+ // ----- Canvas -----
6
  const canvas = document.getElementById("viewport");
7
  const ctx = canvas.getContext("2d");
8
 
9
+ function resize() {
10
+ canvas.width = window.innerWidth - 380;
11
+ canvas.height = window.innerHeight;
12
+ }
13
+ window.addEventListener("resize", resize);
14
+ resize();
15
+
16
+ // ----- Console -----
17
  const log = document.getElementById("log");
18
  const input = document.getElementById("input");
19
 
20
+ function print(msg) {
 
 
 
 
21
  log.innerHTML += msg + "<br/>";
22
  log.scrollTop = log.scrollHeight;
23
  }
24
 
25
+ // ----- World Parameters -----
26
  const W = 200;
27
  const H = 200;
28
 
29
+ // ----- World State Ξ -----
30
  let field = new Float32Array(W * H);
31
 
32
+ // ----- System Controls -----
33
+ let Psi = 0.01; // intent injection
34
+ let sigma = 0.5; // superposition
35
  let running = true;
36
+ let t = 0;
37
 
38
+ // ----- Ω Memory (Branching Timelines) -----
39
+ const snapshots = {};
40
+
41
+ // ----- Initialize -----
42
+ function resetField() {
43
+ for (let i = 0; i < field.length; i++) {
44
+ field[i] = Math.random();
45
+ }
46
  }
47
+ resetField();
48
 
49
+ // ----- Evolution Operator Φ -----
50
+ function evolve() {
51
+ const next = new Float32Array(field.length);
52
 
53
+ for (let y = 1; y < H - 1; y++) {
54
+ for (let x = 1; x < W - 1; x++) {
55
+ const i = y * W + x;
56
 
57
  const laplace =
58
+ field[i - 1] +
59
+ field[i + 1] +
60
+ field[i - W] +
61
+ field[i + W] -
62
+ 4 * field[i];
63
 
64
  next[i] =
65
+ (1 - sigma) * field[i] +
66
+ sigma * (field[i] + 0.25 * laplace) +
67
  Psi;
68
  }
69
  }
 
70
  field = next;
71
  }
72
 
73
+ // ----- Rendering Θ -----
74
+ function render() {
75
  const img = ctx.createImageData(W, H);
76
 
77
+ for (let i = 0; i < field.length; i++) {
78
  const v = Math.max(0, Math.min(1, field[i]));
79
  const c = Math.floor(v * 255);
80
 
81
+ img.data[i * 4 + 0] = c;
82
+ img.data[i * 4 + 1] = c;
83
+ img.data[i * 4 + 2] = 255;
84
+ img.data[i * 4 + 3] = 255;
85
  }
86
 
87
  ctx.putImageData(img, 0, 0);
88
  ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height);
89
  }
90
 
91
+ // ----- Main Loop -----
92
+ function loop() {
93
+ if (running) {
94
  evolve();
95
+ t++;
96
  }
97
  render();
98
  requestAnimationFrame(loop);
99
  }
 
100
  loop();
101
 
102
+ // ----- Ω Snapshot System -----
103
+ function snapshot(name) {
104
+ snapshots[name] = {
105
+ field: field.slice(),
106
+ Psi,
107
+ sigma,
108
+ t
109
+ };
110
+ print(`Ω snapshot saved: ${name}`);
111
+ }
112
+
113
+ function restore(name) {
114
+ if (!snapshots[name]) {
115
+ print("No such snapshot.");
116
+ return;
117
+ }
118
+ const s = snapshots[name];
119
+ field = s.field.slice();
120
+ Psi = s.Psi;
121
+ sigma = s.sigma;
122
+ t = s.t;
123
+ print(`Ω restored: ${name}`);
124
+ }
125
+
126
+ // ----- CLI / Chat Command Interface -----
127
+ function handle(cmd) {
128
  const p = cmd.split(" ");
129
+
130
+ switch (p[0]) {
131
  case "help":
132
  print("Commands:");
133
+ print(" inject <v> (Ψ)");
134
+ print(" superposition <v> (σ)");
135
+ print(" pause | resume");
 
136
  print(" reset");
137
+ print(" snapshot <name> (Ω)");
138
+ print(" restore <name>");
139
  break;
140
 
141
  case "inject":
 
159
  break;
160
 
161
  case "reset":
162
+ resetField();
 
 
163
  print("World reset");
164
  break;
165
 
166
+ case "snapshot":
167
+ snapshot(p[1] || `t${t}`);
168
+ break;
169
+
170
+ case "restore":
171
+ restore(p[1]);
172
+ break;
173
+
174
  default:
175
+ print("Unknown command. Type `help`.");
176
  }
177
  }
178
 
179
+ // ----- Input Handler -----
180
+ input.addEventListener("keydown", e => {
181
+ if (e.key === "Enter") {
182
  print("> " + input.value);
183
  handle(input.value.trim());
184
  input.value = "";
185
  }
186
  });
187
 
188
+ // ----- Boot -----
189
+ print("CodexReality3D v4 — Operational");
190
  print("Type `help`");