(window.onresize = () => {
canvas.width = innerWidth, canvas.height = innerHeight;
})();
(window.onresize=e=>{canvas.width=innerWidth,canvas.height=innerHeight})()
"use strict";
function main() {
var canvas = document.querySelector("#canvas");
var gl = canvas.getContext("webgl");
if (!gl) {
return;
}
var program = webglUtils.createProgramFromScripts(gl, ["vertex-shader-2d", "fragment-shader-2d"]);
gl.useProgram(program);
var positionAttributeLocation = gl.getAttribLocation(program, "a_position");
var colorLocation = gl.getUniformLocation(program, "u_color");
var matrixLocation = gl.getUniformLocation(program, "u_matrix");
var positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
requestAnimationFrame(drawScene);
function drawScene(now) {
now *= 0.001;
gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.useProgram(program);
gl.enableVertexAttribArray(positionAttributeLocation);
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
var size = 2;
var type = gl.FLOAT;
var normalize = false;
var stride = 0;
var offset = 0;
gl.vertexAttribPointer(
positionAttributeLocation, size, type, normalize, stride, offset);
var radius = Math.sqrt(gl.canvas.width * gl.canvas.width + gl.canvas.height * gl.canvas.height) * 0.5;
var angle = now;
var x = Math.cos(angle) * radius;
var y = Math.sin(angle) * radius;
var centerX = gl.canvas.width / 2;
var centerY = gl.canvas.height / 2;
setGeometry(gl, centerX + x, centerY + y, centerX - x, centerY - y);
var projectionMatrix = m3.projection(gl.canvas.width, gl.canvas.height);
gl.uniformMatrix3fv(matrixLocation, false, projectionMatrix);
gl.uniform4fv(colorLocation, [1, 0, 0, 1]);
var primitiveType = gl.LINES;
var offset = 0;
var count = 2;
gl.drawArrays(primitiveType, offset, count);
requestAnimationFrame(drawScene);
}
}
function setGeometry(gl, x1, y1, x2, y2) {
gl.bufferData(
gl.ARRAY_BUFFER,
new Float32Array([
x1, y1,
x2, y2]),
gl.STATIC_DRAW);
}
main();