Created
November 1, 2019 14:57
-
-
Save hugo4715/e7052ec7c50cb64e602c68987285fd79 to your computer and use it in GitHub Desktop.
sin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
from pygame.locals import * | |
import math | |
import random | |
ROUGE = (255, 0, 0) | |
BLANC = (255, 255, 255) | |
VERT = (0, 255, 0) | |
pygame.init() | |
police = pygame.font.SysFont('Comic Sans MS', 30) | |
screen = pygame.display.set_mode((800, 600)) | |
clock = pygame.time.Clock() | |
# remplir l'ecran en blanc | |
screen.fill(BLANC) | |
# | |
# CREATION DU SINUS | |
# | |
# creer une surface de 80 de large et 600 de haut pour en mettre pouvoir la mettre 10x dans l'ecran | |
surface = pygame.Surface((80, 600)) | |
# on trace des lignes pour creer le sinus | |
lastX = 0 | |
lastY = 300 | |
for i in range(0, 80): | |
x = i | |
y = 300-(math.sin((x*2*math.pi)/80)*100) | |
# on trace un petit segment du sinus | |
pygame.draw.line(surface, ROUGE, (lastX, lastY), (x, y)) | |
lastX = x | |
lastY = y | |
# on copie 10 fois la periode qu'on a dessine au dessus | |
for i in range(0, 10): | |
screen.blit(surface, (i*80, 0)) | |
# | |
# CREATION DES RAYONS | |
# | |
# pour chaque rayon | |
for numeroRayon in range(0, 10): | |
# on trouve le x et le y de la partie haute | |
rayonX = (numeroRayon*800)/10 + (80 * random.random()) | |
rayonY = 300-(math.sin((rayonX*2*math.pi)/80)*100) | |
# on trouve la derivee en x du sin pour avoir la pente | |
pente = math.cos((rayonX*2*math.pi)/80) | |
print(str(numeroRayon) + " => pente=" + str(pente)) | |
# on trace la partie haute du segment en vert | |
pygame.draw.line(screen, VERT, (rayonX, 0), (rayonX, rayonY)) | |
screen.blit(police.render(str(numeroRayon), False, (255, 0, 0)), (rayonX+10, rayonY)) | |
# on fait un triangle pour trouver l'angle entre l'axe x et la pente | |
vec1 = pygame.math.Vector3(0, 0, 1) | |
vec2 = pygame.math.Vector3(1, pente, 0) | |
result = vec2.cross(vec1).normalize() * 50 | |
pygame.draw.line(screen, BLANC, (rayonX, rayonY), (rayonX-result[0], rayonY+result[1])) | |
pygame.display.flip() | |
exit = False | |
while not exit: | |
# on regarde si l'utilisateur veut fermer la fenetre | |
events = pygame.event.get() | |
for event in events: | |
if event.type == pygame.QUIT: | |
# si oui on arrete la boucle | |
exit = True | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment