initial draft
This commit is contained in:
parent
e0067b8b85
commit
f3d014419f
2 changed files with 137 additions and 0 deletions
62
OnScreen.py
Executable file
62
OnScreen.py
Executable file
|
@ -0,0 +1,62 @@
|
|||
#!/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(230, 150)
|
||||
self.set_position(Gtk.WindowPosition.CENTER)
|
||||
self.connect("delete-event", Gtk.main_quit)
|
||||
self.show_all()
|
||||
|
||||
|
||||
def on_draw(self, wid, cr):
|
||||
|
||||
cr.set_line_width(9)
|
||||
cr.set_source_rgb(0.7, 0.2, 0.0)
|
||||
|
||||
w, h = self.get_size()
|
||||
|
||||
cr.translate(w/2, h/2)
|
||||
cr.arc(0, 0, 50, 0, 2*math.pi)
|
||||
cr.stroke_preserve()
|
||||
|
||||
cr.set_source_rgb(0.3, 0.4, 0.6)
|
||||
cr.fill()
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
app = Example()
|
||||
Gtk.main()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
75
divergenza.py
Executable file
75
divergenza.py
Executable file
|
@ -0,0 +1,75 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
'''
|
||||
Schotter pdf reproduction
|
||||
|
||||
It design SchotterR
|
||||
Author: Jan Bodnar
|
||||
Website: zetcode.com
|
||||
Last edited: April 2016
|
||||
'''
|
||||
|
||||
import math,cairo,random
|
||||
|
||||
def plotSquares(ctx):
|
||||
global rsum
|
||||
for i in xrange(1,w):
|
||||
|
||||
rsum += i*rs # add to the random value
|
||||
|
||||
ctx.translate(s*i, 0)
|
||||
for j in xrange(1,h):
|
||||
|
||||
rv = random.uniform(-rsum, rsum)
|
||||
# here comes the box :-)
|
||||
#box = shapes.square(s)
|
||||
|
||||
# box position
|
||||
#curr_cx = - w*s/2 + i*s + rv*dp ; curr_cy = - h*s/2 + j*s + rv*dp
|
||||
# transforms.center_at(box, [curr_cx, curr_cy])
|
||||
#
|
||||
# # rotate the box of rv degrees around its center
|
||||
# transforms.rotate(box, rv, pivot=(curr_cx, curr_cy))
|
||||
#
|
||||
# draw the damn box
|
||||
# plotter.write(box)
|
||||
#
|
||||
ctx.translate(0, s*j)
|
||||
#ctx.rotate(math.pi * 1 / 4)
|
||||
ctx.rotate(rv)
|
||||
ctx.rectangle(0,0, s, s)
|
||||
ctx.stroke()
|
||||
|
||||
|
||||
|
||||
#float RGB touple
|
||||
FG_RGB_COLOR=(0,0,0)
|
||||
#A4 in 300 DPI
|
||||
width, height = 3508,2480
|
||||
w = 1 # width (how many squares - es. 22)
|
||||
h = 12 # height (how many squares - es. 12)
|
||||
s = 100 # square size (es. 15)
|
||||
|
||||
rs = 0.015 # random step (rotation increment in degrees)
|
||||
dp = 2.25 # dampen (soften random effect for position)
|
||||
rsum = 0 # dummy initial value for rsum
|
||||
|
||||
|
||||
|
||||
|
||||
surface = cairo.PDFSurface ("/tmp/circle.pdf",width,height)
|
||||
ctx = cairo.Context (surface)
|
||||
|
||||
ctx.set_source_rgb(FG_RGB_COLOR[0],FG_RGB_COLOR[1],FG_RGB_COLOR[2])
|
||||
ctx.set_line_width(1)
|
||||
ctx.translate(100, 500)
|
||||
plotSquares(ctx)
|
||||
|
||||
|
||||
|
||||
|
||||
ctx.show_page()
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue