[img]http://dl.dropbox.com/u/2951174/programs/game%20of%20life.png[/img]
[img]http://dl.dropbox.com/u/2951174/programs/glifescreen1.png[/img]
Here's my implementation of game of life.
I'm going to use this for a school project at the annual science faire (involving a huge touchscreen board)
It still needs some work, I thought I'd add a menu, a proper instructions page and the ability to edit cell interaction rules, and maybe optimise it a bit. And fix the shitty colors.
I could also try and rewrite it in java for better performance, but I'm still learning it.
[B]Here are the instructions[/B] (also written on the titlebar at startup):
R = Run Simulation
C = Clear canvas
Left Mouse Btn = Draw
Right Mouse Btn = Erase
Center Mouse Btn = DrawToggle (makes dead cells alive and kills alive cells)
(the game currently uses a bad system to decide when to draw or not, so if you're drawing and you want to erase first release any button, then go to another area of the screen, click, then
[release][highlight]NEW! [/highlight][B]Version 1.2, 22/11/2010[/B]
[B]Download:[/B] [url]http://dl.dropbox.com/u/2951174/programs/gameoflife22-11-2010.7z[/url]
[B]Changelog[/B]
[list]
[*]Added a toggleable grid (Key: G)
[*]Added ability to change fps (MouseWheel) (thanks to Metroid48)
[*]Changed the information system to show all information in 6 pages (Key: I)
[*]Added ability to skip frame by frame (Key: right key)
[*]Added simple pattern save/load (one pattern at a time) (Key: S and L)
[/list]
[/release]
[release][B]Version 1.1, Base release 21/11/2010[/B]
[B]Download[/B]:
[url]http://dl.dropbox.com/u/2951174/programs/gameoflife.7z[/url]
[/release]
[B]Here you will find some fun patterns[/B]: [url]http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life#Examples_of_patterns[/url]
You can also fiddle with grid size and window size by going into main.py and editing SCREEN_SIZE or CELL_SIZE. For proper results, make sure both values in SCREEN_SIZE are divisible by CELL_SIZE.
Also if anyone could make a vid of it in action I would be very pleased, since all my screen recorders decided to break.
Colors! :D
Very colourful. I changed the size of the blocks and the grid size but the gradients did not adjust so the bottom right was pure white. I'd suggest ammending it to have a nice gradient no-matter what size the grid is.
[QUOTE=eXeC64;26209810]Very colourful. I changed the size of the blocks and the grid size but the gradients did not adjust so the bottom right was pure white. I'd suggest ammending it to have a nice gradient no-matter what size the grid is.[/QUOTE]
That gradient was just a stupid placeholder, I'd like to make something proper which works well at any resolution and doesn't go black and white at top-left and bottom-right borders. Does anyone know what I could use?
Should I add a grid?
Don't use a static image as gradient, let the computer make a gradient on resize ?
[QUOTE=TerabyteS;26209877]That gradient was just a stupid placeholder, I'd like to make something proper which works well at any resolution and doesn't go black and white at top-left and bottom-right borders. Does anyone know what I could use?[/QUOTE]
Take a look at this: [url]http://www.mediafire.com/?x7tem2ib1errn2x[/url]
It's java, but the idea should be pretty clear, feel free to ask if you have any questions.
[QUOTE=TerabyteS;26220543]Should I add a grid?[/QUOTE]
Yes, I tried to draw some of those patterns on wiki and it was pretty hard without a grid.
[QUOTE=quincy18;26220841]Don't use a static image as gradient, let the computer make a gradient on resize ?[/QUOTE]
It is not an image, it's just math, but I have no idea how to rescale it properly
well if its already mathematical just input other width and height value's lol ?
[QUOTE=quincy18;26224538]well if its already mathematical just input other width and height value's lol ?[/QUOTE]
No. It's mathematical, but if I resize it it stays the same. And I have no idea how to make it go relative to the size.
[editline]22nd November 2010[/editline]
[QUOTE=RyanDv3;26222522]Take a look at this: [url]http://www.mediafire.com/?x7tem2ib1errn2x[/url]
It's java, but the idea should be pretty clear, feel free to ask if you have any questions.[/QUOTE]
I tried reading, but didn't understand anything at all really.. could you please translate that to a general algorythm?
Basically, I use parabolas to determine the color over an interval (the top of your window to the bottom, for instance.
[img]http://www.cubeupload.com/files/5a8f4dparabola.png[/img]
Let's say this was your red curve and you decided to make x= 0 be the top of your page, and x= 1 be the bottom of your page, then the y values at any point would be how much red you use. Thus, the top of the page would have no red, and the bottom would be fully red.
You of course could use any mathematical curve, such as a simple line if you wanted; the curves will simply define how fast your color grows or shrinks over the interval.
[QUOTE=RyanDv3;26225504]Basically, I use parabolas to determine the color over an interval (the top of your window to the bottom, for instance.
[img_thumb]http://www.cubeupload.com/files/5a8f4dparabola.png[/img_thumb]
Let's say this was your red curve and you decided to make x= 0 be the top of your page, and x= 1 be the bottom of your page, then the y values at any point would be how much red you use. Thus, the top of the page would have no red, and the bottom would be fully red.
You of course could use any mathematical curve, such as a simple line if you wanted; the curves will simply define how fast your color grows or shrinks over the interval.[/QUOTE]
:eek: isn't that a bit too slow to calculate for every frame and square?
Anyway I've implemented a simple save-load mechanism, it's pretty bad right now but it works (only one save is allowed and only one file can be loaded, the saved one)
[QUOTE=TerabyteS;26220543]Should I add a grid?[/QUOTE]
Toggleable grid, maybe.
Oh and just added a way to go to next frame with left arrow
Right now I'm just throwing shit in, then I'll rewrite it properly with menus, a proper file browser and possibly rule editing.
And the grid. I can't be arsed to do it now, it takes too much thinking. Easier to do when working from scratch.
EDIT: Actually, I'm doing it now, I got the idea how to do it without much arse involved.
[QUOTE=TerabyteS;26225712]:eek: isn't that a bit too slow to calculate for every frame and square?[/QUOTE]
Not if you use [i]Hardware Acceleration[/i] :science:
But more likely you want to store the colour values and only recalculate for new blocks and when the screen's resized.
[QUOTE=TerabyteS;26225712]:eek: isn't that a bit too slow to calculate for every frame and square?
Anyway I've implemented a simple save-load mechanism, it's pretty bad right now but it works (only one save is allowed and only one file can be loaded, the saved one)[/QUOTE]
1. Who said you needed to calculate every frame? You only need to calculate the colors on resize.
2. A parabola is simply squaring, so to find the y, you would do pow(x, 2).
3. Why are you bothering with a gradient if you are so concerned with speed?
3. Seriously, stop worrying about speed. Optimization is something you learn by optimizing something that is running too slow, not by guessing at what might make something faster when it's speed is already adequate.
[QUOTE=TerabyteS;26209563]
Also if anyone could make a vid of it in action I would be very pleased, since all my screen recorders decided to break.[/QUOTE]
I'm trying but I can't figure out VLCs screen recording thing and there doesn't seem to be any good alternatives on linux. :frown:
[QUOTE=BlkDucky;26226171]I'm trying but I can't figure out VLCs screen recording thing and there doesn't seem to be any good alternatives on linux. :frown:[/QUOTE]
Not sure but camstudio might work on linux too.
[editline]22nd November 2010[/editline]
[QUOTE=RyanDv3;26226134]1. Who said you needed to calculate every frame? You only need to calculate the colors on resize.
2. A parabola is simply squaring, so to find the y, you would do pow(x, 2).
3. Why are you bothering with a gradient if you are so concerned with speed?
3. Seriously, stop worrying about speed. Optimization is something you learn by optimizing something that is running too slow, not by guessing at what might make something faster when it's speed is already adequate.[/QUOTE]
mmm I see, maybe I'm a bit paranoid..
So would this method work well:
-on init, calculate the parabola thingy and make a 2D list (array) of the colors for each cell
-when drawing, look up the cell's pos on the list and take the color from there
would work?
[editline]22nd November 2010[/editline]
Also, what the fuck
[img]http://dl.dropbox.com/u/2951174/programs/grid.png[/img]
That's what i get for copy-pasting code
[QUOTE=TerabyteS;26226345]mmm I see, maybe I'm a bit paranoid..
So would this method work well:
-on init, calculate the parabola thingy and make a 2D list (array) of the colors for each cell
-when drawing, look up the cell's pos on the list and take the color from there
would work?[/QUOTE]
Yup, that'd work fine.
By the way, I'm finding that the simulation runs a bit fast - mind if I add a simulation rate control?
[QUOTE=TerabyteS;26226345]
So would this method work well:
-on init, calculate the parabola thingy and make a 2D list (array) of the colors for each cell
-when drawing, look up the cell's pos on the list and take the color from there
would work?
[/QUOTE]
Yep
[QUOTE=Metroid48;26226509]Yup, that'd work fine.
By the way, I'm finding that the simulation runs a bit fast - mind if I add a simulation rate control?[/QUOTE]
Yes if you can dive through all that shit code, but anyway it's just a matter of using pygame.clock, which I didn't use. Right now it's running at fastest speed (which is slow), and that means the algorythm needs some optimisation
[editline]22nd November 2010[/editline]
Oh and could you share in case you manage to get it working?
[QUOTE=TerabyteS;26226971]Oh and could you share in case you manage to get it working?[/QUOTE]
Sure thing! With the unchanged parts snipped:
[code]...
CELL_SIZE = 10 #Size of a cell in the game, pixels
SIMULATION_RATE = 11 #Ticks per second
pygame.init()
lastTime=0
...
cb.clear()
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 4:
SIMULATION_RATE +=1
elif event.button== 5:
SIMULATION_RATE -=1
if SIMULATION_RATE<=0:
SIMULATION_RATE = 1
...
#Grid update
if (calculate and pygame.time.get_ticks()-lastTime>(1000.0/SIMULATION_RATE)):
cb.run()
lastTime=pygame.time.get_ticks()
...[/code]
There's a one-day expiry upload [url=http://pastebin.com/raw.php?i=LHtn45ca]here[/url], too. It also adds mousewheel control for the simulation speed.
[QUOTE=Metroid48;26227600]Sure thing! With the unchanged parts snipped:
[code]...
CELL_SIZE = 10 #Size of a cell in the game, pixels
SIMULATION_RATE = 11 #Ticks per second
pygame.init()
lastTime=0
...
cb.clear()
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 4:
SIMULATION_RATE +=1
elif event.button== 5:
SIMULATION_RATE -=1
if SIMULATION_RATE<=0:
SIMULATION_RATE = 1
...
#Grid update
if (calculate and pygame.time.get_ticks()-lastTime>(1000.0/SIMULATION_RATE)):
cb.run()
lastTime=pygame.time.get_ticks()
...[/code]
There's a one-day expiry upload [url=http://pastebin.com/raw.php?i=LHtn45ca]here[/url], too. It also adds mousewheel control for the simulation speed.[/QUOTE]
It looks good but it's pretty redundant, you should use this instead:
clock = pygame.time.Clock() #Clock object to be defined out of the game loop
and
clock.tick(framerate=0) #function to be used inside the game loop, once per frame. It'll add a delay to limit the framerate to the number specified in the call
[editline]22nd November 2010[/editline]
Oh and anyway I think I'm gonna upload the new version with the new nice stuff, one thing I'm not sure about is, since I want to add version numbers, which version the old one was and which this one is.
Suggestions?
tick(framerate) would be more convenient, but that slows user input too! By only limiting the execution of cb.run() we get accurate input, even at slower simulation rates :)
[QUOTE=Metroid48;26228375]tick(framerate) would be more convenient, but that slows user input too! By only limiting the execution of cb.run() we get accurate input, even at slower simulation rates :)[/QUOTE]
Ah, that's right. Gonna go and implement your version in the game if that's ok with you :D
I managed to beat this game once
[release][highlight]NEW! [/highlight][B]Version 1.2, 22/11/2010[/B]
[B]Download:[/B] [url]http://dl.dropbox.com/u/2951174/programs/gameoflife22-11-2010.7z[/url]
[B]Changelog[/B]
[list]
[*]Added a toggleable grid (Key: G)
[*]Added ability to change fps (MouseWheel) (thanks to Metroid48)
[*]Changed the information system to show all information in 6 pages (Key: I)
[*]Added ability to skip frame by frame (Key: right key)
[*]Added simple pattern save/load (one pattern at a time) (Key: S and L)
[/list]
[/release]
[editline]22nd November 2010[/editline]
Also: relevant pixel art (nsfw)
[media]http://img684.imageshack.us/img684/9595/artis.png[/media]
you should make colors change according to what blocks breed with whatever other blocks
have it produce new colors
and add toggleable bloom/motion blur
[QUOTE=Soda;26232056]you should make colors change according to what blocks breed with whatever other blocks
have it produce new colors
and add toggleable bloom/motion blur[/QUOTE]
That's quite a bit too much for poor pygame. It's already struggling to render those squares
Sorry, you need to Log In to post a reply to this thread.