MCPcopy Create free account
hub / github.com/chyyuu/os_kernel_lab / draw

Method draw

user/src/bin/gui_snake.rs:213–240  ·  view source on GitHub ↗
(&mut self, target: &mut D)

Source from the content-addressed store, hash-verified

211 self.snake.set_direction(direction);
212 }
213 pub fn draw<D>(&mut self, target: &mut D) -> ()
214 where
215 D: DrawTarget<Color = T>,
216 {
217 self.snake.make_step();
218 let hit = self.snake.contains(self.food.get_pixel().0);
219 if hit {
220 self.snake.grow();
221 }
222 self.food_age += 1;
223 if self.food_age >= self.food_lifetime || hit {
224 self.food.replace(&self.snake);
225 self.food_age = 0;
226 }
227
228 let mut scaled_display = ScaledDisplay::<D> {
229 real_display: target,
230 size_x: self.size_x / self.scale_x,
231 size_y: self.size_y / self.scale_y,
232 scale_x: self.scale_x,
233 scale_y: self.scale_y,
234 };
235
236 for part in self.snake.into_iter() {
237 _ = part.draw(&mut scaled_display);
238 }
239 _ = self.food.get_pixel().draw(&mut scaled_display);
240 }
241}
242
243/// A dummy DrawTarget implementation that can magnify each pixel so the user code does not need to adapt for scaling things

Callers 6

draw_iterMethod · 0.80
mainFunction · 0.80
paintMethod · 0.80
unpaintMethod · 0.80
paintMethod · 0.80
unpaintMethod · 0.80

Calls 6

make_stepMethod · 0.80
containsMethod · 0.80
get_pixelMethod · 0.80
growMethod · 0.80
replaceMethod · 0.80
into_iterMethod · 0.45

Tested by

no test coverage detected