This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Runtime.CompilerServices; | |
int FRAME = 0; | |
var sched = new Schedule(); | |
async Task DelayFrames(int frames) | |
{ | |
while (frames-- > 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// coroutines in c#/unity are missing something like javascript's yield* which both wait for another | |
// coroutine *and* returns a value when that coroutine is finished. | |
// i think we can reproduce it with roslyn source transformations or something similar | |
// the trick is a WaitFor static method that allows the type inference to line up | |
// the method is never meant to actually be called though, and will throw if it ever is | |
// instead calls to the method are replaced with a local variable store, a yield return, and a field access | |
public class Coroutines { | |
public static T WaitFor<T>(IEnumerator<T> ie) { | |
throw new NotImplementedException(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const distance = (x1, y1, x2, y2) => | |
Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)) | |
const approx = (a, b) => | |
Math.abs(a - b) < 0.00001 | |
/** | |
* Compute the intersection of a line segment and a line | |
* | |
* @param x1 x coordinate of the first endpoint of the line segment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/reset.min.css"> | |
<script type="module"> | |
import * as PIXI from "https://cdnjs.cloudflare.com/ajax/libs/pixi.js/6.2.0/browser/pixi.min.mjs" | |
let app = new PIXI.Application() | |
document.body.appendChild(app.view) | |
window.onresize = function() { | |
app.renderer.resize(window.innerWidth, window.innerHeight) | |
app.stage.position = { x:window.innerWidth/2, y:window.innerHeight/2 } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/reset.min.css"> | |
<canvas></canvas> | |
<script> | |
const vertexShader = `#version 300 es | |
uniform vec2 screen; | |
in vec2 position; | |
in vec3 color; | |
out vec3 pcolor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const render = (template, values) => | |
template.replace(/\{\{([^}]+)\}\}/g, (_, key) => values[key]); | |
render("hello {{place}}", { place: "world" }) | |
// => "hello world" | |
render("shell='{{SHELL}}', term='{{TERM}}'", process.env) | |
// => "shell='/bin/bash', term='xterm-256color'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/reset.min.css"> | |
<script type="module"> | |
import * as THREE from "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js" | |
import { OrbitControls } from "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/controls/OrbitControls.js" | |
var scene = new THREE.Scene() | |
var camera = new THREE.PerspectiveCamera(75) | |
camera.position.z = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// based on coroutine.wrap in lua (https://www.lua.org/pil/9.3.html) | |
function wrap(generator) { | |
let g = null | |
return function(...args) { | |
if(!g) | |
g = generator(...args) | |
return g.next(...args).value | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const esprima = require("esprima") | |
const escodegen = require("escodegen") | |
const THREE = require("three") | |
/// implementation | |
let opMap = { | |
"+=": "add", | |
"/": "divideScalar", | |
// ... more operators here ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// multiple dispatch generic functions and polymorphic inline caches | |
class GenericFunction { | |
cache: any = {} | |
addMethod(signature: string[], method) { | |
let cacheObject = this.cache; | |
for (const typeName of signature) { | |
if (!cacheObject.hasOwnProperty(typeName)) { | |
cacheObject[typeName] = {} | |
} | |
cacheObject = cacheObject[typeName]; |
NewerOlder