Skip to content

Instantly share code, notes, and snippets.

@nandakoryaaa
nandakoryaaa / png2font.php
Last active March 22, 2023 21:41
convert raster font image to array of bitmask bytes
<?php
$infile = $argv[1]; // font image file name
$w = $argv[2]; // font char width
$h = $argv[3]; // font char height
$color_x = $argv[4] ?? 0; // x coordinate of font color sample
$color_y = $argv[5] ?? 0; // y coordinate of font color sample
$img = imagecreatefrompng($infile);
$img_w = imagesx($img);
$img_h = imagesy($img);
@nandakoryaaa
nandakoryaaa / apple.rs
Created March 16, 2023 18:19
Apple game initial implementation
extern crate sdl2;
use sdl2::rect::Rect;
use sdl2::pixels::Color;
use sdl2::render::WindowCanvas;
use std::time::Duration;
trait Renderer {
fn render(
& self, canvas: & mut WindowCanvas,
@nandakoryaaa
nandakoryaaa / merge_sort_bingo.py
Last active February 16, 2023 22:02
Merge sort implementing true external sequential file/stream emulation
def read_chunk(dst, src, chunk_size, pos, len_src):
while chunk_size > 0 and pos < len_src:
dst.append(src[pos])
pos += 1
chunk_size -= 1
return pos
def get_bingo_size(pos, chunk_size, len_src):
if pos + chunk_size > len_src:
return len_src - pos
class State:
state_handlers = {
's_open': ('h_open', 'h_num'),
's_close': ('h_close', 'h_op'),
's_num': ('h_num'),
's_op': ('h_op')
}
state_map = {
'h_open': 's_open',
from random import randint
import pygame
from pygame.locals import *
import time
W = 10
PLAYER = 20
ROBOT = 30
DEAD_ROBOT = 35
HAZARD = 40