Exemple #1
0
def main():
	parser = lib.create_options()
	opts, args = parser.parse_args()

	w, h = 24 * 72, 36 * 72

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

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

	pctx = pangocairo.CairoContext(context)
	pctx.set_antialias(cairo.ANTIALIAS_SUBPIXEL)

	layout = pctx.create_layout()
	layout.set_font_description(
		create_font_desc())
	layout.set_text('12')
	context.set_source_rgb(*color_of(0x0099ff))
	pctx.update_layout(layout)
	pctx.show_layout(layout)

	ink_rect, log_rect = layout.get_pixel_extents()
	context.rectangle(*ink_rect)
	context.set_source_rgba(*color_of(0x333333, a=0.5))
	context.stroke()

	context.rectangle(*log_rect)
	context.set_source_rgba(*color_of(0x333333, a=0.5))
	context.stroke()

	lib.commit(surface, os.path.basename(__file__) + '.png')
Exemple #2
0
def main():
	parser = lib.create_options()
	parser.add_option('--size', default=20, dest='size', type='int',
		help='')
	opts, args = parser.parse_args()

	w, h = 24 * 72, 36 * 72


	pad = Padding(w/16.0, w/16.0, w/16.0, w/16.0)

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

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

	context.rectangle(0, 0, w, h)
	context.set_source_rgb(*color_of(0xffffff))
	context.fill()

	nx = int(math.ceil(vw / float(opts.size)))
	ny = int(math.ceil(vh / float(opts.size)))

	mask = HeartMask(nx, ny)

	for j in range(ny):
		for i in range(nx):
			r, g, b = rgb_of(mask.pixel_at(i, j))
			if luminance(r, g, b) < 0.5:
				draw_doodle_dah(context,
					pad.l + i*opts.size + opts.size/2.0,
					pad.t + j*opts.size + opts.size/2.0,
					i / 8.0,
					j / 8.0,
					opts.size*0.3)
			else:
				draw_empty_spot(context,
						pad.l + i*opts.size + opts.size/2.0,
						pad.t + j*opts.size + opts.size/2.0,
						i / 8.0,
						j / 8.0,
						opts.size*0.3)

			context.set_source_rgb(*color_of(0x333333))
			context.arc(
				pad.l + i*opts.size + opts.size/2.0,
				pad.t + j*opts.size + opts.size/2.0,
				opts.size * 0.1,
				0,
				2*math.pi)
			context.fill()


	lib.commit(surface, os.path.basename(__file__) + '.png')
Exemple #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('--nx', default=100, dest='nx', type='int', help='')
	opts, args = parser.parse_args()

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

	w, h = 16 * 72, 10 * 72

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

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

	pad = w/16.0
	pa = Pt(pad, pad + (h - 2*pad) * random.random())
	pb = Pt(w - pad, pad + (h - 2*pad) * random.random())

	dx = pb.x - pa.x
	dy = pb.y - pa.y
	n = math.sqrt(dx*dx + dy*dy)
	m = dy / dx

	context.move_to(pa.x, pa.y)
	context.line_to(pb.x, pb.y)
	context.set_source_rgb(*color_of(0xaa, 0xaa, 0xaa))
	context.stroke()

	di = dx / opts.nx
	context.set_line_width(1.0)
	context.set_source_rgb(*color_of(0xee, 0xee, 0xee))
	for i in range(opts.nx + 1):
		context.move_to(pa.x + di*i, pad)
		context.line_to(pa.x + di*i, h - 2*pad)
		context.stroke()

	dj = 0.0
	r = 5

	pts = []
	for i in range(opts.nx + 1):
		x = di*i
		pts.append(Pt(pa.x + x, x*m + pa.y + r*noise.pnoise1(x/10.0, 1)))
		#pts.append(Pt(pa.x + x, x*m + pa.y + dj))
		#dj = max(min(dj + random.random()*r - r/2.0, r), -r)

	context.move_to(pts[0].x, pts[0].y)
	for i in range(1, len(pts)):
		# context.line_to(pts[i].x, pts[i].y)
		a = pts[i - 1]
		b = pts[i]
		context.curve_to(
			a.x + di/2.0, a.y,
			b.x - di/2.0, b.y,
			b.x, b.y)
	context.set_source_rgb(*color_of(0xff, 0x00, 0xff))
	context.stroke()


	lib.commit(surface, os.path.basename(__file__) + '.png')
Exemple #4
0
def main():
	parser = lib.create_options()
	parser.add_option('--size', default=10, dest='size', type='int',
		help='')
	opts, args = parser.parse_args()

	w, h = 24 * 72, 36 * 72

	pad = Padding(w/16.0, w/16.0, w/16.0, w/16.0)

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

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

	context.rectangle(0, 0, w, h)
	context.set_source_rgb(*color_of(0xffffff))
	context.fill()

	nx = int(math.ceil(vw / float(opts.size)))
	ny = int(math.ceil(vh / float(opts.size)))

	heart_mask = Mask(nx, ny, draw_heart)
	text_mask = Mask(nx, ny, draw_text)

	for j in range(ny):
		for i in range(nx):
			a = text_mask.pixel_at(i, j)
			if a > 128:
				# context.set_source_rgb(*color_of(0xb3351a))
				# context.set_source_rgb(*color_of(0xef826b))
				context.set_source_rgb(*color_of(0x999999))
				context.arc(
					pad.l + i*opts.size + opts.size/2.0,
					pad.t + j*opts.size + opts.size/2.0,
					opts.size * 0.15,
					0,
					2*math.pi)
				context.fill()
				continue

			a = heart_mask.pixel_at(i, j)
			if a > 128:
				context.set_source_rgb(*color_of(0xef4723))
				context.arc(
					pad.l + i*opts.size + opts.size/2.0,
					pad.t + j*opts.size + opts.size/2.0,
					opts.size * 0.2,
					0,
					2*math.pi)
				context.fill()
				continue

			context.set_source_rgb(*color_of(0x999999))
			context.arc(
				pad.l + i*opts.size + opts.size/2.0,
				pad.t + j*opts.size + opts.size/2.0,
				opts.size * 0.1,
				0,
				2*math.pi)
			context.fill()

	if opts.debug:
		draw_debug_lines(context, pad, vw, vh, 12)

	lib.commit(surface, os.path.basename(__file__) + '.png')
Exemple #5
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('--nx', default=10, dest='nx', help='')
	opts, args = parser.parse_args()

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

	w, h = 24 * 72, 36 * 72

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

	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

	nx = opts.nx

	dx = vw / float(nx)
	dy = dx / math.sin(math.pi / 3)
	ny = int(math.ceil(vh / dx))

	context.rectangle(0, 0, w, h)
	context.set_source_rgb(*color_of(0x33, 0x33, 0x33))
	context.fill()

	context.rectangle(pad.l, pad.t, w - pad.l - pad.r, h - pad.t - pad.b)
	context.set_source_rgb(*color_of(0xff, 0xff, 0xff))
	context.fill()

	context.rectangle(pad.l, pad.t, w - pad.l - pad.r, h - pad.t - pad.b)
	context.clip()


	idx = {}
	for i in range(0, nx):
		for j in range(0, ny):
			idx[(i, j)] = True

	colors = junk_colors(4, 0.1, 0.8, 0.5)[:10]


	a = float(nx * ny)

	while len(idx)/a > 0.15:
		x = random.randint(-2, nx + 2)
		y = random.randint(-2, ny + 2)
		r = random.randint(2, 3)
		for i in range(x, x + r):
			for j in range(y, y + r):
				if idx.has_key((i, j)):
					del idx[(i, j)]
		hexagon(context, pad.l + x * dx + dx/2.0, pad.t + y*dy + dy/2.0, r*dy - dy/2.0)
		context.set_source_rgba(*random.choice(colors))
		context.fill()

		hexagon(context, pad.l + x * dx + dx/2.0, pad.t + y*dy + dy/2.0, r*dy - dy/2.0)
		context.set_source_rgba(*color_of(0x00, 0x00, 0x00, 0.3))
		context.stroke()

	context.set_line_width(1.0)
	for x in range(1, nx):
		context.move_to(pad.l + x*dx, pad.t)
		context.line_to(pad.l + x*dx, h - pad.b)
		context.set_source_rgba(*color_of(0x99, 0x99, 0x99, 0.2))
		context.stroke()

	for y in range(1, ny):
		context.move_to(pad.l, pad.t + y*dy)
		context.line_to(w - pad.r, pad.t + y*dy)
		context.set_source_rgba(*color_of(0x99, 0x99, 0x99, 0.2))
		context.stroke()

	for i, color in enumerate(colors):
		print '%s %s %0.2f' % (color[:3], color_of(*color[:3]), luminance(*color[:3]))

		context.rectangle(pad.l + 10 + i * 20, pad.t + 20, 20, 20)
		context.set_source_rgb(*color[:3])
		context.fill()

		context.rectangle(pad.l + 10 + i * 20, pad.t + 20, 20, 20)
		context.set_source_rgb(*color_of(0x33, 0x33, 0x33))
		context.stroke()

	lib.commit(surface, os.path.basename(__file__) + '.png')
Exemple #6
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')