Beispiel #1
0
	def __init__(self, w, h):
		surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
		context = cairo.Context(surface)

		context.rectangle(0, 0, w, h)
		context.set_source_rgb(1, 1, 1)
		context.fill()

		context.translate(w/2.0, h/2.0)
		context.set_source_rgb(0, 0, 0)
		lib.parse_svg_path(HEART).scale(w/24.0, w/24.0).draw(context)
		context.fill()

		self.surface = surface
Beispiel #2
0
def draw_heart(context, w, h):
	context.translate(w/2.0, h/2.0)
	context.set_source_rgb(0, 0, 0)
	lib.parse_svg_path(HEART).scale(w/24.0, w/24.0).draw(context)
	context.fill()
Beispiel #3
0
def main():
	parser = optparse.OptionParser()
	parser.add_option('--seed', default=create_seed(), dest='seed', help='')
	parser.add_option('--fmt', default='pdf', dest='fmt', help='')
	parser.add_option('--ny', default=250, dest='ny', type='int', help='')
	parser.add_option('--debug', default=False, action='store_true', help='')
	opts, args = parser.parse_args()

	print('seed = %s' % opts.seed)
	random.seed(opts.seed)

	debug_color = color_of(0x00, 0x99, 0xff)

	w, h = 24 * 72, 36 * 72

	pad = Pad(h/32, h/32, h/32, h/32)

	surface = lib.create_surface(opts.fmt, os.path.basename(__file__), w, h)
	context = cairo.Context(surface)

	vw, vh = w - pad.l - pad.r, h - pad.t - pad.b

	context.rectangle(0, 0, w, h)
	context.set_source_rgb(1.0, 1.0, 1.0)
	context.fill()

	bg_sketcher = Sketcher(5.0, 1.0, 300)
	context.save()
	context.rectangle(pad.l, pad.t, vw, vh)
	context.clip()
	draw_hatches(context,
		pad.l,
		pad.t,
		vw,
		vh,
		opts.ny,
		color_of(0x44, 0x44, 0x44, 1.0),
		bg_sketcher.draw)
	context.restore()

	scale = vw/24.0
	path = lib.parse_svg_path(HEART).scale(scale, scale)

	context.save()
	context.translate(w/2.0, h/2.0)
	path.draw(context)
	context.set_source_rgba(*color_of(0xff, 0xff, 0xff, 1.0))
	context.fill()

	context.set_line_width(10.0)
	path.draw(context)
	context.set_source_rgba(*color_of(0xff, 0xff, 0xff, 1.0))
	context.stroke()
	context.restore()

	context.save()
	context.translate(w/2.0, h/2.0)
	path.draw(context)
	context.clip()

	ht_sketcher = Sketcher(10.0, 1.0, 250)
	draw_hatches(context,
		-scale*10,
		-scale*10,
		scale*20,
		scale*20,
		int(opts.ny * 0.6),
		color_of(0xff, 0x00, 0x00, 1.0),
		ht_sketcher.draw)
	context.restore()

	# context.save()
	# context.set_line_width(8.0)
	# context.rectangle(pad.l, pad.t, vw, vh)
	# context.set_source_rgb(*color_of(0x33, 0x33, 0x33))
	# context.stroke()
	# context.restore()

	if opts.debug:
		context.move_to(w / 2.0, 0)
		context.line_to(w / 2.0, h)
		context.set_source_rgb(*debug_color)
		context.stroke()

		context.move_to(0, h / 2.0)
		context.line_to(w, h / 2.0)
		context.set_source_rgb(*debug_color)
		context.stroke()

	lib.commit(surface, os.path.basename(__file__) + '.png')