canvas如何做出黑色背景的青色煙火
這次為大家帶來canvas怎樣做出黑色背景的青色煙火,canvas做出黑色背景的青色煙火的注意事項有哪些,下面就是實戰案例,一起來看一下。
html
<canvas></canvas><h1 id="span-span">201<span>8</span></h1>
css
html,body { padding: 0px; margin: 0px; background: #222; font-family: 'Karla', sans-serif; color: #FFF; height: 100%; overflow: hidden; }h1 { z-index: 1000; position: fixed; top: 50%; left: 50%; transform: translateX(-50%) translateY(-100%); font-size: 58px; overflow: hidden; }span { position: relative; display: inline-block; animation: drop 0.75s ease 0s; }canvas { width: 100%; height: 100%; } @keyframes drop { 0% { transform: translateY(-100px); opacity: 0; } 90% { opacity: 1; transform: translateY(10px); } 100% { transform: translateY(0px); } }
js
var ctx = document.querySelector('canvas').getContext('2d')ctx.canvas.width = window.innerWidthctx.canvas.height = window.innerHeightvar sparks = []var fireworks = []var i = 20;while (i--) { fireworks.push( new Firework(Math.random() * window.innerWidth, window.innerHeight * Math.random()) )}render()function render() { setTimeout(render, 1000 / 60) ctx.fillStyle = 'rgba(0, 0, 0, 0.1)'; ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height) for (var firework of fireworks) { if (firework.dead) continue firework.move() firework.draw() } for (var spark of sparks) { if (spark.dead) continue spark.move() spark.draw() } if (Math.random() < 0.05) { fireworks.push(new Firework()) }}function Spark(x, y, color) { this.x = x this.y = y this.dir = Math.random() * (Math.PI * 2) this.dead = false this.color = color this.speed = Math.random() * 3 + 3; this.walker = new Walker({ radius: 20, speed: 0.25 }) this.gravity = 0.25 this.dur = this.speed / 0.1 this.move = function () { this.dur-- if (this.dur < 0) this.dead = true if (this.speed < 0) return if (this.speed > 0) this.speed -= 0.1 var walk = this.walker.step() this.x += Math.cos(this.dir + walk) * this.speed this.y += Math.sin(this.dir + walk) * this.speed this.y += this.gravity this.gravity += 0.05 } this.draw = function () { drawCircle(this.x, this.y, 3, this.color) }}function Firework(x, y) { this.xmove = new Walker({ radius: 10, speed: 0.5 }) this.x = x || Math.random() * ctx.canvas.width this.y = y || ctx.canvas.height this.height = Math.random() * ctx.canvas.height / 2 this.dead = false this.color = randomColor() this.move = function () { this.x += this.xmove.step() if (this.y > this.height) this.y -= 1; else this.burst() } this.draw = function () { drawCircle(this.x, this.y, 1, this.color) } this.burst = function () { this.dead = true var i = 100; while (i--) sparks.push(new Spark(this.x, this.y, this.color)) }}function drawCircle(x, y, radius, color) { color = color || '#FFF' ctx.fillStyle = color ctx.fillRect(x - radius / 2, y - radius / 2, radius, radius)}function randomColor() { return ['#6ae5ab', '#88e3b2', '#36b89b', '#7bd7ec', '#66cbe1'][Math.floor(Math.random() * 5)];}function Walker(options) { this.step = function () { this.direction = Math.sign(this.target) * this.speed this.value += this.direction this.target ? this.target -= this.direction : (this.value) ? (this.wander) ? this.target = this.newTarget() : this.target = -this.value : this.target = this.newTarget() return this.direction } this.newTarget = function () { return Math.round(Math.random() * (this.radius * 2) - this.radius) } this.start = 0 this.value = 0 this.radius = options.radius this.target = this.newTarget() this.direction = Math.sign(this.target) this.wander = options.wander this.speed = options.speed || 1}
相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!
推薦閱讀:
以上是canvas如何做出黑色背景的青色煙火的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

win11預設的底部任務欄是淺藍色的,比較好看,但是有朋友發現突然win11底部狀態欄變成了黑色,這可能是更改了主題或背景顏色,改回來就可以了。 win11底部狀態列變成了黑色:1、首先點開底部開始選單,打開「設定」2、接著進入左邊欄的「個人化」設定。 3、然後開啟其中的「顏色」設定。 4.進入後,關掉其中的「透明效果」(如果打開後,我們的桌面是黑色的那狀態欄就是黑色的)5、如果壁紙不是黑色的,那麼把選擇模式改為「淺色」即可。 6.喜歡別的顏色的話,還可以在主題色裡自由選擇。

微軟邀請Canary和Dev頻道的WindowsInsider專案成員,測試和體驗新版畫圖(Paint)應用,最新版本號為11.2306.30.0。這次版本更新最值得關注的新功能是一鍵摳圖功能,使用者只需要點擊一下,就能自動消除背景,凸顯畫面主體,方便使用者後續操作。整個步驟非常簡單,使用者在新版畫圖應用程式中匯入圖片,然後點擊工具列上「移除背景」(removebackground)按鈕,就可以刪除圖片中的背景,使用者也可以使用矩形來選擇要消除背景的區域。

PPT背景替換是一種重要的操作,可快速統一簡報的視覺風格。透過修改投影片母版或使用「格式背景」功能,可以快速替換整個簡報的背景。此外,某些PPT版本還提供批次替換功能,可以輕鬆替換所有投影片的背景。在替換背景時,應注意選擇與簡報主題相符的背景,並確保背景清晰度和解析度符合要求。

探索Canvas框架:了解常用的Canvas框架有哪些,需要具體程式碼範例引言:Canvas是HTML5中提供的一個繪圖API,透過它我們可以實現豐富的圖形和動畫效果。為了提高繪圖的效率和便利性,許多開發者開發了不同的Canvas框架。本文將介紹一些常用的Canvas框架,並提供具體程式碼範例,以幫助讀者更深入地了解這些框架的使用方法。一、EaselJS框架Ea

在iPhone和iPad上,Apple包含的多項輔助功能之一是背景聲音。這些聲音旨在幫助您保持專注、保持冷靜,並幫助您在忙於某事時盡量減少分心。提供的背景聲音包括平衡、明亮和黑暗的噪音,以及海洋、雨水和溪流等自然聲音。所有聲音都可以設定為在背景播放,以掩蓋不需要的環境或外部噪音,並且聲音混合到其他音訊和系統聲音或隱藏在其他音訊和系統聲音下。在iPhone和iPad上啟用背景聲音以下步驟介紹如何在運行iOS15/iPadOS15及更高版本的iPhone和iPad上啟用背景聲音。在iPhone或i

1.開啟美圖秀軟體,選擇【圖片美化】,從相簿匯入照片。 2.點選底部工具列的【摳圖】,選擇【背景替換】功能。 3.在【背景】選項中,從純色方格中挑選所需底色,或上傳自訂圖片。 4.確認選擇後,點選【儲存】即可完成底色更換。

Go語言誕生於Google,旨在解決C++的複雜性和並發支援不足的問題。它的初衷是創造一種簡潔易學、高效並發、記憶體安全、跨平台的語言,以提高程式設計師的生產力,建立可靠可擴展的系統,並促進程式碼的移植和共享。

html2canvas的版本有html2canvas v0.x、html2canvas v1.x等。詳細介紹:1、html2canvas v0.x,這是html2canvas的早期版本,目前最新的穩定版本是v0.5.0-alpha1。它是一個成熟的版本,已經被廣泛使用,並且在許多專案中得到了驗證;2、html2canvas v1.x,這是html2canvas的新版本。
