MF6-27.09.2024

nie można dać -a; nie można zrobić minusowej zmiennej; nie zrobisz "-a"

ale można zamienić kolejność i ustawić "-10" - "a" zamiana kolejności w tym wypadku robi ujemną wartość a

Kod wypluty przez czat:

import bpy
# Funkcja tworzenia sfery (kuli)
def create_sphere(radius, location, name):
bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, location=location)
obj = bpy.context.object
obj.name = name
return obj
# Funkcja tworzenia stożka (marchewkowego nosa)
def create_cone(radius1, depth, location, rotation, name):
bpy.ops.mesh.primitive_cone_add(radius1=radius1, depth=depth, location=location, rotation=rotation)
obj = bpy.context.object
obj.name = name
return obj
# Funkcja tworzenia cylindra (gałęzie)
def create_cylinder(radius, depth, location, rotation, name):
bpy.ops.mesh.primitive_cylinder_add(radius=radius, depth=depth, location=location, rotation=rotation)
obj = bpy.context.object
obj.name = name
return obj
# Tworzenie kul dla ciała bałwana
body_bottom = create_sphere(1, (0, 0, 1), "Bottom Sphere")
body_middle = create_sphere(0.75, (0, 0, 2.5), "Middle Sphere")
body_top = create_sphere(0.5, (0, 0, 3.75), "Top Sphere")
# Tworzenie oczu (dwie małe czarne kule)
eye_left = create_sphere(0.1, (-0.2, 0.45, 4), "Left Eye")
eye_right = create_sphere(0.1, (0.2, 0.45, 4), "Right Eye")
# Tworzenie nosa (stożek, marchewka)
nose = create_cone(0.1, 0.5, (0, 0.6, 3.75), (0, 1.57, 0), "Nose")
# Tworzenie ust (kilka małych kulek)
mouth_1 = create_sphere(0.05, (-0.25, 0.35, 3.5), "Mouth1")
mouth_2 = create_sphere(0.05, (-0.12, 0.4, 3.45), "Mouth2")
mouth_3 = create_sphere(0.05, (0, 0.42, 3.4), "Mouth3")
mouth_4 = create_sphere(0.05, (0.12, 0.4, 3.45), "Mouth4")
mouth_5 = create_sphere(0.05, (0.25, 0.35, 3.5), "Mouth5")
# Tworzenie rąk (gałęzie z cylindrów)
arm_left = create_cylinder(0.05, 2, (-1.2, 0, 2.5), (0, 0, 1.2), "Left Arm")
arm_right = create_cylinder(0.05, 2, (1.2, 0, 2.5), (0, 0, -1.2), "Right Arm")
# Dodawanie materiałów
def assign_material(obj, color):
mat = bpy.data.materials.new(name="Material")
mat.diffuse_color = (*color, 1) # Ustawienie koloru
obj.data.materials.append(mat)
# Biały materiał na ciało bałwana
assign_material(body_bottom, (1, 1, 1))
assign_material(body_middle, (1, 1, 1))
assign_material(body_top, (1, 1, 1))
# Czarny materiał na oczy i usta
assign_material(eye_left, (0, 0, 0))
assign_material(eye_right, (0, 0, 0))
assign_material(mouth_1, (0, 0, 0))
assign_material(mouth_2, (0, 0, 0))
assign_material(mouth_3, (0, 0, 0))
assign_material(mouth_4, (0, 0, 0))
assign_material(mouth_5, (0, 0, 0))
# Pomarańczowy materiał na nos
assign_material(nose, (1, 0.5, 0))
# Brązowy materiał na ręce
assign_material(arm_left, (0.4, 0.2, 0))
assign_material(arm_right, (0.4, 0.2, 0))
# Ustawienie tła i dodanie światła
bpy.ops.object.light_add(type='SUN', location=(5, -5, 5))
bpy.context.object.data.energy = 3
bpy.ops.object.camera_add(location=(0, -10, 5), rotation=(1.1, 0, 0))
bpy.context.scene.camera = bpy.context.object

Poprawiony kod:

import bpy
# Funkcja tworzenia sfery (kuli)
def create_sphere(radius, location, name):
bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, location=location)
obj = bpy.context.object
obj.name = name
return obj
# Funkcja tworzenia stożka (marchewkowego nosa)
def create_cone(radius1, depth, location, rotation, name):
bpy.ops.mesh.primitive_cone_add(radius1=radius1, depth=depth, location=location, rotation=rotation)
obj = bpy.context.object
obj.name = name
return obj
# Funkcja tworzenia cylindra (gałęzie)
def create_cylinder(radius, depth, location, rotation, name):
bpy.ops.mesh.primitive_cylinder_add(radius=radius, depth=depth, location=location, rotation=rotation)
obj = bpy.context.object
obj.name = name
return obj
# Tworzenie kul dla ciała bałwana
body_bottom = create_sphere(1, (0, 0, 1), "Bottom Sphere")
body_middle = create_sphere(0.75, (0, 0, 2.5), "Middle Sphere")
body_top = create_sphere(0.5, (0, 0, 3.75), "Top Sphere")
# Tworzenie oczu (dwie małe czarne kule)
eye_left = create_sphere(0.1, (-0.2, 0.45, 4), "Left Eye")
eye_right = create_sphere(0.1, (0.2, 0.45, 4), "Right Eye")
# Tworzenie nosa (stożek, marchewka)
nose = create_cone(0.1, 0.5, (0, 0.6, 3.75), (0, 1.57, 1.5), "Nose")
# Tworzenie ust (kilka małych kulek)
mouth_1 = create_sphere(0.05, (-0.25, 0.35, 3.5), "Mouth1")
mouth_2 = create_sphere(0.05, (-0.12, 0.4, 3.45), "Mouth2")
mouth_3 = create_sphere(0.05, (0, 0.42, 3.4), "Mouth3")
mouth_4 = create_sphere(0.05, (0.12, 0.4, 3.45), "Mouth4")
mouth_5 = create_sphere(0.05, (0.25, 0.35, 3.5), "Mouth5")
# Tworzenie rąk (gałęzie z cylindrów)
arm_left = create_cylinder(0.05, 2, (-1.2, 0, 2.5), (1, 0, 1.2), "Left Arm")
arm_right = create_cylinder(0.05, 2, (1.2, 0, 2.5), (1, 0, -1.2), "Right Arm")
# Dodawanie materiałów
def assign_material(obj, color):
mat = bpy.data.materials.new(name="Material")
mat.diffuse_color = (*color, 1) # Ustawienie koloru
obj.data.materials.append(mat)
# Biały materiał na ciało bałwana
assign_material(body_bottom, (1, 1, 1))
assign_material(body_middle, (1, 1, 1))
assign_material(body_top, (1, 1, 1))
# Czarny materiał na oczy i usta
assign_material(eye_left, (0, 0, 0))
assign_material(eye_right, (0, 0, 0))
assign_material(mouth_1, (0, 0, 0))
assign_material(mouth_2, (0, 0, 0))
assign_material(mouth_3, (0, 0, 0))
assign_material(mouth_4, (0, 0, 0))
assign_material(mouth_5, (0, 0, 0))
# Pomarańczowy materiał na nos
assign_material(nose, (1, 0.5, 0))
# Brązowy materiał na ręce
assign_material(arm_left, (0.4, 0.2, 0))
assign_material(arm_right, (0.4, 0.2, 0))
# Ustawienie tła i dodanie światła
bpy.ops.object.light_add(type='SUN', location=(5, -5, 5))
bpy.context.object.data.energy = 3
bpy.ops.object.camera_add(location=(0, -10, 5), rotation=(1.1, 0, 0))
bpy.context.scene.camera = bpy.context.object