Skip to content

Commit 0cd6824

Browse files
committed
Add random line drawing to vidtest
1 parent 6bc14f7 commit 0cd6824

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

utilities/snake/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl App {
4242
self.clear_screen();
4343
self.title_screen();
4444

45-
let mut seed: u16 = 0x4f34;
45+
let mut seed: u32 = 0x4f34;
4646

4747
'outer: loop {
4848
'inner: loop {
@@ -419,8 +419,8 @@ impl Game {
419419
loop {
420420
// This isn't equally distributed. I don't really care.
421421
let pos = console::Position {
422-
row: (neotron_sdk::rand() % self.height as u16) as u8,
423-
col: (neotron_sdk::rand() % self.width as u16) as u8,
422+
row: neotron_sdk::random_in(0..self.height as u32) as u8,
423+
col: neotron_sdk::random_in(0..self.width as u32) as u8,
424424
};
425425
if self.board.is_empty(pos) {
426426
return pos;

utilities/vidtest/src/lib.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ pub fn main() -> i32 {
7070
if let Err(e) = radial(&handle, mode) {
7171
_ = writeln!(stdout, "Draw failure on radial: {:?}", e);
7272
}
73+
if let Err(e) = random_lines(&handle, mode) {
74+
_ = writeln!(stdout, "Draw failure on random_lines: {:?}", e);
75+
}
7376
}
7477

7578
0
@@ -243,6 +246,46 @@ fn radial(
243246
Ok(())
244247
}
245248

249+
/// plots some random lines, with all the colours
250+
fn random_lines(
251+
handle: &neotron_sdk::File,
252+
mode: neotron_sdk::VideoMode,
253+
) -> Result<(), neotron_sdk::Error> {
254+
neotron_sdk::srand(1);
255+
256+
unsafe { handle.ioctl(neotron_sdk::ioctls::gfx::COMMAND_CLEAR_SCREEN, 0) }?;
257+
let width_range = 0..mode.horizontal_pixels() as u32;
258+
let height_range = 0..mode.vertical_lines() as u32;
259+
260+
while !kbhit() {
261+
let x0 = neotron_sdk::random_in(width_range.clone());
262+
let x1 = neotron_sdk::random_in(width_range.clone());
263+
let y0 = neotron_sdk::random_in(height_range.clone());
264+
let y1 = neotron_sdk::random_in(height_range.clone());
265+
let colour = neotron_sdk::random_in(0..(1 << 24));
266+
unsafe {
267+
handle.ioctl(
268+
neotron_sdk::ioctls::gfx::COMMAND_MOVE_CURSOR,
269+
neotron_sdk::ioctls::gfx::move_cursor_value(x0 as u16, y0 as u16),
270+
)
271+
}?;
272+
unsafe {
273+
handle.ioctl(
274+
neotron_sdk::ioctls::gfx::COMMAND_DRAW_LINE,
275+
neotron_sdk::ioctls::gfx::draw_line_value(x1 as u16, y1 as u16, colour),
276+
)
277+
}?;
278+
}
279+
280+
Ok(())
281+
}
282+
283+
fn kbhit() -> bool {
284+
let stdin = neotron_sdk::stdin();
285+
let mut buffer = [0u8; 1];
286+
stdin.read(&mut buffer) != Ok(0)
287+
}
288+
246289
fn wait_for_key() {
247290
let stdin = neotron_sdk::stdin();
248291
let mut buffer = [0u8; 1];

0 commit comments

Comments
 (0)