--Code to go with Open Jump
-- <start id="code_sql_art" /> --
SELECT art.n,  art.geom
FROM 
(SELECT n, ST_Translate( -- <co id="co_code_sql_art_1" /> --
  ST_Buffer(            -- <co id="co_code_sql_art_2a" /> --
		ST_MakeLine(pt) -- <co id="co_code_sql_art_3" /> --
		, mod(n,6) + 2, -- <co id="co_code_sql_art_2b" /> --
		'endcap=' || endcaps[mod(n,3) + 1] 
		|| 
		' join=' || joins[mod(n,array_upper(joins,1)) + 1]
		|| ' quad_segs=' || n) -- <co id="co_code_sql_art_2c" /> --
	, n*10,n*random()*pi() 
	) As geom
FROM 
(SELECT ceiling(random()*100)::integer As n, 
	ARRAY['square', 'round', 'flat'] As endcaps,
	ARRAY['round','mitre','bevel'] As joins,
       ST_Point(x*random(),y*random()) As pt
  FROM generate_series(1,200, 7) As x  -- <co id="co_code_sql_art_4" /> --
		CROSS JOIN generate_series(1,500,20) As y
) As foo
GROUP BY foo.n, foo.endcaps, foo.joins
HAVING count(foo.n) > 10) As art;
-- <end id="code_sql_art" /> --
-- #1 ST_Translate shift randomly up and down
-- #2 ST_Buffer the line
