Skip to content

Instantly share code, notes, and snippets.

View morningtoast's full-sized avatar

Brian Vaughn morningtoast

View GitHub Profile
@morningtoast
morningtoast / spriterotate.p8
Created April 2, 2019 17:31
Good sprite rotation
-- rspr(spritesheetX,spritesheetY, screenX,screenY, angle, tileWidth, transColor)
-- tileWidth is squared when look at sprites. So a tileWidth=2 will do a 2x2 tile size (16x16) at sx,sy
function rspr(sx,sy,x,y,a,w,trans)
local ca,sa=cos(a),sin(a)
local srcx,srcy,addr,pixel_pair
local ddx0,ddy0=ca,sa
local mask=shl(0xfff8,(w-1))
w*=4
ca*=w
sa*=w
@morningtoast
morningtoast / outline_sprite.p8.lua
Last active March 12, 2019 15:31 — forked from Liquidream/outline_sprite.p8.lua
Useful sprite draw function for PICO-8 (and maybe Lua in general)
--
-- draws a sprite to the screen with an outline of the specified colour
-- transc is color to use as transparent; default is black (0)
function outline_sprite(n, col_outline,transc x,y, w,h, flip_x,flip_y)
transc=transc or 0
-- reset palette to black
palt(transc,true)
for c=1,15 do
pal(c,col_outline)
@morningtoast
morningtoast / pico8-crt.html
Created March 5, 2019 03:03
CRT export template for PICO-8 games
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>PICO-8 Cartridge</title>
<meta name="description" content="">
<STYLE TYPE="text/css">
<!--
@morningtoast
morningtoast / tail.p8
Created March 4, 2019 15:43
Snake taile for PICO-8
pico-8 cartridge // http://www.pico-8.com
version 16
__lua__
-- scratch
function newall()
local obj={
x=120,y=120,tail={}
}
@morningtoast
morningtoast / mouse.p8
Last active March 23, 2023 05:31
Mouse input for PICO-8
--[[
Put mouse.init() in the _init()
Put the following in the _update loop
mouse_x,mouse_y = mouse.pos()
mouse_btn = mouse.button()
Then use mouse_* variables for position and button clicks.
]]
@morningtoast
morningtoast / srand.p8
Last active February 6, 2019 20:47
Pico8 seeding
pico-8 cartridge // http://www.pico-8.com
version 16
__lua__
-- seeding testing
-- goal is to use the date as seed value, which will make it so
-- the sequence of values coming out of the pool are the same
-- every time the cart is reset
function rand_table(t)
@morningtoast
morningtoast / jsrepeat.js
Created February 13, 2018 20:40
Vanilla JS element repeater, useful for flat prototyping
// Add data-repeat attribute to the element you want repeated, the value being the quantity
// That element will be cloned and appended X number of times *after* the original.
var torepeat=document.querySelectorAll("[data-repeat]");
for (a=0;a<torepeat.length;a+=1) {
var el=torepeat[a];
var rpt=el.getAttribute("data-repeat");
for (r=0;r<rpt;r+=1) {
@morningtoast
morningtoast / external-link.css
Created July 31, 2017 18:31
External link indicator with CSS
@morningtoast
morningtoast / color-contrast-foundation6.scss
Created March 10, 2017 20:00
Contrast color function for Foundation 6
@function get-contrast-color($bgcolor) {
$darker-ratio: color-contrast($bgcolor, #000);
$lighter-ratio: color-contrast($bgcolor, #fff);
@if($darker-ratio > $lighter-ratio){
@return #000;
}
@if($lighter-ratio > $darker-ratio){
@return #fff;
@morningtoast
morningtoast / varnameloop.sass
Created March 6, 2017 19:34
Sass looping for variables
// Color options
$grad_names: "green" "fuchsia" "teal" "purple" "orange"; // Name to used as modifier
$color_p: $color-green $color-fuchsia $color-teal $color-purple $color-orange; // Dark color
$color_s: $color-green-dark $color-fuchsia-dark $color-teal-dark $color-purple-dark $color-orange-dark; // Light color
@for $i from 1 through length($grad_names) {
$gn: nth($grad_names, $i);
$cp: nth($color_p, $i);
$cs: nth($color_s, $i);