Skip to content

Instantly share code, notes, and snippets.

const canvas = document.createElement("canvas");
canvas.width = 600;
canvas.height = 400;
document.body.appendChild(canvas);
const ctx = canvas.getContext("2d");
const BODIES = [];
const COLLISIONS = [];
let LEFT, UP, RIGHT, DOWN;
@jeantimex
jeantimex / BoxBlender3.gltf
Created July 22, 2024 01:00
Load glTF for a simple cube
{
"asset" : {
"generator" : "Khronos glTF Blender I/O v1.7.33",
"version" : "2.0"
},
"scene" : 0,
"scenes" : [
{
"name" : "Scene",
"nodes" : [
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebGL2 Red Cube with Lighting and Shadow</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gl-matrix/2.8.1/gl-matrix-min.js"></script>
</head>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebGL2 Triangle, Plane, Point Light, and Rotating Shadow</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gl-matrix/2.8.1/gl-matrix-min.js"></script>
</head>
@jeantimex
jeantimex / triangle-plane.html
Created July 19, 2024 06:43
WebGL 2 - A triangle rotates above a plane in 3D scene
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebGL2 Rotating Triangle and Static Plane</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gl-matrix/2.8.1/gl-matrix-min.js"></script>
</head>
@jeantimex
jeantimex / express-static-server-cros.js
Last active February 21, 2021 20:50
Express server with Cross-Origin-Opener-Policy
const express = require('express');
const app = express();
// Setting up the public directory
app.use(express.static('public', {
setHeaders: (res) => {
res.set('Cross-Origin-Opener-Policy', 'same-origin');
res.set('Cross-Origin-Embedder-Policy', 'require-corp');
}
}));
@jeantimex
jeantimex / gl-boilerplate.js
Created February 15, 2021 04:39 — forked from migurski/gl-boilerplate.js
WebGL GeoJSON tile rendering II
function linkProgram(gl, vsource, fsource)
{
if(gl == undefined)
{
alert("Your browser does not support WebGL, try Google Chrome? Sorry.");
throw "Your browser does not support WebGL, try Google Chrome? Sorry.";
}
var program = gl.createProgram(),
vshader = createShader(gl, vsource, gl.VERTEX_SHADER),
/*
Common vector operations
Author: Tudor Nita | cgrats.com
Version: 0.51
*/
function Vec2(x_,y_)
{
this.x = x_;
this.y = y_;
@jeantimex
jeantimex / parse-options.sh
Created July 31, 2020 01:57 — forked from cosimo/parse-options.sh
Example of how to parse options with bash/getopt
#!/bin/bash
#
# Example of how to parse short/long options with 'getopt'
#
OPTS=`getopt -o vhns: --long verbose,dry-run,help,stack-size: -n 'parse-options' -- "$@"`
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
echo "$OPTS"
@jeantimex
jeantimex / Vector2D.js
Created July 29, 2020 07:11
JavaScript 2D Vector Class
/*
Simple 2D JavaScript Vector Class
Hacked from evanw's lightgl.js
https://github.com/evanw/lightgl.js/blob/master/src/vector.js
*/
function Vector(x, y) {