Image sequence

For scripts to aid with computation or simulation in cellular automata.
Post Reply
User avatar
gamnamno
Posts: 23
Joined: March 5th, 2014, 3:39 pm
Location: Rambaud, France
Contact:

Image sequence

Post by gamnamno » March 5th, 2014, 8:51 pm

Hi,
I've tried several ways to create an animation with Golly, like the Perl script "Giffer", but the exported gif doesn't work, or the Python script "save bmp", available at this page : http://www.conwaylife.com/scripts/
but it's no way to create an animation with hundreds or thousands of pictures, so is there any way to export a sequence of images ?
I don't want to use a screen capture software like Camtasia, because I have to export very big pictures in order to unzoom or accelerate smoothly using a video editing software like After Effects.

I also found this script : http://pastebin.com/8vVGCgKE
which was used to create this very good metapixel video : http://www.youtube.com/watch?v=xP5-iIeKXE8
but it doesn't work with me and I guess it's only made to create a Metapixel animation.

I'm not good at scripting, but if what I ask is not too hard (like adding something in the "save bmp" or the "output metalife" script), I can learn it, but I'd like a little help
Thanx

User avatar
gamnamno
Posts: 23
Joined: March 5th, 2014, 3:39 pm
Location: Rambaud, France
Contact:

Re: Image sequence

Post by gamnamno » March 11th, 2014, 8:47 pm

Andrew answered my problem in this topic :
viewtopic.php?f=9&t=1342

Here's the script:

Code: Select all

# Run the current pattern and save the selection as a separate .bmp file
# for each generation.  The files are saved in the same folder as the script.
# Author: Andrew Trevorrow (andrew@trevorrow.com), March 2014.

import golly as g
from glife import validint
from glife.WriteBMP import WriteBMP
import os.path

if g.empty(): g.exit("There is no pattern.")

srect = g.getselrect()
if len(srect) == 0: g.exit("There is no selection.")
x = srect[0]
y = srect[1]
wd = srect[2]
ht = srect[3]

# prevent Python allocating a huge amount of memory
if wd * ht >= 100000000:
   g.exit("Bitmap area is restricted to < 100 million cells.")

multistate = g.numstates() > 2
colors = g.getcolors()     # [0,r0,g0,b0, ... N,rN,gN,bN]
state0 = (colors[1],colors[2],colors[3])

# --------------------------------------------------------------------

def CreateBMPFile(filename):
    global x, y, wd, ht, multistate, colors, state0

    # create 2D array of pixels filled initially with state 0 color
    pixels = [[state0 for col in xrange(wd)] for row in xrange(ht)]
   
    cellcount = 0
    for row in xrange(ht):
       # get a row of cells at a time to minimize use of Python memory
       cells = g.getcells( [ x, y + row, wd, 1 ] )
       clen = len(cells)
       if clen > 0:
          inc = 2
          if multistate:
             # cells is multi-state list (clen is odd)
             inc = 3
             if clen % 3 > 0: clen -= 1    # ignore last 0
          for i in xrange(0, clen, inc):
             if multistate:
                n = cells[i+2] * 4 + 1
                pixels[row][cells[i]-x] = (colors[n],colors[n+1],colors[n+2])
             else:
                pixels[row][cells[i]-x] = (colors[5],colors[6],colors[7])
             cellcount += 1
             if cellcount % 1000 == 0:
                # allow user to abort huge pattern/selection
                g.dokey( g.getkey() )
   
    WriteBMP(pixels, filename)

# --------------------------------------------------------------------

# remove any existing extension from layer name
outname = g.getname().split('.')[0]

# prompt user for number of generations (= number of files)
numgens = g.getstring("The number of generations will be\n" +
                      "the number of .bmp files created.",
                      "100", "How many generations?")
if len(numgens) == 0:
    g.exit()
if not validint(numgens):
    g.exit('Sorry, but "' + numgens + '" is not a valid integer.')

numcreated = 0
intgens = int(numgens)
while intgens > 0:
   outfile = outname + "_" + g.getgen() + ".bmp"
   g.show("Creating " + outfile)
   CreateBMPFile(outfile)
   numcreated += 1
   g.run(1)
   g.update()
   intgens -= 1

g.show("Number of .bmp files created: " + str(numcreated))
Last edited by gamnamno on September 11th, 2015, 5:55 pm, edited 1 time in total.

larrylazzardo
Posts: 10
Joined: September 10th, 2015, 6:39 pm

Re: Image sequence

Post by larrylazzardo » September 10th, 2015, 6:49 pm

I am an artist completely new to Golly and Python, but I have many patterns I would like to export as video or image sequences.

I found this script through the forum but it keeps giving me an error:
http://pastebin.com/8vVGCgKE

I would like to try the script you have suggested here, but I don't know how to copy it and save it as a Python file... It must be simple. Can you help me out?
thank you!

User avatar
dvgrn
Moderator
Posts: 10612
Joined: May 17th, 2009, 11:00 pm
Location: Madison, WI
Contact:

Re: Image sequence

Post by dvgrn » September 11th, 2015, 6:22 pm

larrylazzardo wrote:I would like to try the script you have suggested here, but I don't know how to copy it and save it as a Python file... It must be simple. Can you help me out?
Notepad, or any other text editor, will work. Just click the Select All button at the top of the code box, hit Ctrl+C to copy, open Notepad and paste the text in, and save as something like collect-images.py, in an otherwise empty folder.

Then, if you have Python installed, you should be able to open that same collect-images.py script with Golly, using File > Run Script...

Smooth zooms on evolving patterns have always been a big weak point for Golly. Haven't figured out exactly what to do about that yet. For the time being, I've been playing around with Chris Rowett's LifeViewer, which allows for easy scripting of zooms and pans, color changes, rotations and so forth. At the moment you'd have to screen-capture the resulting animation, though.

Below is a sample viewer with a scripted pattern in case you want to try solving your problem that way. You can reply to this message, change the RLE code to whatever pattern you want to showcase, modify the script and see how it comes out. No need to actually post any messages if you don't want to -- just hit the Preview button after each set of changes. Hit 'H' when the cursor is over the viewer and scroll down to see all the available script commands.

When you get everything the way you want it, you can save the pattern and script seperately in a text file (again with Notepad or whatever). You can also save the HTML of the preview page and edit out the parts you don't need, if that's more to your liking.

Code: Select all

#C sample attempt to follow a glider around in the p59 gun
#C [[ AUTOSTART GPS 60 WIDTH 656 HEIGHT 656 THEME 2 LAYERS 2 DEPTH 0.4 T 0 X 48 Y -58 ZOOM 12
#C PAUSE 1 "3..."
#C PAUSE 1 "2..."
#C PAUSE 1 "1..."
#C PAUSE 1 "Go!"
#C T 140 X 80 Y -94 ZOOM 20
#C T 310 X 120 Y -52 ZOOM 16 ANGLE 45 STEP 4
#C T 360 X 130 Y -65 ZOOM 10 ANGLE 90 STEP 1
#C PAUSE 2 "Dramatic pause"
#C T 480 THEME 3 DEPTH 5 LAYERS 6 GPS 15 X 110 Y -95 ANGLE 0 ZOOM 15 "Slow motion"
#C T 610 THEME 1 DEPTH 0.4 GPS 30 AUTOFIT ANGLE 10 STEP 2
#C T 675 THEME 4 GPS 60 LAYERS 2 X 106 Y -50 ZOOM 10 ANGLE 350 STEP 3
#C T 858 X 140 Y 0 ZOOM 8 ANGLE 10 STEP 1
#C PAUSE 5 X 0 Y -5 ZOOM 1.5 DEPTH 0 ANGLE 0 "Show me the world..."
#C PAUSE 5 AUTOFIT THEME 5 "That's all folks!"
#C LOOP 1300 ]]
x = 299, y = 239, rule = B3/S23
118b2o3b2o$118b2o2bob3o$122bo4bo$118b4ob2o2bo$118bo2bobobob2o$121bobob
obo$122b2obobo$126bo2$112b2o$113bo7b2o$113bobo$114b2o$121b2o$121b2obo
98b2o3b2o26b2o3b2o$122b2o99b2o2bob3o22b3obo2b2o$123bo103bo4bo20bo4bo$
223b4ob2o2bo20bo2b2ob4o$223bo2bobobob2o18b2obobobo2bo$124b2o100bobobob
o20bobobobo$124bo102b2obobo20bobob2o$125b3o103bo22bo$127bo$136bobo78b
2o48b2o$137b2o79bo7b2o29b3o7bo$126b2o3b2o4bo80bobo5b2o28bo3bo4bobo$
124b3obo2b2o86b2o34bo5bo3b2o$108b2o13bo4bo125bo3bo3bo$109b2o12bo2b2ob
4o121bo2bobo2bo$108bo13b2obobobo2bo92b2o27bo3bo3bo$123bobobobo94bobo
28bo5bo$123bobob2o97bo33bo$124bo130bo3bo$229b2o24bo$137b2o90bo8bobo15b
o$128bo8bo92b3o6b2o12b3o$127b3o5bobo94bo6bo13bo$126b5o4b2o15bo$125b2o
3b2o21bo115bo$124b3o3b3o18b3o87bo26b2o$125b2o3b2o107b2o27bobo$126b5o
109b2o$93b3o31b3o$95bo30b3o$94bo30b2o83b2o$126bo54bo29b2o$123b3o55b3o
26bo$123bo60bo$183b2o69bo$153bo16b2o48b2o33bo$110bo27b3o12b3o14b2o48b
2o31b3o34bo$110bobo25bo17bo115b2o14b5o$110b2o27bo15b2o9bo103bo2bo13bo
5bo$167b2o101b2obobo4bo7b3o2bo$92bo67b3o3b2o12b3o26b3o13bo46bob2o3bobo
9bob2o$92b3o64bo4bo13bo4bo24bo4bo11bobo44bo5bo3bo5b4o2bo$79bo15bo129b
2o7b2o34b3o5bo3bo5bo3b2o$79b2o13b2o59bobo2bo3bo13bo3bo2bobo16bobo2bo3b
o20bo34bo8bo3bo6b3o$78bobo74bobo3b3o6b3o6b3o3bobo16bobo3b3o6b3o10bobo
34b2o8bobo9bo$154bo15b3o15bo14bo15b3o10b2o46bo10bob2o$86b2o66b2o15bo
15b2o14b2o15bo69b2ob2o$86bo67b3o14bo14b3o14b3o14bo15b2o7bo21b2o$83b2ob
o68b2o14bo14b2o16b2o14bo15b2o5b3o20bo2bo$83bo2b3o7bobo53b2ob2o13bobo
15bo14bo15bobo20bo39b2o$84b2o3bo6bo2bo53bobo81bo4b2o22b3o13bo$86b4o6bo
2bo48b2o4bo81bobo20b2o22b3o$86bo11bo3b2o45bo20bobo15bo14bo15bobo13b2ob
2o18bobo24bo$87b3o12bobo41b3o5b2o15bo14b2o16b2o14bo14b2o21bo$90bo13bo
41bo7b2o15bo14b3o14b3o14bo14b3o19b2o$85b5o14b2o65bo15b2o14b2o15bo15b2o
$84bo73b2o10b3o15bo14bo15b3o15bo33bo$64b2o17bo2b2o69bobo10b3o6b3o3bobo
16bobo3b3o6b3o6b3o3bobo30b2obobo$63bobo16bob2obo69bo20bo3bo2bobo16bobo
2bo3bo13bo3bo2bobo29bobobobo$65bo10b2o4bo73b2o7b2o96bo2bobobob2o$74bo
2bo2b2ob4o77bobo11bo4bo24bo4bo13bo4bo30b4ob2o2bo$74b2obobobobo2bo79bo
13b3o26b3o12b2o3b3o35bo4bo$77bobobobo139b2o38b2o2bob3o$77bobob2o37bo
104bo9b2o15bo10b2o3b2o$78bo28bo10b3o114bo17bo$108bo8bo52b2o19b2o27b2o
14b3o12b3o$91b2o13b3o8b2o51b2o18bobo27b2o16bo$82b2o7bo100bo$82b2o5bobo
$89b2o34b2ob2o51bo28bo$126bob2o49b2o30b2o$126bo53b2o28b2o$49b2o67b2o4b
3o$50b2o66b2o3bo3b2o70b2o3b2o$49bo22bo13bo36b4o2bo20b2o45b3obo2b2o$71b
o13b2o22b2o15bob2o21b2o43bo4bo$71b3o5b2o4bobo20bobo12b3o2bo21bo45bo2b
2ob4o32b3o$80bo27bo13bo5bo66b2obobobo2bo32bo$77b3o27b2o6bo7b5o68bobobo
bo36bo26bo$77bo35b2o10bo70bobob2o65b2o$114b2o60b2o19bo68b2o$100bo76b2o
$100b3o73bo33b2o$103bo97b2o7bo28bo$102b2o61bo35b2o5bobo15bo10b3o$165bo
bo40b2o14bobo9bo$105bo59b2o58b2o9b2o51bo$34b3o67bo2bo179b3o$36bo71bo
177bo$35bo22bo9b2o3b2o24b2o4bo29b3o106b2o40b2o$56b2o10b2o2bob3o23bo4bo
3bo27bo53bo53bo8bo$57b2o13bo4bo22bo2bo5bo2b2o22bo54bobo11b2o31bo6bob2o
4b2o$68b4ob2o2bo24b2o8bobo76b2o5b2o4b2o31bo6b2o2bo4bobo38b2ob2o$68bo2b
o3bob2o24bobobo6bo84bo6bo30b2o3b2o2b2o34bo12bob2o$71bobobobo26b3o7b2o
80b3o43b2obo34bobo12bo$72b2obobo83b3o32bo31b2o15bo35b2o4b2o4b3o$76bo
24bo3bo57bo63bobo12b3o24bo17b2o3bo3b2o$100bob2obo56bo64bo13bo9b2o14b5o
20b4o2bo$34bo27b2o36bobo3b2o118b2o5bobo6b5o5bo13bo5bo5b2o15bob2o$34b3o
26bo8bo26b2obobobo2bo40bobo68bo11b2o11bo5bobo12b3o2bo4bobo12b3o2bo$37b
o25bobo5b2o27bo2b2ob4o40b2o69b3o10bo9bo8b2o15bob2o3bo13bo5bo$20bo15b2o
26b2o34bo4bo45bo72bo19b2o21b4o2bo2b2o14b5o$20b2o56bo22b3obo2b2o113b2o
37b2o3bo3b2o21bo$19bobo57bo23b2o3b2o11bo140b2o4b3o$25b2ob2o12bo34b3o
41b2o132b2o13bo$25b2obo13bobo75bobo53bobo75bobo13bob2o$28bo13b2o132b2o
41b3o34bo12b2ob2o$28b3o4b2o140bo11b2o3b2o23bo57bobo$4bo21b2o3bo3b2o37b
2o113b2o2bob3o22bo56b2o$2b5o14b2o2bo2b4o21b2o19bo72bo45bo4bo34b2o26b2o
15bo$bo5bo13bo3b2obo15b2o8bo9bo10b3o69b2o40b4ob2o2bo27b2o5bobo25bo$bo
2b3o12bobo4bo2b3o12bobo5bo11b2o11bo68bobo40bo2bobobob2o26bo8bo26b3o$2o
bo15b2o5bo5bo13bo5b5o6bobo5b2o118b2o3bobo36b2o27bo$o2b4o20b5o14b2o9bo
13bo64bo56bob2obo$b2o3bo3b2o17bo24b3o12bobo63bo57bo3bo24bo$3b3o4b2o4b
2o35bo15b2o31bo32b3o83bobob2o$3bo12bobo34bob2o43b3o80b2o7b3o26bobobobo
$2obo12bo34b2o2b2o3b2o30bo6bo84bo6bobobo24b2obo3bo2bo$2ob2o38bobo4bo2b
2o6bo31b2o4b2o5b2o76bobo8b2o24bo2b2ob4o$44b2o4b2obo6bo31b2o11bobo54bo
22b2o2bo5bo2bo22bo4bo13b2o$44bo8bo53bo53bo27bo3bo4bo23b3obo2b2o10b2o$
11b2o40b2o106b3o29bo4b2o24b2o3b2o9bo22bo$12bo177bo71bo$9b3o179bo2bo67b
3o$9bo51b2o9b2o58b2o59bo$62bo9bobo14b2o40bobo$59b3o10bo15bobo5b2o35bo
61b2o$59bo28bo7b2o97bo$87b2o33bo73b3o$120b2o76bo$31b2o68bo19b2o60b2o$
30b2o65b2obobo70bo10b2o35bo$32bo26bo36bobobobo68b5o7bo6b2o27b3o$60bo
32bo2bobobob2o66bo5bo13bo27bo$58b3o32b4ob2o2bo45bo21bo2b3o12bobo20bobo
4b2o5b3o$97bo4bo43b2o21b2obo15b2o22b2o13bo$93b2o2bob3o45b2o20bo2b4o36b
o13bo22bo$93b2o3b2o70b2o3bo3b2o66b2o$172b3o4b2o67b2o$87b2o28b2o53bo$
86b2o30b2o49b2obo$88bo28bo51b2ob2o34b2o$207bobo5b2o$106bo100bo7b2o$60b
o16b2o27bobo18b2o51b2o8b3o13b2o$45b3o12b3o14b2o27b2o19b2o52bo8bo$45bo
17bo114b3o10bo28bo$29b2o3b2o10bo15b2o9bo104bo37b2obobo$27b3obo2b2o38b
2o139bobobobo$26bo4bo35b3o3b2o12b3o26b3o13bo79bo2bobobobob2o$26bo2b2ob
4o30bo4bo13bo4bo24bo4bo11bobo77b4ob2o2bo2bo$25b2obobobo2bo96b2o7b2o73b
o4b2o10bo$26bobobobo29bobo2bo3bo13bo3bo2bobo16bobo2bo3bo20bo69bob2obo
16bobo$26bobob2o30bobo3b3o6b3o6b3o3bobo16bobo3b3o6b3o10bobo69b2o2bo17b
2o$27bo33bo15b3o15bo14bo15b3o10b2o73bo$61b2o15bo15b2o14b2o15bo65b2o14b
5o$40b2o19b3o14bo14b3o14b3o14bo15b2o7bo41bo13bo$40bo21b2o14bo14b2o16b
2o14bo15b2o5b3o41bobo12b3o$13bo24bobo18b2ob2o13bobo15bo14bo15bobo20bo
45b2o3bo11bo$13b3o22b2o20bobo81bo4b2o48bo2bo6b4o$16bo13b3o22b2o4bo81bo
bo53bo2bo6bo3b2o$15b2o39bo20bobo15bo14bo15bobo13b2ob2o53bobo7b3o2bo$
29bo2bo20b3o5b2o15bo14b2o16b2o14bo14b2o68bob2o$30b2o21bo7b2o15bo14b3o
14b3o14bo14b3o67bo$4b2ob2o69bo15b2o14b2o15bo15b2o66b2o$4b2obo10bo46b2o
10b3o15bo14bo15b3o15bo$7bo9bobo8b2o34bobo10b3o6b3o3bobo16bobo3b3o6b3o
6b3o3bobo74bobo$7b3o6bo3bo8bo34bo20bo3bo2bobo16bobo2bo3bo13bo3bo2bobo
59b2o13b2o$5b2o3bo5bo3bo5b3o34b2o7b2o129bo15bo$4bo2b4o5bo3bo5bo44bobo
11bo4bo24bo4bo13bo4bo64b3o$4b2obo9bobo3b2obo46bo13b3o26b3o12b2o3b3o67b
o$5bo2b3o7bo4bobob2o101b2o$5bo5bo13bo2bo103bo9b2o15bo27b2o$6b5o14b2o
115bo17bo25bobo$8bo34b3o31b2o48b2o14b3o12b3o27bo$43bo33b2o48b2o16bo$
44bo$175bo$88bo28bo55b3o$72bo13b2o30b2o52bo$72b3o12b2o28b2o53b2o30bo$
75bo94b3o30bo$74b2o93b3o31b3o$57b2o109b5o$28bobo27b2o107b2o3b2o$29b2o
26bo87b3o18b3o3b3o$29bo115bo21b2o3b2o$146bo15b2o4b5o$45bo13bo6bo94bobo
5b3o$43b3o12b2o6b3o92bo8bo$42bo15bobo8bo90b2o$43bo24b2o$39bo3bo130bo$
38bo33bo60bo36b2obobo$37bo5bo28bobo56bobo35bobobobo$36bo3bo3bo27b2o58b
2o32bo2bobobob2o13bo$36bo2bobo2bo121b4ob2o2bo12b2o$36bo3bo3bo125bo4bo
13b2o$32b2o3bo5bo34b2o86b2o2bob3o$31bobo4bo3bo28b2o5bobo80bo4b2o3b2o$
31bo7b3o29b2o7bo79b2o$30b2o48b2o78bobo$171bo$44bo22bo103b3o$40b2obobo
20bobob2o102bo$39bobobobo20bobobobo100b2o$36bo2bobobob2o18b2obobobo2bo
$36b4ob2o2bo20bo2b2ob4o$40bo4bo20bo4bo74bobo26bo$36b2o2bob3o22b3obo2b
2o71b2o26b2o$36b2o3b2o26b2o3b2o71bo26bob2o$176b2o$183b2o$183bobo$176b
2o7bo$185b2o2$172bo$171bobob2o$171bobobobo$170b2obobobo2bo$171bo2b2ob
4o$162bo8bo4bo$163bo8b3obo2b2o$161b3o10b2o3b2o!

User avatar
gamnamno
Posts: 23
Joined: March 5th, 2014, 3:39 pm
Location: Rambaud, France
Contact:

Re: Image sequence

Post by gamnamno » September 11th, 2015, 6:35 pm

Paste the code in a text file and replace the .txt extension by a .py extension (name the file whatever you want).
Then put the file in Golly's python scripts directory and you'll find it inside Golly, in the scripts panel.

How to use it :
- Select an area
- Run the script
- If it asks for the Perl dll click cancel (it happened to me somehow)
- Enter the number of frames
- The files are saved in the same folder as the one you put the script in.

If it doesn't work, try resetting your prefs by deleting this file :
C:\Users\Your username\AppData\Roaming\Golly\GollyPrefs
make sure you use python 2.7 (or 2.7.10) and Golly 2.7 (or 2.6)

I didn't come on this website for about a year so this is quite a coïncidence. Also I happen to have the same other script you found on the forum. I guess I went trough the same research but I don't remember. I also get an error when I execute it. What is it's purpose again ? Do you have a link to the related topic ?

edit : Woops, dvgrn was faster than me.
Last edited by gamnamno on March 8th, 2017, 10:46 am, edited 1 time in total.

User avatar
dvgrn
Moderator
Posts: 10612
Joined: May 17th, 2009, 11:00 pm
Location: Madison, WI
Contact:

Re: Image sequence

Post by dvgrn » September 11th, 2015, 7:07 pm

gamnamno wrote: Also I happen to have the same other script you found on the forum. I guess I went trough the same research but I don't remember. I also get an error when I execute it. What is it's purpose again ?
It appears to have been used specifically to make the Life in Life video. It would take quite a bit of recoding to get it to do anything else, I think (as you said in your original post!)

larrylazzardo
Posts: 10
Joined: September 10th, 2015, 6:39 pm

Re: Image sequence

Post by larrylazzardo » September 15th, 2015, 2:21 am

Hi thank you for your help. :) Sadly I am in way over my head. While all the scripts that came with Golly seem to work fine, these ones I am now copying into notepad, saving as .py etc, all give me an error message.

"Syntax Error: unexpected character after line continuation character"

Any thoughts?
thank you :)

User avatar
dvgrn
Moderator
Posts: 10612
Joined: May 17th, 2009, 11:00 pm
Location: Madison, WI
Contact:

Re: Image sequence

Post by dvgrn » September 15th, 2015, 10:03 am

larrylazzardo wrote:Hi thank you for your help. :) Sadly I am in way over my head. While all the scripts that came with Golly seem to work fine, these ones I am now copying into notepad, saving as .py etc, all give me an error message.

"Syntax Error: unexpected character after line continuation character"
Not to worry, you're just having the inevitable problems with backslash characters -- \ -- that everybody runs into at some point.

Python uses backslashes as line-continuation characters: at the very end of a line, a backslash means "read the next line as part of this line."

Unfortunately, Python also uses backslashes as escape characters -- so \n means a newline character, \t means a tab, and so forth. Most horribly, \' and \" are treated as single-quote and double-quote characters, respectively. Suddenly they're just single characters like any other, meaning that Python won't treat them as an end marker for a quoted string... So if you somehow get the number of quote marks mismatched after editing a file path, you'll end up with the error you're asking about.

Possibly you have a path to a folder somewhere in the code that looks something like this:

Code: Select all

    foldername = `C:\hereis\mydata\'
and Python is thinking that the last backslash is a line continuation, so the quote mark after it is not allowable.

Make sure that all your quotes are real straight quotes -- " -- and not some other strange characters mangled by Microsoft Word, such as `. Then, to make assurance doubly sure, go through all your quoted file and folder path names and replace any backward slashes -- \ -- with foward slashes -- /. Backward slashes will work in path strings sometimes, but they're very unreliable because of the escape-character behavior -- very weird things happen when a folder name starts with "n" or "t", for example.

So always use forward slashes in path names. After that you'll probably be all right... or at least, any remaining error messages you get will be a little more likely to make sense.

If not, please go ahead and post here the actual code that you're trying to run. If it doesn't work for you, it won't work for anyone else either, and someone will be able to find the specific problem easily. Just paste your code into a message, and then optionally select it and hit the "Code" button at the top of the message window to get the BBCode

Code: Select all

[/b] tags around your problem code.

larrylazzardo
Posts: 10
Joined: September 10th, 2015, 6:39 pm

Re: Image sequence

Post by larrylazzardo » November 22nd, 2016, 2:18 pm

Hello! I went away and had to leave my attempts on the back burner. Thank you for your previous responses, I apologize for not responding sooner. I am still stuck where I left off.

gamnamno
I have been trying to use the script found here which you also found some time ago. Perhaps all this time later you have had some luck exporting sequences of images from Golly?
viewtopic.php?f=9&t=1342

dvgrn, I have looked through the code as per your suggestions and cannot identify the problem. There is one \n" that bares resemblance to what you describe as a possible problem, but that is about it?

Code: Select all

# Run the current pattern and save the selection as a separate .bmp file
# for each generation.  The files are saved in the same folder as the script.
# Author: Andrew Trevorrow (andrew@trevorrow.com), March 2014.

import golly as g
from glife import validint
from glife.WriteBMP import WriteBMP
import os.path

if g.empty(): g.exit("There is no pattern.")

srect = g.getselrect()
if len(srect) == 0: g.exit("There is no selection.")
x = srect[0]
y = srect[1]
wd = srect[2]
ht = srect[3]

# prevent Python allocating a huge amount of memory
if wd * ht >= 100000000:
   g.exit("Bitmap area is restricted to < 100 million cells.")

multistate = g.numstates() > 2
colors = g.getcolors()     # [0,r0,g0,b0, ... N,rN,gN,bN]
state0 = (colors[1],colors[2],colors[3])

# --------------------------------------------------------------------

def CreateBMPFile(filename):
    global x, y, wd, ht, multistate, colors, state0

    # create 2D array of pixels filled initially with state 0 color
    pixels = [[state0 for col in xrange(wd)] for row in xrange(ht)]
    
    cellcount = 0
    for row in xrange(ht):
       # get a row of cells at a time to minimize use of Python memory
       cells = g.getcells( [ x, y + row, wd, 1 ] )
       clen = len(cells)
       if clen > 0:
          inc = 2
          if multistate:
             # cells is multi-state list (clen is odd)
             inc = 3
             if clen % 3 > 0: clen -= 1    # ignore last 0
          for i in xrange(0, clen, inc):
             if multistate:
                n = cells[i+2] * 4 + 1
                pixels[row][cells[i]-x] = (colors[n],colors[n+1],colors[n+2])
             else:
                pixels[row][cells[i]-x] = (colors[5],colors[6],colors[7])
             cellcount += 1
             if cellcount % 1000 == 0:
                # allow user to abort huge pattern/selection
                g.dokey( g.getkey() )
    
    WriteBMP(pixels, filename)

# --------------------------------------------------------------------

# remove any existing extension from layer name
outname = g.getname().split('.')[0]

# prompt user for number of generations (= number of files)
numgens = g.getstring("The number of generations will be\n" +
                      "the number of .bmp files created.",
                      "100", "How many generations?")
if len(numgens) == 0:
    g.exit()
if not validint(numgens):
    g.exit('Sorry, but "' + numgens + '" is not a valid integer.')

numcreated = 0
intgens = int(numgens)
while intgens > 0:
   outfile = outname + "_" + g.getgen() + ".bmp"
   g.show("Creating " + outfile)
   CreateBMPFile(outfile)
   numcreated += 1
   g.run(1)
   g.update()
   intgens -= 1

g.show("Number of .bmp files created: " + str(numcreated))

User avatar
dvgrn
Moderator
Posts: 10612
Joined: May 17th, 2009, 11:00 pm
Location: Madison, WI
Contact:

Re: Image sequence

Post by dvgrn » November 22nd, 2016, 4:25 pm

larrylazzardo wrote:Hello! I went away and had to leave my attempts on the back burner. Thank you for your previous responses, I apologize for not responding sooner. I am still stuck where I left off.
Interesting! Okay, I've read back a few posts. If I understand right, you're reporting that it's still true that
While all the scripts that came with Golly seem to work fine, these ones I am now copying into notepad, saving as .py etc, all give me an error message.

"Syntax Error: unexpected character after line continuation character"
I don't have a good theory for that, so let's gather more data. Does the following script work when you copy into Notepad and save as .py?

Code: Select all

import golly as g

g.note("No errors here!")
Also, there should be a line number reported by Python along with the syntax error. Maybe if you Ctrl+C copy the whole error message that you see -- e.g., when you run Andrew's March 2014 script that you quoted -- then maybe I'll be able to come up with a less incorrect theory.

I saved that script to a folder on my (Windows) desktop, and it worked fine for me. What OS are you running, and where exactly (full path) are you saving your copy of the script?

larrylazzardo
Posts: 10
Joined: September 10th, 2015, 6:39 pm

Re: Image sequence

Post by larrylazzardo » November 23rd, 2016, 8:39 pm

Hi, yes !

I am using Mac OSX 10.10.5

I am using a program called TextEdit for copying and saving scripts (and suddenly as I write this thinking that TextEdit may not actually be good for code editing and probably meant for simple word processing, perhaps it does something disruptive to the code.)

I am saving my script files to: /Applications/golly-2.7-mac109/Scripts/Python/testgolly.py

Indeed the little test script you have supplied also gives me the same error which I wasn't able to copy but which I made an image that is available here: https://postimg.org/image/n2eo4qtdv/
(sorry it's maybe a lame image host I hope you aren't getting spammed with ads)

I am going to look for a proper code editor for Mac now.
thank you!
eli

larrylazzardo
Posts: 10
Joined: September 10th, 2015, 6:39 pm

Re: Image sequence

Post by larrylazzardo » November 23rd, 2016, 9:00 pm

Well there you have it. The problem was indeed the text editor I was using. I have successfully run the script and generating a whole bunch of bmap images; exactly what I wanted.

Coding is something I rarely work with save the ocassional audio/visual solution at my workplace. Thanks for helping this novice think though a silly problem.

Proceeding I will most likely start having questions about exporting at certain resolutions etc. but for now I will spend more time teaching myself about code. I fear it may become addictive.
best
eli

User avatar
gamnamno
Posts: 23
Joined: March 5th, 2014, 3:39 pm
Location: Rambaud, France
Contact:

Re: Image sequence

Post by gamnamno » March 8th, 2017, 11:07 am

Glad you solved your problem larrylazzardo.
For getting a higher resolution I personnally do it externally from a 2D application that supports animations (in my case Krita) and scale it up while disabling anti-aliasing (Box Filter in Krita)
Sorry I didn't reply before, I've been quite absent from this forum for a while.

User avatar
gamnamno
Posts: 23
Joined: March 5th, 2014, 3:39 pm
Location: Rambaud, France
Contact:

Re: Image sequence

Post by gamnamno » March 11th, 2017, 12:12 pm

Andrew made a Lua version of the script and it seems we run into less problems with it :

Code: Select all

-- Run the current pattern and save the selection as a separate .bmp file
-- for each generation.  The files are saved in the same folder as the script.
-- Author: Andrew Trevorrow (andrew@trevorrow.com), March 2017.

local g = golly()
local gp = require "gplus"
local chr = string.char
local getcell = g.getcell

if g.empty() then g.exit("There is no pattern.") end

local srect = g.getselrect()
if #srect == 0 then g.exit("There is no selection.") end
local x, y, wd, ht = table.unpack(srect)

-- avoid creating huge files
if wd * ht >= 100000000 then
   g.exit("Bitmap area is restricted to < 100 million cells.")
end

local colors = g.getcolors()     -- {0,r0,g0,b0, ... N,rN,gN,bN}
local state0 = chr(colors[4])..chr(colors[3])..chr(colors[2])
local statebgr = {}
for i = 1, g.numstates() - 1 do
    local j = i * 4 + 2
    statebgr[i] = chr(colors[j+2])..chr(colors[j+1])..chr(colors[j])
end

--------------------------------------------------------------------------------

-- Pack a given +ve integer into a little-endian binary string of size numbytes.
-- Based on code at http://lua-users.org/wiki/ReadWriteFormat.

local function lpack(numbytes, value)
    local result = ""
    for i = 1, numbytes do
        result = result .. chr(value % 256)
        value = math.floor(value / 256)
    end
    return result
end

--------------------------------------------------------------------------------

-- create a minimal dictionary with values for a Windows Version 3 DIB header:
local d = {
    mn1=66,
    mn2=77,
    filesize=0,
    undef1=0,
    undef2=0,
    offset=54,
    headerlength=40,
    width=wd,
    height=ht,
    colorplanes=1,
    colordepth=24,
    compression=0,
    imagesize=0,
    res_hor=0,
    res_vert=0,
    palette=0,
    importantcolors=0
}

-- we only need to create the header data once:
local header =
    lpack(1, d.mn1) ..
    lpack(1, d.mn2) ..
    lpack(4, d.filesize) ..
    lpack(2, d.undef1) ..
    lpack(2, d.undef2) ..
    lpack(4, d.offset) ..
    lpack(4, d.headerlength) ..
    lpack(4, d.width) ..
    lpack(4, d.height) ..
    lpack(2, d.colorplanes) ..
    lpack(2, d.colordepth) ..
    lpack(4, d.compression) ..
    lpack(4, d.imagesize) ..
    lpack(4, d.res_hor) ..
    lpack(4, d.res_vert) ..
    lpack(4, d.palette) ..
    lpack(4, d.importantcolors)

-- we may need to pad each row:
local row_mod = (d.width * d.colordepth / 8) % 4
local padding = ""
if row_mod > 0 then
    for i = 1, 4 - row_mod do
        padding = padding..chr(0)
    end
end

--------------------------------------------------------------------------------

function CreateBMPFile(filename)
    -- create a BMP file showing the pattern in the current selection
    local outfile = io.open(filename,'wb')
    if not outfile then g.exit("Unable to create BMP file:\n"..filename) end

    -- write the header info
    outfile:write(header)

    -- write the byte data (BMPs are encoded left-to-right from the bottom-up)
    for row = ht, 1, -1 do
        for col = 1, wd do
            local state = getcell(x + col - 1, row + y - 1)
            if state == 0 then
                outfile:write(state0)
            else
                outfile:write(statebgr[state])
            end
        end
        if row_mod > 0 then
            -- add padding so the byte count for each row is divisible by 4
            outfile:write(padding)
        end
    end

    outfile:close()
end

--------------------------------------------------------------------------------

-- remove any existing extension from layer name
local outname = gp.split(g.getname(),"%.")

-- prompt user for number of generations (= number of files)
local numgens = g.getstring("The number of generations will be\n" ..
                            "the number of .bmp files created.",
                            "100", "How many generations?")
if #numgens == 0 then
    g.exit()
end
if not gp.validint(numgens) then
    g.exit('Sorry, but "' .. numgens .. '" is not a valid integer.')
end

local numcreated = 0
local intgens = tonumber(numgens)
while intgens > 0 do
    local outfile = outname .. "_" .. g.getgen() .. ".bmp"
    g.show("Creating " .. outfile)
    CreateBMPFile(outfile)
    numcreated = numcreated + 1
    if intgens == 1 then break end
    g.run(1)
    g.update()
    intgens = intgens - 1
end
g.show("Number of .bmp files created: " .. numcreated)
Also I made a tutorial on how to make an image sequence with Golly :
https://caetano-veyssieres.com/cellular ... -tutorial/

User avatar
Andrew
Moderator
Posts: 919
Joined: June 2nd, 2009, 2:08 am
Location: Melbourne, Australia
Contact:

Re: Image sequence

Post by Andrew » March 11th, 2017, 8:24 pm

gamnamno wrote:Also I made a tutorial on how to make an image sequence with Golly
I think you forgot to remove these 2 sentences (near the end):

If an error pops up when you run the script, chances are you didn’t install the Python Imaging Library (PIL or Pillow). Make sure to have the appropriate one for your Python version and operating system.

Note that even the old Python script I wrote didn't need PIL.
Use Glu to explore CA rules on non-periodic tilings: DominoLife and HatLife

User avatar
gamnamno
Posts: 23
Joined: March 5th, 2014, 3:39 pm
Location: Rambaud, France
Contact:

Re: Image sequence

Post by gamnamno » March 12th, 2017, 10:06 am

These sentences are not for the BMP-sequence script but for the image_import.py script that I also wanted to mention in this tutorial, because I find it very useful to build your own patterns from a 2D application. I just edited the sentence to try and make it clearer.

User avatar
gamnamno
Posts: 23
Joined: March 5th, 2014, 3:39 pm
Location: Rambaud, France
Contact:

Re: Image sequence

Post by gamnamno » December 5th, 2020, 3:29 pm

Just realised the tutorial link is outdated. Here is the one that works now : https://chameleonscales.wordpress.com/c ... -tutorial/
Also here's the gitlab repository which I seem to have forgotten to mention : https://gitlab.com/ChameleonScales/Goll ... ree/master

Post Reply