日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

关于canvas

發布時間:2025/6/15 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于canvas 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?//在給定的矩形內清除指定的像素
//語法:context.clearRect(x,y,width,height)
//參數:要清除的矩形左上角的 x,y 坐標,以及寬與高,單位是像素?
// 加載圖片
var gravel = new Image();
gravel.src = "gravel.jpg";?

// 保存當前狀態
context.save();
// 字號為60,字體為Impact
context.font = "60px impact";

//填充顏色
context.fillStyle = '#996600';

//居中
context.textAlign = 'center';

// 顏色黑色,20%透明度
// 向右移動15px,向左移動10px
context.shadowOffsetX = 15;
context.shadowOffsetY = -10;

// 將第二圖的高寬放大到原來的2倍
context.scale(2, 2);

// 輕微模糊陰影
context.shadowBlur = 2;
context.shadowColor = 'rgba(0, 0, 0, 0.2)';

//繪制文本
context.fillText('Happy Trails!', 200, 60, 400);

// 恢復之前的canvas狀態
context.restore();

下面是一些具體寫法


????創建畫布
?????<canvas width="1000px" height="600px" id="canvas">不支持canvas</canvas>
????
????<script>
????function $(id){
????return document.getElementById(id)
????}
????var canvas=$("canvas")
????var context=canvas.getContext("2d")//畫筆
????
????
????//填充
????fillRect();調用函數
????function fillRect(){
????//context.fillStyle="rgb(255 0 255)"//填充顏色
????context.fillStyle="red";

????context.fillRect(20,10,100,100)???????//x、y、width、height
????}

????//設置陰影
????setShadow();
????function setShadow(){
????context.fillStyle="blue";
????context.shadowColor="red"//顏色
????context.shadowBlur="30"//模糊級數
????context.shadowOffsetX=10;//方向
????context.shadowOffsetY=10;
????context.fillRect(130,10,100,100)
????
????
????}
????//畫空白框
????drawStrokeRect()
????function drawStrokeRect(){
????context.strokeStyle = "blue";//顏色
????context.lineWidth = 2;//border寬度
????context.strokeRect(x,y,width,height);//xy左上點坐標,矩形寬長
????}
????//設置漸變
????var grd;
????setGradinet()
????function setGradinet(){
????grd = context.createLinearGradient(10,0,210,0);//x0,y0漸變開始點坐標,x1,y1結束點坐標
????grd.addColorStop(0,"rgb(255,0,255)");
????grd.addColorStop(1,"white");
????//同心圓
?????/* grd = context.createRadialGradient(80,160,20,80,160,50);//x0,y0,r0,x1,y1,r1兩圓不相交
?????grd.addColorStop(0,"rgb(255,0,255)");//第一個圓,0表示圓的位置
?????grd.addColorStop(1,"white");//第二個圓,1表示圓的位置
????*/
????context.fillStyle=grd;
????context.fillRect(10,130,150,100)
????
????}??
????</script>

轉載于:https://www.cnblogs.com/zengjie123/p/4641519.html

總結

以上是生活随笔為你收集整理的关于canvas的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。