/* Copyright (C) 2011, Stephane Bisaro, aka iri License : you can do what you want with this source code This code is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */ /* With the 2dOS API : - Colorize a bitmap pixel by pixel - Create a gauge See http://www.scolring.org/files/doc_html/bitmap.html _GETpixel24 retrieves the color of a pixel _PUTpixel24 sets a color of a pixel */ typeof window = ObjWin;; typeof gauge = ObjWin;; typeof text = ObjText;; typeof bmp = ObjBitmap;; typeof bmpgauge = ObjBitmap;; /* Draw a rectangle with the wiodth is equal to the progress and repaint the gauge. Return the same value. Prototype : fun [I] I */ fun setGauge (value)= _DRAWrectangle bmpgauge 0 0 value 16 DRAW_SOLID 1 0xFF0000 DRAW_SOLID 0xFF0000; _PAINTwindow gauge; value;; /* Set the color for each pixel. If the pixel is in the lower left half, its color is black. Otherwise, its color is random. If y is increased, the gauge is updated. Prototype : fun [I I I I] I */ fun bypixel (x, y, width, height)= if x >= width then ( set x = 0; _SETtext text strcat itoa setGauge set y = y+1 " %"; 0 ) else 0; if y >= height then 0 else let if x < y*2 then 0x000000 else (mod rand 512) * (mod rand 0xFFFFFF) -> color in ( _PUTpixel24 bmp x y color; _PAINTwindow window; bypixel x+1 y width height );; /* Paint the main window : the bitmap is displayed inside it Prototype : fun [ObjWin I] I */ fun CBpaint (win, user_parameter)= _BLTbitmap window bmp 0 0; 0;; /* Paint the gauge window : the bitmap is displayed inside it Prototype : fun [ObjWin I] I */ fun CBpaintGauge (win, user_parameter)= _BLTbitmap gauge bmpgauge 5 2; 0;; /* Close the current VM after destroying bitmaps Prototype : fun [ObjWin I] I */ fun CBend (win, user_parameter)= _DSbitmap bmp; _DSbitmap bmpgauge; _closemachine;; /* Main function. All components are created. Prototype : fun [] I */ fun main ()= _showconsole; srand (time); // create and fill two bitmaps set bmp = _FILLbitmap _CRbitmap _channel 200 100 0xFFFFFF; set bmpgauge = _FILLbitmap _CRbitmap _channel 100 16 0xFFFFFF; set window = _CRwindow _channel nil 0 0 200 130 WN_MENU " Examples > Bitmaps > Bypixels"; set gauge = _CRwindow _channel window 5 105 110 20 WN_CHILDINSIDE ""; set text = _CRtext _channel window 150 105 45 20 ET_ALIGN_RIGHT "0"; _CBwinPaint window @CBpaint 0; _CBwinPaint gauge @CBpaintGauge 0; _CBwinDestroy window @CBend 0; // call the function to set each pixel color bypixel 0 0 200 100; // end _fooS "Done !"; 0;;