[reportlab-users] Sunday pleasures: 12 queens animated
Dinu Gherman
reportlab-users@reportlab.com
Mon, 4 Nov 2002 09:26:06 +0100
--Apple-Mail-5-109108517
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
Andy Robinson:
> I just checked in a new canvas method setPageDuration, and
> modified tools\pythonpoint\demos\pythonpoint.xml to use it.
> You can specify a 'wait time' in seconds for all subsequent
> pages. If - and only if - Acrobat Reader is in full screen
> mode, it will auto-advance to the next page after that many
> seconds.
Cool, but it doesn't quite work on my box. I tried ints and floats
as arguments to setPageDuration(), but no effect, although the PDF
source has the appropriate dictionary entry /D. The full screen
option is correctly used, although the method is still contains
a trailing 0: showFullScreen0().
> You can tell me when I can download the 'animated' 12 queens, and
> whether Acrobat Reader catches fire at 24 frames per second :-)
I've attached a standalone generating script for 8 queens to illu-
strate the effect. Does the resulting PDF animate on your box?
--Apple-Mail-5-109108517
Content-Disposition: attachment;
filename=8queensPDF.py
Content-Transfer-Encoding: 7bit
Content-Type: application/text;
x-mac-creator=522A6368;
x-unix-mode=0644;
x-mac-type=54455854;
name="8queensPDF.py"
#!/usr/bin/env python
## from addons import *
def make_PDF():
"Create a PDF file with all solutions to the N-queens problem."
from reportlab.lib import colors
from reportlab.pdfgen.canvas import Canvas
a = 100
n = 8
# setup canvas
c = Canvas('8queens.pdf')
c.setPageSize((n*a, n*a))
c.showFullScreen0()
c.setPageDuration(1.0)
# create list of solutions
## sols = n_queens(n, n)
## sols = remove_mirror_solutions(sols)
sols = [[0, 4, 7, 5, 2, 6, 1, 3],
[0, 5, 7, 2, 6, 3, 1, 4],
[1, 3, 5, 7, 2, 0, 6, 4],
[1, 4, 6, 0, 2, 7, 5, 3],
[1, 4, 6, 3, 0, 7, 5, 2],
[1, 5, 0, 6, 3, 7, 2, 4],
[1, 5, 7, 2, 0, 3, 6, 4],
[1, 6, 2, 5, 7, 4, 0, 3],
[1, 6, 4, 7, 0, 3, 5, 2],
[2, 4, 1, 7, 0, 6, 3, 5],
[2, 4, 7, 3, 0, 6, 1, 5],
[2, 5, 1, 4, 7, 0, 6, 3]]
print "#solutions:", len(sols)
# add one page per solution to the canvas
na = n*a
for sol in sols:
# draw grid
c.setFillColor(colors.gray)
for i in range(0, na, a):
c.line(0, i, na, i)
c.line(i, 0, i, na)
# draw queens
c.setFillColor(colors.red)
for i in range(len(sol)):
c.rect(i*a, sol[i]*a, a, a, fill=1)
c.showPage()
c.save()
if __name__ == '__main__':
make_PDF()
--Apple-Mail-5-109108517
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
Regards,
Dinu
--
Dinu C. Gherman
......................................................................
"Any sufficiently advanced technology is indistinguishable
from magic." (Arthur C. Clarke)
--Apple-Mail-5-109108517--