Skip to content

Instantly share code, notes, and snippets.

View jaames's full-sized avatar
🐳
~

James jaames

🐳
~
  • UK, '97
  • 01:30 (UTC +01:00)
View GitHub Profile
@jaames
jaames / playdate-curve.lua
Last active January 17, 2025 22:51
Simple bezier curve drawing functions for the Playdate Lua SDK
-- bezier curve drawing functions for playdate lua
-- these are based on de Casteljau's algorithm
-- this site has a nice interactive demo to compare both types of curve: https://pomax.github.io/bezierinfo/#flattening
-- draws a curve starting at x1,y1, ending at x3,y3, with x2,y2 being a control point that "pulls" the curve towards it
-- steps is the number of line segments to use, lower is better for performance, higher makes your curve look smoother
-- the playdate is kinda slow, so it's recommended to find a relatively low step number that looks passable enough!
function drawQuadraticBezier(x1, y1, x2, y2, x3, y3, steps)
steps = steps or 8
local d = 1 / steps
@jaames
jaames / playdate_adpcm.c
Last active April 2, 2022 23:07
Example for decoding and playing an ADPCM audio buffer on the Playdate in C, only supports mono IMA-ADPCM with no blocks!
// adpcm.h
#define CLAMP(n, l, h) \
if (n < l) n = l; \
if (n > h) n = h;
#define min(a,b) (((a) < (b)) ? (a) : (b))
static const int8_t indexTable[8] =
{ -1, -1, -1, -1, 2, 4, 6, 8 };
@jaames
jaames / pd_bitmap_notes.c
Created March 8, 2022 11:00
playdate->graphics->getBitmapData pixel format notes
int width = 0;
int height = 0;
int stride = 0;
int hasMask = 0;
u8* bitmapBuffer;
pd->graphics->getBitmapData(bitmap, &width, &height, &stride, &hasMask, &bitmapBuffer);
// bitmap data is comprised of two maps for each channel, one after the other
int mapSize = height * stride;
@jaames
jaames / astro.config.mjs
Last active October 5, 2024 17:55
Injecting global SCSS variables in Astro (https://astro.build), using additionalData and a path alias
// note for typescript users: you will need to install node.js types into your project with `npm i -D @types/node`
import { fileURLToPath } from 'url';
import path, { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export default {
// all the usual config goes here...
@jaames
jaames / main.c
Last active November 27, 2023 03:29
Playdate C memory management functions (and extras!) as macros
// usage example in your C entry file...
#include "pd_api.h"
#include "platform.h"
PlaydateAPI *pd = NULL;
int eventHandler(PlaydateAPI *playdate, PDSystemEvent event, uint32_t arg)
{
if (event == kEventInitLua) {
@jaames
jaames / playdate-disk.py
Last active March 2, 2022 10:32
Puts a USB-connected Playdate into disk mode - workaround for the Simulator not recognising that a Playdate is connected in macOS Monterey
# playdate-disk.py
# Puts a USB-connected Playdate into disk mode
# requires Python 3 and pyUSB (pip install pyusb)
# python3 playdate-disk.py
import usb.core
import usb.util
# Playdate USB vendor and product IDs
PLAYDATE_VID = 0x1331;
@jaames
jaames / ppm.lua
Last active December 8, 2021 00:40
Flipnote PPM parser made in Lua, for the Playdate. It's horrendously slow, so maybe don't use this, it's only preserved lest future generations repeat the same mistakes
import 'CoreLibs/object'
import 'CoreLibs/graphics'
-- Flipnote Studio (DSiWare version) animation parser
-- Format reference:
-- https://github.com/Flipnote-Collective/flipnote-studio-docs/wiki/PPM-format
class("PpmParser").extends()
local gfx <const> = playdate.graphics
@jaames
jaames / kana.txt
Created November 24, 2021 21:23
Plaintext Japanese Hiragana and Katakana list for font testing
あいうえおやゆよかきくけこきゃきゅきょさしすせそしゃしゅしょたちつてとちゃちゅちょなにぬねのにゃにゅにょはひふへほひゃひゅひょまみむめもみゃみゅみょやゆよらりるれろりゃりゅりょわゐゑをんがぎぐげごぎゃぎゅぎょざじずぜぞじゃじゅじょだぢづでどぢゃぢゅぢょばびぶべぼびゃびゅびょぱぴぷぺぽぴゃぴゅぴょ
アイウエオャュョカキクケコキャキュキョサシスセソシャシュショタチツテトチャチュチョナニヌネノニャニュニョハヒフヘホヒャヒュヒョマミムメモミャミュミョヤユヨラリルレロリャリュリョワヰヱヲンガギグゲゴギャギュギョザジズゼゾジャジュジョダヂヅデドヂャヂュヂョバビブベボビャビュビョパピプペポピャピュピョ
@jaames
jaames / baba-api.md
Last active May 22, 2022 10:20
Baba Is You level editor API details

API

The API base URL is https://8778eno8ha.execute-api.eu-central-1.amazonaws.com

GET /prod/list_levels2

Returns the asset URL, the number of total pages in this list, and a list of level details

URL params

version: 0.10.2 md5: 2e80ff35027fc4a72e9dcd9e8b15a27b

version: 1.7.0 md5: 4156d02939ebfd3929b53dcc61d69cd1

version: 1.9.1-beta.1 md5: 2dbef3db9a98239079c47dd1a4dc8867