日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
HTML5Canvas組件繪制太極圖案

一、實(shí)現(xiàn)思路:

實(shí)現(xiàn)原理主要是利用HTML5的Canvas組件提供的path函數(shù)功能來繪制圓,首先繪制兩個半圓,分別為黑色和白色,組成一個圓,繪制完成以后再分別繪制一個黑色和白色的圓在繪制好的黑白圓之內(nèi),半徑恰好是黑白大圓一半。 ***在繪制好的兩個黑白小圓內(nèi)分別填充白色和黑色的點(diǎn),半徑大小為10pixel左右。

二、程序效果如下:

三、關(guān)鍵程序解析:

繪制半圓的程序,其中200,200表示開始繪制圓心點(diǎn)坐標(biāo),第三個參數(shù)150表示繪制圓的半徑

第四個參數(shù)表示開始角度,第五個參數(shù)表示結(jié)束角度,***一個參數(shù)表示是否為順時(shí)針或者逆時(shí)針

繪制白色半圓的代碼如下:

 
 
 
 
  1. ctx.fillStyle="#fff";    
  2. ctx.beginPath();     
  3. ctx.arc(200, 200, 150, 1.5*Math.PI, Math.PI/2, false);    
  4. ctx.closePath();    
  5. ctx.fill(); 

繪制黑色半圓的代碼如下:31358.cn

 
 
 
 
  1. ctx.fillStyle="#000";    
  2. ctx.beginPath();     
  3. ctx.arc(200, 200, 150, Math.PI/2, 1.5*Math.PI, false);    
  4. ctx.closePath();    
  5. ctx.fill(); 

在太極圖案中添加文字的代碼使用了透明處理,Canvas全局透明度設(shè)置函數(shù)

如下:

 
 
 
 
  1. // set transparency value      
  2. ctx.globalAlpha = 0.2; 

繪制文字的代碼如下:

 
 
 
 
  1. // Draw semi transparent text    
  2. ctx.fillStyle = "#f00";    
  3. ctx.font = "32pt Arial";    
  4. ctx.fillText("Hello", 220, 200);    
  5. ctx.fillText("Canvas", 100, 250);  

程序完全JavaScript代碼如下:

 
 
 
 
  1. window.onload = function() {    
  2.     var cvs = document.getElementById("canvas-path");    
  3.     ctx = cvs.getContext("2d");    
  4.     // Create circle, radius = 150    
  5.     // start point(x, y), radius, start angle, end angle, boolean antiClockWise    
  6.     ctx.fillStyle="#fff";    
  7.     ctx.beginPath();     
  8.     ctx.arc(200, 200, 150, 1.5*Math.PI, Math.PI/2, false);    
  9.     ctx.closePath();    
  10.     ctx.fill();    
  11.     ctx.fillStyle="#000";    
  12.     ctx.beginPath();     
  13.     ctx.arc(200, 200, 150, Math.PI/2, 1.5*Math.PI, false);    
  14.     ctx.closePath();    
  15.     ctx.fill();    
  16.     // draw sub circle    
  17.     // start point(x, y), radius, start angle, end angle, boolean antiClockWise    
  18.     ctx.fillStyle="#000";    
  19.     ctx.beginPath();     
  20.     ctx.arc(200, 275, 75, 0, Math.PI*2, false);     
  21.     ctx.closePath();    
  22.     ctx.fill();    
  23.     ctx.fillStyle="#fff";    
  24.     ctx.beginPath();     
  25.     ctx.arc(200, 125, 75, 0, Math.PI*2, false);    
  26.     ctx.closePath();    
  27.     ctx.fill();    
  28.     // fill black and white point    
  29.     ctx.fillStyle="#fff";    
  30.     ctx.beginPath();     
  31.     ctx.arc(200, 275, 10, 0, Math.PI*2, false);     
  32.     ctx.closePath();    
  33.     ctx.fill();    
  34.     ctx.fillStyle="#000";    
  35.     ctx.beginPath();     
  36.     ctx.arc(200, 125, 10, 0, Math.PI*2, false);    
  37.     ctx.closePath();    
  38.     ctx.fill();    
  39.     // set transparency value      
  40.     ctx.globalAlpha = 0.2;       
  41.     // Draw semi transparent text    
  42.     ctx.fillStyle = "#f00";    
  43.     ctx.font = "32pt Arial";    
  44.     ctx.fillText("Hello", 220, 200);    
  45.     ctx.fillText("Canvas", 100, 250);    
  46.     ctx.globalAlpha = 1.0;     
  47.     ctx.shadowOffsetX = 2;      
  48.     ctx.shadowOffsetY = 2;      
  49.     ctx.shadowBlur = 2;      
  50.     ctx.shadowColor = "rgba(0, 0, 0, 0.5)";      
  51.     ctx.fillStyle = "#000";    
  52.     ctx.font = "20px Times New Roman";    
  53.     ctx.fillText("-created by gloomyfish", 100, 30);    
  54. }; 

原文:http://www.31358.cn/html5_study/919.html


網(wǎng)頁名稱:HTML5Canvas組件繪制太極圖案
文章起源:http://www.5511xx.com/article/cdchiih.html