From 3fc8db582ab295ebf7a16546e867e6ba62d282bf Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Mon, 17 Dec 2018 21:00:11 +0300 Subject: improvements to starfield on different aspect ratios, mouse wheel event --- starfield/stars.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/starfield/stars.js b/starfield/stars.js index 01628e3..6d649f8 100644 --- a/starfield/stars.js +++ b/starfield/stars.js @@ -1,5 +1,5 @@ /* -Starfield JS v1.0.0 +Starfield JS v1.0.1 Copyright 2018 Yaroslav de la Peña Smirnov All rights reserved. @@ -90,15 +90,13 @@ function warpLaunch(options={}){ // and accordingly resize the canvas, then reinitialize canvas.height = parseInt(container.offsetHeight); canvas.width = parseInt(container.offsetWidth); - ox = canvas.height/3; - oy = canvas.width/2; - if (canvas.width < canvas.height){ - ox = canvas.height/2; - oy = canvas.width/3; + ox = canvas.width/3; + oy = canvas.height/2; + if (canvas.height/canvas.width < 0.25){ + oy = canvas.height*1.5; } - if (canvas.width == canvas.height){ - ox = canvas.height/3; - oy = canvas.width/3; + else if (canvas.height/canvas.width < 0.5){ + oy = canvas.height; } try{ window.cancelAnimationFrame(requestedFrame); } catch(e) {} @@ -196,6 +194,8 @@ function warpLaunch(options={}){ function updateSpeed(e){ // If mouse wheel scrolls up, increase speed, if down, decrease + e.preventDefault(); + e.stopPropagation(); let new_speed = e.deltaY > 0 ? speed - step : speed + step; if (new_speed > 250){ speed = 250; @@ -213,7 +213,7 @@ function warpLaunch(options={}){ if (interactive){ console.log("Interactivity is on, move the mouse wheel to control speed"); - document.addEventListener("wheel", updateSpeed); + canvas.addEventListener("wheel", updateSpeed); } window.addEventListener("resize", resize); -- cgit v1.2.3