Skip to content

Instantly share code, notes, and snippets.

View audinue's full-sized avatar

Audi Nugraha audinue

  • Surabaya, Jawa Timur, Indonesia
View GitHub Profile
const renderTriangles = (triangles, options) => {
options = {
eye: [0, 1, 1],
center: [0, 0, 0],
mode: 'both',
orbit: true,
...options
}
const wireframe = ([a, b, c]) => [a, b, b, c, c, a]
<canvas id="canvas" width="500" height="500"></canvas>
<script>
var mouseX = 0
var mouseY = 0
canvas.onmousemove = function (e) {
mouseX = e.offsetX
mouseY = e.offsetY
}
@audinue
audinue / pan-zoom.html
Created January 28, 2022 10:01
Simple viewport panning and zooming without the use of matrix.
<canvas id="canvas" width="500" height="500" style="border: 1px solid"></canvas>
<script>
var panX = 0
var panY = 0
var zoom = 1
draw()
function textBBox (text, attributes) {
var ns = 'http://www.w3.org/2000/svg'
var svg = document.createElementNS(ns, 'svg')
var svgText = document.createElementNS(ns, 'text')
for (var name in attributes) {
svgText.setAttribute(name, attributes[name])
}
svgText.textContent = text
svg.appendChild(svgText)
svg.style.position = 'fixed'
@audinue
audinue / render.html
Created December 12, 2021 13:30
Simple DOM diff :P
<script src="render.js"></script>
<script>
var a = 0
var b = 0
var c = function () {
return a + b
}
function render (e) {
if (e.type === 'input') {
<script>
// Data abstracts storage
let Data = {
_count: 0,
get count () {
return Data._count
},
set count (value) {
Data._count = value
}
function parseTokens (code) {
return code
.split(/([()]|"(?:\\.|[^"])*"|;[^\n]*|\s+)/)
.filter(token => !/^;|^\s|^$/.test(token))
}
function parseArray (tokens) {
const array = []
if (tokens.shift() !== '(') {
throw new Error(`Expected '('`)
var foo = function (match, offset) {
return { tag: 'foo', offset: offset }
}
var bar = function (match, offset) {
return { tag: 'bar', offset: offset }
}
var baz = function (match, offset) {
return { tag: 'baz', offset: offset }
@audinue
audinue / tiny-curry.min.mjs
Last active December 9, 2020 06:46
Tiny curry with placeholder support.
let __={},curry=_=>{let r=l=>(...e)=>{let t=l.map(_=>_===__?e.length?e.shift():__:_);return t.some(_=>_===__)?r(t):_.apply(null,t)};return r(Array(_.length).fill(__))};export{__,curry}
@audinue
audinue / flow-example.js
Created December 5, 2020 11:19
Simple flow based programming.
import { Flow } from '/path/to/flow.js'
let num = new Flow(1)
.map(x => x + 1)
.map(x => x * 2)
.map(x => x / 8)
console.log(num.get())