Litecanvas plugin to handle simple timers.
litecanvas()
function init() {| /** | |
| * @param {number} frequency | |
| * @param {number} [duration] in seconds | |
| * @param {number} [wavetype] 0 (sine), 1 (triangle), 2 (saw), 3 (tan), 4 (noise) or 5 (square) | |
| * @param {volume} | |
| */ | |
| function beep (frequency, duration = 0.1, wavetype = 1, volume = .5) { | |
| sfx([, 0, frequency, 0.01, duration, 0.01, wavetype], 0, volume) | |
| } |
| litecanvas() | |
| framerate(1) | |
| draw() | |
| function draw() { | |
| cls(3) | |
| block = randi(10,100) | |
| for (let y = 0; y < H; y += block) { | |
| for (let x = 0; x < W; x += block) { |
| litecanvas({}) | |
| function draw() { | |
| cls(0) | |
| textfont("monospace") | |
| textalign("center", "middle") | |
| const dots = ".".repeat(wrap(T*1.5,0,5)+1) | |
| text(W/2, H/2, "LOADING\n"+dots) |
| //! Based on https://slicker.me/javascript/physics/physics_engine.htm | |
| // Vector utilities | |
| class Vec { | |
| constructor(x=0, y=0) { | |
| this.x = x; | |
| this.y = y; | |
| } | |
| add(v) { | |
| return new Vec(this.x + v.x,this.y + v.y); |
| litecanvas({ | |
| width: 8*8, | |
| autoscale: 3 | |
| }) | |
| const p = { | |
| x: 0, | |
| y: 0, | |
| dx: 0, | |
| dy: 0, |
| litecanvas({}) | |
| let cards = [], sprites, opens = [], timer = 0, score = 0 | |
| const | |
| SIZE = 64, | |
| OFFSET = SIZE/1.5, | |
| CLOSED_CARD = paint(SIZE, SIZE, () => { | |
| cls(2) | |
| }) |
| litecanvas({}) | |
| function init() { | |
| framerate(1) | |
| } | |
| function draw() { | |
| cls(0) | |
| // linedash([10,5]) | |
| // circ(W/2, H/2, 150, 2) |
| litecanvas({ | |
| width: 320, | |
| autoscale: false | |
| }) | |
| let offset = 0 | |
| let pos = vec(10, 10) | |
| function tapped(x, y) { | |
| vecSet(pos, x, y) |
| let pos = {}, | |
| speed = 100, | |
| ts = 32, | |
| bg | |
| litecanvas({ | |
| width: 320, | |
| autoscale: 0 | |
| }) |