Hide
Bored? Check out the Recent Activity on Siafoo Join Siafoo Now or Learn More

Blender Script to create a sin wave Atom Feed 0

# 's
 1#!BPY
2"""
3Name: 'Sine wave creator'
4Blender: 243
5Group: 'Mesh'
6Tooltip: 'Create a sin wave'
7"""
8
9# License: Public Domain... yay
10
11from Blender import Redraw, Scene, Mesh, Window, sys
12import BPyMessages
13import bpy
14
15from math import radians, sin
16
17def main():
18
19 # Gets the current scene, there can be many scenes in 1 blend file.
20 sce = bpy.data.scenes.active
21
22 Window.WaitCursor(1)
23 t = sys.time()
24
25 window = Mesh.New('Terrain')
26
27 sce.objects.new(window, 'mySin')
28
29 segments = 10
30 angle_r = 360 / segments
31
32 pts = [(i, 0, sin(radians(angle_r*i))) for i in xrange(segments)]
33 window.verts.extend(pts)
34
35 edges = [(i, i+1) for i in xrange(segments - 1)]
36 window.edges.extend(edges)
37
38 # Timing the script is a good way to be aware on any speed hits when scripting
39 print 'My Script finished in %.2f seconds' % (sys.time()-t)
40 Window.WaitCursor(0)
41 Redraw()
42
43
44# This lets you can import the script without running it
45if __name__ == '__main__':
46 main()