forked from cory/tildefriends
Cory McWilliams
d293637741
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3530 ed5197a5-7fde-0310-b194-c3ffbd925b24
34 lines
860 B
JavaScript
34 lines
860 B
JavaScript
//! {"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);
|
|
} |