-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircle_lines.rs
132 lines (108 loc) · 3.18 KB
/
circle_lines.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use nannou::prelude::*;
use nannou::app::Draw;
use core::iter::Map;
use std::cell::RefCell;
use nannou::noise::*;
fn main() {
nannou::app(model).update(update).run();
}
struct Model {
circle_steps: usize,
incrementing: bool,
}
fn model(app: &App) -> Model {
app.set_loop_mode(LoopMode::rate_fps(30.0));
let _window = app
.new_window()
.with_dimensions(800, 400)
.view(view)
.key_released(key_released)
.build()
.unwrap();
Model {
circle_steps: 1,
incrementing: true
}
}
fn key_released(_app: &App, model: &mut Model, key: Key) {
if key == nannou::winit::VirtualKeyCode::Down {
model.circle_steps -= 1;
}
if key == nannou::winit::VirtualKeyCode::Up {
model.circle_steps += 1;
}
}
fn update(_app: &App, model: &mut Model, _update: Update) {
if model.incrementing {
if model.circle_steps == 180 {
model.incrementing = false;
} else {
model.circle_steps += 1;
}
} else {
if model.circle_steps == 1 {
model.incrementing = true;
} else {
model.circle_steps -= 1;
}
}
}
fn custom_noise(value: f32) -> f32 {
let pow = value as i32 % 11;
value.sin().powi(pow)
}
// fn circle_points<'a>(radius: &f32) -> impl Iterator< Item = &eom::vertex::Srgba<nannou::geom::vector::Vector2>> {
fn circle_points<'a>(radius: &f32) -> Vec<geom::vector::Vector2> {
let mut new_radius = *radius;
let noise = Perlin::new();
let mut radius_noise = 0.0;
let points = (0..361).step_by(1).map( |p| {
let new_noise = noise.get([1.0, radius_noise as f64]) as f32;
let cust_noise = custom_noise(radius_noise);
let to_add = cust_noise * 10.0;
radius_noise += 0.1;
let rad = deg_to_rad(p as f32);
let x = radius * rad.sin();
let y = radius * rad.cos();
pt2(x,y)
});
points.collect::<Vec<_>>()
}
fn view(app: &App, model: &Model, frame: &Frame) {
// Begin drawing
let win = app.window_rect();
let t = app.time;
let draw = app.draw();
// Clear the background to blue.
draw.background().color(BLACK);
let offset = 40;
let win_x = win.w() / 2.0;
let win_y = win.h() / 2.0;
let radius = 50.0;
let rgba = srgba(1.0, 1.0, 1.0,1.0);
let points = circle_points(&radius);
let vertexes = points.clone().into_iter().map( |p| {
geom::vertex::Srgba(p, rgba)
}).collect::<Vec<_>>();
let mut iter = 1;
for i in (-3..4) {
for j in (-3..4) {
let vertices = points.clone().into_iter().map( |p| {
let x = p.x + (j as f32 * radius) * 2.0;
let y = p.y - (i as f32 * radius) * 2.0;
let pt = pt2(x, y);
pt
}).collect::<Vec<_>>();
for (i, vertex) in vertices.iter().step_by(iter).enumerate() {
let index = &vertexes.len() - i - 1;
let verts = [vertex, &vertices[index]];
let points = verts.iter().map( |point| {
pt2(point.x, point.y)
});
draw.polyline().weight(0.2).points(points);
}
iter += 1;
}
}
draw.to_frame(app, &frame).unwrap();
}