@@ -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+
246289fn wait_for_key ( ) {
247290 let stdin = neotron_sdk:: stdin ( ) ;
248291 let mut buffer = [ 0u8 ; 1 ] ;
0 commit comments