Search results for 'pygame'
2010-01-16
Math
Different stuff that have some math inside
2D Vector Library
Attractors
Attractor
Lorenz attractor
Fractals
Simple Fractal
Blender Fractal
Blender Towers
Numerical
Simposon integration method
Other
Voronoi
Pascal Triangle
added new variable tha tcheck in with mode now screen is
Used new event type
if event.type == pygame.KEYDOWN:
When pressing key m we making new screen surface in fullscreen mode. If screen is in fuulscreen mode make window.
if event.key == pygame.K_m:
if not fullscreen:
screen = pygame.display.set_mode( (SCREEN_X,SCREEN_Y) , pygame.FULLSCREEN )
fullscreen = True
else:
screen = pygame.display.set_mode( (SCREEN_X,SCREEN_Y) )
fullscreen = False
All boxes moving with same speed in same directions and all boxes have same size and colorMake changes step by step to see result
self.dx = randint(1,BOX_SPEED)
self.dy = randint(1,BOX_SPEED)
and boxes now moving all seperatly at diferent directions. self.boxes.append( Box( i*2 , i*2 , randint(BOX_MIN_SIZE,BOX_MAX_SIZE) ,
(i,0,0) )
now boxes have diferent sizes
Tutorial source
New class boxes handles many boxes. Number of boxes depends on cpnstant MAX_BOXES.
MAX_BOXES = 100
and all class Boxes methods is the same only diference is that it handles many boxes.Tutorial Source
Here is Lorenz attractor whery popular attractor i have used basic coloring tehnique.
Script
PovRay source
added constants that helps controlling screen size
SCREEN_X = 500
SCREEN_Y = 500
BOX_SIZE = 20
BOX_SPEED = 1
box have speed by axisself.dx = BOX_SPEED
self.dy = BOX_SPEE
detecting if given rect is inside screen borders or not if not then change it directiondef move( self ):
if self.rect.left+BOX_SIZE > SCREEN_X:
self.dx = -BOX_SPEED
if self.rect.left < 0:
self.dx = BOX_SPEED
if self.rect.top+BOX_SIZE > SCREEN_Y:
self.dy = -BOX_SPEED
if self.rect.top < 0:
self.dy = BOX_SPEED
self.rect.left += self.dx
self.rect.top += self.dyafter few line of code where added box move inside given screen and coalide with screen borders
Tutorial Source
There is new object Box. We can draw, mask and move it.Once you init it you can use it with simple interface
box = Box( position_x , position_y , size ,
(color_red,color_green,color_blue,color_alpha) )
moving box to new position. new position calculates x_new = x_old + xbox.move( add_x , add_y )
drawes box on the screenbox.draw()
draw black box on the screenbox.mask()
Tutorial Source
Draw some image and make for it
surface image = pygame.image.load("image_name.format")
then copy image surface to screen surface. screen.blit( source_surface , (position_x,position_y) )
Tutorial source
Now you can set application window. But there is one problem you have to terminate application by killing.
Adding event handling help us exit from application by clicking close button or pressing some other button.
for event in pygame.event.get():
if event.type == pygame.QUIT:
runing = False
Now you can exit from application by clicking close button.
Event types
There are defined other event types pygame.(KEYUP, KEYDOWN, MOUSEMOTION, MOUSEBUTTONP, MOUSEBUTTONDOWN, VIDEORESIZE). All of these events described in pygame documentation
Tutorial source
First application and we opening window
screen = pygame.display.set_mode( (width_of_window ,height_of_window ) )
In future we will use screen for drawing.
Also there possible make full screen with value pygame.FULLSCREEN
it looks like:
pygame.display.set_mode( (width,height), pygame.FULLSCREEN )
Tutorial Source
Python Pygame tutorial. This tutorial goal show how to make small and simple pygame pythone script that include all that is need for bigger application. Every tutorial part add only few new lines of code.
Moving Boxes
Goal
Make featured applications with boxes that coaliding one with another.
1. [Set Display]
2. [Event Sytem]
3. [Image loading]
4. [Box object]
5. [Box move]
6. [Boxes move]
7. [Randomnes]
8. [Fullscreen]
I where interested to see how looks visualy distance to the closest point. When I saw result i remembered that it is Voronoi diagramm.
Download
I have found old article about attractors that is resoult what I have done with playing with attractor values. Attractor formula is very simple but result is interesting.
Flower where all list rotating around lists.
SDownload
This is simple map editor for small games. Also I think it will be useful for other people who started writing game and made first test maps.
Download
Wanted to know how will looks when mousepointer moving and all arrows shows it direction
Download
You can shut your bullets and they will contact with difrent boxes with diffrent result there is boxes that speed up, freeze, slow down bullets.
Download
I wanted to know how many simple object can be drawn by Pygame. Red point is starting point for flying bullets. And only thing with bullets have coalision is screen border. You can shut new bullets with mouse.
Download Script
After some optimisations script works faster.
Download Script v2
Also I have implemented the same on C++.
Download Source
Python scripth with generating picture of points from bmp image. Colors in bmp image is like koeficent map with allow generate more random points in any place of image you want. There shown source image from what where generated points on black image.
Download
Here is some Fractal examples. That is my first fractals.
Start Script
Circle Script