Style

All renderable objects in Tissue Forge have a style attribute, which can refer to a rendering.Style object (Style in the rendering namespace in C++). A rendering.Style object behaves like a container for a variety of style descriptors. Each instance of an object with a style automatically inherits the style of its type, which can then be individually manipulated. The style attribute currently supports setting the color (setColor) and visibility (setVisible) of its parent object.

Styling Particles

Each ParticleType instance is initialized with a rendering.Style instance that is stored in its style attribute. By default, all particles are rendered according to the style of their type, which can be changed at any time during simulation. However, each Particle instance also has a style that, when set, provides instructions on how to uniquely render the Particle instance. The style of a Particle can be set using the style attribute of its handle.

import tissue_forge as tf

class MyParticleType(tf.ParticleTypeSpec):
    pass

my_particle_type = MyParticleType.get()
my_particle = my_particle_type()
my_particle.style = tf.rendering.Style()
my_particle.style.visible = True

Styling Particle Types in Python

The ParticleType has a special procedure for specifying the style of a type as a class definition in Python. The style attribute of a ParticleType subclass can be defined in Python as a dictionary with key-value pairs for particle type class definitions. The color of a type can be specified with the key "color" and value of the name of a color as a string. The visibility of a type can be specified with key "visible" and value of a Boolean.

class MyBlueParticleType(tf.ParticleTypeSpec):
    style = {'color': 'CornflowerBlue', 'visible': False}

Styling Bonds

Bonds, angles, and dihedrals have a rendering.Style instance. All instances of each class share the same rendering.Style instance by default. To customize the appearance of an individual bond, angle, or dihedral, create and set a new style instance using the same procedure as for particles.:

# Create a bond between particles "part_a" and "part_b"
bh: tf.BondHandle = tf.Bond.create(potential, part_a, part_b)
# Make the bond invisible
bond_style = tf.rendering.Style()
bond_style.visible = False
bh.style = bond_style