45 lines
1.3 KiB
Text
45 lines
1.3 KiB
Text
programa {
|
|
inclua biblioteca Matematica --> math // math library
|
|
inclua biblioteca Util --> u // util library
|
|
inclua biblioteca Graficos --> g // graphics library
|
|
inclua biblioteca Teclado --> t // keyboard library
|
|
|
|
real accel, bx, by
|
|
real theta = math.PI * 0.5
|
|
real g = 9.81
|
|
real l = 1.0
|
|
real speed = 0.0
|
|
real px = 320.0
|
|
real py = 10.0
|
|
inteiro w = 10 // circle width and height (radius)
|
|
|
|
// main entry
|
|
funcao inicio() {
|
|
|
|
g.iniciar_modo_grafico(verdadeiro)
|
|
g.definir_dimensoes_janela(640, 400)
|
|
|
|
// while ESC key not pressed
|
|
enquanto (nao t.tecla_pressionada(t.TECLA_ESC)) {
|
|
bx = px + l * 300.0 * math.seno(theta)
|
|
by = py - l * 300.0 * math.cosseno(theta)
|
|
|
|
g.definir_cor(g.COR_PRETO)
|
|
g.limpar()
|
|
|
|
g.definir_cor(g.COR_BRANCO)
|
|
g.desenhar_linha(px, py, bx, by)
|
|
g.desenhar_elipse(bx - w, by - w, w * 2, w * 2, verdadeiro)
|
|
|
|
accel = g * math.seno(theta) / l / 100.0
|
|
speed = speed + accel / 100.0
|
|
theta = theta + speed
|
|
|
|
g.desenhar_texto(0, 370, "Pendulum")
|
|
g.desenhar_texto(0, 385, "Press ESC to quit")
|
|
|
|
g.renderizar()
|
|
u.aguarde(10)
|
|
}
|
|
}
|
|
}
|