function motion(instruction,namespace) {
var frame = document.getElementById(namespace)
var speed = document.getElementById(namespace + "speed")
if (instruction === "left") {left(frame,speed)}
if (instruction === "right") {right(frame,speed)}
if (instruction === "up") {up(frame,speed)}
if (instruction === "down") {down(frame,speed)}
if (instruction === "plus") {plus(frame,speed)}
if (instruction === "minus") {minus(frame,speed)}
if (instruction === "faster") {faster(speed)}
if (instruction === "slower") {slower(speed)}
if (instruction === "stop") {stop(namespace)}
function left(frame,speed) {
frame.style.left = (parseFloat(frame.style.left) - parseFloat(speed.innerHTML))+ "px"}
function right(frame,speed) {
frame.style.left = (parseFloat(frame.style.left) + parseFloat(speed.innerHTML)) + "px"}
function up(frame,speed) {
frame.style.top = (parseFloat(frame.style.top) - parseFloat(speed.innerHTML)) + "px"}
function down(frame,speed) {
frame.style.top = (parseFloat(frame.style.top) + parseFloat(speed.innerHTML)) + "px"}
frame.style.height = newheight + "px"
function plus(frame,speed) {
var left = parseFloat(frame.style.left)
var top = parseFloat(frame.style.top)
var width = parseFloat(frame.style.width)
var height = parseFloat(frame.style.height)
var newwidth = width * (1 + (speed / 100))
var newheight = height * (1 + (speed / 100))
newleft = left - ((newleft - left) / 2)
newtop = top - ((newtop - top) / 2)
frame.style.left = newleft + "px"
frame.style.top = newtop + "px"
frame.style.width = newwidth + "px"frame.style.height = newheight + "px"
frame.style.fontSize = newheight + "px"}
function minus(frame,speed) {
var left = parseFloat(frame.style.left)
var top = parseFloat(frame.style.top)
var width = parseFloat(frame.style.width)
var height = parseFloat(frame.style.height)
var newwidth = width / (1 + (speed / 100))
var newheight = height / (1 + (speed / 100))
newleft = left - ((newleft - left) / 2)
newtop = top - ((newtop - top) / 2)
frame.style.left = newleft + "px"
frame.style.top = newtop + "px"
frame.style.width = newwidth + "px"frame.style.height = newheight + "px"
frame.style.fontSize = newheight + "px"}
function faster(speed) {speed.innerHTML = parseFloat(speed.innerHTML) * 2}
function slower(speed) {speed.innerHTML = parseFloat(speed.innerHTML) / 2}
function stop(namespace) {
document.getElementById(namespace + "motion").innerHTML = 0}
No comments:
Post a Comment