简体   繁体   中英

Add random color to active object python blender

Basically I want to add a random color to an active object in blender using python

I want to use random.randrange and i want the rgb- scale to start at 0.00 and stop at 1.0 with a difference of at least 0.3.

This is my code but somehow it doesn't work

r, g, b = random.randrange(0.0, 1.0[, 0.3])

mat.diffuse_color = (r,g,b)

Im new to blender and not sure how to this. What is the best solution?

Thanks!

You can accomplish the same with use of random.uniform(stat, end) , but here you won't get any option for skipping 0.3 .

So, it would be better to be with random.randrange() and here is the solution:

import random

rgb = ()
for i in range(3) :
    rgb += ((random.randrange(1, 10, 3) /10),)

mat.diffuse_color = rgb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM