You find 3x random(), random(), random() in my script, which is used to generate the random color.
It stands for red, green, blue.
I replaced the inline code for random rgb by a function call, so it’s easier to replace the code (random_color function):
bl_info = {
"name": "Random Vertex Colors",
"author": "CoDEmanX",
"version": (1, 0),
"blender": (2, 65, 0),
"location": "View3D > Vertex Paint mode > Paint > Random Vertex Colors",
"description": "Assign random vertex colors per Loop, Edge or Face",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Mesh"}
import bpy
from random import random
def random_color():
return 0, 0, random()
def main(self, context):
me = context.object.data
vcol_data = me.vertex_colors.active.data
if self.random_per == 'LOOP':
for l in me.loops:
vcol_data[l.index].color = random_color()
elif self.random_per == 'VERT':
vert_loop_map = {}
for l in me.loops:
try:
vert_loop_map[l.vertex_index].append(l.index)
except KeyError:
vert_loop_map[l.vertex_index] = [l.index]
for vertex_index in vert_loop_map:
color = random_color()
for loop_index in vert_loop_map[vertex_index]:
vcol_data[loop_index].color = color
# per EDGE isn't possible, there are no distinct edge loops
else: # == 'FACE'
for p in me.polygons:
color = random_color()
for loop_index in p.loop_indices:
vcol_data[loop_index].color = color
me.update()
class MESH_OT_vertex_color_random(bpy.types.Operator):
"""Assign random vertex colors"""
bl_idname = "mesh.vertex_color_random"
bl_label = "Random Vertex Colors"
bl_options = {'REGISTER', 'UNDO'}
random_per = bpy.props.EnumProperty(name="Random per",
items=(('LOOP', "Loop", "Give every loop a random color"),
('VERT', "Vertex", "Give every vertex a random color"),
('FACE', "Face", "Give every face a random color"))
)
@classmethod
def poll(cls, context):
return (context.object is not None and
context.object.type == 'MESH' and
context.object.data.vertex_colors.active is not None)
def execute(self, context):
main(self, context)
return {'FINISHED'}
def draw_func(self, context):
self.layout.operator(MESH_OT_vertex_color_random.bl_idname)
def register():
bpy.utils.register_class(MESH_OT_vertex_color_random)
bpy.types.VIEW3D_MT_paint_vertex.append(draw_func)
def unregister():
bpy.utils.unregister_class(MESH_OT_vertex_color_random)
bpy.types.VIEW3D_MT_paint_vertex.remove(draw_func)
if __name__ == "__main__":
register()
0, 0, random() will give blue variations, although they tend to be very dark. You probably want cyan, reddish blue, light blue etc., but no colors close to black.
Here’s a bit hacky but practical code snippet to generate variations of (perceived) blue:
def random_color():
if random() > 0.6:
r = uniform(0.0, 0.3)
g = random()
b = uniform(max(g, r+g+0.2), 1.0)
else:
r = uniform(0.0, 0.1)
g = uniform(0.0, 0.2)
b = uniform(0.4, 1.0)
return r, g, b