Advertisement
Kitomas

kit_w32 test main.cpp as of 2024-02-16

Feb 16th, 2024
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.69 KB | None | 0 0
  1. #include <kit/all.hpp>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5.  
  6. using namespace kit;
  7.  
  8. #if defined(_DEBUG)
  9. #include <stdio.h>
  10. #define loghere printf("line %4i: (%s)\n",__LINE__,__FILE__);
  11. #else
  12. #define loghere ; /* do {} while(0); */
  13. #endif /* _DEBUG */
  14.  
  15. //get random 64-bit float value from 0.0 -> 1.0
  16. f64 drand(){
  17.   u32 value = ((u32)rand())<<15 | rand();
  18.   return (f64)value/(KIT_U32_MAX>>2);
  19. }
  20.  
  21.  
  22. //colors; white, cyan, magenta (treated as transparent color)
  23. #define wht 0x00ffffff
  24. #define cyn 0x0000ffff
  25. #define mgn 0x00ff00ff
  26.  
  27. //bitmaps go from bottom-up instead of top-down,
  28.  //but this is a ball that's mirrored both ways so it doesn't matter
  29. color::ARGB ball[] = {
  30.   mgn,mgn,wht,wht,wht,wht,mgn,mgn,
  31.   mgn,wht,cyn,cyn,cyn,cyn,wht,mgn,
  32.   wht,cyn,cyn,cyn,cyn,cyn,cyn,wht,
  33.   wht,cyn,cyn,wht,wht,cyn,cyn,wht,
  34.   wht,cyn,cyn,wht,wht,cyn,cyn,wht,
  35.   wht,cyn,cyn,cyn,cyn,cyn,cyn,wht,
  36.   mgn,wht,cyn,cyn,cyn,cyn,wht,mgn,
  37.   mgn,mgn,wht,wht,wht,wht,mgn,mgn,
  38. };
  39.  
  40.  
  41.  
  42. s32 bx, by;
  43. f64 bx_s = 0,  by_s = 0;
  44. int main(int argc, char** argv){
  45.   //seed rng
  46.   srand(time::getTicks()&KIT_U32_MAX);
  47.  
  48.  
  49.   //create test bmp from pixel data
  50.   Bitmap bmpTest(ball, 8,8, true); //pixel data, w,h, direct-access pixels
  51.  
  52.  
  53.   //create window
  54.   Window win("confetti time",   //window title
  55.              1280,720,          //initial window size
  56.              WINFLAG_RESIZABLE, //window capability flags
  57.              WINPOS_CENTERED,   //window x position
  58.              WINPOS_CENTERED,   //window y position
  59.              256,144);          //canvas size
  60.  
  61.   //run loop
  62.   while(!win.isDestroyed()){
  63.  
  64.     //process messages in event queue
  65.     WindowEvent event;
  66.     while(win.pollEvent(&event)){
  67.       //(user event processing not implemented yet)
  68.     }
  69.  
  70.  
  71.     win.lock(true);
  72.  
  73.     //fill canvas with 1 color every frame (black by default)
  74.     win.clear();
  75.  
  76.     //put 1000 random pixels on the canvas
  77.     shape::point canvasSize = win.getCanvasSize();
  78.     color::ARGB* pixels     = win.getPixels();
  79.     s32 numPixels = canvasSize.x*canvasSize.y;
  80.     if(canvasSize.x!=0 && canvasSize.y!=0){
  81.       for(s32 i=0; i<1000; ++i)
  82.         pixels[(s32)(numPixels*drand())].v = (s32)(drand()*0x00ffffff);
  83.     }
  84.  
  85.  
  86.     //some logic so the bmp ball can bounce around
  87.     bx = 128 + (s32)(sin(bx_s)*96) - 4;
  88.     by =  72 + (s32)(sin(by_s)*54) - 4;
  89.     bx_s += 0.020;
  90.     by_s += 0.009;
  91.  
  92.     //placeholder function to blit test bmp with transparent color (to the canvas)
  93.     win.tblitns(&bmpTest, bx, by, 0x00ff00ff);
  94.  
  95.     win.present(); //blit the canvas to the window
  96.  
  97.     win.lock(false);
  98.  
  99.     time::sleep(10); //Sleep() has weird granularity and i'm working on it
  100.   }
  101.  
  102.  
  103.   return 0;
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement