Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
This commit also assigns correct version to each internal package.
  • Loading branch information
cbgbt committed Nov 19, 2024
1 parent 75c3237 commit d4a3230
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ members = [

[workspace.dependencies]
raydeon = { path = "./raydeon", version = "0.2" }
pyrayeon = { path = "./pyraydeon", version = "0.1" }
pyrayeon = { path = "./pyraydeon", version = "0.1.0-alpha" }

anyhow = "1"
cgmath = "0.17"
Expand Down
165 changes: 90 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,90 @@
## raydeon
A port of Michael Fogleman's [ln](https://github.com/fogleman/ln) in Rust. Like Michael, I also developed this to plot images with a [pen plotter](https://shop.evilmadscientist.com/productsmenu/846).
To steal his words (because this port isn't theft enough):

> The output of an OpenGL pipeline is a rastered image. The output of raydeon is a set of 2D vector paths.
![](/examples/cityscape.png)

Currently less featureful and probably also less performant than the prior art. The name is only different because the planned featureset diverges from `ln` in crucial ways.

## Example
Draws the cube which is included as an example in the original `ln` repo.

```rust
use lnrs::shapes::RectPrism;
use lnrs::{Camera, Scene, WPoint3, WVec3};

fn main() {
let scene = Scene::new(vec![Box::new(Cube::new(
WVec3::new(-1.0, -1.0, -1.0),
WVec3::new(1.0, 1.0, 1.0)
))]);

let eye = WPoint3::new(4.0, 3.0, 2.0);
let focus = WVec3::new(0.0, 0.0, 0.0);
let up = WVec3::new(0.0, 0.0, 1.0);

let fovy = 50.0;
let width = 1024.0;
let height = 1024.0;
let znear = 0.1;
let zfar = 10.0;

let camera = Camera::look_at(eye, focus, up)
.perspective(fovy, width, height, znear, zfar);

let line_chop_len = 0.1;

let paths = scene.render(camera, line_chop_len);

// We currently don't have any functionality to aid in emitting SVG images, so you will
// be required to use the [svg crate.](https://crates.io/crates/svg)
let mut svg_doc = svg::Document::new()
.set("width", "8in")
.set("height", "8in")
.set("viewBox", (0, 0, width, height))
.set("stroke-width", "0.7mm")
.set("stroke", "black")
.set("fill", "none")
.add(svg::node::element::Rectangle::new()
.set("x", 0)
.set("y", 0)
.set("width", "100%")
.set("height", "100%")
.set("fill", "white"));

// We have to flip the y-axis in our svg...
let mut item_group = svg::node::element::Group::new()
.set("transform", format!("translate(0, {}) scale(1,-1)", height));

for (p1, p2) in &paths.lines {
item_group = item_group.add(svg::node::element::Line::new()
.set("x1", p1.x)
.set("y1", p1.y)
.set("x2", p2.x)
.set("y2", p2.y));
}

svg_doc = svg_doc.add(item_group);

svg::save("out.svg", &svg_doc);
}
```

![](/examples/cube.png)
## raydeon

A port of Michael Fogleman's [ln](https://github.com/fogleman/ln) in Rust, with
exposed bindings for Python. Like Michael, I also developed this to plot images
with a [pen plotter](https://shop.evilmadscientist.com/productsmenu/846). To
steal his words (because this port isn't theft enough):

> The output of an OpenGL pipeline is a rastered image. The output of raydeon is
> a set of 2D vector paths.
![](/raydeon/examples/cityscape.png)

Currently less featureful though probably more performant than the prior art.

## Example

Have a look at any of the [Rust examples](/raydeon/examples) or
[Python examples](/pyraydeon/examples/).

The following Rust code draws the cube which is included as an example in the
original `ln` repo.

```rust
use raydeon::shapes::RectPrism;
use raydeon::{Camera, Scene, WPoint3, WVec3};
use std::sync::Arc;

fn main() {
env_logger::Builder::from_default_env()
.format_timestamp_nanos()
.init();

let scene = Scene::new(vec![Arc::new(RectPrism::new(
WVec3::new(-1.0, -1.0, -1.0),
WVec3::new(1.0, 1.0, 1.0),
))]);

let eye = WPoint3::new(4.0, 3.0, 2.0);
let focus = WVec3::new(0.0, 0.0, 0.0);
let up = WVec3::new(0.0, 0.0, 1.0);

let fovy = 50.0;
let width = 1024.0;
let height = 1024.0;
let znear = 0.1;
let zfar = 10.0;

let camera = Camera::look_at(eye, focus, up).perspective(fovy, width, height, znear, zfar);

let paths = scene.attach_camera(camera).render();

// We currently don't have any functionality to aid in emitting SVG images, so you will
// be required to use the [svg crate.](https://crates.io/crates/svg)
let mut svg_doc = svg::Document::new()
.set("width", "8in")
.set("height", "8in")
.set("viewBox", (0, 0, width, height))
.set("stroke-width", "0.7mm")
.set("stroke", "black")
.set("fill", "none")
.add(
svg::node::element::Rectangle::new()
.set("x", 0)
.set("y", 0)
.set("width", "100%")
.set("height", "100%")
.set("fill", "white"),
);

// We have to flip the y-axis in our svg...
let mut item_group = svg::node::element::Group::new()
.set("transform", format!("translate(0, {}) scale(1,-1)", height));

for path in paths {
let (p1, p2) = (path.p1, path.p2);
item_group = item_group.add(
svg::node::element::Line::new()
.set("x1", p1.x)
.set("y1", p1.y)
.set("x2", p2.x)
.set("y2", p2.y),
);
}

svg_doc = svg_doc.add(item_group);
println!("{}", svg_doc);
}
```

![](/raydeon/examples/cube.png)
2 changes: 1 addition & 1 deletion pyraydeon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyraydeon"
version = "0.1.0"
version = "0.1.0-alpha"
edition = "2021"
publish = false

Expand Down
1 change: 1 addition & 0 deletions pyraydeon/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ build-backend = "maturin"

[project]
name = "pyraydeon"
version = "0.1.0-alpha"
requires-python = ">=3.9"
dependencies = []
classifiers = [
Expand Down
3 changes: 1 addition & 2 deletions raydeon/examples/cube.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::Arc;

use raydeon::shapes::RectPrism;
use raydeon::{Camera, Scene, WPoint3, WVec3};
use std::sync::Arc;

fn main() {
env_logger::Builder::from_default_env()
Expand Down

0 comments on commit d4a3230

Please sign in to comment.