User:Antilived/Cannon-ball

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  Physics model

var START_X = 10; var START_Y = 94; var ball; var x;       var y;        var frame_speed = 50;

var launch_force; var launch_radian; var i;       var svgDocument

function svg_onload(evt) { if ( window.svgDocument == null ) svgDocument = evt.target.ownerDocument; ball = svgDocument.getElementById("cannon_ball"); ball.setAttributeNS(null, "cx", START_X); ball.setAttributeNS(null, "cy", START_Y); set_ball_color("red",ball); }

function set_ball_color(color, ball) { ball.setAttributeNS(null, "fill", color); }

function start_animation(ball) { //if ( window.svgDocument == null ) //   svgDocument = evt.target.ownerDocument; //ball = svgDocument.getElementById("cannon_ball"); var launch_angle = document.getElementById("launch_angle").value;; launch_radian = (launch_angle)/180.0*Math.PI;

launch_force = document.getElementById("launch_force").value;;

x = START_X; y = START_Y; i = 0; ball.setAttributeNS(null, "cx", x); ball.setAttributeNS(null, "cy", y); setTimeout("advance('ball')", frame_speed); }

function advance(ball) { i++ var x_change = Math.cos(launch_radian)*launch_force;

var y_change = Math.sin(launch_radian)*launch_force - i*9.81*(frame_speed/1000);

y = y - (y_change * frame_speed/1000);

if (y >= 95) { y = 95 x_change = 0 }           else { x = x + (x_change * frame_speed/1000); ball.setAttributeNS(null, "cx", x); ball.setAttributeNS(null, "cy", y); setTimeout("advance('ball')", frame_speed); }       }  Ball Color:  red yellow blue Launch angle:  Launch force:  Fire!   