I'm trying to create a function that draws with the mouse using allegro. Here is the original code:

int SCREEN_WIDTH;
int SCREEN_HEIGHT;
BITMAP *buffer;
int sandcol;
int pthickness;
int mx, my, mx2, my2;
void ThickLine(BITMAP *bmp, int x, int y, int x_, int y_,int thickness, int color){
     int dx = x - x_;
     int dy = y - y_;
     int d = sqrtf(dx * dx + dy * dy);
     if (!d)
     return;

     int v[4 * 2];
     v[0] = x - thickness * dy / d;
     v[1] = y + thickness * dx / d;
     v[2] = x + thickness * dy / d;
     v[3] = y - thickness * dx / d;
     v[4] = x_ + thickness * dy / d;
     v[5] = y_ - thickness * dx / d;
     v[6] = x_ - thickness * dy / d;
     v[7] = y_ + thickness * dx / d;
     polygon(bmp, 4, v, color);
}
void CreateGrains(){
     ThickLine(buffer, mx2, my2, mx, my, pthickness, sandcol);
     circlefill(buffer, mx, my, pthickness, sandcol);     
}
int main(int argc, char *argv[]){
     allegro_init();
     install_mouse();
     SCREEN_WIDTH = 620;
     SCREEN_HEIGHT = 300;
     set_gfx_mode( GFX_AUTODETECT_WINDOWED, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
     show_mouse(screen);
     pthickness=5;
     buffer = create_bitmap(SCREEN_WIDTH, SCREEN_HEIGHT); 
     sandcol=makecol( 255, 255, 255);
     while(!key[KEY_ESC]){
          mx2 = mx;
          my2 = my;
          mx = mouse_x;
          my = mouse_y;
          if(mouse_b){
               CreateGrains();
          }
     }
}

when i click the mouse, it doesn't look natural; what is a better way to do this?

sorry!!!! I didn't know it double posted!!!! I'l mark the other one as solved...

This article has been dead for over six months. Start a new discussion instead.