Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Canvas to realize 3D Water body Simulation Animation in HTML5

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the HTML5 how to use Canvas to achieve 3D water body simulation animation related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone in this HTML5 how to use Canvas to achieve 3D water body simulation animation article will have a harvest, let's take a look.

JavaScript

Language:

JaveScriptBabelCoffeeScript

Confirm

Var canvas, ctx, tim, bai

Canvas = document.getElementsByTagName ('canvas') [0]

Ctx = canvas.getContext ('2d')

Canvas.width = canvas.height = 400

Aaa ()

Function aaa () {

Var a, b, c, s, p, r, x, y, z, x1, y1, max, p2, han, h, pt, hei

Ctx.globalCompositeOperation = "source-over"

Ctx.fillStyle = "rgb (0jin0pj0pl 0)"

Ctx.fillRect (0,0, canvas.width, canvas.height)

Ctx.globalCompositeOperation = "lighter"

Tim = new Date () .getTime () / 10

Ctx.strokeStyle = ctx.fillStyle = "hsla (244, 60%, 60%, 0.3)"

Bai = 0.6 + Math.sin (tim / 471) * 0.2

Hei = 0.9 + Math.sin (tim / 100) * 0.3

Pt = []

For (c = 0; c < 180; C++) {

S = (c + 1) / 180

Han = Math.cos (s * Math.PI / 2)

H = Math.sin (s * Math.PI / 2)

S = 1-s

P = []

Max = (100 * han) | 0

R = 0

For (a = 0; a < max; asides +) {

X = Math.cos (r) * han

Y = Math.sin (r) * han

Z = nami (r, s)

X-= z * s

P.push ([x, y, hei + z * s + h])

R + = Math.PI * 2 / max

}

Pt.push (p)

}

For (c = 0; c < 100; C++) {

S = (c + 1) / 100

P = []

Max = 100s

R = 0

For (a = 0; a < max; asides +) {

X = Math.cos (r) * s

Y = Math.sin (r) * s

Z = nami (r, s)

X-= z * s

P.push ([x, y, hei + z * s])

R + = Math.PI * 2 / max

}

Pt.push (p)

}

For (c = 0; c < pt.length; C++) {

P = pt [c]

P2 = []

For (a = 0; a < p. Resume; averse +) {

X = p [a] [0]

Y = p [a] [1]

Z = p [a] [2]

B = Math.pow (1.5, y / 2)

X1 = x * b * 150 + 200

Y1 = z * b * 200-hei * 200 + 150

P2.push ([x1, y1])

}

Ctx.beginPath ()

For (a = 0; a < p2.roomth; aquidus +) ctx.lineTo (p2 [a] [0], p2 [a] [1])

Ctx.closePath ()

Ctx.stroke ()

}

RequestAnimationFrame (aaa)

}

Function nami (r, s) {

Var a = Math.sin (r * 2-tim / 13 + s * 13) / 20 +

Math.sin (r * 5-tim / 17 + s * 13) / 20 +

Math.sin (r * 7-tim / 19 + s * 13) / 40

Return a * bai

}

This is the end of the article on "how to use Canvas to realize 3D water body simulation animation in HTML5". Thank you for reading! I believe that everyone has a certain understanding of "how to use Canvas to achieve 3D water body simulation animation in HTML5". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report