golnaz/golnaz.py
2020-09-29 08:51:34 +02:00

90 lines
1.9 KiB
Python
Executable file

#!/usr/bin/python
'''
ZetCode PyCairo tutorial
This code example draws a circle
using the PyCairo library.
Author: Jan Bodnar
Website: zetcode.com
Last edited: April 2016
'''
from gi.repository import Gtk
import cairo
import math
class Example(Gtk.Window):
def __init__(self):
super(Example, self).__init__()
self.init_ui()
def init_ui(self):
darea = Gtk.DrawingArea()
darea.connect("draw", self.on_draw)
self.add(darea)
self.set_title("Fill & stroke")
self.resize(3000, 2000)
self.set_position(Gtk.WindowPosition.CENTER)
self.connect("delete-event", Gtk.main_quit)
self.show_all()
def on_draw(self, wid, cr):
stroke_size = 8
line_factor = 1/8
iterations = 1000
w, h = self.get_size()
cr.set_line_width(stroke_size)
cr.set_source_rgb(1, 0, 0)
cr.translate(0, h/2)
cr.move_to(0,0)
cr.line_to(w,0)
cr.stroke()
cr.save()
#prima linea nera sotto
cr.translate(0, stroke_size/2)
stroke_size = 1
cr.set_line_width(1)
cr.set_source_rgb(0, 0, 0)
#qui il for delle linee sopra
drawLines(cr, w, h,1, iterations)
cr.restore()
stroke_size =8
#prima linea nera sotto
cr.translate(0, -stroke_size/2)
stroke_size = 1
cr.set_line_width(1)
cr.set_source_rgb(0, 0, 0)
drawLines(cr, w, h, -1, iterations)
def drawLines(cr,w, h, direction, iterations):
print(direction)
for l in range(0,iterations):
cr.translate(0, direction * 1.05**l)
cr.move_to(0,0)
cr.line_to(w,0)
cr.stroke()
def main():
app = Example()
Gtk.main()
if __name__ == "__main__":
main()