11/6/2025

This is a script in Blender that makes generative stars. Very basic with very few parameters.

import bpy
import bmesh
import math
import random

creates a random int for number of verts

number_verts = random.randint(1,16) * 2
x_scaler = random.randint(1,10)
y_scaler = random.randint(1,10)
z_mover = random.randint(10,30)

creates variable that represents all objects in scene

all_objects = bpy.context.scene.objects

deletes all objects with “cylinder” in name

for obj in all_objects:
if “cylinder” in obj.name.lower():
bpy.data.objects.remove(obj, do_unlink=True)

adds cyliner at origin with 12 verts, r = 5, depth=2

bpy.ops.mesh.primitive_cylinder_add(enter_editmode=True, vertices=number_verts, radius=5.0, depth=2.0, end_fill_type=’TRIFAN’, align=’WORLD’, location=(0.0, 0.0, 0.0))

Current object is variable cyl, creates variables for data and mesh

cyl = bpy.context.object
cyl_data = cyl.data
cyl_mesh = bmesh.new()
cyl_mesh = bmesh.from_edit_mesh(cyl_data)
cyl_mesh.verts.ensure_lookup_table()
cyl_mesh.edges.ensure_lookup_table()

selects the every other top vert on the side and moves it up by z_mover

for index, v in enumerate(cyl_mesh.verts):
if index % 4 == 1:
cyl_mesh.verts[index].co.z = cyl_mesh.verts[index].co.z + z_mover

selects every other vert on the top and bottom sides and scales it by x or y scaler

for index, v in enumerate(cyl_mesh.verts):
if index % 4 == 0 or index % 4 == 1:
cyl_mesh.verts[index].co.x = cyl_mesh.verts[index].co.x * x_scaler
cyl_mesh.verts[index].co.y = cyl_mesh.verts[index].co.y * y_scaler