Example #1
0
/*******************************************************************************
* Рисуем компас
 ******************************************************************************/
void compass(mtk_t * mtk) {
	char sTemp[10];
	uint8_t x, y, x1, y1, x2, y2, x3, y3;

	x = 60;
	y = 80;
	x1 = 60;
	y1 = 30;
	x2 = 50;
	y2 = 60;
	x3 = 70;
	y3 = 60;

	u8g_DrawCircle(mtk->u8g, 60, 80, 50, U8G_DRAW_ALL);
	u8g_DrawCircle(mtk->u8g, 60, 80, 20, U8G_DRAW_ALL);
	u8g_DrawStr(mtk->u8g, 55, 87, "N");

	rotate(x, y, &x1, &y1, angle);
	rotate(x, y, &x2, &y2, angle);
	rotate(x, y, &x3, &y3, angle);

	u8g_DrawTriangle(mtk->u8g, x1,y1, x2,y2, x3,y3);
	sprintf(sTemp, "Degree: %d", angle);
	u8g_DrawStr(mtk->u8g, 120, 40, sTemp);
}
Example #2
0
/* callback to draw the clock face */
int gui_draw_clock_face_cb(u8g_t *u8g, struct GuiWindow *win,
                struct GuiPoint abspos)
{
    struct GuiClockface *f = (struct GuiClockface *)win;

    int center_x = f->center_x + abspos.x;
    int center_y = f->center_y + abspos.y;

    /* clear background to white */
    u8g_SetDefaultBackgroundColor(u8g);
    u8g_DrawBox(u8g, center_x-f->radius, center_y-f->radius, 2*f->radius, 2*f->radius);
    u8g_SetDefaultForegroundColor(u8g);

    /* face */
    u8g_DrawCircle(u8g, center_x, center_y, f->radius, U8G_DRAW_ALL);
    u8g_DrawCircle(u8g, center_x, center_y, f->radius+1, U8G_DRAW_ALL);

    /* hour markers */
    for (int h = 0; h < 12; ++h) {
        u8g_DrawCircle(u8g, 
            sintab60[absrot60(h*5+15)] + center_x, 
            sintab60[h*5] + center_y, 2, U8G_DRAW_ALL);
    }

    int hours = (f->hours % 12);
    int minutes = f->minutes % 60;

    /* hours hand */
    int angle = absrot60(-(short)hours*5 - (short)minutes/12 + 15);
    int x2 = sintab60[absrot60(angle+15)]/2 + center_x;   // cos, x-axis is natural direction
    int y2 = (-sintab60[angle]/2) + center_y;         // sin, y-axis is inverted

    u8g_DrawLine(u8g, center_x, center_y, x2, y2);
    u8g_DrawLine(u8g, center_x+1, center_y, x2+1, y2);
    u8g_DrawLine(u8g, center_x, center_y+1, x2, y2+1);
    u8g_DrawLine(u8g, center_x-1, center_y, x2-1, y2);
    u8g_DrawLine(u8g, center_x, center_y-1, x2, y2-1);

    /* minutes hand */
    angle = absrot60(-(short)minutes + 15);
    x2 = sintab60[absrot60(angle+15)]*30/34 + center_x;   // cos, x-axis is natural direction
    y2 = (-sintab60[angle])*30/34 + center_y;         // sin, y-axis is inverted

    u8g_DrawLine(u8g, center_x, center_y, x2, y2);

    return 0;
}
Example #3
0
// Lua: u8g.drawCircle( self, x0, y0, rad, opt = U8G_DRAW_ALL )
static int lu8g_drawCircle( lua_State *L )
{
    lu8g_userdata_t *lud;

    if ((lud = get_lud( L )) == NULL)
        return 0;

    u8g_uint_t args[3];
    lu8g_get_int_args( L, 2, 3, args );

    u8g_uint_t opt = luaL_optinteger( L, (1+3) + 1, U8G_DRAW_ALL );

    u8g_DrawCircle( LU8G, args[0], args[1], args[2], opt );

    return 0;
}
Example #4
0
int main(void)
{
  
  u8g_t u8g;
  uint8_t rad;
  
  u8g_Init(&u8g, &u8g_dev_sdl_1bit);
  u8g_FirstPage(&u8g);
  
  do
  {
    //u8g_SetFont(&u8g, u8g_font_unifont);
    //u8g_SetFont(&u8g, u8g_font_osb18r);
    
    for( rad = 2+3*2; rad < 30; rad += 3 )
    {
      u8g_DrawEmpCirc(&u8g, 0, 35, rad, U8G_DRAW_UPPER_RIGHT);
      u8g_DrawCircle(&u8g, 0, 35+35, rad, U8G_DRAW_UPPER_RIGHT);
      
      u8g_DrawEmpCirc(&u8g, 0+31, 5, rad, U8G_DRAW_LOWER_RIGHT);
      u8g_DrawCircle(&u8g, 0+31, 5+35, rad, U8G_DRAW_LOWER_RIGHT);

      u8g_DrawEmpCirc(&u8g, 30+31*2, 5, rad, U8G_DRAW_LOWER_LEFT);
      u8g_DrawCircle(&u8g, 30+31*2, 5+35, rad, U8G_DRAW_LOWER_LEFT);

      u8g_DrawEmpCirc(&u8g, 0+31*4, 35, rad, U8G_DRAW_UPPER_LEFT);
      u8g_DrawCircle(&u8g, 0+31*4, 35+35, rad, U8G_DRAW_UPPER_LEFT);
      
    }
  } while( u8g_NextPage(&u8g) );

  while( u8g_sdl_get_key() < 0 )
    ;


  for( rad = 2+3*2; rad < 30; rad += 3 )
  {
    u8g_FirstPage(&u8g);
    do
    {
      //u8g_SetFont(&u8g, u8g_font_unifont);
      //u8g_SetFont(&u8g, u8g_font_osb18r);
      
      u8g_DrawFillCirc(&u8g, 0, 35, rad, U8G_DRAW_UPPER_RIGHT);
      u8g_DrawDisc(&u8g, 0, 35+35, rad, U8G_DRAW_UPPER_RIGHT);
      
      u8g_DrawFillCirc(&u8g, 0+31, 5, rad, U8G_DRAW_LOWER_RIGHT);
      u8g_DrawDisc(&u8g, 0+31, 5+35, rad, U8G_DRAW_LOWER_RIGHT);

      u8g_DrawFillCirc(&u8g, 30+31*2, 5, rad, U8G_DRAW_LOWER_LEFT);
      u8g_DrawDisc(&u8g, 30+31*2, 5+35, rad, U8G_DRAW_LOWER_LEFT);

      u8g_DrawFillCirc(&u8g, 0+31*4, 35, rad, U8G_DRAW_UPPER_LEFT);
      u8g_DrawDisc(&u8g, 0+31*4, 35+35, rad, U8G_DRAW_UPPER_LEFT);
      
    } while( u8g_NextPage(&u8g) );

  while( u8g_sdl_get_key() < 0 )
    ;
    
  }
  
  return 0;
}