Here’s what I came up with:
import bpy
from bpy.types import PropertyGroup, Operator
from bpy.props import FloatProperty, FloatVectorProperty, PointerProperty
default_colors = (
(1.0, 0.0, 0.01),
(1.0, 0.26, 0.0),
(0.9, 1.0, 0.0),
(0.0, 1.0, 0.03),
(0.0, 0.54, 1.0),
)
def color1_cb(self, context):
update_color(self.color1, 1)
def color2_cb(self, context):
update_color(self.color2, 2)
def color3_cb(self, context):
update_color(self.color3, 3)
def color4_cb(self, context):
update_color(self.color4, 4)
def color5_cb(self, context):
update_color(self.color5, 5)
def update_color(color, index):
wm = bpy.context.window_manager
if Kuler.update:
Kuler.update = False
for i in range(1, 6):
if i != index:
colprop = "color%i" % i
col = getattr(wm.kuler, colprop)
new_col = col.copy()
new_col.v = color.v
setattr(wm.kuler, "color%i" % i, new_col)
Kuler.update = True
def shift_cb(self, context):
wm = context.window_manager
Kuler.update = False
for i in range(1, 6):
colprop = "color%i" % i
col = getattr(wm.kuler, colprop)
new_col = col.copy()
new_col.h = new_col.h + 0.01 % 1.0
setattr(wm.kuler, "color%i" % i, new_col)
Kuler.update = True
class Kuler(PropertyGroup):
color1 = FloatVectorProperty(subtype='COLOR', min=0, max=1, update=color1_cb)
color2 = FloatVectorProperty(subtype='COLOR', min=0, max=1, update=color2_cb)
color3 = FloatVectorProperty(subtype='COLOR', min=0, max=1, update=color3_cb)
color4 = FloatVectorProperty(subtype='COLOR', min=0, max=1, update=color4_cb)
color5 = FloatVectorProperty(subtype='COLOR', min=0, max=1, update=color5_cb)
shift = FloatProperty(min=0, max=1000, update=shift_cb)
Kuler.update = True
class WM_OT_kuler_default_colors(Operator):
bl_idname = "wm.kuler_default_colors"
bl_label = "Default Colors"
def execute(self, context):
wm = context.window_manager
Kuler.update = False
for i, col in zip(range(1,6), default_colors):
setattr(wm.kuler, "color%i" % i, col)
Kuler.update = True
return {'FINISHED'}
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
def draw(self, context):
layout = self.layout
wm = context.window_manager
row = layout.row(align=True)
row.prop(wm.kuler, "color1", text="")
row.prop(wm.kuler, "color2", text="")
row.prop(wm.kuler, "color3", text="")
row.prop(wm.kuler, "color4", text="")
row.prop(wm.kuler, "color5", text="")
layout.prop(wm.kuler, "shift")
layout.operator(WM_OT_kuler_default_colors.bl_idname)
def register():
bpy.utils.register_module(__name__)
bpy.types.WindowManager.kuler = PointerProperty(type=Kuler)
def unregister():
bpy.utils.unregister_module(__name__)
del bpy.types.WindowManager.kuler
if __name__ == "__main__":
register()
The color shifting isn’t that great, it’s not based on perceived color and the float property is only used to add to the hue, no matter what value it is actually set to.