From: Michael D. Lowis Date: Thu, 15 Nov 2018 03:26:17 +0000 (-0500) Subject: checkin bezier curve example for race track X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=f653deb4b94ec1c1eb1908c6633a5ee2be502124;p=proto%2Fjstoys.git checkin bezier curve example for race track --- diff --git a/racer.html b/racer.html new file mode 100644 index 0000000..583eb9e --- /dev/null +++ b/racer.html @@ -0,0 +1,92 @@ + + + + + Racer + + + + + + diff --git a/raycast.html b/raycast.html index 5a2484e..6330e62 100644 --- a/raycast.html +++ b/raycast.html @@ -21,8 +21,7 @@ const START_POS = { x: 15.3, y: -1.2, direction: Math.PI * 0.3}; const Keys = { left: 37, right: 39, up: 38, down: 40 }; const Canvas = display.getContext('2d'); -const FrameTimer = (()=>{ - let prev = 1, curr = 1; +const FrameTimer = ((prev = 1, curr = 1)=>{ return { update: (now) => (prev = curr, curr = now, (curr - prev) / 1000), render: () => { @@ -33,8 +32,7 @@ const FrameTimer = (()=>{ }; })(); -const Controls = (()=>{ - const self = {}; +const Controls = ((self = {})=>{ const onKey = (val) => ((e)=>{ self[e.keyCode] = val; e.preventDefault && e.preventDefault(); @@ -45,9 +43,7 @@ const Controls = (()=>{ return self; })(); -const Player = (()=>{ - const self = START_POS; - +const Player = ((self = START_POS)=>{ const rotate = (angle)=>(self.direction = (self.direction + angle + TAU) % TAU); const walk = (distance)=>{ @@ -67,18 +63,14 @@ const Player = (()=>{ return self; })(); -const Map = (()=>{ - let grid = new Uint8Array(MAP_SIZE * MAP_SIZE); +const Map = ((grid = new Uint8Array(MAP_SIZE ** 2))=>{ return { get: (x, y)=>(grid[Math.floor(y) * MAP_SIZE + Math.floor(x)] || -1), randomize: ()=>(grid = grid.map((i) => (Math.random() < 0.3 ? 1 : 0))), }; })(); -const Camera = (()=>{ - const self = {}; - let columns = [], ceiling = null, floor = null; - +const Camera = ((self = {}, columns = [], ceiling = null, floor = null)=>{ const resizeView = ()=>{ if (self.width != window.innerWidth || self.height != window.innerHeight) { self.width = display.width = Math.floor(window.innerWidth * VIEW_SCALER); @@ -104,9 +96,9 @@ const Camera = (()=>{ }; self.render = ()=>{ + resizeView(); Canvas.save(); const data = {}; - resizeView(); Canvas.fillStyle = ceiling; Canvas.fillRect(0, 0, self.width, self.height/2);