-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
231 lines (211 loc) · 6.29 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML 5 Canvas Animation Example - Cellular Automata</title>
<link rel="stylesheet" type="text/css" href="styles.css"/>
<meta http-equiv="Content-Style-Type" content="text/css"/>
<meta http-equiv="expires" content="Wed, 26 Feb 1993 08:21:57 GMT"/>
<script language="javascript">
var c=1;
var t;
var x=0;
var pixelSize = 4;
var width = 70;
var height = 40
var prev = new Array(2800);
var next = new Array(2800);
function loadGosperGliderGunSE() {
var x = 30;
var y = 20;
// origin is at 0,0 lower right
prev[(x)+ (width*(y-1))]=1;
prev[(x-1) + (width * (y))]=1;
prev[(x-1) + (width * (y-1))]=1;
prev[(x-2) + (width * (y-2))]=1;
prev[(x) + (width * (y-2))]=1;
// end of glider
prev[(x+10) + (width * (y-8))]=1;
prev[(x+10) + (width * (y-9))]=1;
prev[(x+11) + (width * (y-8))]=1;
prev[(x+11) + (width * (y-9))]=1;
prev[(x+6) + (width * (y-6))]=1;
prev[(x+6) + (width * (y-7))]=1;
prev[(x+1) + (width * (y-5))]=1;
prev[(x+1) + (width * (y-6))]=1;
prev[(x+1) + (width * (y-10))]=1;
prev[(x+1) + (width * (y-11))]=1;
prev[(x) + (width * (y-6))]=1;
prev[(x) + (width * (y-7))]=1;
prev[(x) + (width * (y-8))]=1;
prev[(x) + (width * (y-9))]=1;
prev[(x) + (width * (y-10))]=1;
prev[(x-1) + (width * (y-6))]=1;
prev[(x-1) + (width * (y-7))]=1;
prev[(x-1) + (width * (y-9))]=1;
prev[(x-1) + (width * (y-10))]=1;
prev[(x-2) + (width * (y-6))]=1;
prev[(x-2) + (width * (y-7))]=1;
prev[(x-2) + (width * (y-9))]=1;
prev[(x-2) + (width * (y-10))]=1;
prev[(x-3) + (width * (y-7))]=1;
prev[(x-3) + (width * (y-8))]=1;
prev[(x-3) + (width * (y-9))]=1;
prev[(x-8) + (width * (y-5))]=1;
prev[(x-8) + (width * (y-6))]=1;
prev[(x-8) + (width * (y-7))]=1;
prev[(x-9) + (width * (y-5))]=1;
prev[(x-9) + (width * (y-6))]=1;
prev[(x-9) + (width * (y-7))]=1;
prev[(x-10) + (width * (y-4))]=1;
prev[(x-10) + (width * (y-8))]=1;
prev[(x-11) + (width * (y-3))]=1;
prev[(x-11) + (width * (y-9))]=1;
prev[(x-12) + (width * (y-4))]=1;
prev[(x-12) + (width * (y-8))]=1;
prev[(x-13) + (width * (y-5))]=1;
prev[(x-13) + (width * (y-6))]=1;
prev[(x-13) + (width * (y-7))]=1;
prev[(x-23) + (width * (y-6))]=1;
prev[(x-23) + (width * (y-7))]=1;
prev[(x-24) + (width * (y-6))]=1;
prev[(x-24) + (width * (y-7))]=1;
}
function init() {
var x=0;
var y=0;
var offset = 0;
for(y=0;y<height;y++) {
offset = y * width
for(x=0;x<width;x++) {
prev[offset + x] = 0;
//next[offset + x] = 1;
}
}
var example = document.getElementById('example');
var context = example.getContext('2d');
context.fillStyle = "rgb(0,0,0)";
context.fillRect(0, 0, width * pixelSize, height * pixelSize);
loadGosperGliderGunSE();
}
function copy() {
var x=0;
var y=0;
var offset = 0;
for(y=0;y<height;y++) {
offset = y * width;
for(x=0;x<width;x++) {
prev[offset+x] = next[offset + x];
}
}
}
function display() {
var example = document.getElementById('example');
var context = example.getContext('2d');
var x=0;
var y=0;
var offset = 0;
var yPixel = 0;
for(y=0;y<height;y++) {
offset = y * width;
yPixel = y * pixelSize;
for(x=0;x<width;x++) {
if(prev[offset + x] > 0) {
context.fillStyle = "rgb(192,192,255)";
} else {
context.fillStyle = "rgb(0,0,0)";
}
context.fillRect(x * pixelSize, yPixel, pixelSize, pixelSize);
}
}
}
function iterate() {
t=setTimeout("iterate()",10);
var x=0;
var y=0;
var offset = 0;
var sum = 0;
var i =0;
var cell = 0;
// non-toroidal for now
offset = width * height - width;
for(x=0;x<width;x++) {
prev[x] = 0;
prev[x + offset] = 0;
}
for(y=0;y<height;y++) {
offset = width * y;
prev[offset] = 0;
prev[offset + width - 1] = 0;
}
for(y=1;y<height-1;y++) {
offset = y * width
for(x=1;x<width-1;x++) {
sum = 0;
for(i=0;i<3;i++) {
sum = sum + prev[offset + x - width + i - 1];
sum = sum + prev[offset + x + width + i - 1];
}
cell = prev[offset + x];
sum = sum + prev[offset + x - 1];
sum = sum + prev[offset + x + 1];
// dead cells are born if 3 adjacent
// live cells are terminated if 0,1,4,5,6,7,8 adjacent
// live cells unchanged if 2,3 adjacent
if(cell > 0) {
if(sum < 2) { // clear
next[offset + x] = 0;
} else {
if(sum < 4) { // live
next[offset + x] = 1;
} else {
next[offset + x] = 0;
}
}
} else {
if(sum < 3) {
next[offset + x] = 0;
} else {
if(sum > 3) {
next[offset + x] = 0;
} else {
next[offset + x] = 1;
}
}
}
}
}
display();
copy();
}
// http://en.wikipedia.org/wiki/Canvas_element
function start() {
init();
//load();
iterate();
}
</script>
</head>
<body text="#ffffff" bgcolor="#303030" link="#33D033" vlink="#D030D0" alink="#D03000" onload="javascript:start();">
<!-- img src="block_fff.jpg" alt="vOacis Application"/-->
<h3></h3>
obrienlabs.dev
<br/>
Of course - the William (Bill) Gosper <a href="https://en.wikipedia.org/wiki/Gun_(cellular_automaton)">glider gun</a> for the game of life.
<a href="display/DEV/Architecture.html">obrienlabs wiki</a>
Canvas:start <br/>
<canvas id="example" width="400" height="160">
This text is displayed if your browser does not support HTML5 Canvas - try the latest Android 2.3, IE9, Firefox or Chrome.
</canvas>
<br/>
Canvas:end <br/>
<br/>
<a href="rest-json.html">rest-json</a> - simulated https rest call
<br/>
<h3>Quotes of note</h3>
- 20240724 - "There is no place like 127.0.0.1" - BTTF reference in https://ai.google.dev/competition
<h3>Links</h3>
- <a href="https://en.wikipedia.org/wiki/Satya_Nadella">Microsoft empoowers all developers under CEO Satya Nadella</a><br/>
- <a href="https://survey.stackoverflow.co/2024/technology#2-web-frameworks-and-technologies">Stackoverflow.co Technology Ranking</a>
</body>
</html>