Capstone Project for Part 1
I made a script that clears the scene if there was anything superfluous), and adds two types of trees. With each click of the script, the trees are positioned differently, as well as their height.
Script and screen
import bpy
import random
green_plane = bpy.data.materials.new(name= "Trava")
green_plane.diffuse_color = [0, 0.45, 0, 1]
green_tree = bpy.data.materials.new(name= "Listva")
green_tree.diffuse_color = [0, 0.7, 0, 1]
brown_tree = bpy.data.materials.new(name= "Stvol")
brown_tree.diffuse_color = [0.2, 0.1, 0, 1]
green_black = bpy.data.materials.new(name= "Elka")
green_black.diffuse_color = [0, 0.2, 0, 1]
def clean_scene():
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
def add_plane():
bpy.ops.mesh.primitive_plane_add()
plane = bpy.context.active_object
plane.scale.x = 20
plane.scale.y = 20
plane.data.materials.append(green_plane)
def add_tree():
for i in range(10):
x = random.randint(-19, 19)
y = random.randint(-19, 19)
height = random.randint(4, 6)
bpy.ops.mesh.primitive_cylinder_add(radius = 0.5, location = (x,y, height / 2), depth = height)
cyl = bpy.context.active_object
cyl.data.materials.append(brown_tree)
bpy.ops.mesh.primitive_uv_sphere_add(location = (x,y, height), radius = 3)
uv = bpy.context.active_object
uv.data.materials.append(green_tree)
for i in range(10):
x = random.randint(-19, 19)
y = random.randint(-19, 19)
height = random.randint(4, 6)
bpy.ops.mesh.primitive_cylinder_add(radius = 0.5, location = (x,y, height / 2), depth = height)
cyl = bpy.context.active_object
cyl.data.materials.append(brown_tree)
bpy.ops.mesh.primitive_cone_add(location = (x,y, height), depth = height,radius1= 2)
cone = bpy.context.active_object
cone.data.materials.append(green_black)
clean_scene()
add_plane()
add_tree()
2
1 comment
Виктор Руф
1
Capstone Project for Part 1
CG Python Academy (Free)
skool.com/cgpython
3D artists learning Blender Python.
Leaderboard (30-day)
Powered by