Skip to content

Instantly share code, notes, and snippets.

@CGArtPython
Last active October 2, 2022 01:15
Show Gist options
  • Save CGArtPython/029a24513fcd0656028693bd9445be95 to your computer and use it in GitHub Desktop.
Save CGArtPython/029a24513fcd0656028693bd9445be95 to your computer and use it in GitHub Desktop.
Version of script for a tutorial using a circle mesh instead of a ico sphere https://www.youtube.com/watch?v=uOQ-CPcaqMo&lc=UgzQQKuVzGyx6Ke4DvJ4AaABAg
"""
https://stackoverflow.com/a/42879185
https://en.wikipedia.org/wiki/Parametric_equation#Circle
https://sinestesia.co/blog/tutorials/python-tubes-cilinders/
https://blog.wolfram.com/2015/06/28/2-pi-or-not-2-pi/
Great explanation of the math behind this
"Parametrizing a Circle" by @JCCCmath
https://www.youtube.com/watch?v=H9GEuAMcVwo
"""
# give Python access to Blender's functionality
import bpy
# extend Python's math functionality
import math
# extend Python's print functionality
import pprint
# initialize paramaters
vert_count = 32 # show with 16 and 64
# angle_step = 2 * math.pi / vert_count
angle_step = math.tau / vert_count
# create a list of vert coordinates
vert_coordinates = list()
# repeat code in a loop
for i in range(vert_count):
# calculate current current_angle
current_angle = angle_step * i
# calculate coordinate
x = math.cos(current_angle)
y = math.sin(current_angle)
# visualize what we are doing
# bpy.ops.mesh.primitive_ico_sphere_add(radius=0.05, location=(x, y, 0))
bpy.ops.mesh.primitive_circle_add(radius=0.05, location=(x, y, 0))
# add current coordinate to list
vert_coordinates.append((x, y, 0))
pprint.pprint(vert_coordinates)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment