Loading...
(function(){<br />
let canvas = document.createElement('canvas'),<br />
ctx = canvas.getContext('2d'),<br />
w = canvas.width = innerWidth,<br />
h = canvas.height = innerHeight,<br />
particles = [],<br />
properties = {<br />
bgColor : 'rgba(17, 17, 19, 1)',<br />
particleColor : 'rgba(255, 40, 40, 1)',<br />
particleRadius : 3,<br />
particleCount : 60,<br />
particleMaxVelocity : 0.5,<br />
lineLength : 150,<br />
particleLife : 6,<br />
};<br />
<br />
document.querySelector('body').appendChild(canvas);<br />
<br />
window.onresize = function() {<br />
w = canvas.width = innerWidth;<br />
h = canvas.height = innerHeight;<br />
}<br />
<br />
class Particle {<br />
constructor() {<br />
this.x = Math.random()*w;<br />Loading...
To round numbers in JavaScript, you can use the built-in Math methods.
parseInt() always returns an integer.
1// Math.floor2console.log(3 Math.floor(1.5), // 14 Math.floor(9.6), // 95 Math.floor(7.3) // 76)78// Math.ceil()9console.log(10 Math.ceil(7.5), // 811 Math.ceil(3.6), // 412 Math.ceil(1.3), // 213 Math.ceil(-0.65), // -014 Math.ceil(-5.001) // -515)1617// Math.trunc18console.log(19 Math.trunc(0.5), // 020 Math.trunc(2.67), // 221 Math.trunc(7.8), // 722)2324// Math.round25console.log(26 Math.round(0.5), // 127 Math.round(2.6), // 328 Math.round(8.36), // 829)3031// parseInt32console.log(33 parseInt("15,123", 10), //1534 parseInt(-15.1, 10), // -1535 parseInt(0.000000123, 10), // 136)37