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
158
159
160
161
162
163
164
165
|
use crate::font::BakedFont;
use crate::generated::fonts::{FONT_CHERRY_BOMB_ONE, FONT_GALMURI};
use rand::Rng;
use sdl2::pixels::{Color, PixelFormatEnum};
use sdl2::rect::Rect;
use sdl2::render::{Canvas, Texture, TextureCreator};
use sdl2::surface::Surface;
use sdl2::video::{Window, WindowContext};
use std::ops::DerefMut;
pub fn render(
canvas: &mut Canvas<Window>,
texture_creator: &TextureCreator<WindowContext>,
time_seconds: f64,
) {
let i = ((time_seconds * 60.0) % 510.0).round();
let i = if i > 255.0 {
(255.0 - (i - 255.0)) as u8
} else {
i as u8
};
let sin_offset = time_seconds * 0.1;
let win_size = canvas.window().drawable_size();
canvas.set_draw_color(Color::RGB(12, 12, 12));
canvas.clear();
let mut offset: f32 = 0.0;
{
let bounce_time_offset = 1.5;
let bounce_speed = 90.0;
let padding_x = 16.0;
let padding_y = 16.0;
let (offset_x, offset_y) = if time_seconds > bounce_time_offset {
let mut uwu_width = padding_x;
let mut uwu_height: f32 = padding_y * 2.0;
for c in "UwU-Space".chars() {
let char = FONT_CHERRY_BOMB_ONE.get_char(c);
uwu_width += char.advance_width;
if f32::from(char.height) > uwu_height {
uwu_height = char.height.into();
}
}
let virtual_screen_size = (
f64::from(win_size.0) - f64::from(uwu_width + padding_x),
f64::from(win_size.1) - f64::from(uwu_height + padding_y),
);
let t = (time_seconds - bounce_time_offset) * bounce_speed;
let offset_x = t % (virtual_screen_size.0 * 2.0);
let offset_x = if offset_x > virtual_screen_size.0 {
virtual_screen_size.0 * 2.0 - offset_x
} else {
offset_x
};
let offset_y = t % (virtual_screen_size.1 * 2.0);
let offset_y = if offset_y > virtual_screen_size.1 {
virtual_screen_size.1 * 2.0 - offset_y
} else {
offset_y
};
(
(f64::from(padding_x) + offset_x).round() as i32,
(f64::from(padding_y) + offset_y).round() as i32,
)
} else {
(padding_x.round() as i32, padding_y.round() as i32)
};
for c in "UwU-Space".chars() {
let char = FONT_CHERRY_BOMB_ONE.get_char(c);
canvas
.copy(
&char
.to_texture(&texture_creator, Color::RGB(i, 64, 255 - i))
.unwrap(),
None,
char.to_rect(offset as i32 + offset_x, offset_y),
)
.unwrap();
offset += char.advance_width;
}
}
offset = 0.0;
let mut rng = rand::thread_rng();
for c in "sorry for shit invite we have adhd".chars() {
let char = FONT_GALMURI.get_char(c);
canvas
.copy(
&char
.to_texture(&texture_creator, Color::RGB(i, 64, 255 - i))
.unwrap(),
None,
char.to_rect(
offset as i32 + 18 + rng.gen_range(-2..2),
16 + 36 + rng.gen_range(-2..2),
),
)
.unwrap();
offset += char.advance_width / 1.0;
}
{
let mut sin_surface = Surface::new(512, 256, PixelFormatEnum::RGBA32).unwrap();
let w = sin_surface.width();
let h = sin_surface.height();
let f = &mut sin_surface.deref_mut().without_lock_mut().unwrap();
for x in 0..w {
let f64_w = f64::from(w);
let f64_h = f64::from(h);
let sin_x = {
let mut sin_x = f64::from(x) + (sin_offset * f64_w);
if sin_x > f64_w {
sin_x = sin_x - f64_w;
}
sin_x
};
let sin_y =
((f64::sin(sin_x * (3.141 * 2.0) / f64_w) + 1.0) * (f64_h / 2.0)).floor() as usize;
// let sin_idx = (sin_y * w as usize + x as usize) * 4;
for y in 0..h {
let idx = (y * w + x) as usize * 4;
f[idx] = 122 - (x / 8) as u8;
f[idx + 1] = 255 - (x / 2) as u8;
f[idx + 2] = (x / 2) as u8;
f[idx + 3] = if sin_y < y as usize {
if idx % 5 == 0 {
255
} else {
122
}
} else {
0
};
}
}
let sin_texture = Texture::from_surface(&sin_surface, &texture_creator).unwrap();
canvas
.copy(&sin_texture, None, Rect::new(0, 0, win_size.0, win_size.1))
.unwrap();
}
offset = 0.0;
for c in "Come to Cosin25 :3".chars() {
let char = FONT_GALMURI.get_char(c);
canvas
.copy(
&char
.to_texture(&texture_creator, Color::RGB(i, 64, 255 - i))
.unwrap(),
None,
char.to_rect(offset as i32 + 18, win_size.1 as i32 - 32),
)
.unwrap();
offset += char.advance_width / 1.1;
}
}
|