Skip to content

Instantly share code, notes, and snippets.

@2DArray
2DArray / AutoCopyToGPU.cs
Last active October 12, 2020 13:56
[CopyToGPU] Attribute for structs and consts
// AutoCopyToGPU, written by Eli Piilonen in 2020, MIT license
// Whenever your C# scripts compile, structs/consts/enums that you
// mark with [CopyToGPU] will be copied to a shader-include file.
// DO NOT put this file in an Editor folder! It will break.
///// C# Usage:
//
// [CopyToGPU]
-- "bar" contains:
-- pt1 {x, y, vx, vy} or {x, y, oldx, oldy}
-- pt2 {x, y, vx, vy} or {x, y, oldx, oldy}
-- dist (intended distance between points)
function updatebar(bar)
-- find the current vector between our points
local dx = bar.pt1.x-bar.pt2.x
local dy = bar.pt1.y-bar.pt2.y
-- clear the screen
cls()
-- make a shorter alias far pico8's
-- "get random number" function.
-- usage: r(10) means "random number in [0,10)"
r=rnd
-- print "grow" to the screen,
-- a weird shorthand for print("grow")
@2DArray
2DArray / fluid_sim_pico8.lua
Created May 5, 2018 01:26
Pico8 Fluid Sim
fluid={}
poke(0x5f2d,1)
function spawndrop(x,y)
// {x, y, old_x, old_y, hit_count}
add(fluid,{x,y,x,y,1})
end
function sortfluid()
for i=2,#fluid do
function drawfish(cfish,fishx,fishy,scale)
srand(cfish.seed)
local length=flr(20+cfish.size*5)
length=min(length,120)
local keycount=-flr(-length/(5+rnd(20)))
local keys={}
keys[1]=0
for i=2,keycount do
keys[i]=(rnd(length/8)+length/16)*scale