Jump to content

File:Lichess funny II.gif

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
From Wikipedia, the free encyclopedia

Original file (800 × 800 pixels, file size: 583 KB, MIME type: image/gif, looped, 18 frames, 27 s)

Summary

Description
English: White to play.
Date
Source Own work
Author Kaotao
GIF development
InfoField
 
This GIF graphic was created with Python.
Source code
InfoField

Python code

Source code
#!/usr/bin/env python
# Plot a PGN game using python-chess and ImageMagick, highlighting last moves
import os
import chess.pgn
import chess.svg

pgn = open('game.pgn')
game = chess.pgn.read_game(pgn)
game = game.next()
board = game.board()

if input("Whose point of view? ('b' for black, nothing for white)\n") == 'b':
    pov = chess.BLACK
else:
    pov = chess.WHITE

delay = input("Delay per move, in centiseconds? (default is 150)\n")
if delay == '':
    delay = "150"
start = input("Starting delay? (default is 1)\n")
if start == '':
    start = "1"
end = input("End delay? (default is 3)\n")
if end == '':
    end = "3"
out = input("Output file name? ('.gif' is suffixed automatically, default is 'pgn.py')\n")
if out == '':
    out = "pgn_py"

def svg(i):
    s = chess.svg.board(board, lastmove = board.peek(), orientation = pov, coordinates = False, size = 800)

    f1 = "pgn_py_temp_%04u.svg" % i
    f2 = "pgn_py_temp_%04u.png" % i

    with open(f1, 'w') as f:
        f.write(s)
    os.system("magick %s %s" % (f1, f2))
    os.system("rm %s" % f1)

i = 0

#try to find it!
lm = board.peek()
while i < int(start):
    s = chess.svg.board(board, lastmove = lm, orientation = pov, coordinates = False, size = 800)

    f1 = "pgn_py_temp_%04u.svg" % i
    f2 = "pgn_py_temp_%04u.png" % i

    with open(f1, 'w') as f:
        f.write(s)
    os.system("magick %s %s" % (f1, f2))
    os.system("rm %s" % f1)
    i += 1

for m in game.mainline_moves():
    board.push(m)
    svg(i)
    i += 1

# pause animation at the end:
for j in range(int(end)):
    svg(i)
    i += 1

# create animation
os.system("magick -delay " + delay + " pgn_py_temp_*.png -loop 0 " + out + ".gif")
#please don't run this script if you use this naming scheme for family photos
os.system("rm pgn_py_temp_*")

# ~/ Input \~

# Whose point of view? ('b' for black, nothing for white)
#
# Delay per move, in centiseconds? (default is 150)
# 
# Starting delay? (default is 1)
# 10
# End delay? (default is 3)
#
# Output file name? ('.gif' is suffixed automatically, default is 'pgn_py')
#

PGN

[Variant "From Position"]
[FEN "2rq3r/pp3pk1/2pp1nb1/n3p1N1/4P2B/P1PP1Q1K/B1P2P2/R5R1 b - - 4 22"]

22... Qd7+ 23. Ne6+ Qxe6+ 24. Bxe6 Rxh4+ 25. Kxh4


Licensing

I, the copyright holder of this work, hereby publish it under the following license:
Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Captions

White to play.

In dieser Datei abgebildete Objekte

depicts

1 February 2025

image/gif

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current13:09, 1 February 2025Thumbnail for version as of 13:09, 1 February 2025800 × 800 (583 KB)KaotaoUploaded own work with UploadWizard

The following page uses this file: