Crates.io | duku |
lib.rs | duku |
version | 0.2.1 |
source | src |
created_at | 2020-11-24 19:40:17.04006 |
updated_at | 2020-12-09 08:45:09.32898 |
description | A Rust crate for creating graphic experiences |
homepage | https://github.com/oberzs/duku |
repository | https://github.com/oberzs/duku |
max_upload_size | |
id | 315930 |
size | 3,611,038 |
Simple Example • Usage • Features • Documentation
A Rust crate for creating graphic experiences, with a focus on ease of use and beginner friendliness. Also helpful for visualizing algorithms when learning Rust.
This creative coding library draws a lot of inspiration from p5.js.
This example draws a cube in the center of the window, rotating and coloring it based on the time that has passed.
use duku::Camera;
use duku::Duku;
use duku::Hsb;
use duku::Light;
use duku::Result;
use std::time::Instant;
fn main() -> Result<()> {
// create duku context and window
let (mut duku, window) = Duku::windowed(500, 500)?;
// create 3D camera with 90 fov
let camera = Camera::perspective(90);
// create directional light
let light = Light::directional("#ffffff", [-1.0, -1.0, 1.0]);
// start timer for rotation and color
let timer = Instant::now();
// start window loop
window.while_open(move |_| {
// start drawing on window
duku.draw(Some(&camera), |t| {
// setup scene
t.background("#ababab");
t.light(light);
// get elapsed time since start
let elapsed = timer.elapsed().as_secs_f32();
// transform scene
let angle = elapsed * 45.0;
t.rotate_x(angle);
t.rotate_y(angle);
t.translate_z(2.0);
// draw cube
let hue = (elapsed * 60.0) as u16;
t.tint(Hsb::new(hue, 70, 80));
t.cube([1.0, 1.0, 1.0]);
});
});
Ok(())
}
To use this crate, add this dependency to your Cargo.toml
file.
[dependencies]
duku = "0.2.1"
This crate supports additional features that you can add
to your dependency in your Cargo.toml
file.
[dependencies]
duku = { ... , features = ["feature-name"] }
The features include:
Name | Default | Uses | Description |
---|---|---|---|
window |
yes | winit | adds OS window creation support |
png |
no | png | adds png file loading support |
jpeg |
no | jpeg-decoder | adds jpeg file loading support |
gltf |
no | gltf | adds gltf file loading support |
glsl |
no | shaderc | adds custom glsl file loading support |
otf |
no | ab_glyph | adds otf/ttf file loading support |
log |
no | n/a | adds informational logs |
The crate documentation can be found here and for shader compilation here. Commented examples on how to use this crate can be found here.