enzyme69 / blendersushi

Blender Sushi related scripts. Mostly about Sverchok, Geometry Nodes, Animation Nodes, and related Python scripts.
243 stars 33 forks source link

LIVENODING 713 / Fractal Script Node using SV and AN #105

Open enzyme69 opened 7 years ago

enzyme69 commented 7 years ago

prtscr capture_40 prtscr capture_39 prtscr capture_38 prtscr capture_37

SVERCHOK SCRIPT NODE:

"""
in seed s   d=1   n=2
in maxLoop s   d=1000   n=2
in x s   d=100   n=2
in y s   d=100   n=2
out verts      v
"""

import random

random.seed(seed)

def makeFractal(maxLoop, x=100, y=100):
    listFractal = []

    for i in range(1,maxLoop):

        r = random.randint(0, 2)

        if r==1:
            ux = 30
            uy = 1000
        elif r==2:
            ux = 1000
            uy = 1000
        else:
            ux = 150
            uy = 30

        x = (x + ux) / 2
        y = (y + uy) / 2  

        listFractal.append([x,y,0])

    return listFractal

point_gen = makeFractal(maxLoop, x, y)

verts = [[point_gen]]

AN SCRIPT NODE:

import mathutils
import random

random.seed(seed)

VectorList = []

for i in range(1,maxLoop):

    r = random.randint(0, 2)

    if r==1:
        ux = 30
        uy = 1000
    elif r==2:
        ux = 1000
        uy = 1000
    else:
        ux = 150
        uy = 30

    x = (x + ux) / 2
    y = (y + uy) / 2

    VectorList.append(Vector((x,y,0)))
enzyme69 commented 7 years ago

The script for AN and SV can be improved, probably not the best, but interesting to learn how each node works with Python.

In fact, you can also set this up using ADD-ON and Python and BPY. All good and interesting.

enzyme69 commented 7 years ago

AN: an_fractal_002_2017_09_04_13_08.zip

SV: sv_fractal_003_2017_09_04_13_07.zip