Skip to content

Instantly share code, notes, and snippets.

View tomlagier's full-sized avatar

Tom Lagier tomlagier

View GitHub Profile
import * as glBuffer from 'gl-buffer';
import * as glClear from 'gl-clear';
import * as context from 'gl-context';
import * as glShader from 'gl-shader';
import * as frag from 'raw!./shader.frag';
import * as vert from 'raw!./shader.vert'
import * as create from 'gl-mat4/create';
import * as identity from 'gl-mat4/identity';
import * as translate from 'gl-mat4/translate';
import * as scale from 'gl-mat4/scale';
//Vert
precision mediump float;
attribute vec2 aPosition;
uniform mat4 uModelView;
uniform mat4 uProjection;
void main() {
gl_Position = uProjection * uModelView * vec4(aPosition, 0.0, 1.0);
//To serialize and send
function serializeResponse(nodes: Array<WireNode>) {
const te = new TextEncoder();
return te.encode(JSON.stringify(nodes)).buffer;
}
function transferNodes(children: Array<Node>, nodes: any) {
let node:WireNode;
const wireNodes:WireNode[] = [];
for (var i = 0; i < nodes.size(); i++) {
//To receive
function fromHeap(heap: ArrayBufferView) {
const decoder = new TextDecoder();
const file = decoder.decode(heap);
const profile = new HeapProfile(JSON.parse(file), dispatcher);
return profile;
}
//To serialize and send
function serializeResponse(nodes: Array<WireNode>) {
const fr = new FileReader();
fr.readAsArrayBuffer(file);
fr.onloadend = heap => this.worker.postMessage({
command: 'TransferProfile',
data: {
heap
}
}, [heap]); //Passing [heap] as a 2nd parameter flags it as Transferable
root = d3.hierarchy({children})
//Value becomes the retainedSize of each node
.sum(node => node.retainedSize);
const layout = d3.pack()
.size([d.width, d.width])
.padding(1.5);
//Apply the layout to our root, then return all leaf nodes
const nodes = layout(root).leaves()
int_sqrt = Module.cwrap('int_sqrt', 'number', ['number'])
int_sqrt(12)
int_sqrt(28)
var result = Module.ccall('int_sqrt', // name of C function
'number', // return type
['number'], // argument types
[28]); // arguments
var result = Module._int_sqrt(28);
interface Paint { };
interface SolidColor : Paint {
attribute double red;
attribute double green;
attribute double blue;
};
interface Pattern : Paint {
attribute DOMString imageURL;
EMSCRIPTEN_BINDINGS(hierarchy) {
register_vector<HNode*>("VectorHNode");
class_<HBasis>("HBasis")
.property("x", &HBasis::x)
.property("y", &HBasis::y)
.property("r", &HBasis::r);
class_<HNode, base<HBasis>>("HNode")
.constructor<emscripten::val>()
function generateLayout(children: Node[], width: number) {
const root = new Module.Hierarchy({
size: [width, width],
padding: 1.5
}, { value: 0, children});
return root.pack().leaves();
}