-
Notifications
You must be signed in to change notification settings - Fork 2
/
of.color.pd
48 lines (48 loc) · 2.04 KB
/
of.color.pd
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#N canvas 395 79 715 640 12;
#X obj 31 14 inlet;
#X obj 90 12 inlet;
#X obj 160 12 inlet;
#X obj 230 12 inlet;
#X obj 300 12 inlet;
#X text 566 582 RI;
#X text 81 583 Todo: add HSB with arguments;
#X obj 31 586 outlet;
#X obj 623 571 outlet;
#X msg 90 38 red \$1;
#X msg 160 38 green \$1;
#X msg 230 38 blue \$1;
#X msg 300 38 alpha \$1;
#X obj 31 65 ofelia d -c12 color-\$0 \; local log = ofLog("of.color")
\; local c = ofCanvas(this) \; local args = c:getArgs() \; local color
= ofColor() \; local outlet = ofOutlet(this) \; \; function M.new()
\; if args[1] == nil then color.r = 255 else color.r = args[1] end
\; if args[2] == nil then color.g = 255 else color.g = args[2] end
\; if args[3] == nil then color.b = 255 else color.b = args[3] end
\; if args[4] == nil then color.a = 255 else color.a = args[4] end
\; if #args == 1 then \; log:error("requires 3 (rgb) or 4 (rgba) creation
argument") \; end \; end \; \; function M.red(f) color.r = ofClamp(f
\, 0 \, 255) end \; function M.green(f) color.g = ofClamp(f \, 0 \,
255) end \; function M.blue(f) color.b = ofClamp(f \, 0 \, 255) end
\; function M.alpha(f) color.a = ofClamp(f \, 0 \, 255) end \; function
M.brightness(f) color:setBrightness(f) end \; function M.saturation(f)
color:setSaturation(f) end \; function M.hue(f) color:setHue(f) end
\; function M.hex(s) color:setHex(tonumber(s:gsub("#" \, "") \, 16))
end \; function M.hsb(l) color:setHsb(table.unpack(l)) end \; function
M.list(l) color:set(table.unpack(l))end \; function M.rgb(l) color:set(table.unpack(l))end
\; function M.invert() color:invert() end \; function M.get() outlet:outletList(1
\, ofTable (color.r \, color.g \, color.b \, color.a \, color:getHue()
\, color:getSaturation() \, color:getBrightness() \, color:getHex()))end
\; \; function M.bang() \; ofSetColor(color) \; outlet:outletBang(0)
\; end \;;
#X f 85;
#X connect 0 0 13 0;
#X connect 1 0 9 0;
#X connect 2 0 10 0;
#X connect 3 0 11 0;
#X connect 4 0 12 0;
#X connect 9 0 13 0;
#X connect 10 0 13 0;
#X connect 11 0 13 0;
#X connect 12 0 13 0;
#X connect 13 0 7 0;
#X connect 13 1 8 0;