Skip to content

DnaHelix3D

Cargo featurefeatures = ["biology"]

DnaHelix3D needs the 3d feature as well (features = ["biology", "3d"]), which turns on fframes/3d. It renders the helix with fframes::three_d on every frame, on the CPU or, with wgpu, on the GPU, into a width x height image around center.

  • Model: the helix has B-DNA proportions, with ten pairs a turn and a minor and a major groove. Each pair is a rung of its two bases in bases colours, the same as DnaHelix. The rung runs between two backbones of beads in strand_color.
  • View: the axis runs across the image and the camera fits the whole length. The camera looks from elevation degrees above while the helix turns spin degrees a second about its own axis.
  • Motion: from delay the pairs build up from the left, one every pair_time seconds. Their beads grow, the backbone reaches over from the pair before, and the two bases meet in the middle.

Gallery scene: DnaHelix3D. Its five seconds of 24 pairs render on the CPU in about three seconds on this machine’s 32 threads.

DnaHelix3D demo, first frame
DnaHelix3D 5 s
use fframes_kit::prelude::*;
fn helix<'a>(ui: &mut Ui<'a, '_, '_>) -> Svgr<'a> {
ui.show(DnaHelix3D {
sequence: "GATTACAGATTACA".into(),
width: 1000.0,
height: 420.0,
spin: 20.0,
..ui.defaults()
})
}

Components are plain structs. Set the fields you need and fill the rest with ..ui.defaults(): the defaults below come from the current theme (theme. values are fields of Theme).

Field Type Default Description
sequence String "ATGCGTACCTGAATCGGATCCATG".into() Bases read from the left, one pair per letter (A, T, G, C); the partner base is the complement.
delay f32 0.0 Seconds after the container’s start before the first pair appears.
center (f64, f64) (0.0, 0.0) The middle of the image, in units of ui.space.
width f32 1500.0 Width of the rendered image in pixels.
height f32 560.0 Height of the rendered image in pixels.
spin f32 40.0 Rotation about the helix axis, in degrees per second.
elevation f32 12.0 Angle of the camera above the helix, in degrees.
pair_time f32 0.12 Seconds between one pair appearing and the next.
bases BaseColors BaseColors::default() Colour of each base letter’s rung half.
strand_color Color theme.colors.text Colour of the two sugar-phosphate backbones.
enter Option<FadeIn> None Fade in at the start; None for none.
exit Option<FadeOut> None Fade out before the end; None for none.

Feature biology · Source