[spircles] a
parent
ad5a2276cc
commit
e79e93b623
|
@ -169,13 +169,6 @@ version = "0.1.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
|
||||
|
||||
[[package]]
|
||||
name = "circle"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"nannou",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clipboard-win"
|
||||
version = "2.2.0"
|
||||
|
@ -2302,6 +2295,13 @@ dependencies = [
|
|||
"smithay-client-toolkit 0.6.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spircles"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"nannou",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spirv_cross"
|
||||
version = "0.23.1"
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "spircles"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
nannou = "0.17"
|
|
@ -0,0 +1,83 @@
|
|||
use nannou::prelude::*;
|
||||
|
||||
fn main() {
|
||||
nannou::app(model).update(update).simple_window(view).run();
|
||||
}
|
||||
|
||||
struct Model {}
|
||||
|
||||
fn model(_app: &App) -> Model {
|
||||
Model {}
|
||||
}
|
||||
|
||||
fn update(_app: &App, _model: &mut Model, _update: Update) {}
|
||||
|
||||
const fn color(red: u8, green: u8, blue: u8) -> Rgb<u8> {
|
||||
Rgb {
|
||||
red,
|
||||
green,
|
||||
blue,
|
||||
standard: std::marker::PhantomData::<nannou::color::encoding::Srgb>,
|
||||
}
|
||||
}
|
||||
|
||||
const BG: Rgb<u8> = color(0, 5, 5);
|
||||
const BALL: Rgb<u8> = color(255, 255, 255);
|
||||
|
||||
const COLORS: &[Rgb<u8>] = &[
|
||||
color(125, 22, 22),
|
||||
color(107, 19, 16),
|
||||
color(69, 15, 16),
|
||||
color(72, 0, 50),
|
||||
color(223, 0, 84),
|
||||
color(255, 139, 106),
|
||||
color(255, 214, 194),
|
||||
];
|
||||
|
||||
const fn sm_color(i: i32, j: i32) -> Rgb<u8> {
|
||||
if i == 0 && j == 0 {
|
||||
BG
|
||||
} else {
|
||||
BALL
|
||||
}
|
||||
}
|
||||
const fn bg_color(i: i32, j: i32) -> Rgb<u8> {
|
||||
if i == 0 && j == 0 {
|
||||
return BALL;
|
||||
}
|
||||
|
||||
let x = i * i * i * j + j * j + 3 + i + j + i * j;
|
||||
COLORS[x.abs() as usize % COLORS.len()]
|
||||
}
|
||||
|
||||
fn view(app: &App, _model: &Model, frame: Frame) {
|
||||
let draw = app.draw();
|
||||
|
||||
draw.background().color(BG);
|
||||
|
||||
for i in -4..=4 {
|
||||
for j in -4..=4 {
|
||||
let speed = map_range((i + j).abs() as f32, 0.0, 8.0, 0.1, 2.0);
|
||||
let dis = (app.time * speed).sin() * 10.0;
|
||||
|
||||
let circ_offset = vec2(
|
||||
(app.time + (i * i) as f32).sin() * dis,
|
||||
(app.time + (j * i) as f32).cos() * dis,
|
||||
);
|
||||
|
||||
let x = i as f32 * 100.0 * (app.time * 0.7).sin();
|
||||
let y = j as f32 * 100.0 * (app.time * 0.7).cos();
|
||||
|
||||
draw.ellipse()
|
||||
.w_h(40.0, 40.0)
|
||||
.x_y(x + circ_offset.x, y + circ_offset.y)
|
||||
.color(bg_color(i, j));
|
||||
draw.ellipse()
|
||||
.w_h(10.0, 10.0)
|
||||
.x_y(x, y)
|
||||
.color(sm_color(i, j));
|
||||
}
|
||||
}
|
||||
|
||||
draw.to_frame(app, &frame).unwrap();
|
||||
}
|
Loading…
Reference in New Issue