Ver Mensaje Individual
  #3 (permalink)  
Antiguo 13/08/2012, 14:06
Avatar de gilber966
gilber966
 
Fecha de Ingreso: abril-2010
Mensajes: 117
Antigüedad: 14 años, 10 meses
Puntos: 4
Respuesta: parabola javascript

Ya lo hize , si a alguien le sirve:

Código Javascript:
Ver original
  1. function loopGame(){
  2. segundos=segundos+0.1;
  3. //alert("angulo en radianes"+radian);//alert("velocidad inicial general"+velocidad);
  4. //velocidad inicial en y:
  5. vyi=(velocidad)*Math.sin(radian);//alert("velocidad en y inicial:"+vyi),
  6. //velocidad inicial en x:
  7. vxi=velocidad*Math.cos(radian);//alert("velocidad en x inicial:"+vxi);
  8. //altura maxima:
  9. amax=-(vyi*vyi)/(2*(-9.8));//alert("altura maxima:"+amax);
  10. //tiempo en el aire
  11. tiempoTotal=(-2*(vxi))/(-(9.8));//alert("tiempo total:"+tiempoTotal);
  12. //distancia en x:
  13. Y=(vyi*segundos)+((-9.8*cuadrado(segundos))/2);//pos y actual
  14. X=vxi*segundos;
  15. dx=vxi*tiempoTotal;//alert("distancia recorrida en x:"+dx);
  16. //X=quitarDecimales(X);
  17. //Y=quitarDecimales(Y);
  18. if(X <= 825 && Y > 0){
  19. X=vxi*segundos;
  20. Y=(vyi*segundos)+((-9.8*cuadrado(segundos))/2);
  21. X=quitarDecimales(X);
  22. Y=quitarDecimales(Y);
  23. document.getElementById('bala').style.top= "-"+String(Y)+"px";
  24. document.getElementById('bala').style.left= String(X)+"px";
  25. idetener=setTimeout('loopGame()',50);
  26.  }else{
  27.  clearTimeout(idetener);
  28.  }
  29.  
  30. }
  31. function detener(){
  32.  
  33.     clearTimeout(idetener);
  34. }

la funcion que inicia:

Código Javascript:
Ver original
  1. function iniciar(){
  2.     ang=document.getElementById('angulo').value;
  3.     velocidad=document.getElementById('vel').value;
  4.     radian=toRadianes(ang);
  5.    
  6.     //vx=velocidad*Math.cos(radian);
  7.    // vy=velocidad*Math.sin(radian);
  8.     loopGame();
  9.    
  10.    
  11. }