Home Web Front-end H5 Tutorial HTML5 simulates flat throwing motion (simulating the flat throwing motion process of a small ball)_html5 tutorial skills

HTML5 simulates flat throwing motion (simulating the flat throwing motion process of a small ball)_html5 tutorial skills

May 16, 2016 pm 03:48 PM
html5

The object is thrown in the horizontal direction with a certain initial velocity. If the object is only affected by gravity, such a motion is called a horizontal throwing motion. The horizontal throwing motion can be regarded as the combined motion of uniform linear motion in the horizontal direction and free fall motion in the vertical direction. Since the net external force on an object in horizontal motion is a constant force, the motion of an object in horizontal motion is a uniform variable speed curve motion, and the trajectory of a horizontally thrown object is a parabola. The horizontal throwing motion is a curved motion. The time of the horizontal throwing motion is only related to the vertical height of the throwing point; the horizontal displacement of the object landing is related to time (vertical height) and horizontal initial velocity.


Copy code
The code is as follows:


< head>

html5 cannonball
<script> <br>//box <br>var box_x=0; <br>var box_y=0; <br>var box_width=300; <br>var box_height=300; <br>//ball <br>var ball_x=10; <br>var ball_y=10; =10; <br>var ball_vx=10; <br>var ball_vy=0; <br>//constant <br>var g=10;//note <br>var rate=0.9; <br>//bound <br>var bound_left=box_x ball_radius; <br>var bound_right=box_x box_width-ball_radius; <br>var bound_top=box_y ball_radius; <br>var bound_bottom=box_y box_height-ball_radius; <br>//context <br>var ctx; <br>function init() <br>{ <br>ctx=document.getElementById('canvas').getContext('2d'); <br>ctx.lineWidth=ball_radius; <br>ctx.fillStyle= "rgb(200,0,50)"; <br>move_ball(); <br>setInterval(move_ball,100); <br>} <br>function move_ball() <br>{ <br>ctx.clearRect( box_x,box_y,box_width,box_height); <br>move_and_check(); <br>ctx.beginPath(); <br>ctx.arc(ball_x,ball_y,ball_radius,0,Math.PI*2,true); <br>ctx.fill(); <br>ctx.strokeRect(box_x,box_y,box_width,box_height); <br>} <br>function move_and_check() <br>{ <br>var cur_ball_x=ball_x ball_vx; <br>var temp=ball_vy; <br>ball_vy=ball_vy g; <br>var cur_ball_y=ball_y ball_vy g/2; <br>if(cur_ball_x<bound_left) <br />{ <br />cur_ball_x=bound_left; <br />ball_vx =-ball_vx*0.9; <br />ball_vy=ball_vy*0.9; <br />} <br />if(cur_ball_x>bound_right) <br>{ <br>cur_ball_x=bound_right; <br>ball_vx=-ball_vx*0.9; <br>ball_vy=ball_vy*0.9; <br>} <br>if(cur_ball_y<bound_top) <br />{ <br />cur_ball_y=bound_top; <br />ball_vy=-ball_vy*0.9; <br />ball_vx=ball_vx*0.9 ; <br />} <br />if(cur_ball_y>bound_bottom) <br>{ <br>cur_ball_y=bound_bottom; <br>ball_vy=-ball_vy*0.9; <br>ball_vx=ball_vx*0.9; <br>} <br>ball_x=cur_ball_x; <br>ball_y=cur_ball_y; <br>} <br></script>






html5 simulation ball Flat throwing motion process.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles