Guest User

Untitled

a guest
Jul 16th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. import bpy
  2. import bmesh
  3. import math
  4.  
  5. n = 1000 # number of points
  6. c = 0.1 # scale factor
  7.  
  8. mesh = bpy.data.meshes.new(name="Spiral")
  9. bm = bmesh.new()
  10.  
  11. for i in range(0, n):
  12. theta = i * math.radians(137.5)
  13. r = c * math.sqrt(i)
  14. bm.verts.new((math.cos(theta) * r, math.sin(theta) * r, 0.0))
  15.  
  16. bm.to_mesh(mesh)
  17. mesh.update()
  18.  
  19. from bpy_extras import object_utils
  20. object_utils.object_data_add(bpy.context, mesh)
  21.  
  22. import bpy
  23. import math
  24. import mathutils
  25. from mathutils import Euler
  26. # make sure 3d cursor is at the center of the scene
  27.  
  28. num_items_in_spiral = 13
  29. num_spiral_arms = 29
  30. z_rotation = 2.0 * math.pi / num_spiral_arms
  31.  
  32. # add cone, modify the mesh,
  33. bpy.ops.mesh.primitive_cone_add(vertices=12, radius1=0.354406, depth=0.901211)
  34. obj = bpy.context.active_object
  35. obj.data.transform(mathutils.Matrix.Translation((-0.5, 0, 0)))
  36.  
  37. # add empty for spiral arm
  38. bpy.ops.object.empty_add()
  39. obj = bpy.context.active_object
  40. obj.name = "Empty_spiral"
  41. obj.location = (-0.8, 0, 0)
  42. obj.rotation_euler = Euler((0, 0, 0.179609), 'XYZ')
  43.  
  44. # add empty for radial array
  45. bpy.ops.object.empty_add()
  46. obj = bpy.context.active_object
  47. obj.name = "Empty_radial_array"
  48. obj.rotation_euler = Euler((0, 0, z_rotation), 'XYZ')
  49.  
  50. # add modifiers to the cone
  51. obj = bpy.data.objects["Cone"]
  52.  
  53. mod = obj.modifiers.new(name="Array_1", type='ARRAY')
  54. mod.use_relative_offset = False
  55. mod.use_object_offset = True
  56. mod.offset_object = bpy.data.objects["Empty_spiral"]
  57. mod.count = num_items_in_spiral
  58.  
  59. mod = obj.modifiers.new(name="Array_2", type='ARRAY')
  60. mod.use_relative_offset = False
  61. mod.use_object_offset = True
  62. mod.offset_object = bpy.data.objects["Empty_radial_array"]
  63. mod.count = num_spiral_arms
  64.  
  65. function sflo1 ( N:float,k:int):Vector3{//phi based pylospiral
  66. //N=numpts k=currentpt
  67. k=k;
  68. var inc = Mathf.PI * ( 3 - Mathf.Sqrt ( 5 ) );
  69. var off = 2 / N;
  70. var y = k * off - 1 + (off / 2);
  71. var r = Mathf.Sqrt (Mathf.Abs(y)) ;
  72. var phi = k * inc;
  73. return Vector3(-Mathf.Cos(phi)*r, 0, -Mathf.Sin(phi)*r);
  74.  
  75. };
  76.  
  77. function sflo ( N:float,k:int):Vector3{//easy formula based on 137.5 pylospiral
  78. var n = k;
  79. var r=Mathf.Sqrt (n)*1/(Mathf.Sqrt (N));;
  80. var t=137.5*pi/180*n;
  81. return Vector3(r*Mathf.Cos(t),0, r*Mathf.Sin(t));
  82. }
  83.  
  84. function sflosq ( N:float,k:int):Vector3{//my own version it's stupid!
  85. //N=numpts k=currentpt
  86.  
  87. var inc = Mathf.PI * ( 3 - Mathf.Sqrt ( 5 ) );
  88. var off = 2 / N;
  89. var y = k * off - 1 + (off / 2);
  90. var r = Mathf.Sqrt (Mathf.Abs(y)) * Mathf.Sign(y) ;
  91. var phi = k * inc;
  92. return Vector3(Mathf.Asin(Mathf.Cos(phi))*r, 0, (-Mathf.Acos(Mathf.Sin(phi))+pi/2)*r);
  93.  
  94. };
  95.  
  96. import bpy
  97. import bmesh
  98. import math
  99. from mathutils import Vector
  100.  
  101. n = 400 # number of points
  102. r = 3 #radius
  103. ob = bpy.context.object
  104. obs = []
  105. sce = bpy.context.scene
  106.  
  107. for i in range(1, n):
  108. theta = i * math.radians(137.5)#degrees
  109. phi = (math.radians(180)/n) * i
  110. x = r*math.sin(phi)*math.cos(theta)
  111. y = r*math.sin(phi)*math.sin(theta)
  112. z = r*math.cos(phi)
  113.  
  114. if x<0:
  115. a = x*(-1)
  116. else:
  117. a = x
  118.  
  119. if y < 0:
  120. b = y*(-1)
  121. else:
  122. b = y
  123.  
  124. c = math.sqrt((a*a)+(b*b))
  125. size = 0.06+(c*0.09) #This can be messed about with to get the right size
  126.  
  127. copy = ob.copy()
  128. copy.location = (x,y,z)
  129. copy.scale = (size,size,size)
  130.  
  131. copy.rotation_euler=(phi,math.radians(0),theta+math.radians(90))
  132.  
  133. copy.data = copy.data.copy()
  134. obs.append(copy)
  135.  
  136. for ob in obs:
  137. sce.objects.link(ob)
  138.  
  139. sce.update() # don't place this in either of the above loops!
  140.  
  141. import bpy
  142. import bmesh
  143. import math
  144. from mathutils import Vector
  145.  
  146. # prepare a scene
  147. scn = bpy.context.scene
  148. ob = bpy.context.object
  149.  
  150. #number of frames
  151. n = 143
  152. #degrees to rotate
  153. d = 0 #Change to apply spin
  154.  
  155. for i in range(0, n):
  156.  
  157. bpy.context.scene.frame_set(i)
  158.  
  159. # do something with the object. A rotation, in this case
  160. ob.rotation_euler=(0.0,0.0,math.radians(d))
  161.  
  162. d = (d + 137.5) #Change to subtract to change direction of appeared flow
  163.  
  164. # create keyframe
  165. bpy.ops.anim.keyframe_insert_menu(type='Rotation')
Add Comment
Please, Sign In to add comment