æ¤ç¤ºä¾æ¼ç¤ºäºå¦ä½éè¿ç¨æ·å廿¶ç¨éæºé¢è²æ¸²æä¸ä¸ææ¥å°ç¨æ·äº¤äºä¸ WebGL å¾å½¢æä½ç»åèµ·æ¥ã
ç¨éæºé¢è²æ¸²æä¸ä¸æè¿ä¸ªä¾åæä¾äºä¸ä¸ªç®åçä¾åï¼è¯´æå¦ä½ç»å WebGL åç¨æ·äº¤äºãæ¯æ¬¡ç¨æ·ç¹å»ç»å¸ææé®æ¶ï¼ç»å¸é½ä¼ä½¿ç¨ä¸ç§æ°çéæºè²ã
注ææä»¬å¦ä½å¨äºä»¶å¤ç彿°ä¸åµå ¥ WebGL 彿°è°ç¨ã
<p>
A very simple WebGL program that still shows some color and user interaction.
</p>
<p>
You can repeatedly click the empty canvas or the button below to change color.
</p>
<canvas id="canvas-view"
>Your browser does not seem to support HTML5 canvas.</canvas
>
<button id="color-switcher">Press here to switch color</button>
body {
text-align: center;
}
canvas {
display: block;
width: 280px;
height: 210px;
margin: auto;
padding: 0;
border: none;
background-color: black;
}
button {
display: inline-block;
font-size: inherit;
margin: auto;
padding: 0.6em;
}
window.addEventListener(
"load",
function setupWebGL(evt) {
"use strict";
// Cleaning after ourselves. The event handler removes
// itself, because it only needs to run once.
window.removeEventListener(evt.type, setupWebGL, false);
// ç» canvas å button æ·»å ç¸åçæ¶é´å¤çå¨
var canvas = document.querySelector("#canvas-view");
var button = document.querySelector("#color-switcher");
canvas.addEventListener("click", switchColor, false);
button.addEventListener("click", switchColor, false);
// åæ¾ WebGLRenderingContext çåé
var gl;
// ç¹å»äºä»¶å¤çå¨
function switchColor() {
// Referring to the externally defined gl variable.
// If undefined, try to obtain the WebGLRenderingContext.
// If failed, alert user of failure.
// Otherwise, initialize the drawing buffer (the viewport).
if (!gl) {
gl =
canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
if (!gl) {
alert(
"Failed to get WebGL context.\n" +
"Your browser or device may not support WebGL.",
);
return;
}
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
}
// 使ç¨è¾
å©å½æ°è·åä¸ç§éæºè²
var color = getRandomColor();
// ç¨éæºè²è®¾ç½®åºè²
gl.clearColor(color[0], color[1], color[2], 1.0);
// Clear the context with the newly set color. This is
// the function call that actually does the drawing.
gl.clear(gl.COLOR_BUFFER_BIT);
}
// éæºé¢è²è¾
å©å½æ°
function getRandomColor() {
return [Math.random(), Math.random(), Math.random()];
}
},
false,
);
è¿ä¸ªä¾åç代ç å¯ä»¥å¨ GitHub ä¸ä¸è½½ã
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4