Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. import os
  5.  
  6.  
  7. def generate_circle_table(table, modulo, point=False):
  8. angle = 360 / modulo
  9.  
  10. graphic.write('\\begin{tikzpicture}[rotate=90, scale=3, yscale=-1, line width=.01pt, draw=Black]\n')
  11.  
  12. # Draw circle
  13. graphic.write('\\draw (0:0) circle (1);\n')
  14.  
  15. # Draw the points
  16. if point is True:
  17. graphic.write(
  18. '''\\foreach \point in {{0, 1, ..., {modulo}}} {{\n
  19. \\fill (\point * {angle}:1) circle (.01);\n
  20. \\node [scale=.5] at (\point * {angle}:1.1) {{\point}};\n'''
  21. .format(
  22. modulo=modulo - 1,
  23. angle=angle
  24. )
  25. )
  26. graphic.write('}\n')
  27.  
  28. # Draw the lines
  29. graphic.write('\draw')
  30. for point in range(modulo):
  31. graphic.write(' ({start_point}:1) -- ({end_point}:1)'.format(
  32. start_point=point * angle,
  33. end_point=((point * table) % modulo) * angle
  34. ))
  35. graphic.write(';\n')
  36.  
  37. # Draw the legend
  38. graphic.write('\\node at (-1,0) [below] {{Table de ${table:.2f}$ modulo ${modulo:.0f}$}};\n'.format(
  39. table=table,
  40. modulo=modulo
  41. ).replace('.', '{,}'))
  42.  
  43. graphic.write('\\end{tikzpicture}\n\n')
  44.  
  45.  
  46. if __name__ == '__main__':
  47. try:
  48. table = float(input("Table ? "))
  49. modulo = int(input("Modulo ? "))
  50.  
  51. with open('graphic.tex', 'w') as graphic:
  52. graphic.write('\\documentclass[multi=tikzpicture]{standalone}\n\n')
  53. graphic.write('\\usepackage[usenames, dvipsnames]{xcolor}\n')
  54. graphic.write('\\usepackage{tikz}\n\n')
  55. graphic.write('\\begin{document}\n\n')
  56.  
  57. # Beautiful values: (380.5, 855), (280.5, 855), (567.98, 6743), (1000, 9648)
  58. generate_circle_table(table, modulo)
  59.  
  60. graphic.write('\\end{document}\n')
  61. except IOError:
  62. print("Impossible d'écrire le fichier.")
  63. exit(1)
  64.  
  65. os.system('buf_size=50000000 pdflatex graphic.tex && rm *.log *.aux')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement