Created
October 17, 2016 16:55
-
-
Save 4Kaylum/883b675661efe2edcfc38333205d8eee to your computer and use it in GitHub Desktop.
Uses Pygame to generate a mystic rose image
This file contains hidden or 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 sys # Args from cmd - sys.argv[1] | |
| import pygame # Display graphically | |
| import math # Position stuff correctly | |
| import random # Shuffle thingies. | |
| class Window: | |
| def __init__(self, *, dimensions=[700, 700], title="Mystic Rose"): | |
| pygame.init() | |
| self.clock = pygame.time.Clock() | |
| # Window itself | |
| self.window = pygame.display.set_mode(dimensions) | |
| pygame.display.set_caption(title) | |
| self.window.fill([255, 255, 255]) | |
| # Some other stuff | |
| self.tick = True | |
| self.frame = 0 | |
| # Change the title of the window | |
| def changeCaption(self, title="Blank"): | |
| self.window.set_caption(title) | |
| # Check if the player clicked quit | |
| def checkQuit(self): | |
| for e in pygame.event.get(): | |
| if e.type == pygame.QUIT: | |
| pygame.quit() | |
| return False | |
| return True | |
| def makeLines(self, nodeList): | |
| pass | |
| class Node: | |
| def __init__(self, angle): | |
| self.angle = angle | |
| self.X = self.Y = 700/2 | |
| self.anglePosChange() | |
| # Get X/Y change values from an angle | |
| def anglePosChange(self): | |
| r_raw = self.angle | |
| # decreasing x decreasing y | |
| if r_raw >= 0 and r_raw < 90: | |
| multiplier = [-1,-1] | |
| # decreasing x increasing y | |
| elif r_raw >= 90 and r_raw < 180: | |
| multiplier = [-1,-1] | |
| # increasing x increasing y | |
| elif r_raw >= 180 and r_raw < 270: | |
| multiplier = [1,1] | |
| r_raw -= 180 | |
| # increasing x decreasing y | |
| else: | |
| multiplier = [-1,-1] | |
| r_y = r_raw - ( r_raw // 90 ) | |
| r_x = 90 - r_y | |
| self.X += multiplier[0] * 680/2 * math.sin(math.radians(r_raw)) | |
| self.Y += multiplier[1] * 680/2 * math.cos(math.radians(r_raw)) | |
| def main(): | |
| # Get the number of nodes | |
| while True: | |
| try: | |
| nodeAmount = int(sys.argv[1]) | |
| break | |
| except: | |
| try: | |
| nodeAmount = int(input("Please give an amount of nodes \n :: ")) | |
| break | |
| except: | |
| pass | |
| # gj. Create all the node points | |
| nodeDegree = 360/nodeAmount | |
| nodeList = [] | |
| i = 0 | |
| while i < 360: | |
| nodeList.append(Node(i)) | |
| i += nodeDegree | |
| # wd. Now blit the points to the screen. | |
| window = Window() | |
| for i in range(1000): | |
| z = [[i.X, i.Y] for i in nodeList] | |
| pygame.draw.lines(window.window, [50, 50, 50], True, z) | |
| random.shuffle(nodeList) | |
| # Display and then wait | |
| pygame.display.flip() | |
| while window.checkQuit(): | |
| pass | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment