/**
A processing sketch to visualize calendar events as flowers.
Every event in your ical file is a flower, the size depends
on the duration of the event.
by Guru
*/
import guru.ical4p.*;
long xmin = Long.MAX_VALUE, xmax = 0;
long hmin = Long.MAX_VALUE, hmax = 0;
color[] colors = new color[] {
color( 255,0,0 ),
color( 255, 100, 0 ),
color( 128, 0, 255 )
};
Set events;
void setup() {
size(600,300);
smooth();
noLoop();
ICal cal = new ICal();
cal.parse( createInput("test.ics"));
events = cal.getEvents();
for (Iterator i = events.iterator(); i.hasNext(); ) {
ICalEvent e = (ICalEvent)i.next();
if (e.getStart().getTime() < xmin) { xmin = e.getStart().getTime(); }
if (e.getStart().getTime() > xmax) { xmax = e.getStart().getTime(); }
if (e.getDurInMin() < hmin) { hmin = e.getDurInMin(); }
if (e.getDurInMin() > hmax) { hmax = e.getDurInMin(); }
}
}
void draw() {
background( color( 100, 180, 255 ));
fill( color( 128, 255, 128 ));
noStroke();
rect(0, 200, width, 100);
for( Iterator i = events.iterator(); i.hasNext(); ) {
ICalEvent e = (ICalEvent)i.next();
flower( map( e.getStart().getTime(), xmin, xmax, 50, 550),
map(e.getDurInMin(), hmin, hmax, 20, 70),
random(5,8),
colors[ (int)random(3)]);
}
/*
flower( 100,
100,
random(5,8),
colors[ (int)random(3)]);
*/
}
void flower( float x, float s, float pedals, color c) {
stroke( 0,255,0);
strokeWeight(3);
line( x, 200, x, 200 - s );
fill( 0, 245, 0);
float peds = 20 * s / 100;
bezier( x, 200, x, 200 - s/3, x , 200 - s/3, x + peds, 200 - s/2 );
bezier( x, 200, x+peds, 200 - s/4, x + peds, 200 - s/4, x + peds, 200 - s/2 );
line( x, 200, x + peds, 200 - s/2);
float ps = 80 * s / 100;
fill( c );
noStroke();
for( int i = 0; i < pedals; i++) {
pushMatrix();
translate( x-1, 200 - s );
rotate( radians( i * 360 / pedals ));
ellipse( ps / 4, 0, ps / 2 , ps / pedals );
popMatrix();
}
fill(255,255,0);
ellipse( x, 200-s, ps/pedals,ps/pedals);
}