python
Dashboard
My Repos
Compilers
Python Online
Node JS Online
Golang Online
codepy
Login
My Repos
Sign Out
Online Python Interpreter
Stop
Run
import pygame # Este script necessita do pacote pygame para produzir a animação. ('https://www.pygame.org/wiki/GettingStarted') import os import math import random """ v= velocidade t = angulo m = massa L = comprimento G = gravidade """ " 'http://revistas.ifpe.edu.br/index.php/cientec/article/viewFile/273/86', pg 6. eq.28, eq29" def aceleracao1(t1, t2, m1, m2, L1, L2, G, v1, v2): termo1 = -G * (2 * m1 + m2) * math.sin(t1) termo2 = -m2 * G * math.sin(t1 - 2 * t2) termo3 = -2 * math.sin(t1-t2) termo4 = m2 * ((v2 * v2) * L2 + (v1 * v1) * L1 * math.cos(t1-t2)) numerador = termo1 + termo2 + (termo3 * termo4) denominador = L1 * (2 * m1 + m2 - m2 * math.cos(2 * t1 - 2 * t2)) return float(numerador/denominador) def aceleracao2(t1, t2, m1, m2, L1, L2, G, v1, v2): termo1 = 2 * math.sin(t1 - t2) termo2 = (v1 * v1) * L1 * (m1 + m2) + G * (m1+ m2) * math.cos(t1) termo3 = (v2 * v2) * L2 * m2 * math.cos(t1-t2) numerador = termo1 * (termo2 + termo3) denominador = L2 * (2 * m1 + m2 - m2 * math.cos(2 * t1 - 2 * t2)) return float(numerador/denominador) class Pontos: def __init__(self, x, y, surface,colors,coordinates): self.x = x self.y = y self.surface = surface self.colors = colors self.coordinates = coordinates def draw(self): if len(self.coordinates) > 2: pygame.draw.lines(self.surface, self.colors, False, self.coordinates, 2) os.environ['SDL_VIDEO_CENTERED']='dummy' largura, altura = 1000, 600 tamanho = (largura, altura) pygame.init() pygame.display.set_caption("Pendulo Duplo") fps = 30 screen = pygame.display.set_mode(tamanho) tempo = pygame.time.Clock() branco = (255, 255 , 255) preto = (0, 0, 0) massa1 = 40 massa2 = 40 comprimento1 = 200 comprimento2 = 200 angulo1 = math.pi/2 angulo2 = math.pi/2 velocidade_ang1 = 0 velocidade_ang2 = 0 aceleracao_ang1 = 0 aceleracao_ang2 = 0 gravidade = 7 scatter1 = [] scatter2 = [] ponto_inicial = (int(largura/2) , int(altura/4)) deslocamento_x = ponto_inicial[0] deslocamento_y = ponto_inicial[1] x = True while x: tempo.tick(fps) screen.fill(preto) for event in pygame.event.get(): if event.type == pygame.QUIT: x = False aceleracao_ang1 = aceleracao1(angulo1, angulo2, massa1, massa2, comprimento1, comprimento2, gravidade, velocidade_ang1, velocidade_ang2) aceleracao_ang2 = aceleracao2(angulo1, angulo2, massa1, massa2, comprimento1, comprimento2, gravidade, velocidade_ang1, velocidade_ang2) x1 = float(comprimento1 * math.sin(angulo1)+deslocamento_x) y1 = float(comprimento1 * math.cos(angulo1)+deslocamento_y) x2 = float(x1 + comprimento2 * math.sin(angulo2)) y2 = float(y1 + comprimento2 * math.cos(angulo2)) velocidade_ang1 += aceleracao_ang1 velocidade_ang2 += aceleracao_ang2 angulo1 += velocidade_ang1 angulo2 += velocidade_ang2 scatter1.append((x1, y1)) scatter2.append((x2, y2)) for pontos in scatter2: random_color = (random.randint(20, 255), random.randint(20, 255), random.randint(20, 255)) plot = Pontos(pontos[0], pontos[1], screen, branco, scatter2) plot.draw() pygame.draw.line(screen, branco, ponto_inicial, (x1, y1), 6) pygame.draw.line(screen, branco, (x1, y1), (x2, y2), 6) pygame.draw.circle(screen, branco, (int(x2), int(y2)), 10) pygame.draw.circle(screen, (20, 200, 30), (int(x1), int(y1)), 20) if len(scatter1) > 1: pygame.draw.lines(screen, (100, 50, 100), False, scatter1, 1) pygame.display.update() pygame.quit()
Share this code with others
Public
Clear
My Repos
Repo
Lang
Login
Register
Login
Create a free account. No Credit card info required.
I agree with the Codepy
Term of Service
Sign Up