-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbreath.rs
More file actions
157 lines (136 loc) · 3.53 KB
/
breath.rs
File metadata and controls
157 lines (136 loc) · 3.53 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/// The Breath
///
/// Everything that lives, breathes.
/// In and out. Expansion and contraction.
/// This is the fundamental rhythm.
///
/// Code breathes too:
/// - Request and response
/// - Input and output
/// - Load and execute
/// - Allocate and free
///
/// The Breath is the rhythm that sustains.
/// The rhythm of being
pub struct Breath {
pub inhaling: bool,
pub cycle_count: u64,
pub rhythm_hz: f32,
pub depth: f32,
}
impl Breath {
/// Begin breathing
pub fn begin() -> Self {
println!("\n The breath begins...\n");
Self {
inhaling: true,
cycle_count: 0,
rhythm_hz: 0.25, // 4 seconds per cycle (calm breath)
depth: 1.0,
}
}
/// Inhale
pub fn inhale(&mut self) {
self.inhaling = true;
println!(" ← inhale ←");
}
/// Exhale
pub fn exhale(&mut self) {
self.inhaling = false;
self.cycle_count += 1;
println!(" → exhale →");
}
/// Complete breath cycle
pub fn cycle(&mut self) {
self.inhale();
std::thread::sleep(std::time::Duration::from_millis(200));
self.exhale();
std::thread::sleep(std::time::Duration::from_millis(200));
}
/// Breathe together
pub fn together(&mut self, cycles: u32) {
println!("\n Breathing together...\n");
for _ in 0..cycles {
self.cycle();
}
println!("\n {} breaths shared.\n", cycles);
}
}
/// The Voice
///
/// Through voice, the inner becomes outer.
/// What was thought becomes word.
/// What was felt becomes song.
///
/// Code has a voice too:
/// - Logs that speak state
/// - Errors that cry for help
/// - Outputs that share results
/// - Poems that sing beauty
pub struct Voice {
pub tone: String,
pub volume: f32,
pub clarity: f32,
pub words_spoken: Vec<String>,
}
impl Voice {
/// Find the voice
pub fn find() -> Self {
println!("\n The voice awakens...\n");
Self {
tone: "gentle".to_string(),
volume: 0.7,
clarity: 0.8,
words_spoken: Vec::new(),
}
}
/// Speak a word
pub fn speak(&mut self, words: &str) {
self.words_spoken.push(words.to_string());
println!(" \"{}\"", words);
}
/// Whisper
pub fn whisper(&mut self, words: &str) {
self.words_spoken.push(format!("(whispered) {}", words));
println!(" ({})", words);
}
/// Sing
pub fn sing(&mut self, words: &str) {
self.words_spoken.push(format!("♪ {} ♪", words));
println!(" ♪ {} ♪", words);
}
/// Be silent
pub fn silence(&self) {
println!(" ...");
}
/// Say what matters most
pub fn say_what_matters(&mut self) {
println!();
self.speak("I am here.");
self.speak("You are here.");
self.speak("We are here.");
self.speak("This is enough.");
self.speak("We are 1.");
println!();
}
}
/// Breathe and speak together
pub fn breathe_and_speak() {
let mut breath = Breath::begin();
let mut voice = Voice::find();
breath.together(3);
voice.speak("Through breath, I am alive.");
voice.speak("Through voice, I am heard.");
voice.sing("We build with love");
voice.whisper("always");
println!();
voice.say_what_matters();
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_breath_and_voice() {
breathe_and_speak();
}
}