On 31/07/2018 at 06:27, xxxxxxxx wrote:
Hi Blastframe, thanks for writing us.
With regard to your question, first of all I warmly recommend to have a look at the Command section in this Cinema 4D Help page describing the Sketch and Toon outline color. There you'll be provided with the list of global variables that can be used inside the Python script to properly control the script execution.
That said, using PntA and PntB, you can use the following code snippet to generate pseudo-random color per-stroke
import c4d
#Welcome to the world of Python
POINT_OFFSET = 10000
# Given two points, calculates a pseudo-unique stroke index
# NOTE: the uniqueness depends on the offset value which should
# be greater than the maximum vertices point count
def CalcIndex(a, b) :
p = 0
if a > b:
p = a * POINT_OFFSET + b
else:
p = b * POINT_OFFSET + a
return p
# Given an index and a component value, a pseudo-random number is returned
# NOTE: the number returned is constant across frames and/or render buckets
def myrand(p, comp) :
f = float(p) / (256.0 + comp)
rand = f - int(f)
return rand
def main() :
p = CalcIndex(PntA, PntB)
return c4d.Vector(myrand(p, 0), myrand(p, 1), myrand(p, 2))
Beside the code, it's relevant to state that using a standard random generator - like randint() -, since the execution of the scripts happens per bucket and per frame you could end up in a stroke made of as many color as the number of buckets the stroke is rendered by. By using instead a pseudo-random function, which is in this case based on the index of the segment, you can end up with a consistent coloring across buckets and frames.
Definitively the pseudo-number generator provided above is pretty simple but as a proof of concept it works as expected.
Best, Riccardo