コード例 #1
0
ファイル: sl.py プロジェクト: puzzlet/cgkit
def point_noise(*args):
    """Returns a point whose value is a (pseudo) random function of its arguments."""
    
    la = len(args)
    if la==1:
        try:
            a = len(args[0])
        except:
            a = 1
        if a==1:
            return noise.vnoise(args[0],0,0)
        elif a==2:
            return noise.vnoise(args[0],0)
        elif a==3:
            return noise.vnoise(args[0])
        else:
            raise ValueError("arg1: invalid argument length")
    elif la==2:
        try:
            a = len(args[0])
        except:
            a = 1
        if a==1:
            return noise.vnoise(args[0],args[1],0)
        elif a==3:
            return noise.vnoise(args[0],args[1])
        else:
            raise ValueError("arg1: invalid argument length")
    elif la==3:
        return noise.vnoise(args[0],args[1],args[2])
    elif la==4:
        x,y,z,t = noise.vnoise(args[0],args[1],args[2],args[3])
        return _vec3(x,y,z)
    else:
        raise TypeError("the function takes between 1 and 4 arguments (%s given)"%(la))
コード例 #2
0
ファイル: sl.py プロジェクト: puzzlet/cgkit
def _tovec3(arg):
    try:
        a = len(arg)
    except:
        a = 1
    if a==1:
        return _vec3(arg,0.0,0.0)
    elif a==2:
        x,y=arg
        return _vec3(x,y,0.0)
    elif a==3:
        x,y,z=arg
        return _vec3(x,y,z)
    elif a==4:
        x,y,z,t=arg
        return _vec3(x,y,z)
    else:
        return _vec3()
コード例 #3
0
def point_cellnoise(*args):
    """Returns a point whose value is a (pseudo) random function of its arguments.

    The return value is constant between integer lattice points.
    """
    
    la = len(args)
    if la==1:
        try:
            a = len(args[0])
        except:
            a = 1
        if a==1:
            return noise.vcellnoise(args[0],0,0)
        elif a==2:
            return noise.vcellnoise(args[0],0)
        elif a==3:
            return noise.vcellnoise(args[0])
        else:
            raise ValueError,"arg1: invalid argument length"            
    elif la==2:
        try:
            a = len(args[0])
        except:
            a = 1
        if a==1:
            return noise.vcellnoise(args[0],args[1],0)
        elif a==3:
            return noise.vcellnoise(args[0],args[1])
        else:
            raise ValueError,"arg1: invalid argument length"
    elif la==3:
        return noise.vcellnoise(args[0],args[1],args[2])
    elif la==4:
        x,y,z,t = noise.vcellnoise(args[0],args[1],args[2],args[3])
        return _vec3(x,y,z)
    else:
        raise TypeError, "the function takes between 1 and 4 arguments ("+`la`+" given)"
コード例 #4
0
ファイル: sl.py プロジェクト: puzzlet/cgkit
def point_random():
    """Return a point (a vec3) whose componenets are a random number between 0 and 1."""
    return _vec3(random.random(), random.random(), random.random())
コード例 #5
0
ファイル: sl.py プロジェクト: puzzlet/cgkit
def color_random():
    """Return a color whose componenets are a random number between 0 and 1.

    The function actually returns a vec3."""
    
    return _vec3(random.random(), random.random(), random.random())