#include "shapes.sl" // draw a chart with random data // freq, fuzz, barlike, density all from [0, 1]; // type: bar, line, dot // //questions:how to define sparseness and increasing property // #define HEIGHT1(col, density, barlike) (noise(sin(col*density*barlike+s*(1-barlike)), cos(col*density*barlike+t*(1-barlike)))-0.35) #define HEIGHT2(col, density, barlike) (noise(cos(col*density*barlike+t*(1-barlike)), sin(col*density*barlike+s*(1-barlike)))-0.35) surface chart(float freq = 30, fuzz = 0.01, barlike = 0.1, density = 1; string type = "bar") { color surface_color, layer_color=0, surface_opac, layer_opac; surface_color = 1.0; surface_opac = Oi; float width = 1.0/freq, radius = width/4.0, height; float i = 1; float col = whichtile(s, freq); float left = col/freq, bottom, nbottom; if (noise(i*100*left-274) < 0.5) height = HEIGHT1(col, density, barlike); else height = HEIGHT2(col, density, barlike); if (height>0) bottom = 0.65 - height; else bottom = 0.65; nbottom = 0.65-height; if (type == "line") { point start = point(left, nbottom, 0); if (noise(i*100*left-274) < 0.5) height = HEIGHT1(col+1, density, barlike); else height = HEIGHT2(col+1, density, barlike); float nbottom2 = 0.65-height; point end = point(left+width, nbottom2, 0); layer_opac = line(start, end, 0.01, fuzz, s, t); } else if (type == "dot") { if (noise(i*100*left-274) < 0.5) height = HEIGHT1(col+1, density, barlike); else height = HEIGHT2(col+1, density, barlike); float nbottom2 = 0.65-height; layer_opac = disk(radius, fuzz, s, t, point (left+width/2.0, (nbottom+nbottom2)/2.0, 0)); } else // default: bar chart layer_opac = rect(left, bottom, width, abs(height), fuzz, s, t); if (udn(height+195, 0, 1) <= density) surface_color = blend(surface_color, layer_color, layer_opac); Ci = surface_color; Oi = surface_opac; }