Created
January 22, 2024 16:52
-
-
Save thegoldenmule/5d6b516de0a1abf3021180240f6c43ac to your computer and use it in GitHub Desktop.
Vector example from class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const vec2 = glMatrix.vec2; | |
window.init = (canvas) => { | |
console.log('Init()!!!!!!!!!'); | |
// TODO | |
}; | |
window.loop = (dt, canvas) => { | |
const ctx = canvas.getContext('2d'); | |
const center = vec2.fromValues( | |
canvas.width / 2, | |
canvas.height / 2, | |
); | |
ctx.moveTo(center[0], center[1]); | |
const direction = vec2.create(); | |
const rotated = vec2.create(); | |
const down = vec2.fromValues(0, -1); | |
vec2.rotate( | |
rotated, | |
down, | |
vec2.create(), | |
Math.PI / 6); | |
vec2.scale(direction, rotated, 100); | |
ctx.lineTo(center[0] + direction[0], center[1] + direction[1]); | |
ctx.stroke(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment