Skip to content

Instantly share code, notes, and snippets.

View worldoptimizer's full-sized avatar
💭
Homeoffice

Max Ziebell worldoptimizer

💭
Homeoffice
View GitHub Profile
// Lower value increases trail duration.
const CANVAS_CLEANUP_ALPHA = 0.3;
// Cleans up the canvas by removing older trails.
// ...
function cleanCanvas() {
// Set 'destination-out' composite mode, so additional fill doesn't remove non-overlapping content.
context.globalCompositeOperation = 'destination-out';
// Set alpha level of content to remove.
// Lower value means trails remain on screen longer.

Keybase proof

I hereby claim:

  • I am worldoptimizer on github.
  • I am maxziebell (https://keybase.io/maxziebell) on keybase.
  • I have a public key whose fingerprint is 3CAD 5CF1 89E1 A8C3 A5EF 23E6 B1B4 6EC2 9362 2709

To claim this, I am signing this object:

@worldoptimizer
worldoptimizer / initGame.js
Last active February 6, 2020 08:59
Function initGame (Keyboard Input, Lander Game))
var keyPressLookup = {};
document.addEventListener('keydown', function(e){
keyPressLookup[e.code] = true;
});
document.addEventListener('keyup', function(e){
delete keyPressLookup[e.code];
});
@worldoptimizer
worldoptimizer / initGame.js
Last active February 6, 2020 08:59
Function initGame (preparation)
// fetch scene element and then the lander element in it by classname
var sceneElm = document.getElementById(hypeDocument.currentSceneId());
var lander = sceneElm.querySelector('.lander');
var landerBody = hypeDocument.getElementProperty(lander, 'physics-body');
@worldoptimizer
worldoptimizer / hype stable symbol example.js
Last active March 12, 2020 22:31
A simple example for an extended symbol
function symbolInit (hypeDocument, element, event){
console.log('HypeSymbolInit');
var symbolInstance = hypeDocument.getSymbolInstanceForElement(element);
var symbolElement = symbolInstance.element();
switch (symbolInstance.symbolName()){
case 'counter':
Object.assign( symbolInstance, {
_counter: 0,
increase: function(){
function symbolInitTest (hypeDocument, element, event){
console.log('HypeSymbolInit');
var symbolInstance = hypeDocument.getSymbolInstanceForElement(element);
// do your stuff…
}
window.HYPE_eventListeners.push({"type":"HypeSymbolInit", "callback":symbolInitTest});
@worldoptimizer
worldoptimizer / spine.css
Created May 10, 2020 09:30
Book Spin in CSS
.Product-book .book-section .book-cover .cover-spine-overlay img{
width:100%;
display:block;
-webkit-box-shadow:0 0 16px rgba(0,0,0,0.5);
box-shadow:0 0 16px rgba(0,0,0,0.5)
}
.Product-book .book-section .book-cover .cover-spine-overlay:after{
position:absolute;
content:"";
width:100%;
@worldoptimizer
worldoptimizer / hypeDocument.queryIntersections.js
Created September 12, 2020 12:55
hypeDocument.queryIntersections
/**
* Query intersections between elements using Matter.js
*
* @param {Node} sourceElm The source element used in each check
* @param {Nodelist} targetElms The target elements to query against
* @return {Nodelist} Returns a list of targetElms that intersect with sourceElm
*/
hypeDocument.queryIntersections = function(sourceElm, targetElms) {
var sourceBody = hypeDocument.getElementProperty(sourceElm, 'physics-body');
if (sourceBody) {
@worldoptimizer
worldoptimizer / hypeDocument.disablePhysicsCollisions.js
Created September 12, 2020 12:59
hypeDocument.disablePhysicsCollisions
/**
* Remove phyics elements from the regular Matter.js collision group
*
* @param {Nodelist} targetElms The target elements to remove
*/
hypeDocument.disablePhysicsCollisions = function(targetElms) {
targetElms.forEach(function(elm){
var elmBody = hypeDocument.getElementProperty(elm, 'physics-body');
if (elmBody) elmBody.collisionFilter = { 'group': -1}
});
@worldoptimizer
worldoptimizer / pauseIfPlayingForward.js
Created September 15, 2020 15:10
If you need to create a directional pause this little timeline action should be helpful.
if ( hypeDocument.currentDirectionForTimelineNamed(event.timelineName) == hypeDocument.kDirectionForward) {
hypeDocument.pauseTimelineNamed(event.timelineName);
}