Browse Source

disconnected segments

incandenza 3 years ago
parent
commit
47ea376ac3
1 changed files with 38 additions and 6 deletions
  1. 38 6
      golnaz.py

+ 38 - 6
golnaz.py

@@ -14,6 +14,7 @@ Last edited: April 2016
 from gi.repository import Gtk
 import cairo
 import math
+import random
 
 
 class Example(Gtk.Window):
@@ -52,33 +53,64 @@ class Example(Gtk.Window):
         cr.line_to(w,0)
         cr.stroke() 
         cr.save()
-        
+       
+
+        cr.set_source_rgb(0, 0, 0)
 
         #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
+        #qui il for delle linee sopr
+        drawBlackArea(cr,w,1,10)
         drawLines(cr, w, h,1, iterations)
         cr.restore()
+
+        cr.set_source_rgb(0, 0, 0)
         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)
+        drawBlackArea(cr,w,-1,10)
         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)
+        drawSegmentedLine(cr,w,l)
+        cr.stroke() 
+
+def drawBlackArea(cr,w, direction, iterations):
+     for l in range(0,iterations):
+        cr.translate(0, direction * 1)   
+        cr.move_to(0,0)
         cr.line_to(w,0)
         cr.stroke() 
- 
 
+def drawSegmentedLine(cr,w,currIt):
+    print("segmented line")
+    cr.save()
+    rv = int(random.uniform(10,30))
+    wresiduo=w
+    for l in range(rv,0, -1):
+        lw = wresiduo/l
+        lw = lw + random.uniform(-5,5)
+        print(str(lw))
+        deltaY = random.uniform(-currIt,currIt)
+        cr.move_to(0,0)
+        cr.line_to(lw,deltaY)
+        cr.stroke()
+        cr.translate(lw,0)
+        #cr.arc(0, 0, 5, 0, 2*math.pi)
+        #cr.fill()
+        wresiduo=wresiduo-lw
+
+    cr.line_to(wresiduo,0)
+    cr.stroke()
+    cr.restore()
          
 def main():