国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

使用JS+canvas如何制作圓錐

來源:懂視網 責編:小采 時間:2020-11-27 19:36:07
文檔

使用JS+canvas如何制作圓錐

使用JS+canvas如何制作圓錐:本篇文章給大家講解html中用canvas函數配合JS畫出一個圓錐形的圖形實例,有需要的朋友學習測試下吧。以下是我們給大家分享是實例代碼:<html> <head> <title>我的第一個 HTML 頁面</title> </head>
推薦度:
導讀使用JS+canvas如何制作圓錐:本篇文章給大家講解html中用canvas函數配合JS畫出一個圓錐形的圖形實例,有需要的朋友學習測試下吧。以下是我們給大家分享是實例代碼:<html> <head> <title>我的第一個 HTML 頁面</title> </head>
本篇文章給大家講解html中用canvas函數配合JS畫出一個圓錐形的圖形實例,有需要的朋友學習測試下吧。

以下是我們給大家分享是實例代碼:

<html>
<head>
<title>我的第一個 HTML 頁面</title>
</head>
<body>
<canvas id='cvs' width='1000' height="800">
</canvas>
<script>
const cvs =document.getElementById('cvs');

 // 計算畫布的寬度
 const width = cvs.offsetWidth;
 // 計算畫布的高度
 const height = cvs.offsetHeight;
const ctx = cvs.getContext('2d');
 // 設置寬高
 cvs.width = width;
 cvs.height = height;
/**
ctx:context
x,y:偏移 縱橫坐標
w:度
h:高
color:顏色 數組,可以把顏色提取出來方便自定義
*/
var Cone = function(ctx,x,y,w,h,d,color){
ctx.save();
ctx.translate(x, y);
var blockHeight=h;
// 中點
var x2 = 0;
var y2 = 20;
var k2 = 10;
var w2 = w;
var h2 = h;
// 遞減度
var decrease = d; 
 ctx.beginPath();
ctx.moveTo(x2+w2,y2);
// 橢圓加了邊框,所以加1減1
ctx.bezierCurveTo(x2+w2, y2+k2, x2-w2, y2+k2, x2-w2-1, y2);

ctx.lineTo(x2-w2+decrease,y2+blockHeight);
ctx.bezierCurveTo(x2-w2+decrease, y2+blockHeight+k2, x2+w2-decrease, y2+blockHeight+k2, x2+w2-decrease, y2+blockHeight);
ctx.lineTo(x2+w2+1,y2);
var linear = ctx.createLinearGradient(x2-w2, y2,x2+w2-decrease, y2+blockHeight);
linear.addColorStop(0,color[0]);
linear.addColorStop(1,color[1]);
ctx.fillStyle = linear ; 
ctx.strokeStyle=linear 
ctx.fill();
//ctx.stroke();
ctx.closePath();
//畫橢圓
ctx.beginPath();
ctx.moveTo(x2-w2, y2);
ctx.bezierCurveTo(x2-w2, y2-k2, x2+w2, y2-k2, x2+w2, y2);
ctx.bezierCurveTo(x2+w2, y2+k2, x2-w2, y2+k2, x2-w2, y2);
var linear = ctx.createLinearGradient(x2-w2, y2,x2+w2-decrease, y2+blockHeight);
linear.addColorStop(1,color[0]);
linear.addColorStop(0,color[1]);
ctx.fillStyle = linear ; 
ctx.strokeStyle=linear 
ctx.closePath();

ctx.fill();
ctx.stroke();

ctx.restore();
};
function dr(m){
const colorList =[
{
color:['#76e3ff','#2895ea'],
height:60
},
{
color:['#17ead9','#5d7ce9'],
height:30
},
{
color:['#1ca5e5','#d381ff'],
height:40
},
{
color:['#ffa867','#ff599e'],
height:70
},
{
color:['#ffa6e3','#ec6a70'],
height:50
},
{
color:['#f9c298','#d9436a'],
height:30
},
{
color:['#eb767b','#9971dc'],
height:30
},
{
color:['#f06af9','#5983ff'],
height:100
},
];
const space = 20;
let coneHeight = 0;
// 間隔
const gap = 20;
const x = 380;
const y = 20;
const angle = 30;
let coneWidth=0;
colorList.forEach((item)=>{
coneHeight += item.height +space;
});
// 最下面的先畫(層級)
colorList.reverse().forEach((item,index)=>{
const decrease =Math.tan(Math.PI*angle/180)*(item.height+space);
coneWidth=coneWidth + decrease;
coneHeight = coneHeight-item.height - space;
//圓錐
Cone(ctx,x,coneHeight ,coneWidth ,item.height,decrease,item.color);
// 中點
const cX =parseInt(x)+0.5;
const cY = parseInt(coneHeight + space+ item.height/2)+0.5;
//文字
ctx.save();
ctx.translate(cX , cY );
ctx.textBaseline='top';
ctx.textAlign='center';
const fontSize = item.height/2>=40?40:item.height/2;
ctx.font = fontSize + 'px serif';
//const textMetrics = ctx.measureText('Hello World');
ctx.fillStyle = '#ffffff';
ctx.fillText('5000',0,-fontSize/3);
ctx.restore();
const xLineA =parseInt(coneWidth-decrease/2)+10;
const xLine =parseInt(m+xLineA )>=x?x:m+xLineA ;
//線
ctx.save();
ctx.translate(cX , cY );
ctx.setLineDash([3,2]); 
ctx.strokeStyle = '#a4a4a4'; 
ctx.beginPath(); 
ctx.moveTo(xLineA , 0); 
ctx.lineTo(xLine +20, 0); 
ctx.stroke();
ctx.restore();
//描述文字
ctx.save();
ctx.translate(cX , cY );
ctx.textBaseline='middle';
ctx.textAlign='left';
ctx.font = '22px serif';
//const textMetrics = ctx.measureText('Hello World');
ctx.fillStyle = '#4a4a4a';
ctx.fillText('進入收件列表2',xLine+gap ,0);
ctx.restore();
//轉化率文字
ctx.save();
ctx.translate(cX , cY );
ctx.textBaseline='middle';
ctx.textAlign='left';
ctx.font = '28px bold serif ';
ctx.fillStyle = '#007dfd';
ctx.fillText('20%',xLine+gap ,(item.height+gap)/2 );
ctx.restore();
});
}
let m=0; 
let gravity =10; 
(function drawFrame(){
 window.requestAnimationFrame(drawFrame,cvs);
 ctx.clearRect(0,0,cvs.width,cvs.height);
m += gravity;
 dr(m);
})();
</script>
</body>
</html>

這是腳本之家測試后的完成圖:

上面是我整理給大家的,希望今后會對大家有幫助。

相關文章:

在Django與Vue語法中存在沖突問題如何解決

有關JS抽象工廠模式(詳細教程)

使用Javascript如何開發二維周視圖日歷

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

使用JS+canvas如何制作圓錐

使用JS+canvas如何制作圓錐:本篇文章給大家講解html中用canvas函數配合JS畫出一個圓錐形的圖形實例,有需要的朋友學習測試下吧。以下是我們給大家分享是實例代碼:<html> <head> <title>我的第一個 HTML 頁面</title> </head>
推薦度:
標簽: js 怎么 圓錐
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 日本久久精品免视看国产成人 | 久久成人a毛片免费观看网站 | 亚洲国内精品 | 亚洲一区二区三区精品影院 | 亚洲高清在线观看视频 | 亚洲国产成人久久一区久久 | 国产中文在线观看 | 国产一区免费在线观看 | 欧美日韩亚洲无线码在线观看 | 热re91久久精品国产91热 | 国产亚洲精品a在线观看app | 日韩高清一区二区三区不卡 | 一级黄毛片 | 国产精品免费精品自在线观看 | 日韩 欧美 综合 | 久久久国产成人精品 | 亚洲第二页 | 国产成人精品aaaa视频一区 | 亚洲最新在线观看 | 亚洲午夜久久久久中文字幕 | 国产精品久久久久精 | 欧美日韩一区二区三区四区 | 国产精品久久久久无码av | 国产产一区二区三区久久毛片国语 | 亚洲日韩区在线电影 | 夜夜操夜夜骑 | 中文字幕免费在线播放 | 欧美日韩在线观看视频 | 免费看成人国产一区二区三区 | 乌克兰性欧美精品高清bd | 国产成人拍精品视频网 | 国产成人精品一区二区三区… | 精品国产一区二区三区成人 | 在线免费一区二区 | 日韩国产一区二区 | 欧美成人精品高清在线播放 | 国产v片在线观看 | 日韩国产在线播放 | 中文亚洲欧美日韩无线码 | 亚洲色图国产精品 | www欧美在线观看 |