krljg / lsystem

An L-system add-on for blender
69 stars 12 forks source link

get(i) function always return 0 rather than iteration time #5

Closed HowcanoeWang closed 2 years ago

HowcanoeWang commented 3 years ago
import lsystem.exec
import math
exec = lsystem.exec.Exec()
exec.set_axiom("X")
exec.add_rule("X", "AX")
exec.add_rule("A", "F[-(get(i))F]")
exec.exec(min_iterations=4, angle=25)

the outputs:

X
AX
F[-(0)F]AX
F[-(0)F]F[-(0)F]AX
F[-(0)F]F[-(0)F]F[-(0)F]AX

Expected: F[-(2)F]F[-(3)F]F[-(4)F]AX

I check the source code in lsystem.py, It seems the self.constant value never updated by iteration and keeps 0 as is initialized

krljg commented 2 years ago

Looks like it was a mistake in the readme file and get(i) return instance not iteration. Added new property iter to get iteration. Now

import lsystem.exec
import math
exec = lsystem.exec.Exec()
exec.set_axiom("X")
exec.add_rule("X", "AX")
exec.add_rule("A", "F[-(get(iter))F]")
exec.exec(min_iterations=4, angle=25)

Should result in F[-(1)F]F[-(2)F]F[-(3)F]AX (because I start from 0 and not 1)