golnaz.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/python
  2. '''
  3. ZetCode PyCairo tutorial
  4. This code example draws a circle
  5. using the PyCairo library.
  6. Author: Jan Bodnar
  7. Website: zetcode.com
  8. Last edited: April 2016
  9. '''
  10. from gi.repository import Gtk
  11. import cairo
  12. import math
  13. class Example(Gtk.Window):
  14. def __init__(self):
  15. super(Example, self).__init__()
  16. self.init_ui()
  17. def init_ui(self):
  18. darea = Gtk.DrawingArea()
  19. darea.connect("draw", self.on_draw)
  20. self.add(darea)
  21. self.set_title("Fill & stroke")
  22. self.resize(3000, 2000)
  23. self.set_position(Gtk.WindowPosition.CENTER)
  24. self.connect("delete-event", Gtk.main_quit)
  25. self.show_all()
  26. def on_draw(self, wid, cr):
  27. stroke_size = 8
  28. line_factor = 1/8
  29. iterations = 1000
  30. w, h = self.get_size()
  31. cr.set_line_width(stroke_size)
  32. cr.set_source_rgb(1, 0, 0)
  33. cr.translate(0, h/2)
  34. cr.move_to(0,0)
  35. cr.line_to(w,0)
  36. cr.stroke()
  37. cr.save()
  38. #prima linea nera sotto
  39. cr.translate(0, stroke_size/2)
  40. stroke_size = 1
  41. cr.set_line_width(1)
  42. cr.set_source_rgb(0, 0, 0)
  43. #qui il for delle linee sopra
  44. drawLines(cr, w, h,1, iterations)
  45. cr.restore()
  46. stroke_size =8
  47. #prima linea nera sotto
  48. cr.translate(0, -stroke_size/2)
  49. stroke_size = 1
  50. cr.set_line_width(1)
  51. cr.set_source_rgb(0, 0, 0)
  52. drawLines(cr, w, h, -1, iterations)
  53. def drawLines(cr,w, h, direction, iterations):
  54. print(direction)
  55. for l in range(0,iterations):
  56. cr.translate(0, direction * 1.05**l)
  57. cr.move_to(0,0)
  58. cr.line_to(w,0)
  59. cr.stroke()
  60. def main():
  61. app = Example()
  62. Gtk.main()
  63. if __name__ == "__main__":
  64. main()