Skip to content

Instantly share code, notes, and snippets.

@CookieBox26
Created March 23, 2025 02:45
Show Gist options
  • Select an option

  • Save CookieBox26/8a9d7bedbf265bd180d6f7b7a608ac79 to your computer and use it in GitHub Desktop.

Select an option

Save CookieBox26/8a9d7bedbf265bd180d6f7b7a608ac79 to your computer and use it in GitHub Desktop.
中綴じ冊子のページ割り当てを表示する関数。
def nakatoji(
n_papers=3,
right_binding=True,
include_hyoshi=False,
include_urabyoshi=False,
include_hyoshiura=False,
include_urabyoshiura=False,
):
"""
中綴じ冊子のページ割り当てを表示する関数。
Parameters:
n_papers (int): 用紙(1枚で4ページ分)の数。
right_binding (bool): 右綴じ(True)か左綴じ(False)か。
include_hyoshi (bool): 表紙を含めるか。
include_urabyoshi (bool): 裏表紙を含めるか。
include_hyoshiura (bool): 表紙裏を含めるか。
include_urabyoshiura (bool): 裏表紙裏を含めるか。
"""
n_pages = n_papers * 4
offset = sum([include_hyoshi, include_hyoshiura])
pages = [i_page + 1 - offset for i_page in range(n_pages)]
pages[0] = 'HY_' if include_hyoshi else pages[0]
pages[1] = 'HYU' if include_hyoshiura else pages[1]
pages[-2] = 'UBU' if include_urabyoshiura else pages[-2]
pages[-1] = 'UB_' if include_urabyoshi else pages[-1]
cursor_0 = 0
cursor_1 = n_papers * 4 - 1
i_first = 0 if right_binding else 1
for i_paper in range(n_papers):
print(f'--- paper {(i_paper + 1):03} ---')
for _ in range(2): # omote, ura
i_pages_here = [0, 0]
i_pages_here[i_first] = cursor_0
i_pages_here[1 - i_first] = cursor_1
print(f' [ {pages[i_pages_here[0]]:03} | {pages[i_pages_here[1]]:03} ]')
cursor_0 += 1
cursor_1 -= 1
i_first = 1 - i_first
print('===== 3ページ 右綴じ =====')
nakatoji(n_papers=3, right_binding=True)
print('\n===== 3ページ 左綴じ =====')
nakatoji(n_papers=3, right_binding=False)
print('\n===== 3ページ 右綴じ =====')
nakatoji(n_papers=3, right_binding=True, include_hyoshi=True, include_urabyoshi=True)
print('\n===== 3ページ 右綴じ =====')
nakatoji(
n_papers=3, right_binding=True,
include_hyoshi=True, include_urabyoshi=True,
include_hyoshiura=True, include_urabyoshiura=True)
@CookieBox26
Copy link
Author

===== 3ページ 右綴じ =====
--- paper 001 ---
 [ 001 | 012 ]
 [ 011 | 002 ]
--- paper 002 ---
 [ 003 | 010 ]
 [ 009 | 004 ]
--- paper 003 ---
 [ 005 | 008 ]
 [ 007 | 006 ]

===== 3ページ 左綴じ =====
--- paper 001 ---
 [ 012 | 001 ]
 [ 002 | 011 ]
--- paper 002 ---
 [ 010 | 003 ]
 [ 004 | 009 ]
--- paper 003 ---
 [ 008 | 005 ]
 [ 006 | 007 ]

===== 3ページ 右綴じ =====
--- paper 001 ---
 [ HY_ | UB_ ]
 [ 010 | 001 ]
--- paper 002 ---
 [ 002 | 009 ]
 [ 008 | 003 ]
--- paper 003 ---
 [ 004 | 007 ]
 [ 006 | 005 ]

===== 3ページ 右綴じ =====
--- paper 001 ---
 [ HY_ | UB_ ]
 [ UBU | HYU ]
--- paper 002 ---
 [ 001 | 008 ]
 [ 007 | 002 ]
--- paper 003 ---
 [ 003 | 006 ]
 [ 005 | 004 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment