forked from Nxrix/pixel-8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
364 lines (350 loc) · 10.6 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="img/icon.png">
<title>Pixel-8</title>
<meta property="og:title" content="Pixel-8 | Tiny Fantasy Console">
<meta property="og:type" content="article" />
<meta property="og:description" content="Try this cart on Pixel-8!">
<meta property="og:image" content="https://nxrix.github.io/Pixel-8/img/icon.png">
<meta name="theme-color" content="#262637">
<meta name="twitter:card" content="summary">
<link rel="stylesheet" href="js/prism.css">
</head>
<script src="js/prism.js"></script>
<style>
@font-face {
font-family: font;
src: url("font/ggsans-Semibold.ttf") format("truetype");
}
* {
-webkit-tap-highlight-color: transparent;
}
.language-js * {
font-family: pixel8;
}
::selection {
color: #191a30;
background: #dcddff;
}
.play {
position: fixed;
width: var(--vmin);
height: var(--vmin);
z-index: 2;
image-rendering: pixelated;
}
.consolebtn {
user-select: none;
width: 7.5vmin;
height: 7.5vmin;
top: 2vmin;
left: 2vmin;
background: #242535;
position: absolute;
transition: .25s ease;
border: none;
border-radius: .5vmin;
border-bottom: solid 1vmin #0e0f18;
box-shadow: 0 0 0 .25vmin #3e4061;
}
.consolebtn:active {
transform: translateY(1vmin);
background: #ff0040;
height: 6.5vmin;
border-bottom: solid 0vmin #920f30;
box-shadow: 0 0 0 .25vmin #ff386a;
}
#pixel8_console {
padding: calc(var(--vmin)/100*2.5);
position: absolute;
font-family: font;
font-size: calc(var(--vmin)/100*2.5);
background: #0e0f18;
transition: .25s ease;
width: calc(var(--vmin)/100*90);
height: calc(var(--vmin)/100*90);
border-radius: 1.5vmin;
box-shadow: 0 0 0 .25vmin #4d4e75;
top: calc(var(--vh)/2-var(--vmin));
left: calc(var(--vw)/2-var(--vmin));
transform: scale(0);
overflow: hidden;
image-rendering: pixelated;
}
#pixel8_console_div {
width: calc(var(--vmin)/100*90);
height: calc((var(--vmin)/100*90) - (var(--vmin)/100*12));
white-space: pre;
overflow: auto;
}
#pixel8_console * {
font-family: font;
font-size: calc(var(--vmin)/100*4);
}
#pixel8_console_input {
background: #32354d;
color: #979CD3;
caret-color: #979CD3;
font-family: font;
font-size: calc(var(--vmin)/100*4);
width: calc(var(--vmin)/100*87.5);
height: calc(var(--vmin)/100*5.5);
position: absolute;
border: 0;
padding: calc(var(--vmin)/100*2.5);
left: calc(var(--vmin)/100*1.25);
bottom: calc(var(--vh)/100*1.5);
border-radius: 1.25vmin;
}
#pixel8_console_input:focus {
outline: 0;
}
#pixel8_console_input::placeholder {
color: #686C98
}
#pixel8_console img {
width: calc(var(--vmin)/3);
user-select: none;
}
#pixel8_canvas {
cursor: none;
}
#input {
color: #0000;
}
#input,#input_syntax {
background: #0000;
position: fixed;
resize: none;
border: none;
vertical-align:bottom;
overflow-y: scroll;
display: none;
cursor: none;
touch-action: none;
caret-color: #fff;
}
#input::-webkit-scrollbar {
width: calc((100vmin/128) * 5);
}
#input::-webkit-scrollbar-track {
background: rgb(49,51,113);
}
::-webkit-scrollbar-thumb {
background: rgb(134,134,207);
}
::-webkit-scrollbar-thumb:hover {
background: rgb(220,221,255);
}
#input:focus {
outline: none;
}
#input_syntax {
position: fixed;
line-break: strict;
overflow-y: auto;
}
#input_syntax::-webkit-scrollbar {
display: none;
}
</style>
<body res="128">
<img src="img/sprite.png" id="sprite">
<div id="pixel8_console">
<div id="pixel8_console_div"><img src="img/vox.png" draggable="false"> Pixel-8 Console v.1 <a style="color:#1e90ff" href="javascript:pixel8.console.clear()">Clear Console</a> </div>
<input id="pixel8_console_input" type="text" spellcheck="false" placeholder="type ...">
</div>
<button class="consolebtn">>_</button>
<img class="play" src="img/play.png" draggable="false">
</body>
<script src="js/pixel8.js"></script>
<script>
/*
col=x^y+t;[sx,sy]=rot(c,c,sx,sy,15);[sy,sz]=rot(c,15.5,sy,col%32,-30);
*/
/*
0,㡣Ὤ⿸ṹ㩛ᛸ㵳㨬⽺㦽㫯ᒲᛸ㡣፬ᦳ㪬㪬㈬ḩ㷳Ἣṷ㩛ᛸ㵳Ὕ㉳ᓬ㳳㨬ᦳ㨯ᕣ,0
0,濣㷬碨秞瓞㮩宊磳玬⳹竳㷝濲㋴碨禬掬泯瞥璬㊪璬㊪掬㮩玊⯺瞽珛秳㷝揳⣬磳玬⳹⿷竳掬㮩,0
0,㡣Ὤ⿸ᙹᛴ㳛㴬㨬⽺㦽㫯ᒲᛸ㡣፬ᦳ㪬㪬㈬ᚩ㷳Ἣᛷ㩛ᛸ㵳Ὕ㉳ᓬᛸᡷ㷳㈬Ⴉ,0
0,㡦ᓲὩḰứᢱᢰ㔻ᘫ㲩㦽㋮ᤨᲲᚩό㟲ᓤᦱᔸ㢬㍳ᓴᛸ㲨㵞ᠩᔴ,0
0,㈱㛯㲽㵞⸬ᛸ㷳Ὕ㡲᧴㲨㴬㈬㛯㰥㪬㪬㈬ᚩ㷳Ἣᛷ㩛ᛸ㵳Ὕ㉳ᓬᛸᡷ㷳㈬Ⴉ,ᢱᢰᒬ⁴ᶰὤ㧁ㅲᓹᦱᲲᔸ㎮㛩ᓬᔰⲬ㪽ᖪᰱ㲬ㄽㅴᓮፘᖱㅴᓮㅍ㓴⢮ᗉᙘㅍ㓴ㄮ㕳ᓮ㕳ᓮ㪨ᘵ㕳ᓮᡴᢱ᪲ᠩᔲᦪᖪ⸨ᣛᨬᰬ⼲⸬ᚰᚵᚹᦱᛝᩛᰬᚲᬱᛝᚳᚴᚷ⼹⹝ῴᎷ⼳㫛ιᨱᨦᡝᦱᔩᔩᘩ៤㓳㏩ᓴᚩ៤㭰㓳㲨ᒪឱ᜵ፘᔱᚩ㲨㨫㟩ᤨᩥᒯ፴ᖲᒪ᪱ᒭῴᎳ⾳ῴᎴ⾷ῴᎵᔳᨥᄪ㾨ῴᎴᔷᔩᖪឨ᜵ፘᠱᔲᘩᒨῴᎲᔳἽ㪨ιᬱᨦ㫞ιᨱᨦᔩᒪ㫾ιᎹᔷ㨪㟩ᒨᡴ㺲ῴᎶᔷᖪᔳᲯᒫᡴᦱᠰㅍ㓴⢮ᗉᖲᒪᨧ᮸ᐰ㫛ιᰱᨦᡝᦱᎩᔱᒪῴᎳᔱᠩᔴᤪᲲᤫᲲ
*/
pixel8.console = [];
pixel8.console.clear = () => {
pixel8_console_div.innerHTML = `<img src="img/vox.png" draggable="false"> Pixel-8 Console v.1 <a style="color:#1e90ff" href="javascript:pixel8.console.clear()">Clear Console</a> `
}
pixel8.console.D=false;
document.querySelector(".consolebtn").onclick = () => {
pixel8.console.D=!pixel8.console.D;
if (pixel8.console.D) {
pixel8_console.style.transform = "scale(1,1)";
}
else {
pixel8_console.style.transform = "scale(0,0)";
}
}
pixel8_console.addEventListener("keyup", function(event) {
if (event.key === 'Enter') {
try {
var output = eval(pixel8_console_input.value);
pixel8_console_div.innerHTML += pixel8_console_input.value+":\n"+Prism.highlight((output||"undefined").toString(),Prism.languages.js,"js")+"\n";
}
catch (error){
pixel8_console_div.innerHTML += pixel8_console_input.value+":\n"+"<div style='color:#ff386a'>"+error.toString()+"</div>";
}
pixel8_console_div.scrollTo(0,pixel8_console_div.scrollHeight)
}
});
pixel8.compile = () => {
w=c=vec=scale=undefined;
pixel8.sound.sampleRateScale = (pixel8.sound.ctx.sampleRate/(eval(pixel8.waveTxt.split(",")[0])||8000));
pixel8.error = "";
try {
pixel8.init=new Function (pixel8.initTxt);
cls(3);
pixel8.init();
if (pixel8.updateTxt.substr(0,1)=="1") {
vec=[];
c=32/2-.5;
w=32;
scale=4;
pixel8.update = new Function ("x","y",pixel8.updateTxt.substr(1));
}
else {
pixel8.update = new Function (pixel8.updateTxt);
}
pixel8.wave=new Function((pixel8.waveTxt?"var t=pixel8.sound.t;var PI=Math.PI\nreturn "+pixel8.waveTxt+"":"return 0"));
pixel8.wave();
}
catch(err) {
pixel8.error=err.toString();
}
}
pixel8.decodeT = (x) => {
x=x.split(",");
["init","update","wave"].forEach((i,j) => {eval("pixel8."+i+"Txt = pixel8.decode(x[j]!=0?x[j]:'')")});
}
pixel8.initTxt=pixel8.updateTxt=pixel8.waveTxt="";
pixel8.encode = (x) => {
var y="";
x=x.split("");
var l=Math.ceil(x.length/2);
for (i=0;i<l;i++) {
y+=String.fromCharCode(
x[i*2].charCodeAt(0)+
(x[i*2+1]||String.fromCharCode(32)).charCodeAt(0)*128+128
);
}
return y;
}
pixel8.decode = (x) => {
var y="";
x=x.split("");
for (i=0;i<x.length;i++) y+=String.fromCharCode((x[i].charCodeAt(0)-128)%128)+String.fromCharCode(parseInt((x[i].charCodeAt(0)-128)/128));
return y;
}
pixel8.resize=()=>{
var root = document.querySelector(":root");
var width = window.innerWidth;
var height = window.innerHeight;
root.style.setProperty("--vw",width+"px");
root.style.setProperty("--vh",height+"px");
root.style.setProperty("--vmin",(width<height?width:height)+"px");
root.style.setProperty("--vmax",(width>height?width:height)+"px");
};
window.addEventListener("resize",pixel8.resize);
pixel8.resize();
var url_string = window.location.href;
var url = new URL(url_string);
pixel8.cart = url.searchParams.get("cart");
if (pixel8.cart!=undefined) {
pixel8.decodeT(pixel8.cart);
}
else {
pixel8.decodeT("0,㈱㛯㲽㵞⸻㳳㨬㷳Ὕ㡲᧴㲨㴬㈬㛯ᨥᚲᛴᛴᕣ㨻ᙺ㰽⸻㳳㨬⽹㨽㛣ᒲ㳳㨬ᦳ㨯ᕣ,0");
}
pixel8.inited = true;
window.onclick = function () {
if (pixel8.inited) {
pixel8.inited = false;
document.querySelector(".play").remove();
pixel8.canvas.style.background = pixel8.colors[0];
pixel8.sound = [];
pixel8.sound.ctx = new (window.AudioContext || window.webkitAudioContext)();
pixel8.wave=()=>{return 0};
pixel8.sound.processor = pixel8.sound.ctx.createScriptProcessor(0,1,1);
pixel8.sound.sampleRateScale = Math.floor(pixel8.sound.ctx.sampleRate/8000);
pixel8.sound.frame=0;
pixel8.sound.t=0;
pixel8.sound.processor.onaudioprocess = function(e) {
pixel8.sound.out = e.outputBuffer;
pixel8.sound.outData = pixel8.sound.out.getChannelData(0);
for (var i=0;i<pixel8.sound.outData.length;i++,pixel8.sound.frame++) {
pixel8.sound.out.getChannelData(0)[i] = pixel8.wave()/256%1;
if (pixel8.sound.frame >= pixel8.sound.sampleRateScale) {
pixel8.sound.frame = -1;
pixel8.sound.t++;
}
}
};
pixel8.sound.processor.connect(pixel8.sound.ctx.destination);
pixel8.compile();
pixel8.updateF();
}
}
let t=0;
pixel8.updateF = () => {
if (pixel8.updateTxt.substr(0,1)=="1") {
pixel8.ctx.clearRect(0,0,pixel8.canvas.width,pixel8.canvas.height);
sz=1;col=3;
for (var i=0;i<w;i++) {
for (var j=0;j<w;j++) {
x=i;y=j;sx=i;sy=j;
try {
pixel8.update(x,y);
}
catch(err) {
pixel8.error=err.toString();
break;
}
vec[i+j*w] = {x:sx,y:sy,z:sz,c:col};
}
}
vec.sort((v1,v2) => {
return v2.z - v1.z;
});
for (i in vec) {
[sx,sy,sz,col]=[vec[i].x,vec[i].y,vec[i].z,vec[i].c];
if (sz>0) {
sx=sx*scale;
sy=sy*scale;
if (pixel8.error=="") {
rectfill(sx,sy,scale,scale,parseInt(col)%32);
}
}
}
}
else {
try {
pixel8.update();
}
catch(err) {
pixel8.error=err.toString();
}
}
if (pixel8.error!="") {
cls(3);
pixel8.errorL=pixel8.ctx.measureText(pixel8.error).width+8;
for (i=2;i>0;i--) {
print(pixel8.error.toLowerCase(),-t/4%pixel8.errorL,3+i,4+i);
print(pixel8.error.toLowerCase(),-t/4%pixel8.errorL+pixel8.errorL,3+i,4+i);
}
}
t++;
requestAnimationFrame(pixel8.updateF);
}
</script>
</html>