Skip to content

Instantly share code, notes, and snippets.

View scambier's full-sized avatar

Simon Cambier scambier

View GitHub Profile
@scambier
scambier / waitForKeyElements.js
Created October 12, 2023 15:33 — forked from BrockA/waitForKeyElements.js
A utility function, for Greasemonkey scripts, that detects and handles AJAXed content.
/*--- waitForKeyElements(): A utility function, for Greasemonkey scripts,
that detects and handles AJAXed content.
Usage example:
waitForKeyElements (
"div.comments"
, commentCallbackFunction
);
@scambier
scambier / bayer.lua
Created September 24, 2023 17:18
Bayer dithering in PICO-8
-- https://www.lexaloffle.com/dl/docs/pico-8_manual.html#FILLP
local dither={
0b0000000000000000,
0b1000000000000000,
0b1000000000100000,
0b1010000000100000,
0b1010000010100000,
0b1010010010100000,
0b1010010010100001,
@scambier
scambier / bayer.lua
Created September 24, 2023 10:26
Bayer dithering in TIC-80
local bayerMatrix = {
0, 8, 2, 10,
12, 4, 14, 6,
3, 11, 1, 9,
15, 7, 13, 5
}
function ditherPixel(x, y, col1, col2, level)
local threshold = bayerMatrix[x % 4 + y % 4 * 4 +1] -- Remove the +1 for 0-based arrays
return (level < threshold) and col1 % 15 or col2 % 15
@scambier
scambier / tic80-custom.md
Created April 20, 2023 15:50
TIC-80 custom builds

When exporting your game with TIC-80, a binary specific to your scripting language is downloaded, and your game is injected into it. If you'd like to to fork and customize TIC-80 itself, you need to build those binaries yourself, and host them on your own http server.

This process will explain the steps specific to build TIC-80, but you will have to install some dependencies yourself. It is a step-by-step process that can largely be automated — and actually is through this project's build.yml.

Preparation

  • Clone TIC-80 and make your changes
  • Change the TIC_WEBSITE & TIC_HOST statics
    • The new host MUST be accessible through http, and MUST NOT redirect to https. It can be a subdomain.
--[[
Original: https://gist.github.com/tesselode/e1bcf22f2c47baaedcfc472e78cac55e
moves rectangle A by (dx, dy) and checks for a collision
with rectangle B.
if no collision occurs, returns false.
if a collision does occur, returns:
- the time within the movement when the collision occurs (from 0-1)
- the x component of the normal vector
- the y component of the normal vector
the goal is to find the time range in which rectangle A
--[[
The idea of this tweetcart was to get the "water ripple" effect with a grid of points.
Each point is applied a sinusoidal effect,
depending on its distance from the center, and the elapsed time.
The points go up then down following that sinusoidal,
and a color gradient is applied to get a nice pseudo-3d effect.
You can copy-paste this whole code inside PICO-8 and just run it.
@scambier
scambier / swept-aabb.lua
Last active July 9, 2022 08:56 — forked from tesselode/swept-aabb.lua
swept AABB collision detection implemented in Lua (commented)
--[[
moves rectangle A by (dx, dy) and checks for a collision
with rectangle B.
if no collision occurs, returns false.
if a collision does occur, returns:
- the time within the movement when the collision occurs (from 0-1)
- the x component of the normal vector
- the y component of the normal vector
function setting_sun()
-- set the palette with all the necessary color,
-- in the right order
pal({10,-7,8,-7,10,14,1},1)
-- circle radius
radius=40
-- start loop
::_::
function sunrect()
-- rainbow palette
pal({1,-15,-13,3,-5,11,-6,10,9,-7,8,-8},1)
-- origin x,y and radius
ox,oy,r=64,64,60
::_::
cls()
-- 12 points for the 12 colors
for i=1,12 do
-- the 12 points are equally spread on the circle's top half
@scambier
scambier / boilerplate.lua
Last active March 30, 2021 16:02
PICO-8 boilerplate
-- gobals and tools
left,right,up,down,fire1,fire2=0,1,2,3,4,5
black,dark_blue,dark_purple,dark_green,brown,dark_gray,light_gray,white,red,orange,yellow,green,blue,indigo,pink,peach=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
--
-- simple ecs
-- https://github.com/namuol/pico8-ecs
--
local ecs = {}