bibl.pixi (2400B)
1 // ========== 2 // Draw a grid within a given box 3 // ---------- 4 // IN: 5 // * INT(gs) - cell size 6 // * INT(x) - box x 7 // * INT(y) - box y 8 // * INT(w) - box width 9 // * INT(h) - box height 10 // * PIXEL(col) - box color 11 // ---------- 12 // ========== 13 fn grid($gs, $x, $y, $w, $h, $col) { 14 // draw vert stripes 15 $i = 0 16 while $i <= ($w / $gs - 2) { 17 $i = $i + 1 18 $indent = $gs * $i 19 20 line($x + $indent, $y, $x + $indent, $h - abs($y) - 1, $col) 21 } 22 23 // draw horiz stripes 24 $i = 0 25 while $i <= ($h / $gs - 2) { 26 $i = $i + 1 27 $indent = $gs * $i 28 29 line($x, $y + $indent, $w - abs($x) - 1, $y + $indent, $col) 30 } 31 } 32 33 34 // ========== 35 // Direct conversion of INT to STR 36 // ---------- 37 // IN: 38 // * INT(num) 39 // ---------- 40 // OUT: 41 // * STR(num) 42 // ========== 43 fn n2s($num) { 44 $str="" 45 sprintf($str, "%d", $num) 46 47 ret($str) 48 } 49 50 51 // ========== 52 // Refresh & print function 53 // ---------- 54 // IN: 55 // * STR(str) - string to print 56 // * INT(x) - x coordinate 57 // * INT(y) - y coordinate 58 // * PIXEL(f_col) - string color 59 // * PIXEL(b_col) - background color 60 // ---------- 61 // ========== 62 fn rprint($str, $x, $y, $f_col, $b_col) { 63 $x_size = get_text_xsize($str) + 10 64 $y_size = get_text_ysize($str) + 5 65 66 $x_coord = $x - ($x_size / 2) 67 $y_coord = $y - ($y_size / 2) 68 69 // color previously printed string 70 fbox($x_coord, $y_coord, $x_size, $y_size, $b_col) 71 // print string 72 print($str, $x, $y, $f_col) 73 } 74 75 76 // ========== 77 // Get pixel's color at given coordinates 78 // ---------- 79 // IN: 80 // * INT(x) - pixel x 81 // * INT(y) - pixel y 82 // ---------- 83 // OUT: 84 // * PIXEL(col) 85 // ========== 86 fn get_pixel_color($x, $y) { 87 // get screen dimensions 88 $w = WINDOW_XSIZE 89 $h = WINDOW_YSIZE 90 91 $r = new($w, $h, INT16) 92 $g = new($w, $h, INT16) 93 $b = new($w, $h, INT16) 94 // split the screen on RED GREEN and BLUE 95 // and get an array 1D array of color values 96 split_rgb(0, get_screen(), $r, $g, $b) 97 98 // convert coordinates to the array index 99 $from_above = (($h / 2) - abs($y) + 1) * $w 100 $from_right = ($w / 2) - $x 101 $index = $from_above - $from_right 102 103 // join RED GREEN and BLUE values 104 $color = get_color($r[$index], $g[$index], $b[$index]) 105 106 // remove arrays from the memory 107 remove($r) 108 remove($g) 109 remove($b) 110 111 ret($color) 112 }