标题:五行八卦
只看楼主
leeqihero
Rank: 3Rank: 3
等 级:论坛游侠
威 望:7
帖 子:122
专家分:135
注 册:2016-3-24
结帖率:20%
 问题点数:0 回复次数:0 
五行八卦
程序代码:
<html>
<head>
<meta charset=utf-8>
</head>
<body>
<canvas id=0></canvas>
</body>
<script>
$=function(b){return document.getElementById(b)};
Array.prototype.clock=function(n){
    var len=this.length;
    var n=n<0?len+n:n;
    var a=this.slice(0,n);
    var b=this.slice(n);
    var c=b.concat(a);
    for(var i=0;i<len;i++){
        this[i]=c[i];
    };
};
R=250
cnv=$(0);
cnv.width=2*R;
cnv.height=2*R;
circle={
    n:0,
    diff:0,
    data:['青龙,朱雀,白虎,玄武'.split(','),'木,火,土,金,水'.split(','),'乾,巽,坎,艮,坤,震,离,兑'.split(',').reverse()],
    size:[30,30,30],
    color:'red',
    R:[140,180,220],
    ringColor:['red','black',0],
    run:function(){
        cnv.height=2*R;
        var cxt=cnv.getContext('2d');
        cxt.textAlign='center';    
        for(var step=0;step<this.data.length;step++){
            var data=this.data[step];
            cxt.translate(R,R);
            cxt.fillStyle=step==this.n?this.color:'black';
            var r=this.R[step];
            var f=this.size[step];
            if(this.ringColor[step]){
                cxt.strokeStyle=this.ringColor[step];
                cxt.beginPath();
                cxt.arc(0,0,r-f,0,360,false);
                cxt.stroke();
            }
            cxt.font=f+'px Arial';
            var len=data.length;
            cxt.rotate(this.diff);
            for(var i=0;i<len;i++){
                cxt.fillText(data[i],0,r);
                cxt.rotate(2*Math.PI/len);
            };
            cxt.rotate(-this.diff);
            cxt.translate(-R,-R);
        };
    }
};
circle.run();
cnv.addEventListener('click', function(e) { 
    var cRect=cnv.getBoundingClientRect();              
    var X=Math.round(e.clientX-cRect.left);        
    var Y=Math.round(e.clientY-cRect.top);         
    var d=Math.sqrt((X-R)**2+(Y-R)**2);
    if(d<100){
        circle.data[circle.n].clock((-1)**(X<R));
    }else{
        for(var i=0;i<circle.data.length;i++){
            if(d<circle.R[i]+15){
                circle.color[circle.n]='black';
                circle.n=i;
                circle.color[circle.n]='red';
                break;
            };
        };
    };
    circle.run();
});
</script>
</html>
搜索更多相关主题的帖子: data step this for var 
2019-12-23 16:58



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-498587-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.123713 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved