Created
March 23, 2025 02:45
-
-
Save CookieBox26/8a9d7bedbf265bd180d6f7b7a608ac79 to your computer and use it in GitHub Desktop.
中綴じ冊子のページ割り当てを表示する関数。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Author
CookieBox26
commented
Mar 23, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment