Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jaames's full-sized avatar
🐳
~

James jaames

🐳
~
  • UK, '97
  • 07:41 (UTC +01:00)
View GitHub Profile
@jaames
jaames / dailylogochallenge.txt
Created June 17, 2019 21:07
Logo challenge list from dailylogochallenge.com -- for people like me who dislike inbox clutter
1. Rocketship Logo (Aerolite, Axis, Comet, Quasar)
2. Hot Air Balloon (Lift, Crown (the very top part of the balloon), Whoosh)
3. Panda Logo (Panda Global, Bamboo, Endangered Panda Conservation)
4. Single Letter Logo
5. Driverless Car Logo (Autonome, Vrooom, Onward)
6. Coffee Shop (Dylan's Coffee, The Roasted Bean, Tazza)
7. Fashion Brand Wordmark (OAKAO, Deities, Adams & Abigail)
8. Ski Mountain Logo (Brass Peak, Mount Blanco, Traverse, Snowdrop)
9. Streaming Music Startup (Beat, Pitch, Bass)
10. Flame Logo (Sizzle, Liight, Flint & Flame)
@jaames
jaames / lst.py
Last active April 27, 2023 20:21
convert Flipnote Studio .lst and .pls files to and from .txt
from sys import argv
import hashlib
import numpy as np
xorkey = [
0xF7, 0x4C, 0x6A, 0x3A, 0xFB, 0x82, 0xA6, 0x37,
0x6E, 0x11, 0x38, 0xCF, 0xA0, 0xDD, 0x85, 0xC0,
0xC7, 0x9B, 0xC4, 0xD8, 0xDD, 0x28, 0x8A, 0x87,
0x53, 0x20, 0xEE, 0xE0, 0x0B, 0xEB, 0x43, 0xA0,
0xDB, 0x55, 0x0F, 0x75, 0x36, 0x37, 0xEB, 0x35,
@jaames
jaames / shapeTool.ts
Created November 27, 2022 19:49
projective shape tool demo
export const dist = (x1: number, y1: number, x2: number, y2: number) => Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2));
export class LineSegment {
x0: number = 0;
y0: number = 0;
x1: number = 0;
y1: number = 0;
constructor (x0: number, y0: number, x1: number, y1: number) {
this.x0 = x0;
// run in node.js, version 16.0 or later
// assumes sound effects will be in a folder called 'pda', located next to the script (replace all instances of './pda' to change this)
const fs = require('fs');
function assert(condition, errMsg = 'Assert failed') {
if (!condition) {
console.trace(errMsg);
throw new Error(errMsg);
}
@jaames
jaames / crc32.lua
Last active September 17, 2022 14:32
crc32 function for playdate lua. only works on strings.
local CRC32_LUT = nil
local function crc32_init()
if not CRC32_LUT then
CRC32_LUT = table.create(255, 0)
local rem
for i = 0, 255 do
rem = i
for j = 1, 8 do
if (rem & 1 == 1) then
@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 / playdate_perf.md
Last active August 30, 2022 22:44
James' Playdate performance tips

General tips

  • For repeated expensive drawing options, such as drawing a rotated sprite or a large amount of text, it's a good idea to cache the result to an image once and draw that repeatedly instead.
  • Audio formats in order of decode speed, fastest to slowest: 16-bit pcm wav, 8-bit pcm wav, adpcm, mp3.
  • The Playdate's audio sample rate is 44100, but if you're experiencing lag when playing audio at that rate, you can try halving the rate to 22050.

C tips

  • The Playdate has a weak CPU but a comparatively generous amount of memory. Favour memory-based optimisation techniques, such as lookup tables.
  • Where possible, move branch statements outside of loops, even if it means duplicating the code for the loop. (probably applies to Lua too?)
  • If you need to parse a binary file, use playdate->file->seek to jump to the parts you need and playdate->file->read to only read the data you want. Try to avoid memcpy-ing the whole file to memory in one go.
  • If you're blitting to the frame buffer and need to ap
@jaames
jaames / playdate-prism-highlight.js
Created August 5, 2022 20:15
Prism.js syntax highlighting settings for Playdate-flavour Lua
Prism.languages.lua = {
'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,
// \z may be used to skip the following space
'string': {
pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[^z]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,
greedy: true
},
'number': /\b0x[a-f\d]+(?:\.[a-f\d]*)?(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|(?:\.\d*)?(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,
'keyword': /\b(?:and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|return|then|true|until|while)\b/,
'function': /(?!\d)\w+(?=\s*(?:[({]))/,
@jaames
jaames / PdvParser.ts
Last active July 6, 2022 20:33
Basic Playdate .PDV video format parser in Typescript (doesn't handle frame type 3 yet)
import { unzlibSync } from 'fflate';
function assert(condition: boolean, errMsg: string = 'Assert failed'): asserts condition {
if (!condition) {
console.trace(errMsg);
throw new Error(errMsg);
}
}
function readChars(data: DataView, ptr: number, size?: number) {