效果图: 方法一: 复制代码代码如下: 复制代码代码如下: penyemak imbas anda tidak menyokong teg kanvas <br> var deg = 0; <br> var r = 30; <br> var rl = 100; <br> function drawTaiji() { <br> var canvas = document.getElementById('myCanvas'); <br> var context = canvas.getContext('2d'); <br> var colorA = "rgb(0, 0, 0)"; <br> var colorB = "merah"; <br> <br> var px =Math.sin(deg)*r; <br> var py =Math.cos(deg)*r; <br> context.clearRect(0, 0, 300, 300); <br> context.beginPath(); <br> context.fillStyle = warnaA; <br> context.arc(rl, rl, 60, 0.5 * Math.PI darjah, 1.5 * Math.PI darjah, benar); <br> context.closePath(); <br> context.fill(); <br> context.fillStyle = warnaB; <br> context.beginPath(); <br> context.arc(rl, rl, 60, 1.5* Math.PI deg, 0.5 * Math.PI deg, benar); <br> context.closePath(); <br> context.fill(); <br> context.fillStyle = warnaB; <br> context.beginPath(); <br> context.arc(rl px, rl-py, 30, 0.5 * Math.PI deg, 1.5 * Math.PI deg, benar); <br> context.closePath(); <br> context.fill(); <br> context.fillStyle = warnaA; <br> context.beginPath(); <br> context.arc(rl-px, rl py, 30, 1.5 * Math.PI deg, 0.5 * Math.PI deg, benar); <br> context.closePath(); <br> context.fill(); <br> context.fillStyle = warnaA; <br> context.beginPath(); <br> context.arc(rl px, rl-py, 8, 0, 2 * Math.PI, true); <br> context.closePath(); <br> context.fill(); <br> context.fillStyle = warnaB; <br> context.beginPath(); <br> context.arc(rl-px, rl py, 8, 0, 2 * Math.PI, true); <br> context.closePath(); <br> context.fill(); <br> deg =0.1; <br> } </div> setInterval(drawTaiji, 100); </skrip> </p> <p></body> <p> </html> <br><br> </p> <div class="msgheader">方法二:<div class="right"><span style="CURSOR: pointer" onclick="copycode(getid('phpcode5'));"><u></u></span></div>复制代码</div> <div class="msgborder" id="phpcode5"> <br>代码如下:<br><br> <!DOCTYPE HTML> <br> <html> <br> <badan> <br> <canvas id="myCanvas" width="500" height="500" >penyemak imbas anda tidak menyokong teg kanvas </canvas> <br> <script type="text/javascript"> <br> var canvas = document.getElementById('myCanvas'); <br> var ctx = canvas.getContext("2d"); <br> sudut var = 0; <br> kiraan var = 360; <br> var clrA = '#000'; <br> var clrB = 'merah'; <br> <br> fungsi taiji(x, y, jejari, sudut, bijak) { <br> sudut = sudut || 0; <br> bijak = bijak ? 1: -1; <br> ctx.save(); <br> ctx.translate(x, y); <br> ctx.rotate(sudut); <br> ctx.fillStyle = clrA; <br> ctx.beginPath(); <br> ctx.arc(0, 0, jejari, 0, Math.PI, benar); <br> ctx.fill(); <br> ctx.beginPath(); <br> ctx.fillStyle = clrB; <br> ctx.arc(0, 0, jejari, 0, Math.PI, palsu); <br> ctx.fill(); <br> ctx.fillStyle = clrB; <br> ctx.beginPath(); <br> ctx.arc(bijak * -0.5 * jejari, 0, jejari / 2, 0, Math.PI * 2, benar); <br> ctx.fill(); <br> ctx.beginPath(); <br> ctx.fillStyle = clrA; <br> ctx.arc(bijak * 0.5 * jejari, 0, jejari / 2, 0, Math.PI * 2, palsu); <br> ctx.arc(bijak * -0.5 * jejari, 0, jejari / 10, 0, Math.PI * 2, benar); <br> ctx.fill(); <br> ctx.beginPath(); <br> ctx.fillStyle = clrB; <br> ctx.arc(bijak * 0.5 * jejari, 0, jejari / 10, 0, Math.PI * 2, benar); <br> ctx.fill(); <br> ctx.restore(); <br> } <br> <br> gelung = setInterval(fungsi () { <br> beginTag = benar; <br> ctx.clearRect(0, 0, canvas.width, canvas.height); <br> taiji(200, 200, 50, Math.PI * (sudut / kiraan) * 2, benar); <br> //taiji(350, 350, 50, Math.PI * ((kiraan - sudut) / kiraan) * 2, palsu); <br> sudut = (sudut 5) % kiraan; <br> }, 50); </div> </skrip> </p> <p></body> <br> </html>