Skip to content

Instantly share code, notes, and snippets.

@xem
xem / readme.md
Last active April 5, 2024 23:16
Maths & trigonometry cheat sheet for 2D & 3D games

Conventions

  • A = [xA, yA] is a point on the 2D plane. Same for B, C, ...
  • lengths are in any unit (ex: pixels)
  • code snippets are in JavaScript

Degrees to radians

angleRad = angleDeg * Math.PI / 180;

@xem
xem / codegolf.md
Last active March 22, 2024 15:41
JS code golfing

codegolf JS

Mini projects by Maxime Euzière (xem), subzey, Martin Kleppe (aemkei), Mathieu Henri (p01), Litterallylara, Tommy Hodgins (innovati), Veu(beke), Anders Kaare, Keith Clark, Addy Osmani, bburky, rlauck, cmoreau, maettig, thiemowmde, ilesinge, adlq, solinca, xen_the,...

(For more info and other projects, visit http://xem.github.io)

(Official Slack room: http://jsgolf.club / join us on http://register.jsgolf.club)

@xem
xem / LICENSE.txt
Last active November 20, 2023 13:51 — forked from 140bytes/LICENSE.txt
Mini Game of Life
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@xem
xem / JSGameFramework2020.html
Last active November 11, 2023 19:53
JS game framework 2020
<body style=margin:0>
<canvas id=a>
<script>
// initialize 2D canvas (c)
// initialize game state (s)
// initialize keys states (u,r,d,l for directions, k for all the keyboard)
c=a.getContext`2d`,k=[u=r=d=l=s=0]
// (initialize your global variables here)
@xem
xem / index.html
Created June 26, 2014 09:41
A Pen by xem.
<div class="content smallSizeLayout">
<div class="intro" data-stretch-parent-if-n-lines="2" data-stretch-parent=".content" data-bind="css:{ 'bulletHidden': !isVisited()}" id="id_186">
<p data-bind="html:text"><div class="richText"><p>Intro: Lorem ipsum dolor sit, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa</p></div></p>
</div>
<table class="bulletpoint bulletHidden first">
<tbody>
<tr>
<td class="bullet-icon">
@xem
xem / index.html
Last active July 30, 2023 09:57
miniCodeEditor in 162b (Fx, Chrome, Opera)
<body oninput='f.srcdoc=t2[v="value"]+"<script>"+t0[v]+"</script><style>"+t1[v]'onload='for(i=3;i--;)e.innerHTML+="<textarea id=t"+i+" rows=9>"'id=e><iframe id=f>
@xem
xem / miniEditor.html
Last active July 30, 2023 09:57
mini native live code editor
<body contenteditable oninput=eval(S.textContent)>
<h1>Hi! (edit me)</h1>
<script style="display:block;border:1px solid;;white-space:pre-wrap" id=S>
// JS (edit me)
console.log("test");
</script>
<style style="display:block;border:1px solid;white-space:pre-wrap">
/* CSS (edit me) */
* { background: #def }
</style>
@xem
xem / v1.html
Created November 19, 2016 12:48
1kb ES6 Quines Ideas
<pre id=p><script id="s" style="display:block">setInterval(z=`
/* =<,m#F^ A W###q. */ ;
/* #K q##H######Am */ ;
/* dP cpq#q##########b, */ ;
/* p##@###YG=[#######y */ ;
/* d#qg '*PWo##q#######D */ ;
/* aem1k.com Q###KWR#### W[ */ ;
/* .Q#########Md#.###OP A@ , */ ;
/* , (W#####Xx######.P^ T % */ ;
/* #y '^TqW####P###BP */ ;
@xem
xem / css.md
Last active July 30, 2023 09:57
  • Don't modify strings (content: "...", font-family: '...')
  • Remove all CSS comments (ex: /* ... */ )
  • Remove all unnecessary spaces, tabs and line breaks (ex: around + > ~ ; : , ( ) { } /)
    • Keep spaces before : in selectors (ex: * :before != *:before)
    • Keep spaces around + and - in calc(...) (but not in nth-child and nth-of-type)
  • Remove all unnecessary ; (ex: a{color:red;})
  • Remove all unnecessary * in CSS selectors (ex: *:before => :before)
  • Remove leading and trailing zeros (ex: 0.1%, 1.0%, 0.0px)
  • Remove units after zero (ex: 0px 0rem 0% 0turn 0vmax 0dpi)
@xem
xem / gist:670dec8e70815842eb95
Last active January 19, 2023 22:43
beep boop
<!-- solution 1, 117b, inspired by http://www.p01.org/releases/140bytes_music_softSynth/ -->
<button onclick="new Audio('data:audio/wav;base64,UklGRl9vT19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YU'+Array(1e3).join(123)).play()">Beep</button>
<!-- Solution 2, 107b, inspired by http://xem.github.io/chip8/c8.html -->
<button onclick="o=(A=new AudioContext()).createOscillator();o.connect(A.destination);o.start(0);setTimeout('o.stop(0)',500)">Boop</button>