Expand description
§3D Sphere Rendering
Advanced 3D sphere rendering with realistic lighting, texture mapping, and perspective projection. This module provides a complete 3D rendering pipeline optimized for generative art applications.
§Key Features
- Realistic Lighting: Multiple light sources with diffuse and specular reflection
- Texture Mapping: Apply 2D canvases as textures on 3D spheres
- 3D Rotation: Rotate spheres around X, Y, and Z axes
- Perspective Projection: Realistic perspective with configurable focal length
- Multiple Lights: Support for multiple light sources
§Basic Usage
use wassily_algorithms::*;
use wassily_core::*;
// Create a texture
let mut texture = Canvas::new(256, 256);
texture.fill(*BLUE);
// Set up a basic scene
let scene = SphereScene::basic(pt3(0.0, 0.0, 100.0), &texture);
// Render to output
let mut output = Canvas::new(800, 600);
render_sphere(&scene, &mut output);
§Advanced Lighting
use wassily_algorithms::*;
use wassily_core::*;
let texture = Canvas::new(256, 256);
// Create lights
let lights = vec![
Light::new(pt3(-10.0, 10.0, 5.0), *WHITE, 0.8),
Light::new(pt3(10.0, -5.0, 10.0), *BLUE, 0.3),
];
// Set up scene with custom lighting
let scene = SphereScene::new(
pt3(0.0, 0.0, 0.0), // camera position
400.0, // focal length
pt3(0.0, 0.0, 100.0), // sphere center
50.0, // sphere radius
&texture,
0.1, 0.2, 0.0, // rotation angles
lights,
Some(32.0), // specular exponent
);
§Components
SphereScene
: Complete scene configurationLight
: Light source definition- Main rendering function for sphere scenes
Structs§
- Light
- Sphere
Scene - Configuration for a 3D sphere rendering scene.