python radial_gradient_script.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python radial_gradient_script.py相关的知识,希望对你有一定的参考价值。

# assumes the values of the first indices add up to 100.

import bpy
import random

mats = bpy.data.materials
nodes = mats['Material'].node_tree.nodes
elements = nodes['ColorRamp'].color_ramp.elements

RAN = random.random
get_random_color = lambda: (RAN(), RAN(), RAN(), 1.0)

procents_and_colors = [
    [20, get_random_color()],   # or fill these with prechosen colours
    [30, get_random_color()],
    [50, get_random_color()],
]

# this sections adds or removes elements if you update your 
# procents_and_colors list with more / fewer elements
diff = len(elements) - len(procents_and_colors)
if diff > 0:
    for i in range(abs(diff)):
        elements.remove(elements[-1])
elif diff < 0:
    for i in range(abs(diff)):
        elements.new(position=0.0)
    

position = 0
for idx, section in enumerate(procents_and_colors):
    elements[idx].color = section[1]
    elements[idx].position = position
    position += (section[0] / 100.0)

以上是关于python radial_gradient_script.py的主要内容,如果未能解决你的问题,请参考以下文章

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python

python初识