Skip to content

Instantly share code, notes, and snippets.

View bfgeek's full-sized avatar

Ian Kilpatrick bfgeek

View GitHub Profile
const canvas = new OffscreenCanvas(1000, 1000);
const ctx = canvas.getContext('2d' /* not sure if this is special */);
const layer = new CanvasVRLayer(canvas);
async function drawLoop() {
do {
} while (await ctx.commit());
}
interface VRAnchor {
readonly attribute VRCoordinateSystem coordinateSystem;
};
[Constructor(VRDisplay)]
interface VRStageAnchor : VRAnchor {
readonly attribute float sizeX;
readonly attribute float sizeY;
};
@bfgeek
bfgeek / thing.html
Last active January 10, 2017 22:25
<style>
.painting {
background-image: paint(typed, 10px), url(foo2.png);
background-image: paint(typed, red), url(foo1.png);
}
</style>
<script>
// paint worklet
registerPaint('typed', class {
static inputArguments = ['<length>'];
const source = ???;
const audioWorkletNode = new AudioWorkletNode('filter');
source.connect(audioWorkletNode);
audioWorkletNode.connect(ctx.destination);
|----------|
|---|
registerAnimator('foo', class {
static elements = {
scroller: {
isRoot: true;
scrollInput: true;
},
parallax: {
outputProperties: ['transform']
}
// animation worklet
registerAnimator('parallaxAnim', class {
static inputs = {
'scroller': {
'scrollTop'
},
'parallax': {
'style': ['transform']
}
}
registerAnimator('parallax', class {
static inputs = {
'scroller': ScrollSource;
};
static outputs = {
'parallax': Style(['transform']) // This is bad.
}
animate(inputs, outputs) {
registerAnimator('parallax', class {
animate(inputs, outputs) {
// read scroller vertical scroll offset.
const scrollTop = inputs.scroller.scrollTop;
// update parallax transform
let t = outputs.parallax.styleMap.get('transform').m42;
t = -0.2 * scrollTop;
outputs.parallax.styleMap.set('transform', new CSSTransformValue(... t));
}
registerLayout('my-grid-layout', class {
static inputProperties = [/* etc */];
constructor() {
this.grid = []; // Place items on a cached grid so don't have to recompute each layout call.
}
addRemoveChildren(addRemoveList) {
// Rebuild grid now, only occurs when child list changes.
for (let i = 0; i < addRemoveList.length; i++) {
BlockFlowLayout::layout(Box* box)
{
// START TOP GENERATOR MACRO
switch (m_state) {
case 0:
goto a;
case 1:
goto b;
}