This patch extracts color values from the kuler api via a themeID and converts them to Color objects.
It requires
- the XML quark by Jens Gulden (wow! thanx) for parsing the xml stuff and
- the wslib quark by wouter snoei (wow, too!) for Meta_Color:newHex
- a valid kuler dev-key (see http://kuler.adobe.com/api/ for details)
// Process Kuler rss feed for Color extraction
(
~getFeed = {
arg
fileName,
kulerKey, // insert your kuler key
themeID(347630); // ID of a kuler theme
"curl \"http://kuler-api.adobe.com/rss/search.cfm?itemsPerPage=20&startIndex=0&searchQuery=themeID:%&key=%\" > /tmp/%"
.format(themeID, kulerKey, fileName).unixCmd;
};
~xml2color = {|fileName|
DOMDocument("/tmp/%".format(fileName))
.getElementsByTagName("kuler:swatch")
.collect{|swatch|
swatch.getElementsByTagName("kuler:swatchHexColor")
.collect(_.getText)
}.flatten.collect{|str|
Color.newHex(str)
}
};
~tidy = {|fileName|
"rm /tmp/%".format(fileName).unixCmd;
};
~show = {|color, bounds(Rect(30,300, 100, 30))|
var window;
var extent = bounds.extent.asArray;
window = Window.new("ColorTest", bounds, false);
window.drawHook = {
3.do{|i|
Pen.color = Color.gray(i * 0.5);
Pen.fillRect(
Rect.fromArray([i*(extent.first/3),0] ++
(extent * [1/3, 1]))
);
};
Pen.color = color;
Pen.fillRect(Rect.fromArray(extent*0.1 ++ extent * 0.8));
};
window.front;
}
)
(
{
~fileName = "%.xml".format(Date.getDate.stamp);
~getFeed.value(~fileName, "your Kuler key here");
2.wait;
"less /tmp/%".format(~fileName).unixCmd;
a = ~xml2color.value(~fileName);
1.wait;
~tidy.value(~fileName)
}.fork;
)
a.do{|c| ~show.(c)}