How to use the k3d.color function in k3d

To help you get started, we’ve selected a few k3d examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github K-3D / k3d / tests / mesh / mesh.modifier.BlobbySubtract.py View on Github external
#python

import k3d
import testing

document = k3d.new_document()

source1 = k3d.plugin.create("BlobbyEllipsoid", document)
source1.color = k3d.color(1, 0, 0)

source2 = k3d.plugin.create("BlobbySegment", document)
source2.color = k3d.color(1, 1, 0)

modifier = k3d.plugin.create("BlobbySubtract", document)

k3d.property.connect(document, source1.get_property("output_mesh"), modifier.get_property("input_a"))
k3d.property.connect(document, source2.get_property("output_mesh"), modifier.get_property("input_b"))


testing.require_valid_mesh(document, modifier.get_property("output_mesh"))
testing.require_similar_mesh(document, modifier.get_property("output_mesh"), "mesh.modifier.BlobbySubtract", 5)
github K-3D / k3d / tests / mesh / mesh.modifier.TriangulateFaces.vertex.py View on Github external
polyhedron.shell_types().append(k3d.polyhedron.shell_type.POLYGONS)

polyhedron.face_shells().append(0)
polyhedron.face_first_loops().append(len(polyhedron.loop_first_edges()))
polyhedron.face_loop_counts().append(1)
polyhedron.face_materials().append(None)
polyhedron.face_selections().append(0)

polyhedron.loop_first_edges().append(len(polyhedron.clockwise_edges()))

polyhedron.clockwise_edges().append(1)
polyhedron.edge_selections().append(0)
polyhedron.vertex_points().append(0)
polyhedron.vertex_selections().append(0)
Cs.append(k3d.color(1, 0, 0))

polyhedron.clockwise_edges().append(2)
polyhedron.edge_selections().append(0)
polyhedron.vertex_points().append(1)
polyhedron.vertex_selections().append(0)
Cs.append(k3d.color(0, 1, 0))

polyhedron.clockwise_edges().append(3)
polyhedron.edge_selections().append(0)
polyhedron.vertex_points().append(4)
polyhedron.vertex_selections().append(0)
Cs.append(k3d.color(0, 0, 1))

polyhedron.clockwise_edges().append(0)
polyhedron.edge_selections().append(0)
polyhedron.vertex_points().append(5)
github K-3D / k3d / tests / mesh / mesh.modifier.BlobbyMultiply.py View on Github external
#python

import k3d
import testing

document = k3d.new_document()

source1 = k3d.plugin.create("BlobbyEllipsoid", document)
source1.color = k3d.color(1, 0, 0)

source2 = k3d.plugin.create("BlobbySegment", document)
source2.color = k3d.color(1, 1, 0)

modifier = k3d.plugin.create("BlobbyMultiply", document)
modifier.create_property("k3d::mesh*", "input_mesh1", "Input Mesh 1", "")
modifier.create_property("k3d::mesh*", "input_mesh2", "Input Mesh 2", "")

k3d.property.connect(document, source1.get_property("output_mesh"), modifier.get_property("input_mesh1"))
k3d.property.connect(document, source2.get_property("output_mesh"), modifier.get_property("input_mesh2"))


testing.require_valid_mesh(document, modifier.get_property("output_mesh"))
testing.require_similar_mesh(document, modifier.get_property("output_mesh"), "mesh.modifier.BlobbyMultiply", 5)
github K-3D / k3d / share / scripts / MeshSourceScript / cylinders.py View on Github external
# Construct a sphere mesh primitive ...
cylinder = k3d.cylinder.create(Output)
color = cylinder.parameter_attributes().create("Cs", "k3d::color")

# Add two cylinders ...
cylinder.matrices().append(k3d.translate3(k3d.vector3(-3, 0, 0)))
cylinder.materials().append(None)
cylinder.radii().append(2)
cylinder.z_min().append(-5)
cylinder.z_max().append(5)
cylinder.sweep_angles().append(radians(360))
cylinder.selections().append(0)
color.append(k3d.color(1, 0, 0))
color.append(k3d.color(1, 0, 0))
color.append(k3d.color(1, 1, 0))
color.append(k3d.color(1, 1, 0))

cylinder.matrices().append(k3d.translate3(k3d.vector3(3, 0, 0)))
cylinder.materials().append(None)
cylinder.radii().append(2)
cylinder.z_min().append(-5)
cylinder.z_max().append(5)
cylinder.sweep_angles().append(radians(360))
cylinder.selections().append(0)
color.append(k3d.color(1, 0, 0))
color.append(k3d.color(1, 0, 0))
color.append(k3d.color(0, 0, 1))
color.append(k3d.color(0, 0, 1))
github K-3D / k3d / share / scripts / scripted_plugins / random_colors.py View on Github external
# k3d:plugin-class="document"
# k3d:plugin-type="MeshModifierScript"
# k3d:plugin-name="RandomColors"
# k3d:plugin-description="Adds random colors to the attribute arrays in the polyhedra structure"

import k3d
k3d.check_node_environment(locals(), "MeshModifierScript")

from random import seed, randint

Output.copy(Input)

seed(123)

colors = [ k3d.color(1, 0, 0), k3d.color(1, 1, 0), k3d.color(0, 1, 0), k3d.color(0, 1, 1), k3d.color(0, 0, 1), k3d.color(1, 0, 1), k3d.color(1, 1, 1)]

# We iterate over input primitives, to avoid making a writable copy of every primitive
for prim_idx, const_primitive in enumerate(Input.primitives()):
	if const_primitive.type() == "polyhedron":
		polyhedron = k3d.polyhedron.validate(Output, Output.primitives()[prim_idx])
		if polyhedron:
			Cs = polyhedron.edge_attributes().create("Cs", "k3d::color")
			for i in range(len(polyhedron.vertex_points())):
				Cs.append(colors[i % len(colors)])
			Cs = polyhedron.face_attributes().create("Cs", "k3d::color")
			for i in range(len(polyhedron.face_first_loops())):
				Cs.append(colors[i % len(colors)])
github K-3D / k3d / share / scripts / MeshSourceScript / polyhedron.py View on Github external
face_selection.assign([0.0])

loop_first_edges = polyhedra.create_loop_first_edges()
loop_first_edges.assign([0])

edge_points = polyhedra.create_edge_points()
edge_points.assign([0, 1, 2, 3])

clockwise_edges = polyhedra.create_clockwise_edges()
clockwise_edges.assign([1, 2, 3, 0])

edge_selection = polyhedra.create_edge_selection()
edge_selection.assign([0.0, 0.0, 0.0, 0.0])

Cs = polyhedra.writable_face_varying_data().create_array("Cs", "k3d::color")
Cs.assign([k3d.color(1, 0, 0), k3d.color(0, 1, 0), k3d.color(0, 0, 1), k3d.color(1, 1, 1)])
github K-3D / k3d / share / scripts / MeshSourceScript / point_group.py View on Github external
point_counts = point_groups.create_point_counts()
point_counts.append(len(points))

materials = point_groups.create_materials()
materials.append(None)

constantwidth = point_groups.writable_constant_data().create_array("constantwidth", "double")
constantwidth.append(0.2)

group_points = point_groups.create_points()
for i in range(len(points)):
	group_points.append(i)

Cs = point_groups.writable_varying_data().create_array("Cs", "k3d::color")
for i in range(len(points)):
	Cs.append(k3d.color(uniform(0, 1), uniform(0, 1), uniform(0, 1)))
github K-3D / k3d / share / scripts / MeshSourceScript / linear_curves.py View on Github external
for j in range(5):
	curves.curve_first_points().append(len(curves.curve_points()))
	curves.curve_point_counts().append(3)
	curves.curve_selections().append(0.0)

	curves.curve_points().append(len(points) + 0)
	curves.curve_points().append(len(points) + 1)
	curves.curve_points().append(len(points) + 2)

	positions = [(0, 0, 5), (5, 0, 0), (0, 0, -5)]

	for position in positions:
		points.append(k3d.point3(position[0] + (j * 5), position[1], position[2]))
		point_selection.append(0.0)

	Cs.append(k3d.color(1, 1, j * 0.2))
github K-3D / k3d / share / scripts / MeshModifierScript / random_per_face_colors.py View on Github external
#python

import k3d
k3d.check_node_environment(locals(), "MeshModifierScript")

from random import seed, randint

Output.copy(Input)

seed(123)

colors = [ k3d.color(1, 0, 0), k3d.color(1, 1, 0), k3d.color(0, 1, 0), k3d.color(0, 1, 1), k3d.color(0, 0, 1), k3d.color(1, 0, 1), k3d.color(1, 1, 1)]

for prim_idx, const_primitive in enumerate(Input.primitives()):
	if const_primitive.attributes()["uniform"]:
		Cs = Output.prmitives()[prim_idx].attributes()["uniform"].create_array("Cs", "k3d::color")
		#todo: find out how to get the length for uniform data