1#[cfg(target_os = "unix")]
2use crate::ubuntu_terminal_sceme::*;
3#[cfg(target_os = "linux")]
4use crate::ubuntu_terminal_sceme::*;
5#[cfg(target_os = "windows")]
6use crate::windows_cmd_sceme::*;
7pub enum PixelColors{
9 Red,
10 Green,
11 Yellow,
12 Blue,
13 Black,
14 Cyan,
15 Magenta,
16 White,
17}
18pub struct Screen{
20 width:u8,
21 height:u8,
22 color:PixelColors,
23 pixel_vec:Vec<Vec<u8>>,
24}
25impl Screen{
27 pub fn new(width:u8,height:u8,color:PixelColors)->Option<Screen>{
35 if height == 0 || width == 0{
36 return None;
37 }
38 let mut vec1 = Vec::new();
39 let mut pixel_vec = Vec::new();
40 for i in 0..height{
41 for j in 0..width{
42 &vec1.push(0);
43 }
44 &pixel_vec.push(vec1);
45 vec1 = Vec::new();
46 }
47 let screen1 = Screen{width,height,color,pixel_vec,};
48 Some(screen1)
49 }
50 pub fn print_screen(&self){
52 for y in &self.pixel_vec{
53 for x in y{
54 if *x==0{
55 match self.color{
56 PixelColors::Red=>print!("{}",RedScr),
57 PixelColors::Blue=>print!("{}",BlueScr),
58 PixelColors::Green=>print!("{}",GreenScr),
59 PixelColors::Yellow=>print!("{}",YellowScr),
60 PixelColors::Black=>print!("{}",BlackScr),
61 PixelColors::Magenta=>print!("{}",MagentaScr),
62 PixelColors::Cyan=>print!("{}",CyanScr),
63 PixelColors::White=>print!("{}",WhiteScr),
64 }
65 }else{
66 match *x{
67 1=>print!("{}",RedScr),
68 2=>print!("{}",BlueScr),
69 3=>print!("{}",GreenScr),
70 4=>print!("{}",YellowScr),
71 5=>print!("{}",BlackScr),
72 6=>print!("{}",CyanScr),
73 7=>print!("{}",MagentaScr),
74 8=>print!("{}",WhiteScr),
75 _=>print!("impossible"),
76 }
77 }
78 print!(" ");
79 print!("{}",CLOSING_COLOR);
80 }
81 print!("\n");
82 }
83 }
84 pub fn attach_pixels(&mut self,shape:&Vec<Vec<u8>>,x:u8,y:u8)->Result<(),&str>{
86 if x>self.width{
87 return Err("out of bounds! width is too big");
88 }
89 if x>self.height{
90 return Err("out of bounds! height is too big");
91 }
92 let mut cor_x = (x) as usize;
93 let mut cor_y = y as usize;
94 for i in shape{
95 for j in i{
96 if *j>0{
97 self.pixel_vec[cor_y][cor_x]=*j;
98 }else if *j>8{
99 return Err("no such color");
100 }
101 cor_x+=1;
102 }
103 cor_y+=1;
104 cor_x = (x) as usize;
105 }
106 Ok(())
107 }
108 pub fn attach(&mut self,canvas:&Canvas,x:u8,y:u8)->Result<(),&str>{
121 if x>self.width{
122 return Err("out of bounds! width is too big");
123 }
124 if x>self.height{
125 return Err("out of bounds! height is too big");
126 }
127 let mut cor_x = (x) as usize;
128 let mut cor_y = y as usize;
129 let vec55 = &canvas.pixel_vec;
130 for i in vec55{
131 for j in i{
132 if *j>0{
133 self.pixel_vec[cor_y][cor_x]=*j;
134 }else if *j>8{
135 return Err("no such color");
136 }
137 cor_x+=1;
138 }
139 cor_y+=1;
140 cor_x = (x) as usize;
141 }
142 Ok(())
143 }
144 pub fn dittach(&mut self,canvas:&Canvas,x:u8,y:u8)->Result<(),&str>{
158 if x>self.width{
159 return Err("out of bounds! width is too big");
160 }
161 if x>self.height{
162 return Err("out of bounds! height is too big");
163 }
164 let mut cor_x = x as usize;
165 let mut cor_y = y as usize;
166 let vec55 = &canvas.pixel_vec;
167 for i in vec55{
168 for j in i{
169 if *j>0{
170 self.pixel_vec[cor_y][cor_x]=0;
171 }else if *j>8{
172 return Err("no such color");
173 }
174 cor_x+=1;
175 }
176 cor_y+=1;
177 cor_x = x as usize;
178 }
179 Ok(())
180 }
181 pub fn dittach_pixels(&mut self,shape:&Vec<Vec<u8>>,x:u8,y:u8)->Result<(),&str>{
194 if x>self.width{
195 return Err("out of bounds! width is too big");
196 }
197 if x>self.height{
198 return Err("out of bounds! height is too big");
199 }
200 let mut cor_x = x as usize;
201 let mut cor_y = y as usize;
202 for i in shape{
203 for j in i{
204 if *j>0{
205 self.pixel_vec[cor_y][cor_x]=0;
206 }else if *j>8{
207 return Err("no such color");
208 }
209 cor_x+=1;
210 }
211 cor_y+=1;
212 cor_x = x as usize;
213 }
214 Ok(())
215 }
216}
217pub struct Canvas{
219 width:u8,
220 height:u8,
221 color:PixelColors,
222 pixel_vec:Vec<Vec<u8>>,
223}
224impl Canvas{
225 pub fn new(width:u8,height:u8,color:PixelColors)->Option<Canvas>{
227 if height == 0 || width == 0{
228 return None;
229 }
230 let mut vec1 = Vec::new();
231 let mut pixel_vec = Vec::new();
232 for i in 0..height{
233 for j in 0..width{
234 &vec1.push(0);
235 }
236 &pixel_vec.push(vec1);
237 vec1 = Vec::new();
238 }
239 let canvas1 = Canvas{width,height,color,pixel_vec,};
240 Some(canvas1)
241 }
242 #[cfg(debug_assertions)]
244 pub fn print_canvas(&self){
245 for y in &self.pixel_vec{
246 for x in y{
247 if *x==0{
248 match self.color{
249 PixelColors::Red=>print!("{}",RedScr),
250 PixelColors::Blue=>print!("{}",BlueScr),
251 PixelColors::Green=>print!("{}",GreenScr),
252 PixelColors::Yellow=>print!("{}",YellowScr),
253 PixelColors::Black=>print!("{}",BlackScr),
254 PixelColors::Magenta=>print!("{}",MagentaScr),
255 PixelColors::Cyan=>print!("{}",CyanScr),
256 PixelColors::White=>print!("{}",WhiteScr),
257 }
258 }else{
259 match *x{
260 1=>print!("{}",RedScr),
261 2=>print!("{}",BlueScr),
262 3=>print!("{}",GreenScr),
263 4=>print!("{}",YellowScr),
264 5=>print!("{}",BlackScr),
265 6=>print!("{}",CyanScr),
266 7=>print!("{}",MagentaScr),
267 8=>print!("{}",WhiteScr),
268 _=>print!("impossible"),
269 }
270 }
271 print!(" ");
272 print!("{}",CLOSING_COLOR);
273 }
274 print!("\n");
275 }
276 }
277 pub fn attach(&mut self,shape:&Vec<Vec<u8>>,x:u8,y:u8)->Result<(),&str>{
279 if x>self.width{
280 return Err("out of bounds! width is too big");
281 }
282 if x>self.height{
283 return Err("out of bounds! height is too big");
284 }
285 let mut cor_x = (x) as usize;
286 let mut cor_y = y as usize;
287 for i in shape{
288 for j in i{
289 if *j>0{
290 self.pixel_vec[cor_y][cor_x]=*j;
291 }else if *j>8{
292 return Err("no such color");
293 }
294 cor_x+=1;
295 }
296 cor_y+=1;
297 cor_x = (x) as usize;
298 }
299 Ok(())
300 }
301 pub fn dittach(&mut self,shape:&Vec<Vec<u8>>,x:u8,y:u8)->Result<(),&str>{
303 if x>self.width{
304 return Err("out of bounds! width is too big");
305 }
306 if x>self.height{
307 return Err("out of bounds! height is too big");
308 }
309 let mut cor_x = x as usize;
310 let mut cor_y = y as usize;
311 for i in shape{
312 for j in i{
313 if *j>0{
314 self.pixel_vec[cor_y][cor_x]=0;
315 }else if *j>8{
316 return Err("no such color");
317 }
318 cor_x+=1;
319 }
320 cor_y+=1;
321 cor_x = x as usize;
322 }
323 Ok(())
324 }
325}