Monday, July 11, 2016

motion functions

function leftmotion() {
if (document.getElementById("motion").innerHTML[0] != "0") {
var speed = parseFloat(document.getElementById("atnbgspeed").innerHTML)
var wtm = document.getElementById("atnbgwhattomove").innerHTML
wtm = document.getElementById(wtm)
var newbase = parseFloat(wtm.style.left) - speed
var unit = wtm.style.left[wtm.style.left.length]
if (unit === "x") {unit = "px"}
wtm.style.left = newbase + unit
setTimeout(leftmotion,100)}}

function rightmotion() {
if (document.getElementById("motion").innerHTML[0] != "0") {
var speed = parseFloat(document.getElementById("atnbgspeed").innerHTML)
var wtm = document.getElementById("atnbgwhattomove").innerHTML
wtm = document.getElementById(wtm)
var newbase = parseFloat(wtm.style.left) + speed
var unit = wtm.style.left[wtm.style.left.length]
if (unit === "x") {unit = "px"}
wtm.style.left = newbase + unit
setTimeout(leftmotion,100)}}

function upmotion() {
if (document.getElementById("motion").innerHTML[0] != "0") {
var speed = parseFloat(document.getElementById("atnbgspeed").innerHTML)
var wtm = document.getElementById("atnbgwhattomove").innerHTML
wtm = document.getElementById(wtm)
var newbase = parseFloat(wtm.style.top) - speed
var unit = wtm.style.top[wtm.style.top.length]
if (unit === "x") {unit = "px"}
wtm.style.top = newbase + unit
setTimeout(leftmotion,100)}}

function downmotion() {
if (document.getElementById("motion").innerHTML[0] != "0") {
var speed = parseFloat(document.getElementById("atnbgspeed").innerHTML)
var wtm = document.getElementById("atnbgwhattomove").innerHTML
wtm = document.getElementById(wtm)
var newbase = parseFloat(wtm.style.top) + speed
var unit = wtm.style.top[wtm.style.top.length]
if (unit === "x") {unit = "px"}
wtm.style.top = newbase + unit
setTimeout(leftmotion,100)}}

function plusmotion() {
if (document.getElementById("motion").innerHTML[0] != "0") {
var speed = parseFloat(document.getElementById("atnbgspeed").innerHTML)
var wtm = document.getElementById("atnbgwhattomove").innerHTML
wtm = document.getElementById(wtm)
var leftbase = parseFloat(wtm.style.left)
var topbase = parseFloat(wtm.style.top)
var widthbase = parseFloat(wtm.style.width)
var heightbase = parseFloat(wtm.style.height)
var motioncenter = document.getElementById("atnbgmotioncenter")
motioncenter = motioncenter.innerHTML.split(",")
var mcl = parseInt(motioncenter[0])
var mct = parseInt(motioncenter[1])
var leftpct = (mcl - leftbase) / widthbase
var toppct = (mct - topbase) / heightbase
var motionmultiplier = 1 + (speed * .1)
var newwidth = widthbase * motionmultiplier
var newheight = heightbase * motionmultiplier
var newleft = mcl - (newwidth * leftpct)
var newtop = mct - (newheight * toppct)
var unit = wtm.style.top[wtm.style.top.length]
if (unit === "x") {unit = "px"}
wtm.style.left = newleft + unit
wtm.style.top = newtop + unit
wtm.style.width = newwidth + unit
wtm.style.height = newheight + unit
wtm.style.font-size = wtm.style.height
setTimeout(plusmotion,100)}}