Destructive rotation visualizer.

This is the place to post any code that you want to share with the community. Only completed scripts should be posted here.

Destructive rotation visualizer.

Postby Mekire » Mon Jan 13, 2014 8:47 am

I wrote this to demonstrate how repeated rotations of the same surface are extremely destructive.

But... the visual effect is pretty cool in and of itself:
Code: Select all
import sys
import random
import pygame 
as pg


class Control(object):
    
def __init__(self):
        
pg.init()
        
self.screen pg.display.set_mode((500,500))
        
self.screen_rect self.screen.get_rect()
        
self.clock pg.time.Clock()
        
self.fps 15.0
        self
.done False
        self
.rotate_angle 11.25
        self
.surface_size = (25,50)
        
self.make_image(True)

    
def get_random_color(self):
        return [
random.randint(0,255) for _ in range(3)]

    
def event_loop(self):
        for 
event in pg.event.get():
            if 
event.type == pg.QUIT:
                
self.done True

    def make_image
(self,new=False):
        if new or 
not self.screen_rect.contains(self.rect):
            
self.image pg.Surface(self.surface_size).convert()
            
self.image.fill(self.get_random_color())
        else:
            
self.image pg.transform.rotate(self.image,self.rotate_angle)
        
self.image.fill(self.get_random_color(),(0,0,1,1))
        
self.rect self.image.get_rect(center=self.screen_rect.center)

    
def main_loop(self):
        while 
not self.done:
            
self.event_loop()
##            self.screen.fill(0)
            
self.make_image()
            
self.screen.blit(self.image,self.rect)
            
pg.display.update()
            
self.clock.tick(self.fps)


if 
__name__ == "__main__":
    
app Control()
    
app.main_loop()
    
pg.quit()
    
sys.exit()

Experiment with changing the frame rate, rotation angle and surface size for some interesting results.
-Mek
User avatar
Mekire
 
Posts: 1125
Joined: Thu Feb 07, 2013 11:33 pm
Location: Asakusa, Japan

Re: Destructive rotation visualizer.

Postby XndrK » Sat Jan 18, 2014 8:20 pm

Note to self: get Pygame.
Proverbs 26:14 describes me a bit too well.

Version: Python 2.7.5

https://github.com/4of92000
https://github.com/PythonForum/
User avatar
XndrK
 
Posts: 173
Joined: Sat Jun 15, 2013 7:57 pm


Return to Completed Scripts

Who is online

Users browsing this forum: No registered users and 2 guests