Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import bpy
- from math import pi, sqrt
- radius_size = 1.0
- # Imposta il numero di sfere
- num_spheres = 200
- # Lista delle posizioni delle sfere
- positions = []
- # Crea le sfere in modo casuale
- for i in range(num_spheres):
- # Genera le coordinate casuali per la posizione
- x = random.uniform(-10, 10)
- y = random.uniform(-10, 10)
- z = random.uniform(-10, 10)
- # Verifica se la nuova sfera si sovrappone con quelle precedenti
- overlap = True
- while overlap:
- overlap = False
- for pos in positions:
- distance = sqrt((pos[0] - x)**2 + (pos[1] - y)**2 + (pos[2] - z)**2)
- if distance < (radius_size * 2):
- # Le sfere si sovrappongono, sposta la nuova sfera in una nuova posizione
- x = random.uniform(-10, 10)
- y = random.uniform(-10, 10)
- z = random.uniform(-10, 10)
- overlap = True
- break
- # Aggiungi la posizione alla lista delle posizioni delle sfere
- positions.append((x, y, z))
- # Genera la dimensione casuale
- scale = random.uniform(0.2, 1.5)
- # Genera il colore casuale
- r = random.uniform(0.0, 1.0)
- g = random.uniform(0.0, 1.0)
- b = random.uniform(0.0, 1.0)
- color = (r, g, b)
- # Crea una nuova sfera
- obj =bpy.ops.mesh.primitive_uv_sphere_add(
- radius=radius_size,
- enter_editmode=False,
- align='WORLD',
- location=(x,y,z),
- scale=(scale,scale,scale)
- )
- # Applica lo smooth alla sfera
- bpy.ops.object.shade_smooth()
- # Crea un materiale
- mat = bpy.data.materials.new("Material")
- # Crea un colore Diffuse casuale :
- mat.diffuse_color = (random.random(), random.random(), random.random(), 1)
- # Assegna il materiale all'oggetto
- bpy.context.object.data.materials.append(mat)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement