Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <kit/all.hpp>
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- using namespace kit;
- #if defined(_DEBUG)
- #include <stdio.h>
- #define loghere printf("line %4i: (%s)\n",__LINE__,__FILE__);
- #else
- #define loghere ; /* do {} while(0); */
- #endif /* _DEBUG */
- //get random 64-bit float value from 0.0 -> 1.0
- f64 drand(){
- u32 value = ((u32)rand())<<15 | rand();
- return (f64)value/(KIT_U32_MAX>>2);
- }
- //colors; white, cyan, magenta (treated as transparent color)
- #define wht 0x00ffffff
- #define cyn 0x0000ffff
- #define mgn 0x00ff00ff
- //bitmaps go from bottom-up instead of top-down,
- //but this is a ball that's mirrored both ways so it doesn't matter
- color::ARGB ball[] = {
- mgn,mgn,wht,wht,wht,wht,mgn,mgn,
- mgn,wht,cyn,cyn,cyn,cyn,wht,mgn,
- wht,cyn,cyn,cyn,cyn,cyn,cyn,wht,
- wht,cyn,cyn,wht,wht,cyn,cyn,wht,
- wht,cyn,cyn,wht,wht,cyn,cyn,wht,
- wht,cyn,cyn,cyn,cyn,cyn,cyn,wht,
- mgn,wht,cyn,cyn,cyn,cyn,wht,mgn,
- mgn,mgn,wht,wht,wht,wht,mgn,mgn,
- };
- s32 bx, by;
- f64 bx_s = 0, by_s = 0;
- int main(int argc, char** argv){
- //seed rng
- srand(time::getTicks()&KIT_U32_MAX);
- //create test bmp from pixel data
- Bitmap bmpTest(ball, 8,8, true); //pixel data, w,h, direct-access pixels
- //create window
- Window win("confetti time", //window title
- 1280,720, //initial window size
- WINFLAG_RESIZABLE, //window capability flags
- WINPOS_CENTERED, //window x position
- WINPOS_CENTERED, //window y position
- 256,144); //canvas size
- //run loop
- while(!win.isDestroyed()){
- //process messages in event queue
- WindowEvent event;
- while(win.pollEvent(&event)){
- //(user event processing not implemented yet)
- }
- win.lock(true);
- //fill canvas with 1 color every frame (black by default)
- win.clear();
- //put 1000 random pixels on the canvas
- shape::point canvasSize = win.getCanvasSize();
- color::ARGB* pixels = win.getPixels();
- s32 numPixels = canvasSize.x*canvasSize.y;
- if(canvasSize.x!=0 && canvasSize.y!=0){
- for(s32 i=0; i<1000; ++i)
- pixels[(s32)(numPixels*drand())].v = (s32)(drand()*0x00ffffff);
- }
- //some logic so the bmp ball can bounce around
- bx = 128 + (s32)(sin(bx_s)*96) - 4;
- by = 72 + (s32)(sin(by_s)*54) - 4;
- bx_s += 0.020;
- by_s += 0.009;
- //placeholder function to blit test bmp with transparent color (to the canvas)
- win.tblitns(&bmpTest, bx, by, 0x00ff00ff);
- win.present(); //blit the canvas to the window
- win.lock(false);
- time::sleep(10); //Sleep() has weird granularity and i'm working on it
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement