Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # -*- coding: utf-8 -*-
- import os
- def generate_circle_table(table, modulo, point=False):
- angle = 360 / modulo
- graphic.write('\\begin{tikzpicture}[rotate=90, scale=3, yscale=-1, line width=.01pt, draw=Black]\n')
- # Draw circle
- graphic.write('\\draw (0:0) circle (1);\n')
- # Draw the points
- if point is True:
- graphic.write(
- '''\\foreach \point in {{0, 1, ..., {modulo}}} {{\n
- \\fill (\point * {angle}:1) circle (.01);\n
- \\node [scale=.5] at (\point * {angle}:1.1) {{\point}};\n'''
- .format(
- modulo=modulo - 1,
- angle=angle
- )
- )
- graphic.write('}\n')
- # Draw the lines
- graphic.write('\draw')
- for point in range(modulo):
- graphic.write(' ({start_point}:1) -- ({end_point}:1)'.format(
- start_point=point * angle,
- end_point=((point * table) % modulo) * angle
- ))
- graphic.write(';\n')
- # Draw the legend
- graphic.write('\\node at (-1,0) [below] {{Table de ${table:.2f}$ modulo ${modulo:.0f}$}};\n'.format(
- table=table,
- modulo=modulo
- ).replace('.', '{,}'))
- graphic.write('\\end{tikzpicture}\n\n')
- if __name__ == '__main__':
- try:
- table = float(input("Table ? "))
- modulo = int(input("Modulo ? "))
- with open('graphic.tex', 'w') as graphic:
- graphic.write('\\documentclass[multi=tikzpicture]{standalone}\n\n')
- graphic.write('\\usepackage[usenames, dvipsnames]{xcolor}\n')
- graphic.write('\\usepackage{tikz}\n\n')
- graphic.write('\\begin{document}\n\n')
- # Beautiful values: (380.5, 855), (280.5, 855), (567.98, 6743), (1000, 9648)
- generate_circle_table(table, modulo)
- graphic.write('\\end{document}\n')
- except IOError:
- print("Impossible d'écrire le fichier.")
- exit(1)
- os.system('buf_size=50000000 pdflatex graphic.tex && rm *.log *.aux')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement