Created
May 28, 2022 16:05
-
-
Save reo6/962c3b42687276eec14574231450ce82 to your computer and use it in GitHub Desktop.
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 pyglet | |
from pyglet import shapes | |
import math | |
import random | |
SIZE = (500, 600) | |
TAU = 2 * math.pi | |
SIDE_NUMBER = random.randint(3, 8) | |
# https://gist.github.com/aib/2083288c45b68107454ffb03e977423f | |
def create_polygon(sides, posx, posy, scale): | |
lines = [] | |
for i in range(sides): | |
lines.append(( | |
# First Point | |
posx + math.cos(i * (TAU/sides)) * scale, posy + math.sin(i * (TAU/sides)) * scale, | |
# Second Point | |
posx + math.cos((i+1) * (TAU/sides)) * scale, posy + math.sin((i+1) * (TAU/sides)) * scale, | |
)) | |
return lines | |
class LinesTestWindow(pyglet.window.Window): | |
def __init__(self, width, height): | |
super().__init__(width, height) | |
self.time = 0 | |
self.batch = pyglet.graphics.Batch() | |
#self.line = shapes.Line(SIZE[0]/2, SIZE[1]/2, SIZE[0]/2+200, SIZE[1]/2, 3, color=(255, 255, 0), batch=self.batch) | |
self.line_objects = self.create_lines() | |
def on_draw(self): | |
self.clear() | |
self.batch.draw() | |
def update(self, time_delta): | |
self.time += time_delta | |
self.line.position = ( | |
self.line.x, | |
#SIZE[1]/2 + math.sin(self.time) * 20, | |
self.line.y, | |
SIZE[0]/2 + math.sin(self.time) * 100, | |
# Gelen +50 -50 arasinda degisiyor | |
SIZE[1]/2 + math.sin(self.time) * 100, | |
) | |
#print(self.line.position) | |
def create_lines(self): | |
lines = create_polygon(SIDE_NUMBER, SIZE[0]/2, SIZE[1]/2, 100) | |
line_objects = [shapes.Line(line[0], line[1], line[2], line[3], 3, color=(255, 255, 0), batch=self.batch) for line in lines] | |
return line_objects | |
if __name__ == "__main__": | |
test = LinesTestWindow(SIZE[0], SIZE[1]) | |
#pyglet.clock.schedule_interval(test.update, 1/30) | |
pyglet.app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment