Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A diagram renderer written in Python that can turn an .sgf file for the game of Go/Baduk/Weiqi into a diagram image that's either static or animated.

License

NotificationsYou must be signed in to change notification settings

travisgk/sgf2anim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sgf2anim

A Python script that can turn an .sgf file for the game of Go/Baduk/Weiqi into a diagram image that's either static or animated.



Installation

pip install pillow imageio

pillow is used for graphics rendering.

imageio is used for building animated GIF files.



Creating a Diagram

Static

import sgf2animsgf_path = "my-sgf.sgf"out_path = "my-sgf-output.sgf"sgf2anim.get_settings().set_for_static_diagram()sgf2anim.save_diagram(sgf_path, out_path=out_path)

This will create a static diagram and save it as "my-sgf-output.png" in the same directory.


Animated

import sgf2animsgf_path = "capturing-race.sgf"out_path = "capturing-race.gif"sgf2anim.save_diagram(    sgf_path,    out_path=out_path,    save_as_static=False,    frame_delay_ms=1200,    start_freeze_ms=3000,    end_freeze_ms=10000,    number_display_ms=1200,)
  • sgf_path provides the path for the SGF file to process.
  • out_path provides the path for the image to be written to. It must either be a .png or a .gif.
  • frame_delay_ms is the duration that one node in the SGF will be shown.
  • start_freeze_ms is the duration of the first frame.
  • end_freeze_ms is the duration of the last frame.
  • number_display_ms is the duration of theframe_delay_ms that will show the move number (or placement marker) on the stone.

Multiple Files at Once

import sgf2animsgf_dir = "directory"sgf2anim.process_directory(    sgf_dir,    out_path_addon="-output",    frame_delay_ms=1500,    start_freeze_ms=3000,    end_freeze_ms=10000,    number_display_ms=1000,)

Theprocess_directory function will find any SGF files in the given directory and create both a static and animated diagram for all of them.If an SGF file doesn't contain any played moves, then an animated diagram will not be created.



Styling

Default Profiles

sgf2anim.get_settings().set_for_static_diagram() will change the settings to render all the move numbers and not remove captured stones from the diagram.


sgf2anim.get_settings().set_for_animated_diagram() will change the settings to render each placed stone with a temporary placement marker. Captures will be removed.


Custom Theme

import sgf2anim# defines the graphics directory under sgf2anim/_res to use and the styling properties.sgf2anim.get_settings().STYLE_NAME = "frost"sgf2anim.get_settings().DIGIT_TEXT_SCALE_FACTOR = 0.32sgf2anim.get_settings().LEFTWARD_ONE_CLIP_FACTOR = -0.05sgf2anim.get_settings().LINE_COLOR = (75, 107, 155)sgf2anim.get_settings().LINE_THICKNESS = 1.2sgf2anim.get_settings().MARKER_COLOR = (46, 84, 105)sgf_path = "false-eyes"sgf2anim.save_diagram(sgf_path, "false-eyes-output.gif")

Settings

sgf2anim contains_settings.py, which defines aSettings object whose member attributes determine how diagrams will be rendered.sgf2anim.get_settings() can be used to retrieve theSettings object and modify its properties before running rendering processes.

for the resolution of the output images:

  • MAX_WIDTH provides the maximum width of an output diagram image.
  • MAX_HEIGHT provides the maximum height of an output diagram image.
  • IMAGE_MARGIN provides the relative margin around the displayed stones.
  • MIN_CELL_SIZE provides the smallest size of a graphic that can be used.
  • MAX_CELL_SIZE provides the largest size of a graphic that can be used.

for the appearance of move numbers on stones:

  • SHOW_STONE_NUMBERS, if True, will display a move number/placement marker on the last placed stone.
  • MAINTAIN_STONE_NUMBERS, if True, will permanently keep the move number/placement marker on the last placed stone.
  • MAINTAIN_NUMBERS_AT_END, if True, will permanently keep the move number/placement marker on the final placed stone.
  • MARKER_INSTEAD_OF_NUMBERS, if True, will show a placement marker graphic on the stone instead of the move number.
  • LABEL_TEXT_SCALE is the scale of displayed label on an intersection.
  • NUMBER_TEXT_SCALE is the scale of displayed move number on a stone.
  • DIGIT_TEXT_SCALE_FACTOR is added to theNUMBER_TEXT_SCALE for every digit beyond the first digit.
  • LEFTWARD_ONE_CLIP_FACTOR is the percentage of the move number text image that will be clipped off the left side if the left-most digit is "1" and the move number is not a single digit. This is for accomodating different fonts.
  • CENTER_LABELS_VERTICALLY, if True, will vertically center letter labels on their intersections.
  • LETTERS_PADDING_BOTTOM_PERCENT is the percentage of the label text image's height that will be added to the bottom of the image for ideal alignment.
  • NUMBERS_PADDING_BOTTOM_PERCENT is the percentage of the move number text image's height that will be added to the bottom of the image for ideal alignment.

for the color and line styling:

  • STYLE_NAME is the name of the directory contained insgf2anim/_res whose graphics will be loaded.
  • LINE_COLOR is the RGB for the Go board's lines.
  • LINE_THICKNESS is the relative thickness of the Go board's lines.
  • MARKER_COLOR is the RGB for the annotation shapes.
  • LABEL_COLOR is the RGB for the letter label annotations displayed on intersections.
  • PLACEMENT_MARKER_COLOR is the RGB for the stone placement marker.
  • NUMBER_COLOR_FOR_BLACK is the RGB for the move number text appearing on a black stone.
  • NUMBER_COLOR_FOR_WHITE is the RGB for the move number text appearing on a white stone.
  • ANNOTATE_LINE_COLOR is the RGB used for annotative lines.
  • ANNOTATE_LINE_THICKNESS is the relative thickness of annotative lines.

for other rendering options:

  • DISPLAY_PADDING specifies how many empty intersections should surround the displayed stones.
  • FORCE_STONES_CENTER, if True, will change the stone graphic size on a case-by-case basis in order to make them perfectly centered with the Go board's lines.
  • RENDER_CAPTURES, if True, will clear captured stones from the diagram.

About

A diagram renderer written in Python that can turn an .sgf file for the game of Go/Baduk/Weiqi into a diagram image that's either static or animated.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp