LordXido commited on
Commit
a3394f4
·
verified ·
1 Parent(s): d52a8ee

Update main.js

Browse files
Files changed (1) hide show
  1. main.js +106 -47
main.js CHANGED
@@ -1,86 +1,145 @@
1
- // CodexReality3D — GUI + CLI Chat Engine (HF Ready)
 
 
 
 
 
2
 
3
  const log = document.getElementById("log");
4
  const input = document.getElementById("input");
5
- const canvas = document.getElementById("viewport");
6
 
7
- function print(msg) {
 
 
 
 
8
  log.innerHTML += msg + "<br/>";
9
  log.scrollTop = log.scrollHeight;
10
  }
11
 
12
- // ---- Engine State (Simulated Core) ----
13
- const engine = {
14
- paused: false,
15
- psi: 1.0,
16
- superposition: 0.5,
17
-
18
- injectPsi(v) {
19
- this.psi = v;
20
- print(`Ψ injected → ${v}`);
21
- },
22
-
23
- setSuperposition(v) {
24
- this.superposition = v;
25
- print(`Superposition set → ${v}`);
26
- },
27
-
28
- pause() {
29
- this.paused = true;
30
- print("⏸ Simulation paused");
31
- },
32
-
33
- resume() {
34
- this.paused = false;
35
- print("▶ Simulation resumed");
 
 
 
 
 
 
 
 
 
 
 
36
  }
37
- };
38
 
39
- // ---- Command Interpreter ----
40
- function handleCommand(cmd) {
41
- const parts = cmd.trim().split(" ");
42
- const op = parts[0];
43
- const arg = parseFloat(parts[1]);
44
 
45
- switch (op) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  case "help":
47
  print("Commands:");
48
  print(" inject <value>");
49
  print(" superposition <value>");
50
  print(" pause");
51
  print(" resume");
 
52
  break;
53
 
54
  case "inject":
55
- engine.injectPsi(isNaN(arg) ? 1.0 : arg);
 
56
  break;
57
 
58
  case "superposition":
59
- engine.setSuperposition(isNaN(arg) ? 0.5 : arg);
 
60
  break;
61
 
62
  case "pause":
63
- engine.pause();
 
64
  break;
65
 
66
  case "resume":
67
- engine.resume();
 
 
 
 
 
 
 
 
68
  break;
69
 
70
  default:
71
- print("Unknown command. Type `help`.");
72
  }
73
  }
74
 
75
- // ---- Input Handler ----
76
- input.addEventListener("keydown", e => {
77
- if (e.key === "Enter") {
78
- print(`> ${input.value}`);
79
- handleCommand(input.value);
80
  input.value = "";
81
  }
82
  });
83
 
84
- // ---- Boot ----
85
- print("CodexReality3D Console Ready");
86
- print("Type `help` to begin.");
 
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":
104
+ Psi = parseFloat(p[1]) || Psi;
105
+ print("Ψ = " + Psi);
106
  break;
107
 
108
  case "superposition":
109
+ sigma = parseFloat(p[1]) || sigma;
110
+ print("σ = " + sigma);
111
  break;
112
 
113
  case "pause":
114
+ running = false;
115
+ print("Simulation paused");
116
  break;
117
 
118
  case "resume":
119
+ running = true;
120
+ print("Simulation resumed");
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`");