tildefriends/packages/cory/blink/blink.js

34 lines
860 B
JavaScript
Raw Normal View History

//! {"require": ["libiframe"]}
// Server-side blink! Woo!
require("libiframe").iframe({
source: `
document.body.style.color = '#fff';
document.body.style.backgroundColor = '#000';
var canvas = document.createElement("canvas");
document.body.append(canvas);
canvas.width = 640;
canvas.height = 480;
var context = canvas.getContext("2d");
rpc.export({
setFillStyle: function(style) { context.fillStyle = style; },
fillRect: context.fillRect.bind(context),
fillText: context.fillText.bind(context),
});`,
style: `
border: 0;
`}).then(draw).catch(terminal.print);
var blink = true;
function draw(iframe) {
iframe.setFillStyle('#222');
iframe.fillRect(0, 0, 640, 480);
if (blink) {
iframe.setFillStyle('#fff');
iframe.fillText("Hello, world!", 50, 50);
}
blink = !blink;
setTimeout(function() { draw(iframe); }, 500);
}