This is a little bit of a follow-along HTML5 procedural canvas pixel art tutorial. It makes for wild websites with instant load times using math instead of massive libraries like threejs.
// Edit these values!
const pixel =
const height =
const period =
const canvas = document.querySelector("canvas")
const context = canvas.getContext('2d')
function toPixel(x) {
return pixel * Math.round(x / pixel)
}
function toPoint(x) {
const value = Math.sin(x / period) * height
return value + height
}
function animate() {
const width = canvas.width
for (let x = 0; x < width; x++) {
context.fillRect(toPixel(x), toPixel(toPoint(x)), pixel, pixel)
}
requestAnimationFrame(animate)
}
animate()
// Edit these values!
const pixel =
const height =
const period =
const canvas = document.querySelector("canvas")
const context = canvas.getContext('2d')
const speed =
let counter = 0
function toPixel(x) {
return pixel * Math.round(x / pixel)
}
function toPoint(x) {
const value = Math.sin((x * frequency) / period) * height * Math.sin(counter / (8 * pixel))
return value + height
}
function animate() {
counter += speed
const width = canvas.width
for (let x = 0; x < width; x++) {
context.fillRect(toPixel(x), toPixel(toPoint(x + counter)), pixel, pixel)
}
requestAnimationFrame(animate)
}
animate()
// Edit these values!
const pixel =
const height =
const period =
const canvas = document.querySelector("canvas")
const context = canvas.getContext('2d')
const speed =
let counter = 0
const frequency =
function toPixel(x) {
return pixel * Math.round(x / pixel)
}
function toPoint(x) {
const value = Math.sin((x * frequency) / period) * height * Math.sin(counter / (8 * pixel))
return value + height
}
function animate() {
counter += speed
const width = canvas.width
for (let x = 0; x < width; x++) {
context.fillRect(toPixel(x), toPixel(toPoint(x + counter)), pixel, pixel)
}
requestAnimationFrame(animate)
}
animate()