Math.random() returns a floating point (decimal) number in range 0.0 to 1.0 meaning you'll get stuff like 0.3482182. From that you need to do a little math to get the final values you want. Basically you multiply it to scale the range then add a number to shift it's starting range. A random number in range [0.0 - 1.0] when multiplied by 7 will then be in range [0.0 - 7.0]. Add 4 to that to get a number in range [4.0 - 11.0].
Um, I've...
User Profile
Collapse
-
-
I think you want something like this...
var distance = "" + Math.floor(Math .random() * 100 - 50);
var speedx = "" + Math.floor(Math .random() * 100 - 50);
var speedy = "" + Math.floor(Math .random() * 100 - 50);
Math.random() returns a number in range 0.0 to 1.0. The *100-50 makes the range -50.0 to 50.0. Math.floor() converts that to an integer and the ""+ sorta makes...Leave a comment:
-
does this help...
var txt = document.getEle mentById('myTex tArea');
txt.value = txt.value + '\n' + newStuff;Leave a comment:
-
Thanks for your reply but it turns out you can. Sorta.
I'm making a template to code mouse events the way I'm used to: mouseDown(x,y), return true to go to mouseDrag(x,y,d x,dy) then a mouseUp(x,y). I use the mousemove event to fire the mouseDrag and yes, regular mousemove events only fire inside the browser. If the mouse is down though the mousemove events continue to fire wherever you drag.
My problem was mouseDrag...Leave a comment:
-
Follow mousemove events outside browser?
Hi, I have a canvas that reacts to mousedown and mousemove. Once I click the canvas I want to track the cursor wherever it goes, including outside the browser.
Setting window.onmousem ove only gives events inside the browser of course. I tried window.captureE vents which works on Safari but FireFox says it's deprecated. Mozilla's docs say to use window.addEvent Listener but the behavior is the same: in Safari I can drag outside the window...
No activity results to display
Show More
Leave a comment: