Commit 11c51b14 authored by Pablo Cremades's avatar Pablo Cremades

Mejoras al código del simulador

parent e01b3657
Pipeline #157660394 passed with stages
in 59 seconds
......@@ -24,9 +24,8 @@
* Presione 'K (K mayúscula) para aumentar el valor de la costante de resorte.
* Presione 'a' o 'A' para cambiar la posición inicial de la masa A.
* Presione 'b' o 'B' para cambiar la posición inicial de la masa B.
* Presione 'x' o 'X' para reiniciar la simulación (borra los parámetros de la simulación).
*
* Nota: Para cambiar los parámetros debe reiniciar la simulación presionando el botón STOP de la interfaz
* de Processing y luego Play nuevamente.
*
* Change Log:
****************************************************************************************/
......@@ -68,6 +67,8 @@ float kMin = 0.02;
boolean play = false;
int NLINES = 6;
void draw() {
background(200);
......@@ -95,7 +96,34 @@ void draw() {
}
translate(width/2, height/2);
line(-width, 0, width, 0);
float dist = x2 - x1;
float incDist = dist / NLINES;
float ySpring = 10;
//Dibuja el resorte 1
float x1Fix = x1Ini*3;
float dist1 = x1 - x1Fix;
float incDist1 = dist1 / NLINES;
for( int i = 0; i < NLINES; i++ ){
line( (x1Fix + incDist1*i)*scale, ySpring, (x1Fix + incDist1*(i+1))*scale, -ySpring );
ySpring = -ySpring;
}
//Dibuja el resorte 3
float x2Fix = x2Ini*3;
float dist2 = (x2 - x2Fix);
float incDist2 = dist2 / NLINES;
for( int i = 0; i < NLINES; i++ ){
line( (x2Fix + incDist2*i)*scale, ySpring, (x2Fix + incDist2*(i+1))*scale, -ySpring );
ySpring = -ySpring;
}
for( int i = 0; i < NLINES; i++ ){
line( (x1 + incDist*i)*scale, ySpring, (x1 + incDist*(i+1))*scale, -ySpring );
ySpring = -ySpring;
}
//line(-width, 0, width, 0);
fill(255, 0, 0);
ellipse(x1*scale, y1, radio, radio);
ellipse(x1Ini*scale, y1+radio*2, radio/5, radio/5);
......@@ -104,9 +132,9 @@ void draw() {
ellipse(x2Ini*scale, y1+radio*2, radio/5, radio/5);
fill(0);
textSize(20);
text("A= "+ (round((x1-x1Ini)*100)/100.0), x1Ini*scale - 20, y1+radio+10);
text("B= "+ (round((x2-x2Ini)*100)/100.0), x2Ini*scale - 20, y2+radio+10);
text("Periodo: " + periodo, -100, 100);
text("x_A(t) = "+ (round((x1-x1Ini)*100)/100.0), x1Ini*scale - 20, y1+radio+10);
text("x_B(t) = "+ (round((x2-x2Ini)*100)/100.0), x2Ini*scale - 20, y2+radio+10);
text("Periodo: " + periodo + " ms", -100, 100);
text("M = "+M1+"Kg", -20, -150);
text("k = "+k+"N/m", -20, -100);
}
......@@ -144,5 +172,13 @@ void keyPressed() {
k += 0.01;
k = (round((k)*100)/100.0);
break;
case 'x':
case 'X':
play = false;
x1 = x1Ini;
x2 = x2Ini;
a1 = 0; a2 = 0;
v1 = 0; v2 = 0;
break;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment