Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- l = .25 # length of each segment in the curve
- n = 16 # iterations of the curve-generating algorithm
- # generate sequence of right-left turns
- new = [True]
- for i in range(n-1):
- old = list(new)
- new.append(True)
- old.reverse()
- for j in range(len(old)):
- old[j] = not old[j]
- new.extend(old)
- del old
- # convert the sequence of turns into a sequence of vector "moves"
- versors = [(l, 0)]
- for turn in new:
- vec = versors[-1]
- if turn:
- x = vec[1]
- y = vec[0] * -1
- else:
- x = vec[1] * -1
- y = vec[0]
- versors.append((x, y))
- del new
- # convert the sequence of vectors to a sequence of vertices
- vertices = [(0, 0)]
- for ver in versors:
- lastvert = vertices[-1]
- vertex = (lastvert[0] + ver[0], lastvert[1] + ver[1])
- vertices.append(vertex)
- del versors
- # create the Curve Datablock
- curveData = bpy.data.curves.new('myCurve', type='CURVE')
- curveData.dimensions = '3D'
- curveData.resolution_u = 2
- # map vertices to spline
- polyline = curveData.splines.new('POLY')
- polyline.points.add(len(vertices) - 1)
- for i, coord in enumerate(vertices):
- x,y = coord
- polyline.points[i].co = (x, y, 0, 1)
- del vertices
- # create Object
- curveOB = bpy.data.objects.new('myCurve', curveData)
- # attach to scene and validate context
- scn = bpy.context.scene
- scn.objects.link(curveOB)
- scn.objects.active = curveOB
- curveOB.select = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement