Skip to content

Instantly share code, notes, and snippets.

/Light.hx Secret

Created August 8, 2015 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c885964ca61431a8e90a to your computer and use it in GitHub Desktop.
Save anonymous/c885964ca61431a8e90a to your computer and use it in GitHub Desktop.
import Pico.*;
/**
* @author YellowAfterlife
*/
@:publicFields
class Light {
static inline function main() {
var remap = [
clDarkGray,
clIndigo,
clPink,
clGreen,
clOrange,
clLightGray,
clWhite,
clWhite,
clPeach,
clPeach,
clPeach,
clGreen,
clBlue,
clBlue,
clPink,
clPeach
];
function lightCircle(cx:Fixed, cy:Fixed, dx:Fixed) {
var dy = 1;
var re = 1 - dx;
if (re >= 0) {
dx -= 1;
re += 2 * (dy - dx) + 1;
} else re += 2 * dy + 1;
var vx = dx, vy0 = dy, vy1 = dy;
inline function proc(x:Fixed, y:Fixed) {
pset(x, y, remap[pget(x, y)]);
}
while (dx > dy) {
vy1 = dy;
dy += 1;
if (re >= 0) {
dx -= 1;
re += 2 * (dy - dx) + 1;
//
for (d in loop(-1, 1, 2)) {
var p = cx - vx * d;
for (i in loop(cy - vy1, cy + vy1)) proc(p, i);
p = cy - vx * d;
for (i in loop(cx - vy1, cx + vy1)) proc(i, p);
}
vx = dx;
vy0 = dy;
} else re += 2 * dy + 1;
} // while (dx > dy)
for (y in loop(cy - vx, cy + vx))
for (x in loop(cx - vx, cx + vx)) {
proc(x, y);
}
}
var t = 0.;
onUpdate = function() {
t += .01;
}
onDraw = function() {
cls();
for (dx in 0 ... 4)
for (dy in 0 ... 4) {
spr(0, 4 + dx * 8, 8 + dy * 8);
}
//
var x = 64, y = 64, r = flr(40 + sin(t) * 15);
color(clWhite);
if (!btn(btB)) {
if (!btn(btA)) lightCircle(x, y, r);
else circfill(x, y, r);
}
//
print("cpu=" + stat(1), 1, 1, clPink);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment