main.py
Código python:
Ver original
#!/usr/bin/env python #coding: UTF-8 import pygame import math from math import sin, cos, sinh, cosh, tan, tanh, pi, e, degrees, exp, log, log10, pow, radians, sqrt from pygame import K_LEFT, K_RIGHT, K_UP, K_DOWN, K_ESCAPE blue = (0, 0, 255) black = (0, 0, 0) def init(): pygame.init() size = width, height = 640, 480 screen = pygame.display.set_mode(size) pygame.display.set_caption("Graficadora polar") return screen def translate((t, r)): x = r*cos(radians(t)) y = r*sin(radians(t)) x += 320 y += 240 return (x, y) screen = init() dt = 0.5 t = 0 def r(t): t = radians(t) return 200*sin(4*t) while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: exit() keyboard = pygame.key.get_pressed() if keyboard[K_ESCAPE]: exit() try: start_pos = (int(t), int(r(t))) end_pos = (int(t + dt), int(r(t + dt))) t += dt except ZeroDivisionError: break if t > 360: t = 0 pygame.draw.line(screen, blue, translate(start_pos), translate(end_pos)) pygame.display.flip()