import bpy

from math import pi
from time import sleep

ITERATIONS = 4
STEPS = 1200
T0 = 0
TF = 1/15
L_SYSTEM = "KochCurve()"
PI = 3.14159

def addObject(t):
    bpy.ops.object.select_all(action='DESELECT')
    bpy.context.scene.lsystem_lsystem = L_SYSTEM
    bpy.context.scene.lsystem_iterations = ITERATIONS
    bpy.context.scene.lsystem_turtle = "RPTurtle(angle = "+str(2*PI*t)+")"
    bpy.ops.lsystem.run()

def clean():
    bpy.ops.object.delete(use_global=False)

def render(i):
    aux = str(len(str(STEPS)))
    str_format = "{:0"+aux+"d}"
    index = str_format.format(i)
    bpy.data.scenes['Scene'].render.filepath = 'G:\\render_koch_rot\\img_'+str(STEPS)+'_'+index+'.jpg'
    bpy.ops.render.render( write_still=True )

for i in range(STEPS):
    t = T0 + i*(TF-T0)/STEPS
    addObject(t)
    #sleep(1)
    render(i)
    #sleep(1)
    clean()


