forked from jtmarmon/ColorMime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorMime.sketchplugin
30 lines (23 loc) · 1.07 KB
/
ColorMime.sketchplugin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Draws a random colour palette retrieved from the Top 100 Palettes on Colourlovers
// Requries a base shape layer to be selected
#import 'alessndro_library.js'
if([selection count] != 0) {
// Use as first colour square
var base_colour_layer = selection[0]
var palatteURL = [doc askForUserInput:'Palatte URL:' initialValue:'Enter a ColourLovers Palatte URL']
var palatteURLParts = palatteURL.split('/');
var palatteID = palatteURLParts[4];
var response = alessndro.network.makeRequest("http://www.colourlovers.com/api/palette/" + palatteID + "?format=json", "GET")
response = JSON.parse(response);
var colors = [];
var palette = response[0]["colors"];
for(var i = 0; i < palette.length; i++) {
var colour = alessndro.colour.createColourFromHex(palette[i], 1.0);
colors.push(colour);
}
alessndro.colour.drawColourPalette(base_colour_layer, colors)
}
else {
var app = [NSApplication sharedApplication]
[app displayDialog:"You must first create a base shape layer. Each colour in the palette have the same dimensions as this base layer." withTitle:"Error"]
}