Skip to content

Commit

Permalink
cambio
Browse files Browse the repository at this point in the history
  • Loading branch information
yamoreno2021 committed Apr 11, 2024
1 parent 2c03c4b commit 4b57b1f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions P3/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ <h1>Tiro parabólico</h1>
<canvas id="ctiro"></canvas>

<p>Ángulo de disparo:</p>
<input type="range" id="angle" min="0" max="90" value="0" step="1"><br>
<input type="range" id="angle" min="0" max="70" value="15" step="1"><br>
<p><span id="angle_disp">0</span></p>
<p>Velocidad de disparo:</p>
<input type="range" id="velocity" min="0" max="100" value="0" step="1"><br>
<input type="range" id="velocity" min="0" max="70" value="0" step="1"><br>
<p><span id="velocity_disp">0</span></p>
<input type="button" id="btnLanzar" value="Lanzar">
<input type="button" id="btnIniciar" value="Iniciar">
Expand Down
31 changes: 19 additions & 12 deletions P3/tiro-parabolico.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ let yo = 370;


//-- Dibujar el proyectil
//dibujarP(xop, yop, 50, 50, "green"); // Pintar el proyectil
dibujarP(xop, yop, 50, 50); // Pintar el proyectil //Sin color
dibujarP(xop, yop, 50, 50, "green"); // Pintar el proyectil
//dibujarP(xop, yop, 50, 50); // Pintar el proyectil //Sin color

//-- Dibujbar el objetivo
dibujarO(xo,yo); // Pintar el objetivo

//-- Velocidad del proyectil
let velpx = 5;
let velpy = 1;


//-- Escribir ángulo
angle.onchange = () => {
Expand All @@ -67,18 +65,27 @@ velocity.onchange = () => {
velocity_disp.innerHTML = velocity.value;
}
}
//-- Velocidad inicial total
var v0 = parseFloat(velocity.value); // Obtener la velocidad inicial del input

//-- Ángulo de lanzamiento (en radianes)
var theta = parseFloat(angle.value) * Math.PI / 180; // Convertir a radianes

//-- Velocidad del proyectil
let v0x = v0 * Math.cos(theta); // Velocidad inicial en x
let v0y = v0 * Math.sin(theta); // Velocidad inicial en y

//-- Función principal de actualización
//-- Gravedad
const g = 0.2; // Ajusta según sea necesario
const g = 9.81; // Ajusta según sea necesario

//-- Tiempo inicial
let t = 0;

function lanzar() {
//-- Calcular la posición en función del tiempo
xp = xop + velpx * t;
yp = yop - (velpy * t - 0.5 * g * t ** 2);
xp = xop + v0x * t;
yp = yop - (v0y * t - 0.5 * g * t ** 2);

//-- Incrementar el tiempo para el próximo cuadro
t += 1;
Expand Down Expand Up @@ -119,16 +126,16 @@ function dibujarP(x,y,lx,ly,color) {
ctx.beginPath();
ctx.drawImage(bird, x,y,lx,ly);
//-- Definir un rectángulo de dimensiones lx x ly,
ctx.rect(x, y, lx, ly);
//ctx.rect(x, y, lx, ly);

//-- Color de relleno del rectángulo
ctx.fillStyle = color;
//ctx.fillStyle = color;

//-- Mostrar el relleno
ctx.fill();
// ctx.fill();

//-- Mostrar el trazo del rectángulo
ctx.stroke();
//ctx.stroke();

ctx.closePath();
}
Expand Down

0 comments on commit 4b57b1f

Please sign in to comment.