```__author__ = 'thoth' import bpy from mathutils import * def adjust_handle_right(bpoint): bpoint.handle_right = bpoint.co * 2 - bpoint.handle_left def set_handles(bpoint, dx, dy, dz): bpoint.handle_right = bpoint.co + Vector([dx,dy,dz]) bpoint.handle_left = bpoint.co - Vector([dx,dy,dz]) def make_bezier_helix(name, radius, dz, cycle_count): curve = bpy.data.curves.new(name, 'CURVE') curve.dimensions = '3D' bez = curve.splines.new('BEZIER') after_helix = 4 * cycle_count final_length = after_helix +1 bez.bezier_points.add(final_length - len(bez.bezier_points)) for bp in bez.bezier_points: bp.handle_left_type = 'FREE' bp.handle_right_type = 'FREE' # this is a popular approximation of a circle handle_delta = radius * .552 for i in range(cycle_count): bp0 = bez.bezier_points[i*4] x = radius y = 0 z = (i)*dz bp0.co = (x,y,i*dz) set_handles(bp0, 0, handle_delta, dz/12) bp1 = bez.bezier_points[i*4+1] x = 0 y = radius z = (i+0.25)*dz bp1.co = (x,y,z) set_handles(bp1, -handle_delta,0, dz/12) bp2 = bez.bezier_points[i*4+2] x = -radius y = 0 z = (i+0.5)*dz bp2.co = (x,y,z) set_handles(bp2, 0, -handle_delta, dz/12) bp3 = bez.bezier_points[i*4+3] x = 0 y = -radius z = (i+0.75)*dz bp3.co = (x,y,z) set_handles(bp3, handle_delta,0, dz/12) bp = bez.bezier_points[after_helix] x=100 y = -radius z = dz*(cycle_count -0.25) + x/(handle_delta) * dz/12 bp.co = (x,y,z) set_handles(bp, handle_delta, 0, dz/12) return curve def mission1(scn, radius, dz, cycle_count): name = "helix" obj = bpy.data.objects.get(name) curve = make_bezier_helix(name, radius, dz, cycle_count) if obj is None: obj = bpy.data.objects.new(name, curve) else: obj.data = curve try: scn.objects.link(obj) except: pass # scn = bpy.context.scene mission1(scn, 2, 12, 5) ```

Syntax highlighting by Pygments.