Skip to content

Instantly share code, notes, and snippets.

@jsbueno
Created May 16, 2019 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsbueno/7e2c980fa25a1eadbfb52a2dbddac373 to your computer and use it in GitHub Desktop.
Save jsbueno/7e2c980fa25a1eadbfb52a2dbddac373 to your computer and use it in GitHub Desktop.
Example of raw plotting 2d funciton with pygame
import pygame
larg, alt = 800, 600
intervalo = -10, 10
fator_y = 1.0
tela = pygame.display.set_mode((larg, alt))
f_x= lambda x:3 * x ** 2 + 2 * x + 4
for x_tela in range(larg):
x = (x_tela - (larg / 2) ) / larg * (intervalo[1] - intervalo[0]) + intervalo[0]
y = f_x(x)
y_tela = alt - int(y * fator_y)
tela.set_at((x_tela, y_tela), (255, 255, 255))
pygame.display.flip()
input("pressione ENTER para encerrar")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment