Skip to content

Instantly share code, notes, and snippets.

View lonekorean's full-sized avatar

Will Boyd lonekorean

View GitHub Profile
@lonekorean
lonekorean / file.css
Created March 2, 2018 13:39
Check for Paint API support via CSS
@supports (background: paint(id)) {
/* good to go! */
}
@lonekorean
lonekorean / file.js
Last active March 2, 2018 23:18
Check for Paint API support via JavaScript
if ('paintWorklet' in CSS) {
// good to go!
}
@lonekorean
lonekorean / file.js
Created October 23, 2017 21:17
Matter.js beforeUpdate event
Matter.Events.on(engine, 'beforeUpdate', function(event) {
if (pinball.position.x > 450 && pinball.velocity.y > 0) {
Matter.Body.setVelocity(pinball, { x: 0, y: -10 });
}
});
@lonekorean
lonekorean / file.js
Created October 23, 2017 21:16
Matter.js collisionStart event
Matter.Events.on(engine, 'collisionStart', function(event) {
let a = event.pairs.bodyA;
let b = event.pairs.bodyB;
// check bodies, do whatever...
});
@lonekorean
lonekorean / file.js
Last active October 24, 2017 23:03
Matter.js create body from path
const CUSTOM_PATH = '425.6 327 273.8 315.6...';
function customShape(x, y) {
let vertices = Matter.Vertices.fromPath(CUSTOM_PATH);
return Matter.Bodies.fromVertices(x, y, vertices, {
// set options if you need them...
});
}
@lonekorean
lonekorean / file.html
Created October 23, 2017 21:15
SVG export polygon markup
<polygon points="425.6 327 273.8 315.6..."/>
@lonekorean
lonekorean / file.js
Last active October 23, 2017 21:14
Matter.js chamfer
function wall(x, y, width, height) {
return Matter.Bodies.rectangle(x, y, width, height, {
chamfer: { radius: 10 },
// other options here...
});
}
@lonekorean
lonekorean / file.js
Created October 23, 2017 21:13
Matter.js function syntax
// wrong
square.setAngularVelocity(0.1);
// correct
Matter.Body.setAngularVelocity(square, 0.1);
@lonekorean
lonekorean / file.js
Created October 23, 2017 21:13
Matter.js body creation function
function rect(x, y, width, height, color) {
return Matter.Bodies.rectangle(x, y, width, height, {
isStatic: true,
restitution: 1,
render: { fillStyle: color }
});
}
@lonekorean
lonekorean / file.js
Created October 23, 2017 21:12
Matter.js adding bodies
// params: x, y, width, height, options
let square = Matter.Bodies.rectangle(200, 100, 50, 50, {
// specify options here
});
Matter.World.add(engine.world, square);