Canvas放置反彈效果隨機(jī)圖形(實(shí)例)
天鎮(zhèn)ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!var raf; var arror = []; var running = false; //繪制圓形 function createBall() { return { x: 0, y: 0, vx: 10-Math.random()*10, vy: 10-Math.random()*10, radius: 25, color:"red", draw: function() { ctx.beginPath(); ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, true); ctx.closePath(); ctx.fillStyle = this.color; ctx.fill(); } } } //繪制正方形 function createSquare() { return { x: 0, y: 0, vx: 10-Math.random()*10, vy: 10-Math.random()*10, color:"red", draw: function() { ctx.beginPath(); ctx.fillStyle = this.color; ctx.fillRect(this.x, this.y,30, 30); ctx.closePath(); } } } //繪制五角星 function createStar() { return { x: 0, y: 0, vx: 10-Math.random()*10, vy: 10-Math.random()*10, color:"red", draw: function() { ctx.font = "24px serif"; ctx.textBaseline = "hanging"; ctx.fillStyle=this.color; ctx.fillText("五角星",this.x, this.y); } } } //繪制三角形 function createTriangle() { return { x: 0, y: 0, vx: 10-Math.random()*10, vy: 10-Math.random()*10, color:"red", draw: function() { ctx.beginPath(); ctx.moveTo(this.x,this.y); ctx.lineTo(this.x+25,this.y+25); ctx.lineTo(this.x+25,this.y-25); ctx.fillStyle=this.color; ctx.fill(); } } } //清除 function clear() { ctx.fillStyle = 'rgba(255,255,255,0.3)'; ctx.fillRect(0,0,canvas.width,canvas.height); } //判斷圖形坐標(biāo)是否超出畫布范圍 function draw() { clear(); arror.forEach(function(ball, i){ ball.draw(); ball.x += ball.vx; ball.y += ball.vy; if (ball.y + ball.vy > canvas.height || ball.y + ball.vy < 0) { ball.vy = -ball.vy; } if (ball.x + ball.vx > canvas.width || ball.x + ball.vx < 0) { ball.vx = -ball.vx; } }); raf = window.requestAnimationFrame(draw); } canvas.addEventListener('click',function(e){ if (!running) { raf = window.requestAnimationFrame(draw); running = true; } var colorarr=["#000000","#7F7F7F","#880015","#ED1C24","#FF7F27","#FFF200","#22B14C","#00A2E8","#3F48CC","#A349A4","#B97A57","#FFAEC9","#B5E61D"]; var Graphics = ["Round","Square","Star","Triangle"]; var typexz=Graphics[Math.floor(Math.random()*4)]; var ball; switch(typexz){ case "Round": ball = createBall(); break; case "Square": ball = createSquare(); break; case "Star": ball = createStar(); break; case "Triangle": ball = createTriangle(); break; } ball.x = e.clientX; ball.y = e.clientY; ball.color = colorarr[Math.floor(Math.random() * 10 + 3)]; arror.push(ball); }); draw(); document.addEventListener('keydown',function (e) { if(e.keyCode==32){ event.preventDefault(); window.cancelAnimationFrame(raf); running = false; } })
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
當(dāng)前標(biāo)題:Canvas放置反彈效果隨機(jī)圖形(實(shí)例)-創(chuàng)新互聯(lián)
新聞來源:http://www.rwnh.cn/article32/cchpsc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、網(wǎng)站內(nèi)鏈、網(wǎng)站策劃、定制網(wǎng)站、全網(wǎng)營(yíng)銷推廣、網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容