ry-science
Science module for Ry-Dit — Bezier curves, Statistics, Geometry, Optical illusions
Overview
ry-science is a mathematics and geometry library for the Ry-Dit game engine. It provides Bezier curve calculations, statistical functions, and geometric optical illusion generators — all accessible via a clean JSON-based API.
Features
📈 Bezier Curves
- Linear — Interpolation between 2 points:
P(t) = (1-t)·P0 + t·P1 - Quadratic — 2 points + 1 control point
- Cubic — 2 points + 2 control points (industry standard for animation)
📊 Statistics
- Mean — Arithmetic average
- Median — Middle value of sorted array
- Min / Max — Extremes of dataset
🔷 Geometry (Optical Illusions)
- Penrose Triangle — Impossible tribar
- Impossible Cube — Necker cube variant
- Archimedean Spiral — Parametric spiral points
- Müller-Lyer — Arrow length illusion
- Ponzo — Perspective length illusion
Installation
[]
= "0.7.34"
= "0.8.2"
= "1.0"
Quick Start
use ScienceModule;
use RyditModule;
use json;
let module = ScienceModule;
// Bezier cubic curve
let point = module.execute?;
// Returns: [50.0, 75.0]
// Statistics
let mean = module.execute?;
// Returns: 3.0
let median = module.execute?;
// Returns: 2.5
// Geometry - Penrose triangle coordinates
let lines = module.execute?;
// Returns: [[x1,y1,x2,y2], ...] — lines to draw
API Reference
Bezier Curves
Linear (2 points)
module.execute
Formula: P(t) = (1-t)·P0 + t·P1
Quadratic (3 points)
module.execute
Formula: P(t) = (1-t)²·P0 + 2(1-t)·t·P1 + t²·P2
Cubic (4 points)
module.execute
Formula: P(t) = (1-t)³·P0 + 3(1-t)²·t·P1 + 3(1-t)·t²·P2 + t³·P3
| Parameter | Type | Description |
|---|---|---|
p0..pN |
f64 | Control point coordinates (x, y pairs) |
t |
f64 | Parameter (0.0–1.0, clamped automatically) |
Returns: [x, y] — point on curve at parameter t
Statistics
module.execute // Returns: 2.0
module.execute // Returns: 2.5
module.execute // Returns: 1.0
module.execute // Returns: 4.0
| Function | Input | Output |
|---|---|---|
stats::mean |
[f64, ...] |
f64 average |
stats::median |
[f64, ...] |
f64 middle value |
stats::min |
[f64, ...] |
f64 minimum |
stats::max |
[f64, ...] |
f64 maximum |
Geometry (Optical Illusions)
Penrose Triangle
module.execute
Returns: [[x1,y1,x2,y2], ...] — 12 lines forming the impossible triangle.
Impossible Cube
module.execute
Returns: 14 lines forming an ambiguous/Necker cube.
Archimedean Spiral
module.execute
Returns: [[x, y], ...] — parametric spiral points.
Müller-Lyer Illusion
module.execute
Returns: 10 lines forming the classic arrow illusion.
Ponzo Illusion
module.execute
Returns: 6 lines forming the perspective illusion.
Examples
Smooth Animation Path
// Create a smooth animation path using cubic Bezier
let control_points = ;
for frame in 0..60
Data Analysis
// Analyze game scores
let scores = json!;
let mean = ScienceModule.execute.unwrap;
let median = ScienceModule.execute.unwrap;
let max = ScienceModule.execute.unwrap;
println!;
Drawing Optical Illusions
// Draw a Penrose triangle using the returned coordinates
let lines = ScienceModule.execute.unwrap;
for line in lines.as_array.unwrap
LAZOS Protocol
# Bezier curve
|
# Statistics
|
# Geometry
|
Performance
- O(n) Bezier — Single evaluation, no iterations
- O(n log n) Median — Sort-based, efficient for typical datasets
- Zero allocations for statistical functions (single-pass where possible)
- 21 unit tests ensuring correctness across all functions
Dependencies
| Crate | Version | Purpose |
|---|---|---|
ry-core |
0.8.2 | Module trait system |
serde_json |
1.0 | JSON serialization |
serde |
1.0 | Derive macros |
Roadmap
- Higher-order Bezier curves (N control points)
- Standard deviation and variance
- Percentile calculations
- More optical illusions (Kanizsa triangle, Hering illusion)
- Fractal generation (Mandelbrot, Koch snowflake)
Contributing
Contributions are welcome! This crate is part of the Ry-Dit game engine project.
- Repository: https://github.com/lapumlbb18-blip/Ry-dit
- Issues: https://github.com/lapumlbb18-blip/Ry-dit/issues
- Pull Requests: Welcome!
Please read CONTRIBUTING.md for guidelines.
License
MIT License - See LICENSE for details.
ry-science — Math, stats, and geometry for Ry-Dit game engine 📐📊
21 tests · 988 lines · Bezier + Stats + 5 optical illusions