#!/usr/local/bin/cz --
use b

int r1=180

Main()
	paper()
#	space(640, 480)
#	space(320, 240)
	gprint_anchor(0, 0)

	cstr s = fortune()
	int fs = font_size_to_fit(s)

	col(black)
	move(0, 0)
	gsayf(s)
	gr_sync()

	with_pixel_type(shiny)

cstr fortune()
	cstr s = args ? join(' ', arg) : cmd("fortune -s -n 40")
	if !s || !*s
		s = "Hello World"
	return s

int font_size_to_fit(cstr s)
	font("helvetica-medium", 200)
	num tw = text_width(s)
	int fs = (int)(200*(w-r1*2)/tw * 0.95)
	font("helvetica-medium", fs)
	return fs

def shiny(pixel_type)
	new(v, vec, XPoint)
	pixel_type *px = (pixel_type *)pixel(vid, 1, 1)
	for(y, 1, h-1)
		for(x, 1, w-1)
			pixel_type o = *px
			if o == black &&
			  (px[-1] != black || px[1] != black || px[-w] != black || px[w] != black)
				XPoint *p = vec_push(v)
				p->x = x-w_2
				p->y = h_2-1-y
			++px
		px += 2
	clear()

	back(r, r1+1)
		font("helvetica-medium", fs)
		hsv((r*16) % 360, 1, r*1.0/r1)
		for_vec(i, v, XPoint)
			circle(i->x, i->y, r)
		Paint()

	font("helvetica-medium", fs)
	col(black)
	move(0, 0)
	gsayf(s)
	Paint()
