1.怎么网页Canvas中绘制形?
2.å¦ä½å¨ HTML5 ç»å¸ä¸ç»å¾
3.电脑页面的源码什么特效?
4.QML类型:Context2D
5.quadraticCurveTo()HTML DOM quadraticCurveTo() 方法
6.quadraticCurveTo()描述
怎么网页Canvas中绘制形?
我们可以获取canvas对象为var c=document.getElementById("myCanvas");其应有js属性方法如下列举:
1:绘制渲染对象,c.getContext("2d"),源码获取2d绘图对象,无论我们调用多少次获取的源码对象都将是相同的对象。
2:绘制方法:
clecrRect(left,源码top,width,height)清除制定矩形区域,
fillRect(left,源码top,width,height)绘制矩形,并以fillStyle填充。源码电影源码采集
fillText(text,源码x,y)绘制文字;
strokeRect(left,top,width,height)绘制矩形,以strokeStyle绘制边界。源码
beginPath():开启路径的源码绘制,重置path为初始状态;
closePath():绘制路径path结束,它会绘制一个闭合的源码区间,添加一条起始位置到当前坐标的源码闭合曲线;
moveTo(x,y):设置绘图其实坐标。源码
lineTo(x,源码y);绘制从当前其实位置到x,源码y直线。源码
fill(),stroke(),clip():在完成绘制的最后的填充和边界轮廓,剪辑区域。c 掘金量化源码
arc():绘制弧,圆心位置、起始弧度、终止弧度来指定圆弧的位置和大小;
rect():矩形路径;
drawImage(Imag img):绘制;
quadraticCurveTo():二次样条曲线路径,参数两个控制点;
bezierCurveTo():贝塞尔曲线,参数三个控制点;
createImageData,getImageData,putImageData:为Canvas中像素数据。ImageData为记录width、height、和数据 data,其中data为我们色素的记录为
argb,所以数组大小长度为width*height*4,顺序分别为rgba。getImageData为获取矩形区域像素,而putImageData则为设置矩形区域像素;
… and so on!
3:坐标变换:
translate(x,y):平移变换,原点移动到坐标(x,y);
rotate(a):旋转变换,旋转a度角;
scale(x,y):伸缩变换;
save(),打赏交易源码restore():提供和一个堆栈,保存和恢复绘图状态,save将当前绘图状态压入堆栈,restore出栈,恢复绘图状态;
å¦ä½å¨ HTML5 ç»å¸ä¸ç»å¾
æ¥éª¤ 1: å¨ HTML ä¸è®¾ç½®ç»å¸ï¼å建ä¸ä¸ªå¼ç¨ï¼å¹¶è·åä¸ä¸æ对象ç»å¸å¨ HTML ä¸éè¿ <canvas> æ ç¾å®ä¹ãä¸å ¶ä»æ ç¾ç±»ä¼¼ï¼<canvas> çå±æ§ï¼å¦å®½åº¦åé«åº¦ï¼ä½ä¸ºç¹æ§è¾å ¥ãåè®¾ä½ å¸æå建ä¸ä¸ªå®½ åç´ ãé« åç´ çç»å¸ï¼å¹¶å°å ¶å½å为âcan1âï¼ç¨åå¨ JavaScript ä¸å¼ç¨å®æ¶å°ç¨å°ã
å¨ HTML ææ¡£ä¸è¾å ¥ <canvas> æ ç¾ã
<canvas id="can1" width="" height=""></canvas>å¨ JavaScript ææ¡£ä¸ï¼å建ä¸ä¸ªåéï¼å¨ç¼åèæ¬æ¶è¯¥åéå°ä»£æ¿âcan1âãè¿éï¼æ们å°è¯¥åéå½å为âmyCanvasâï¼å¹¶ä½¿ç¨ getElementById å°å ¶é¾æ¥å°âcan1âã
var myCanvas = document.getElementById("can1");ç»å¸ç CanvasRenderingContext2D å¯¹è±¡å ·ææä½ç»å¸çææå½ä»¤ã è¿éï¼å¨ä¸ä¸æ对象ä¸æ£ç´¢âcan1âãå°æ¤åé称为âmyContextâã
var myContext = myCanvas.getContext("2d");æ¥éª¤ 2: ç»å¶ç©å½¢ãç´çº¿ãè´å¡å°æ²çº¿ãååå½¢ç¶
å¨ç»å¸ä¸ç»å¶ç®åç线æ¡é常容æãä½¿ç¨ JavaScript ç moveTo æ¹æ³å¯è®¾ç½®çº¿æ¡å¼å§ä½ç½®çåæ ãç¶ååªé使ç¨å¦ä¸æ¹æ³è®¾ç½®ç»ç¹ã 第äºæ¥å¯ä»¥ä½¿ç¨è¥å¹²æ¹æ³ï¼æ¯ç§æ¹æ³ä¸ç¨äºå¸®å©åç°ä¸ç§ä¸åç线åï¼æ 论æ¯ç´çº¿ãè´å¡å°æ²çº¿è¿æ¯å弧ãè¥è¦å°çº¿æ¡å并为形ç¶ï¼å¯ä»¥éå对 beginPath å closePath æ¹æ³è°ç¨ä¸ç线æ¡ãå¨æå®æéçå¤è§ä¹åï¼å¯ä»¥ä½¿ç¨ fill æ¹æ³åºç¨é¢è²ï¼å¹¶ä½¿ç¨ stroke æ¹æ³æ§è¡çº¿æ¡åå½¢ç¶çåç°ã
åºç¨ä¸äºåºæ¬é£æ ¼ãè¿éï¼éè¿ä½¿ç¨ fillStyle å±æ§ç»å¶ä¸ä¸ªé»è²ç©å½¢ï¼å°ç»å¸èæ¯è®¾ç½®ä¸ºé»è² (#)ãç¶åä½¿ç¨ strokeStyle å±æ§å°çº¿æ¡é¢è²è®¾ç½®ä¸ºç½è² (#fff)ï¼ä½¿ç¨ fillRect æ¹æ³åºç¨é»è²èæ¯ï¼å¹¶ä½¿ç¨ lineWidth å±æ§å°çº¿æ¡çç²ç»è®¾ç½®ä¸º 3 个åç´ ã
// Specify a black background, and white lines that are 3 pixels thick.
myContext.fillStyle = '#';
myContext.strokeStyle = '#fff';
myContext.fillRect(0,0,,);
myContext.lineWidth = 3;myContext.fill();
å¨åç»æ¥éª¤ä¸ï¼å°å¨è¿ä¸ª à çé»è²ç»å¸ä¸ç»§ç»æ建ã
ç°å¨ï¼åå¤å¨ç»å¸çé»è²è¡¨é¢ç»å¶ä¸ä¸ªç½è²çº¿æ¡ãå ä»ç´çº¿å¼å§ã
ä½¿ç¨ moveTo æ¹æ³è®¾ç½®ç´çº¿çèµ·ç¹ï¼ä½¿ç¨ lineTo æ¹æ³è®¾ç½®ç»ç¹ã
è¿äºæ¹æ³éç¨ä¸¤ä¸ªæ°åä½ä¸ºåæ°ã第ä¸ä¸ªæ°å表示 x è½´åæ ï¼æè 表示æ¤åæ å®ä¹çèªç»å¸å·¦ä¾§ç®èµ·çåç´ æ°ã第äºä¸ªæ°åæ¯ä»é¡¶é¨å¼å§æµéç y è½´åæ ã
// Draw a line that starts at the upper left corner of the canvas and ends at the lower right.
myContext.moveTo(0,0);
myContext.lineTo(,);
myContext.stroke();
è¥è¦ç»å¶äºæ¬¡è´å¡å°æ²çº¿ï¼è¯·ä½¿ç¨ quadraticCurveTo æ¹æ³ï¼è¯¥æ¹æ³éç¨ä¸¤ä¸ªåæ âæ²çº¿çä¸ä¸ªæ§å¶ç¹åä¸ä¸ªç«¯ç¹ã
// Draw a swooping curve that spans the width of the canvas.myContext.moveTo(0,0);
myContext.quadraticCurveTo(0,,,);
myContext.stroke();
è¥è¦ç»å¶ä¸æ¬¡è´å¡å°æ²çº¿ï¼è¯·ä½¿ç¨ bezierCurveTo æ¹æ³ï¼è¯¥æ¹æ³éç¨ä¸ä¸ªåæ âæ²çº¿ç两个æ§å¶ç¹åä¸ä¸ªç«¯ç¹ã
// Draw a V-shaped Bezier curve that spans the entire canvas.myContext.moveTo(0,0);
myContext.bezierCurveTo(, , 0, , , 0);
myContext.stroke();
è¥è¦å建ä¸ä¸ªåï¼è¯·ä½¿ç¨ arc æ¹æ³ï¼å¨è®¾ç½®ç¨äºç»å¶å形轮å»çåç¹æ¶ï¼è¯·ç¡®ä¿å° moveTo æ¹æ³è®¾ç½®å¨æ²¿çº¿æ¡è·¯å¾çä½ç½®ä¸ï¼å¦ååä¸å°æä¸æ¡éå moveToåæ çâ尾巴âã
// Draw a circle that spans the width of the canvas.myContext.moveTo(,);
myContext.arc(,,,0,Math.PI*2,true);
myContext.stroke();
éè¿éå对 beginPath å closePath è°ç¨ä¸çå¤ä¸ªçº¿æ¡ï¼å¯ä»¥ä»ä¸è¿°çº¿æ¡çä»»æç»åä¸ç»å¶ä¸ä¸ª 2D å½¢ç¶ãç¶åï¼æ´ä¸ªå½¢ç¶å¯ä»¥ä½¿ç¨ fill æ¥æ¶ä¸ç§é¢è²ãåé¢è®¾ç½®çç¬åæ ·å¼å°å建ç½è²çº¿æ¡ï¼å¨ä¸åºç¨äºä¸»ä½ççº¢è² (#f) å并æ¶ï¼è¯¥å½¢ç¶å°ç»§æ¿åè²è°å¤è§ã
// Draw a red diamond that spans the entire canvas.myContext.fillStyle = '#f';
myContext.beginPath();
myContext.moveTo(,0);
myContext.lineTo(0,);
myContext.lineTo(,);
myContext.lineTo(,);
myContext.closePath();
myContext.fill();
æ¥éª¤ 3: æ¾ç¤ºä½å¾å¾å
ä½å¾å¾åï¼å¦ .jpgã.png å .gif æ件ï¼å¯ä»¥æ¾ç½®å¨ç»å¸ä¸ï¼çè³å¯ä»¥å¨ä»£ç ä¸ç¼©æ¾åè£åªï¼ä¸ä¼è§¦ååå§æ件ãè¥è¦æ·»å ä½å¾å¾åï¼è¯·æå®è¯¥å¾åç URIï¼ç¶åä½¿ç¨ drawImage æ¹æ³å¨ç»å¸ä¸æå®å ¶ä½ç½®ã使ç¨å¯éåæ°å¯å°å¾å缩æ¾å°æå®ç大å°ï¼çè³ä» æ¾ç¤ºå¾åçä¸ä¸ªç段ï¼è¿å¯¹äºå®ç°æ»å¨èæ¯æ使ç¨åç»é¢è¡¨å¨ææ¾ç¤ºåç»é¢çæä½é常æç¨ã
è¥è¦å¨å±å¹ä¸ç»å¶ä½å¾å¾åèä¸è¿è¡ä»»ä½ä¿®æ¹ï¼è¯·æå®è¦ç¨äºå·¦ä¸è§ç x åæ å y åæ ã
// Draw an image at the upper left corner of the canvas (0, 0).var myImg = new Image();
myImg.src = 'myImageFile.png';
myContext.drawImage(myImg, 0, 0)
è¥è¦ç¼©æ¾å¾åï¼å¯å¨æ«å°¾æ·»å 两个æ°åï¼åå«ä»£è¡¨å®½åº¦åé«åº¦ãå¦ææ帮å©ï¼ä¸å¦¨å°å两个æ°åè§ä¸ºâå³é¨âåâåºé¨âï¼èä¸æ¯â宽度âåâé«åº¦âã
// Scale the image to span the entire x canvas.var myImg = new Image();
myImg.src = 'myImageFile.png';
myContext.drawImage(myImg, 0, 0, , )
è¥è¦ä» 使ç¨å¾åçä¸ä¸ªåçï¼åéè¦å®ä¹ä¸¤ä¸ªç©å½¢åºåï¼å¯¹ drawImage çè°ç¨æé«å° 9 个åæ°ï¼ç¬¬ä¸ä¸ªåæ°æ¯ JavaScript å¾å对象ï¼ãè¦ä¼ å ¥çåå个æ°å表示å¾åçåçãåå个æ°å表示è¦æ¾ç¤ºè¯¥åççç»å¸åºåã
// Take a x slice from the upper left of the image and scale it to span the entire x canvas.var myImg = new Image();
myImg.src = 'myImageFile.png';
myContext.drawImage(myImg, 0, 0, , , 0, 0, , );
æ¥éª¤ 4: æ¸å
ä»»ä½äººåªè¦çæå¨å¾å½¢è®¾è®¡ç¨åºä¸å®ä¹æ¸åç常è§æ¹å¼ï¼é½ä¼åæ¬¢ä½¿ç¨ JavaScript 代ç å®ä¹æ¸åçç®åæ§ãå¨è®¾è®¡ç¨åºä¸æ¯éæ©é¢è²ï¼æ¸åä¸çé¢è²ä½ç½®ä½¿ç¨æ°´å¹³æ»å设置ãJavaScript ä¸çå¯ä¸åºå«æ¯ä½¿ç¨ä» 0 å° 1 èå´å çå°æ°å¼ä»£æ¿æ»åã
å¨è®¾è®¡ç¨åºä¸ï¼çº¿æ§æ¸å使ç¨çº¿æ¡å¨å¾åä¸å®ä½ï¼çº¿æ¡çå¼å§åç»æä½ç½®ç¡®å®æ¹åå缩æ¾çº§å«ãå¨ JavaScript ä¸ï¼è¯¥çº¿æ¡ä½¿ç¨ä¸¤å¯¹ xãy è½´åæ ç»å¶ãç¶åå° 4 个æ°åä¼ éå° createLinearGradient æ¹æ³ä»¥å建 CanvasGradient 对象ãå¨å®ä¹æ¸å对象çå±æ§ä¹åï¼å°±ä¼å¾å°æéçæ¸åï¼CanvasGradient ä½ä¸º fillStyle ä¼ éå° fillRect æ¹æ³è¿è¡åç°ã
// Render a white, red and black gradient diagonally across the canvas.var myGradient = myContext.createLinearGradient(0,0, ,); // gradient starts at upper left and ends at lower right
myGradient.addColorStop(0,"#fff"); // white at the beginning of the gradient
myGradient.addColorStop(0.5,"#f");// red in the middle of the gradient
myGradient.addColorStop(1,"#"); // black at the end of the gradient
myContext.fillStyle = myGradient; // ensure the next call to fillRect will use the specified gradient
myContext.fillRect(0,0,,); // rectangle that contains the gradient spans the entire canvas
å¾åæ¸åçå®ä¹æ¹å¼ç¨æä¸åã为æ¸åçèµ·ç¹åç»ç¹ç»å¶ä¸¤å¯¹ xãy è½´åæ âï¼è¿ä¸çº¿æ§æ¸åä¸ä¸æ ·âï¼ä½æ¯ä¸ªåæ 对é½æ第ä¸ä¸ªä¸å ¶å ³èç z è½´åæ ï¼ç¨äºå®ä¹åå¾ãå¯ä»¥æ³å为å´ç»ä¸ä¸ªåæ ç»å¶ä¸ä¸ªåï¼è¯¥åæ ä½äºä¸å¿ (, )ï¼ç»å¶çåç大å°ä»¥åç´ ä¸ºåä½å®ä¹ãè¿æ ·å®ä¹ä¸¤ä¸ªåä¹åï¼ä¸ä¸ªåè¾å°ï¼ä¸ä¸ªåè·¨æ´ä¸ªç»å¸ï¼æ 6 个æ°åä¼ éå° createRadialGradientãå¨åç°æ¶ï¼å¾åæ¸åå¨ä¸¤ä¸ªåä¹é´ç空é´ä¸ç»å¶ï¼é¢è²ç级ä¸åçåå¾ç大å°ææ£æ¯ã
// Render a white, red and black radial gradient spanning the canvas.var myGradient = myContext.createRadialGradient(,,0, ,,); // gradient is centered and spans the entire canvas
myGradient.addColorStop(0,"#fff"); // white at the beginning of the gradient
myGradient.addColorStop(0.5,"#f"); // red in the middle of the gradient
myGradient.addColorStop(1,"#"); // black at the end of the gradient
myContext.fillStyle = myGradient; // ensure the next call to fillRect will use the specified gradient
myContext.fillRect(0,0,,); // rectangle that contains the gradient spans the entire canvas
æ¥éª¤ 5: å¨ç»
å¯ä»¥ä½¿ç¨å¤ç§æ¹æ³ç»å¶å¨ç»ã
对äºç»å¸å çå ç´ ï¼JavaScript æä¾äº setInterval æ¹æ³ï¼è¯¥æ¹æ³è®¡åä¸ä¸ªéå¤è°ç¨çå½æ°ï¼æ¯ç»è¿å®ä¹çæ¶é´é´é便è°ç¨ä¸æ¬¡è¯¥å½æ°ãå¨è¯¥å½æ°ä¸ï¼éè¦éç»ç»å¸æ¥åæ å¯¹å ¶ä¸åç°ç对象çæ´æ¹ãä¸é¢æ¯ä¸ä¸ªç¤ºä¾ï¼å ¶ä¸ä¸ä¸ªå½æ°åå§å该å¨ç»ï¼å°åç°é¢ç计å为大约æ¯ç§ 帧ï¼æ¯ . 毫ç§ä¸å¸§ï¼ï¼å¹¶ä¸éå¤è°ç¨è¯¥å½æ°å°éç»ç»å¸ãå¨æ¬ä¾ä¸ï¼å¾åæ¸åä»ä¸ä¸ªå°ç¹éæ¸å¢å¤§ï¼ç´å°å¡«å æ´ä¸ªç»å¸ã
// Generate an animation of a growing gradient.// These variables must exist globally so both functions can access them.
var myCanvas;
var myContext;
var outerBoundary = 0, innerBoundary = 0;
// Start the animation.
window.onload = initialize;
function initialize() {
myCanvas = document.getElementById("can1");
myContext = myCanvas.getContext("2d");
setInterval("redrawCanvas()",); // redraw @ approximately frames per second
}
// Run the animation.
function redrawCanvas() {
if (outerBoundary < ) {
outerBoundary++; // grow the size of the gradient
} else {
innerBoundary++; // grow the size of the inner white circle if red is maxed
}
var myGradient = myContext.createRadialGradient(,,innerBoundary, ,,outerBoundary);
myGradient.addColorStop(0,"#fff"); // white at the beginning of the gradient
myGradient.addColorStop(0.5,"#f"); // red in the middle of the gradient
myGradient.addColorStop(1,"#"); // black at the end of the gradient
myContext.fillStyle = myGradient; // ensure the next call to fillRect will use the specified gradient
myContext.fillRect(0,0,,); // rectangle that contains the gradient spans the entire canvas
}
CSS3 转æ¢åå¨ç»å¯ç¨äºè½¬æ¢ç»å¸æ¬èº«åç»å¸å¤é¨ç对象ã
æ¤å¤ï¼æ°ç WinJS åºæ许å¤é«åº¦ä¼åçå¨ç»ï¼å建è¿äºå¨ç»æ¯ä¸ºäºæ¨¡æåæ Windows å¨ç»çè¡ä¸ºã WinJS å¨ç»æå©äºä¸ºä½ çåºç¨ UI æä¾ä¸ä¸ªé«åº¦éæçå¤è§ãæå ³è¯¦ç»ä¿¡æ¯ï¼è¯·åé WinJS.UI.Animation å½å空é´ã
æ¥éª¤ 6: æ´å¤ HTML5 ç»å¸æ示
å¯ä»¥ä½¿ç¨ä¸ç³»åå±æ§ï¼shadowColorãshadowBlurãshadowOffsetX å shadowOffsetYï¼åºç¨é´å½±ã
å¯ä»¥ä½¿ç¨ createPattern æ¹æ³ä½ä¸ºä¸ç§æ¨¡å¼éå¤ç»å¸ä¸çå ç´ ã
å¯ä»¥ä½¿ç¨ save æ¹æ³ä¿åç»å¸ç¶æï¼ç¶åæ§è¡æ´æ¹ï¼åä½¿ç¨ restore æ¹æ³è¿å以åçç¶æã该æ¹æ³å¾å¥½ç¨ï¼å½æ°çè³ä¸éè¦éç¨åæ°ã
å¯ä»¥ä½¿ç¨ globalCompositeOperation å±æ§å®ä¹ä¸¤ä¸ªç»å¸å ç´ éå æ¶ä¼åçä»ä¹æ åµã 使ç¨æ¤å±æ§å§ç»å¯ä»¥å®ä¹å¨æºææ°å ç´ çº§å«åççæ åµãå¯ä»¥æ§è¡çæä½æé¢è²æ··åãé®è½åæ´æ¹éå ä¼å 级çã
注æ globalCompositeOperation 主é¢ä½¿ç¨æºè¡¨ç¤ºæ°å ç´ ï¼ä½¿ç¨ç®æ 表示以ååå¨çå ç´ ã
å¯ä»¥ä½¿ç¨ strokeText æ¹æ³å°ææ¬æ·»å å°ç»å¸ã
电脑页面的什么特效?
这个是html5的效果,以下是源代码:
<!DOCTYPE html>
<html xmlns="/texiao/html5/index/hovertreewelcome.css" type="text/css" rel="stylesheet" />
</head>
<body ondragstart="window.event.returnValue=false" oncontextmenu="window.event.returnValue=false" onselectstart="event.returnValue=false">
<div id="hovertreecontainer">
<div>
<h1 id="h1">何问起 </h1>
<h2 id="h2"> 想问候,不知从何问起,就直接说喜欢你!</h2>
<h3 id="h2">hovertree.com为您提供前端特效,ASP.NET等设计开发资料。<a href="/hvtart/bjae/onxw4ahp.htm">原文</a> <a href="/texiao/">特效</a></h3>
<p> </p>
<p><strong><a href="/">进入主站</a></strong></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
</div>
<canvas id="canvas"></canvas>
<audio autoplay="autoplay">
<source src="" type="audio/ogg">
<source src="/hovertreesound/hovertreexihuanni.mp3" type="audio/mpeg">
您的浏览器不支持播放音乐。请用支持html5的浏览器打开,例如chrome或火狐或者新版IE等。
<br />何问起 hovertree.com
</audio><script type="text/javascript" src="/texiao/html5/index/hovertreewelcome.js">
</script>
<script type="text/javascript">
; (function (window) {
var ctx,
hue,
logo,
form,
buffer,
target = { },
tendrils = [],
settings = { };
settings.debug = true;
settings.friction = 0.5;
settings.trails = ;
settings.size = ;
settings.dampening = 0.;
settings.tension = 0.;
Math.TWO_PI = Math.PI * 2;
// ========================================================================================
// Oscillator 何问起
// ----------------------------------------------------------------------------------------
function Oscillator(options) {
this.init(options || { });
}
Oscillator.prototype = (function () {
var value = 0;
return {
init: function (options) {
this.phase = options.phase || 0;
this.offset = options.offset || 0;
this.frequency = options.frequency || 0.;
this.amplitude = options.amplitude || 1;
},
update: function () {
this.phase += this.frequency;
value = this.offset + Math.sin(this.phase) * this.amplitude;
return value;
},
value: function () {
return value;
}
};
})();
// ========================================================================================
// Tendril hovertree.com
// ----------------------------------------------------------------------------------------
function Tendril(options) {
this.init(options || { });
}
Tendril.prototype = (function () {
function Node() {
this.x = 0;
this.y = 0;
this.vy = 0;
this.vx = 0;
}
return {
init: function (options) {
this.spring = options.spring + (Math.random() * 0.1) - 0.;
this.friction = settings.friction + (Math.random() * 0.) - 0.;
this.nodes = [];
for (var i = 0, node; i < settings.size; i++) {
node = new Node();
node.x = target.x;
node.y = target.y;
this.nodes.push(node);
}
},
update: function () {
var spring = this.spring,
node = this.nodes[0];
node.vx += (target.x - node.x) * spring;
node.vy += (target.y - node.y) * spring;
for (var prev, i = 0, n = this.nodes.length; i < n; i++) {
node = this.nodes[i];
if (i > 0) {
prev = this.nodes[i - 1];
node.vx += (prev.x - node.x) * spring;
node.vy += (prev.y - node.y) * spring;
node.vx += prev.vx * settings.dampening;
node.vy += prev.vy * settings.dampening;
}
node.vx *= this.friction;
node.vy *= this.friction;
node.x += node.vx;
node.y += node.vy;
spring *= settings.tension;
}
},
draw: function () {
var x = this.nodes[0].x,
y = this.nodes[0].y,
a, b;
ctx.beginPath();
ctx.moveTo(x, y);
for (var i = 1, n = this.nodes.length - 2; i < n; i++) {
a = this.nodes[i];
b = this.nodes[i + 1];
x = (a.x + b.x) * 0.5;
y = (a.y + b.y) * 0.5;
ctx.quadraticCurveTo(a.x, a.y, x, y);
}
a = this.nodes[i];
b = this.nodes[i + 1];
ctx.quadraticCurveTo(a.x, a.y, b.x, b.y);
ctx.stroke();
ctx.closePath();
}
};
})();
// ----------------------------------------------------------------------------------------
function init(event) {
document.removeEventListener('mousemove', init);
document.removeEventListener('touchstart', init);
document.addEventListener('mousemove', mousemove);
document.addEventListener('touchmove', mousemove);
document.addEventListener('touchstart', touchstart);
mousemove(event);
reset();
loop();
}
function reset() {
tendrils = [];
for (var i = 0; i < settings.trails; i++) {
tendrils.push(new Tendril({
spring: 0. + 0. * (i / settings.trails)
}));
}
}
function loop() {
if (!ctx.running) return;
ctx.globalCompositeOperation = 'source-over';
ctx.fillStyle = 'rgba(8,5,,0.4)';
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
ctx.globalCompositeOperation = 'lighter';
ctx.strokeStyle = 'hsla(' + Math.round(hue.update()) + ',%,%,0.)';
ctx.lineWidth = 1;
if (ctx.frame % == 0) {
console.log(hue.update(), Math.round(hue.update()), hue.phase, hue.offset, hue.frequency, hue.amplitude);
}
for (var i = 0, tendril; i < settings.trails; i++) {
tendril = tendrils[i];
tendril.update();
tendril.draw();
}
ctx.frame++;
ctx.stats.update();
requestAnimFrame(loop);
}
function resize() {
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
}
function start() {
if (!ctx.running) {
ctx.running = true;
loop();
}
}
function stop() {
ctx.running = false;
}
function mousemove(event) {
if (event.touches) {
target.x = event.touches[0].pageX;
target.y = event.touches[0].pageY;
} else {
target.x = event.clientX
target.y = event.clientY;
}
event.preventDefault();
}
function touchstart(event) {
if (event.touches.length == 1) {
target.x = event.touches[0].pageX;
target.y = event.touches[0].pageY;
}
}
function keyup(event) {
switch (event.keyCode) {
case :
save();
break;
default:
// console.log(event.keyCode); hovertree.com
}
}
function letters(id) {
var el = document.getElementById(id),
letters = el.innerHTML.replace('&', '&').split(''),
heading = '';
for (var i = 0, n = letters.length, letter; i < n; i++) {
letter = letters[i].replace('&', '&');
heading += letter.trim() ? '<span class="letter-' + i + '">' + letter + '</span>' : ' ';
}
el.innerHTML = heading;
setTimeout(function () {
el.className = 'transition-in';
}, (Math.random() * ) + );
}
function save() {
if (!buffer) {
buffer = document.createElement('canvas');
buffer.width = screen.availWidth;
buffer.height = screen.availHeight;
buffer.ctx = buffer.getContext('2d');
form = document.createElement('form');
form.method = 'post';
form.input = document.createElement('input');
form.input.type = 'hidden';
form.input.name = 'data';
form.appendChild(form.input);
document.body.appendChild(form);
}
buffer.ctx.fillStyle = 'rgba(8,5,)';
buffer.ctx.fillRect(0, 0, buffer.width, buffer.height);
buffer.ctx.drawImage(canvas,
Math.round(buffer.width / 2 - canvas.width / 2),
Math.round(buffer.height / 2 - canvas.height / 2)
);
buffer.ctx.drawImage(logo,
Math.round(buffer.width / 2 - logo.width / 4),
Math.round(buffer.height / 2 - logo.height / 4),
logo.width / 2,
logo.height / 2
);
window.open(buffer.toDataURL(), 'wallpaper', 'top=0,left=0,width=' + buffer.width + ',height=' + buffer.height);
// form.input.value = buffer.toDataURL().substr();
// form.submit(); hovertree.com
}
window.requestAnimFrame = (function () {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function (fn) { window.setTimeout(fn, / ) };
})();
window.onload = function () {
ctx = document.getElementById('canvas').getContext('2d');
ctx.stats = new Stats();
ctx.running = true;
ctx.frame = 1;
logo = new Image();
logo.src = 'ht' + 'tp://ho' + 'vertree.c' + 'om/themes/hvtimages/hvtlogo.p' + 'ng';
hue = new Oscillator({
phase: Math.random() * Math.TWO_PI,
amplitude: ,
frequency: 0.,
offset:
});
letters('h1');
letters('h2');
document.addEventListener('mousemove', init);
document.addEventListener('touchstart', init);
document.body.addEventListener('orientationchange', resize);
window.addEventListener('resize', resize);
window.addEventListener('keyup', keyup);
window.addEventListener('focus', start);
window.addEventListener('blur', stop);
resize();
if (window.DEBUG) {
var gui = new dat.GUI();
// gui.add(settings, 'debug');
settings.gui.add(settings, 'trails', 1, ).onChange(reset);
settings.gui.add(settings, 'size', , ).onFinishChange(reset);
settings.gui.add(settings, 'friction', 0., 0.).onFinishChange(reset);
settings.gui.add(settings, 'dampening', 0., 0.4).onFinishChange(reset);
settings.gui.add(settings, 'tension', 0., 0.).onFinishChange(reset);
document.body.appendChild(ctx.stats.domElement);
}
};
})(window);
</script>
</body>
</html>
QML类型:Context2D
Context2D 对象通过调用 Canvas 项的 getContext() 方法创建,其 API 实现了 W3C Canvas 2D Context API 标准,并具备额外增强功能。此对象提供渲染上下文,定义了在 Canvas 项目上绘制所需的方法和属性。例如,将画布渲染上下文分配给变量:var context = mycanvas.getContext("2d")。买入净额指标源码
Context2D API 将画布渲染为坐标系,其原点位于左上角,坐标沿 x 轴从左到右增加,沿 y 轴从顶部到底部增加。该坐标系统包含多种属性成员,如 canvas、fillRule、fillStyle、font、globalAlpha、globalCompositeOperation 等。此外,还包括 lineCap、lineDashOffset、lineJoin、lineWidth、miterLimit、shadowBlur、货品源码是什么shadowColor、shadowOffsetX、shadowOffsetY、strokeStyle、textAlign 和 textBaseline 等。这些属性分别用于控制形状、文本样式、颜色、阴影效果以及路径操作。
Context2D API 还包含多个成员函数,如 arc、arcTo、beginPath、bezierCurveTo、clearRect、clip、closePath、createConicalGradient、createImageData、createLinearGradient、createPattern、createRadialGradient、drawImage、ellipse、fill、fillRect、fillText、getImageData、isPointInPath、lineTo、measureText、moveTo、putImageData、quadraticCurveTo、rect、reset、resetTransform、save、rotate、roundedRect、scale、setTransform、shear、stroke、strokeRect、strokeText、text 和 transform。这些函数允许执行从绘制图形到处理图像、变换和操作路径的多种任务。
总之,Context2D API 提供了全面的绘图和渲染功能,包括形状创建、文本处理、颜色管理、阴影效果和路径操作等,适用于构建动态且具有高度可定制性的图形界面。
quadraticCurveTo()HTML DOM quadraticCurveTo() 方法
在HTML DOM中,当你需要为你的图形路径增添动态效果时,可以使用CanvasRenderingContext2D对象提供的quadraticCurveTo()方法。这个方法主要用于创建一条二次贝塞尔曲线,以丰富你的图形设计。
quadraticCurveTo()方法的语法结构是:context.quadraticCurveTo(cp1x, cp1y, x, y)。其中,'cp1x' 和 'cp1y' 是控制点的坐标,这两个点共同决定了曲线的形状和转折点。'x' 和 'y' 是你想要曲线达到的终点坐标,它是贝塞尔曲线的最终目标位置。
通过调整这些参数,你可以控制曲线的曲率和路径走向。控制点决定了曲线的转折点,而终点则决定了曲线的结束位置。这个方法对于创建平滑的曲线,或者需要精确控制曲线走向的动画效果非常有用。
总的来说,quadraticCurveTo()方法是HTML5 Canvas API中的一种强大工具,它允许开发者在二维图形中创建复杂的曲线,为设计增添更多可能性。通过熟练掌握这个方法,你可以创造出富有表现力和动态感的图形内容。
quadraticCurveTo()描述
在SVG路径的绘制过程中,quadraticCurveTo() 方法发挥着关键作用。它用于在当前路径上添加一条二次贝塞尔曲线,这是一种通过控制点 (cpX, cpY) 来定义的曲线,它连接了当前点和目标点 (x, y)。这个方法的使用涉及到贝塞尔曲线的数学原理,它能够精确控制曲线的弯曲程度和方向,但此处我们不深入探讨其背后的复杂数学公式。
当调用 quadraticCurveTo() 方法后,它会将路径的当前点移动到指定的 (x, y) 处。这个过程是无缝的,让艺术家或开发者能够轻松地构建复杂的路径形状,无论是流畅的曲线还是精确的转折点。曲线的控制点 (cpX, cpY) 的设置,决定了路径如何在两点之间弯曲,是决定路径外观的重要因素。
总的来说,quadraticCurveTo() 方法是SVG路径绘制中的一个实用工具,它通过控制点和目标点的组合,为路径增添动态和美观,是创建各种图形和动画效果的基础之一。