-
Notifications
You must be signed in to change notification settings - Fork 3
/
HTML5 - Beginners - rouletteWheelRandom.html
74 lines (63 loc) · 1.4 KB
/
HTML5 - Beginners - rouletteWheelRandom.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
65
66
67
68
69
70
71
72
73
74
<!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,500);
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.fillStyle="rgb(255,255,255)";
ctx.scale(1.6,1.6);
ctx.fillText("Roulette Wheel : " +rouletteWheel(),10,10);
}
// set the b array here to return
// a value between a range of
// 0.1
// here 12 numbers are set up
// in this roulette wheel method.
// lower = more frequent chance
// of being returned.
function rouletteWheel(){
// here we have 0..12 possible
// values in the wheel.
var b=[
[0,.3],
[.3,.5],
[.5,.6],
[.6,.7],
[.7,.75],
[.75,.80],
[.80,.84],
[.84,.88],
[.88,.92],
[.92,.95],
[.95,.98],
[.98,.99],
[.99,1.0]
]
// we generate a random float
// between 0 and 1
var a = Math.random();
// if we are in the wheel
// section, then return
// that wheel part value(0/12)
for(var i=0;i<b.length;i++){
if(a>=b[i][0] && a<b[i][1])return i;
}
}
</script>
</body>
</html>