-
Notifications
You must be signed in to change notification settings - Fork 3
/
HTML5 - Beginners - rouletteWheelRandom2.html
64 lines (53 loc) · 1.33 KB
/
HTML5 - Beginners - rouletteWheelRandom2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html>
<head>
<meta charsetp="UTF-8">
<meta name="viewport" content="width=device-width" />
</head>
<body bgcolor="black">
<style>#myCanvas {touch-action: none;}</style>
<canvas id="myCanvas" width="320" height="240" style="border:0px solid #d3d3d3;">
Use different browser.
</canvas>
<script>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
gameloop=setInterval(doGameLoop,250);
function doGameLoop(){
ctx.scale(1,1);
myCanvas.height = window.innerHeight*.98;
myCanvas.width = window.innerWidth*.96;
ctx.fillStyle="rgb(0,0,0)";
ctx.fillRect(0,0,c.width,c.height);
ctx.scale(1.6,1.6);
ctx.fillStyle="rgb(255,255,255)";
ctx.fillText("Roulette wheel 10,5,3,2,1 :"+rouletteWheel(10,5,3,2,1),10,10);
}
// roulette wheel random
// numbers. using unlimited
// arguments. the first argument
// is the 0 value, being put
// x times in a array. from
// this array a random element
// is returned.
// rw(10,5) = 10 times 0
// and 5 times 1. one of these
// is returned.
function rouletteWheel(...num){
// create our array
var bag=[];
// run through the arguments
// adding these to the
// array the x amount of tines
for(var i=0;i<num.length;i++){
for(var j=0;j<num[i];j++){
bag.push(i);
}
}
// return one value from our
// array.
return bag[Math.floor(Math.random()*bag.length)];
}
</script>
</body>
</html>