html5 控制概率的抽奖,求一个可挑概率的html5抽奖 圆盘的

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

圆盘抽奖

*.{margin:0;padding:0;}

#elm1{height:40px;background-color:#a00;}

#elm2{height:50px;background-color:#0a0;}

#wrap{position:relative;height:400px;}

#bg{position:absolute;left:0;top:0;}

#cell{position:absolute;left:0;top:0;}

#control{position:absolute;left:430px;top:30px;}

start
end
show

var field = [[0,30],[30,60],[60,90],[90,120],[120,150],[150,180],[180,210],[210,240],[240,270],[270,300],[300,330],[330,360]]

,fillStyle = ['#a00','#0a0','#00a','aa0','#a16','#0aa','#a5a','f31','#784','#a43','#34a','#786']

,width = 400

,height = 400

,c_x = 200

,c_y =200

,radius = 200

,dom_bg = document.getElementById('bg')

,dom_cell = document.getElementById('cell')

,index =0

,timer = null

,stop = false

,running = false

,speed = 300

,flag = false

,stepall

,stepfast = 7

,stepslow

,stepping =0

,selected

,pos;

function setup(){

drawBg();

}

function drawBg(){

var deg = Math.PI/180;

var tmp_1 = 0;

var tmp_2 = 30;

dom_bg.height = height;

dom_bg.width = width;

var ctx=dom_bg.getContext('2d');

for(var i=0;i<12;i++){

ctx.beginPath();

ctx.fillStyle = fillStyle[i];

ctx.moveTo(c_x,c_y);

ctx.arc(c_x,c_y,radius,deg*tmp_1,deg*tmp_2,false);

ctx.fill();

ctx.fillStyle = '#000';

ctx.fillText(tmp_1,200+Math.cos(deg*(tmp_1+15))*130,200+Math.sin(deg*(tmp_1+15))*130);

tmp_1 +=30;

tmp_2 +=30;

}

}

function drawBgText(){

}

function rotate(){

if(!flag && stepping>7){

clearTimer();

speed = 100;

timer = setInterval(rotate,speed);

}

if(flag && stepping > stepslow && stepping

clearTimer();

speed = 300;

timer = setInterval(rotate,speed);

}

if(index ==12){

index = 0;

}

if(flag && stepping == stepall){

clearTimer();

happy();

}

drawCell();

index++;

stepping++;

}

function drawCell(){

var deg = Math.PI/180;

var tmp_1 = field[index][0];

var tmp_2 = field[index][1];

dom_cell.height=height;

dom_cell.width =width;

var ctx=dom_cell.getContext('2d');

ctx.beginPath();

ctx.fillStyle = '#eee';

ctx.moveTo(c_x,c_y);

ctx.arc(c_x,c_y,radius,deg*tmp_1,deg*tmp_2,false);

ctx.fill();

}

function createStop(){

selected = Math.floor(Math.random() * 11); //从0-11个数字中选 想zb在这控制一下。

var circle = Math.floor(Math.random()*3) + 2;

var c_step = circle *12;

var actualIndex = stepping%12;

stepall = selected - actualIndex + c_step;

flag = true;

stepslow = stepall - 7;

stepping = 0;

}

function happy(){

document.getElementById("show").innerText = selected + '选上了';

}

function startClick(){

if(running){

return;

}

running= true;

timer = setInterval(rotate,speed);

}

function endClick(){

if(stop){

return;

}

stop = true;

clearTimer();

createStop();

timer = setInterval(rotate,speed);

}

function clearTimer(){

clearInterval(timer);

timer = null;

}

setup();

document.getElementById('start').addEventListener('click',startClick,false);

document.getElementById('end').addEventListener('click',endClick,false);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值