Skip to content

Instantly share code, notes, and snippets.

@luizbills
Created April 21, 2024 23:52
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 luizbills/114d1389a6650901fc03a79c3842cbb3 to your computer and use it in GitHub Desktop.
Save luizbills/114d1389a6650901fc03a79c3842cbb3 to your computer and use it in GitHub Desktop.
Draw a cube in canvas #litecanvas
litecanvas()
function init () {
loadScript('https://unpkg.com/@litecanvas/plugin-more-shapes/dist/dist.js', (res) => {
if (res) plugin(pluginMoreShapes)
})
size = 100
x = WIDTH/2 - size/2
y = HEIGHT/2 - size/2
colors = [4,5,6]
}
function update (dt) {
if (LOADING) return
}
function draw () {
if (LOADING) return
cls(0)
polfill(
[
x, y,
x + size, y,
x + size, y + size,
x, y + size,
],
colors[0]
)
polfill(
[
x, y,
x + size/2, y - size/2,
x + size/2 + size, y - size/2,
x + size, y,
],
colors[1]
)
polfill(
[
x + size, y,
x + size + size/2, y - size/2,
x + size/2 + size, y - size/2 + size,
x + size, y + size,
],
colors[2]
)
}