1. Home
  2. /
  3. Webgl
  4. /
  5. Animated Triangle

Animated Triangle - Webgl Typing CST Test

Loading…

Animated Triangle — Webgl Code

Animates a triangle by updating vertex positions every frame.

# webgl/demo/animated_triangle.js
const canvas = document.getElementById('canvas');
const gl = canvas.getContext('webgl');

// Setup shaders and buffers
// ... setup code ...
let offset = 0;
function render() {
	offset += 0.01;
	// update vertex positions with offset
	gl.clear(gl.COLOR_BUFFER_BIT);
	gl.drawArrays(gl.TRIANGLES, 0, 3);
	requestAnimationFrame(render);
}
requestAnimationFrame(render);

Webgl Language Guide

WebGL (Web Graphics Library) is a low-level JavaScript API for rendering high-performance 2D and 3D graphics in the browser using the GPU. It provides a JavaScript binding to OpenGL ES, allowing hardware-accelerated graphics without plugins.

Primary Use Cases

  • ▸3D games and engines in the browser
  • ▸3D product configurators (cars, furniture, etc.)
  • ▸Scientific and medical visualization
  • ▸Architectural & engineering simulations
  • ▸GPU-accelerated data visualization dashboards

Notable Features

  • ▸GPU-accelerated real-time rendering
  • ▸Programmable shader pipeline
  • ▸Cross-platform & plug-in free
  • ▸Based on OpenGL ES
  • ▸Broad browser and hardware support

Origin & Creator

WebGL was developed by the Khronos Group, the same industry consortium behind OpenGL, Vulkan, and WebGPU. The first final specification (WebGL 1.0) was released on March 3, 2011, with precursor work starting around 2006 at Mozilla as a Canvas 3D experiment.

Industrial Note

WebGL is widely used in scientific visualization, CAD tools, GIS mapping, medical imaging, and 3D configurators for industries like automotive and e-commerce.

More Webgl Typing Exercises

Simple WebGL TriangleWebGL Clear ColorWebGL Colored TriangleWebGL Texture ExampleWebGL Perspective CubeWebGL Wireframe CubeWebGL Simple LightingWebGL Orbiting CameraWebGL Post-processing Effect

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher