• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ drawPixel函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中drawPixel函数的典型用法代码示例。如果您正苦于以下问题:C++ drawPixel函数的具体用法?C++ drawPixel怎么用?C++ drawPixel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了drawPixel函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: setArea

void MI0283QT9::drawCircle(uint16_t x0, uint16_t y0, uint16_t radius, uint16_t color)
{
  int16_t err, x, y;
  
  err = -radius;
  x   = radius;
  y   = 0;

  setArea(0, 0, lcd_width-1, lcd_height-1);

  while(x >= y)
  {
    drawPixel(x0 + x, y0 + y, color);
    drawPixel(x0 - x, y0 + y, color);
    drawPixel(x0 + x, y0 - y, color);
    drawPixel(x0 - x, y0 - y, color);
    drawPixel(x0 + y, y0 + x, color);
    drawPixel(x0 - y, y0 + x, color);
    drawPixel(x0 + y, y0 - x, color);
    drawPixel(x0 - y, y0 - x, color);

    err += y;
    y++;
    err += y;
    if(err >= 0)
    {
      x--;
      err -= x;
      err -= x;
    }
  }

  return;
}
开发者ID:D4p0up,项目名称:mSD-Shield,代码行数:34,代码来源:MI0283QT9.cpp


示例2: if

void Button::draw(SDL_Surface* s){
	if ((hovered&&!leftDown)||(leftDown&&!hovered)) SDL_FillRect(s,NULL,(foreColour.r<<16)|(foreColour.g<<8)|foreColour.b);
	else if ((leftDown&&hovered)||(!leftDown&&!hovered))SDL_FillRect(s,NULL,(backColour.r<<16)|(backColour.g<<8)|backColour.b);

	SDL_Color darkborder = {0,0,0,0}, lightborder = {170,170,170,255};
	if(hovered&&leftDown){
		SDL_Color temp(darkborder);
		darkborder = lightborder;
		lightborder = temp;
	}
	//draw a border _bBT thick.
	for(int top = 0; top < _bBT; top++) for(int p = top; p <width-top; p++)
		drawPixel(s,p,top,lightborder);
	for(int bottom = 0; bottom < _bBT; bottom++) for(int p = bottom; p <width-bottom; p++)
		drawPixel(s,p,height-bottom-1,darkborder);
	for(int left = 0; left < _bBT; left++) for(int p = left; p <height-left; p++)
		drawPixel(s,left,p,lightborder);
	for(int right = 0; right < _bBT; right++) for(int p = right; p <height-right; p++)
		drawPixel(s,width-right-1,p,darkborder);
	//draw focus box if focused.
	if(focused){
		for(int p = _bBT+1; p <width-_bBT-1; p+=2) drawPixel(s,p,_bBT+2,0,0,0);
		for(int p = _bBT+1; p <width-_bBT-1; p+=2) drawPixel(s,p,height-_bBT-2,0,0,0);
		for(int p = _bBT+1; p <height-_bBT-1; p+=2) drawPixel(s,_bBT+2,p,0,0,0);
		for(int p = _bBT+1; p <height-_bBT-1; p+=2) drawPixel(s,width-_bBT-2,p,darkborder);
	}
	//draw text
	drawText(text,width/2,height/2,font,s,textColour.r,textColour.g,
		textColour.b,Centered);
}
开发者ID:yujinwunz,项目名称:SDLGUI,代码行数:30,代码来源:Button.cpp


示例3: while

void Adafruit_GFX::drawCircleHelper( int16_t x0, int16_t y0,
               int16_t r, uint8_t cornername, uint16_t color) {
  int16_t f     = 1 - r;
  int16_t ddF_x = 1;
  int16_t ddF_y = -2 * r;
  int16_t x     = 0;
  int16_t y     = r;

  while (x<y) {
    if (f >= 0) {
      y--;
      ddF_y += 2;
      f     += ddF_y;
    }
    x++;
    ddF_x += 2;
    f     += ddF_x;
    if (cornername & 0x4) {
      drawPixel(x0 + x, y0 + y, color);
      drawPixel(x0 + y, y0 + x, color);
    } 
    if (cornername & 0x2) {
      drawPixel(x0 + x, y0 - y, color);
      drawPixel(x0 + y, y0 - x, color);
    }
    if (cornername & 0x8) {
      drawPixel(x0 - y, y0 + x, color);
      drawPixel(x0 - x, y0 + y, color);
    }
    if (cornername & 0x1) {
      drawPixel(x0 - y, y0 - x, color);
      drawPixel(x0 - x, y0 - y, color);
    }
  }
}
开发者ID:BorisFR,项目名称:rseries-open-control,代码行数:35,代码来源:Adafruit_GFX.cpp


示例4: while

// from https://web.archive.org/web/20120225095359/http://homepage.smc.edu/kennedy_john/belipse.pdf
void SmartMatrix::drawEllipse(int16_t x0, int16_t y0, uint16_t radiusX, uint16_t radiusY, const rgb24& color) {
    int16_t twoASquare = 2 * radiusX * radiusX;
    int16_t twoBSquare = 2 * radiusY * radiusY;
    
    int16_t x = radiusX;
    int16_t y = 0;
    int16_t changeX = radiusY * radiusY * (1 - (2 * radiusX));
    int16_t changeY = radiusX * radiusX;
    int16_t ellipseError = 0;
    int16_t stoppingX = twoBSquare * radiusX;
    int16_t stoppingY = 0;
    
    while (stoppingX >= stoppingY) {    // first set of points, y' > -1
        drawPixel(x0 + x, y0 + y, color);
        drawPixel(x0 - x, y0 + y, color);
        drawPixel(x0 - x, y0 - y, color);
        drawPixel(x0 + x, y0 - y, color);
        
        y++;
        stoppingY += twoASquare;
        ellipseError += changeY;
        changeY += twoASquare;
        
        if (((2 * ellipseError) + changeX) > 0) {
            x--;
            stoppingX -= twoBSquare;
            ellipseError += changeX;
            changeX += twoBSquare;
        }
    }
    
    // first point set is done, start the second set of points
    
    x = 0;
    y = radiusY;
    changeX = radiusY * radiusY;
    changeY = radiusX * radiusX * (1 - 2 * radiusY);
    ellipseError = 0;
    stoppingX = 0;
    stoppingY = twoASquare * radiusY;
    
    while (stoppingX <= stoppingY) {    // second set of points, y' < -1
        drawPixel(x0 + x, y0 + y, color);
        drawPixel(x0 - x, y0 + y, color);
        drawPixel(x0 - x, y0 - y, color);
        drawPixel(x0 + x, y0 - y, color);
        
        x++;
        stoppingX += twoBSquare;
        ellipseError += changeX;
        changeX += twoBSquare;
        
        if (((2 * ellipseError) + changeY) > 0) {
            y--;
            stoppingY -= twoASquare;
            ellipseError += changeY;
            changeY += twoASquare;
        }
    }
}
开发者ID:Abysmal,项目名称:SmartMatrix,代码行数:61,代码来源:MatrixGraphics.cpp


示例5: swapXY

int Graph::bresenham(Point pt1, Point pt2, float r, float g, float b ){
  Point p1 = pt1;
  Point p2 = pt2;
  int x, y, x_end, y_end, p; 
  int dx = (p2.x - p1.x), dy = (p2.y - p1.y); //for determining sign of slope
  bool steep = false;
  float m = (float)dy/(float)dx ; //find the slope first
  //DPRINT("The slope is %.2f,\tline with color %.2f,%.2f,%.2f\n", m, r,g,b); 
  bool positive_slope;
  if( m >= 0 )  // positive slope
    positive_slope = true;
  else
    positive_slope = false;
  
  if( fabs(m) <= 1 ){ //shallow
    steep = false; 
  }
  else{ //steep
   steep = true;
   swapXY(&p1);
   swapXY(&p2);
  }
  determineStartAndEndPoints(p1, p2, &x, &y, &x_end, &y_end);
  //DPRINT("x: %d,\ty: %d,\tx_end: %d,\ty_end:%d\n", x, y, x_end, y_end);
  dx = abs(x_end - x);
  dy = abs(y_end - y);
  //draw first point  
  if(steep)
    drawPixel(y,x,r,g,b);//x and y was swapped before
  else 
    drawPixel(x,y,r,g,b);
  p = 2 * dy - dx;
  for( ; x < x_end; ){
    x++;
    if( p >= 0){ // if d1 - d2  >= 0, means d2 is shorter, so advance y one level up
        positive_slope? y++:y--; 
        p = p + 2*dy - 2*dx;
    }
    else // if d1 - d2 < 0; means d1 is shorter, so no change of y;
      p = p + 2*dy;
    
    if(steep)
      drawPixel(y,x,r,g,b);//x and y was swapped before
    else 
      drawPixel(x,y,r,g,b);
  }

  return 0;
}
开发者ID:weidongguo,项目名称:ecs175_computer_graphics,代码行数:49,代码来源:graph.cpp


示例6: drawPixel

void SDLWindow::drawPixel(uint32_t x, uint32_t y, const RGBColor& color)
{
    if(mGamma == 1.0)
    {
        drawPixel(x, y, color.r * 255, color.g * 255, color.b * 255);
    }
    else
    {
        drawPixel(x, y,
            pow(color.r, mInvGamma) * 255,
            pow(color.g, mInvGamma) * 255,
            pow(color.b, mInvGamma) * 255
        );
    }
}
开发者ID:RyokoAkizuki,项目名称:backtrace,代码行数:15,代码来源:sdlwindow.cpp


示例7: drawPixel

// drawBitmap() variant w/background for RAM-resident (not PROGMEM) bitmaps.
void Adafruit_GFX::drawBitmap(int16_t x, int16_t y,
 uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg) {

  int16_t i, j, byteWidth = (w + 7) / 8;
  uint8_t byte;

  for(j=0; j<h; j++) {
    for(i=0; i<w; i++ ) {
      if(i & 7) byte <<= 1;
      else      byte   = bitmap[j * byteWidth + i / 8];
      if(byte & 0x80) drawPixel(x+i, y+j, color);
      else            drawPixel(x+i, y+j, bg);
    }
  }
}
开发者ID:digistump,项目名称:OakCore,代码行数:16,代码来源:Adafruit_GFX.cpp


示例8: drawCross

/**************************************************************************//**
 * @brief Draw a 9 pixel cross
 * @param[in] xpos Horizontal position of cross center
 * @param[in] ypos Vertical position of cross center
 * @param[in] color Color to use for cross
 *****************************************************************************/
static void drawCross( uint32_t xpos, uint32_t ypos, uint16_t color )
{
  drawPixel( xpos-2, ypos,   color );
  drawPixel( xpos-1, ypos,   color );
  drawPixel( xpos,   ypos,   color );
  drawPixel( xpos+1, ypos,   color );
  drawPixel( xpos+2, ypos,   color );
  drawPixel( xpos,   ypos-2, color );
  drawPixel( xpos,   ypos-1, color );
  drawPixel( xpos,   ypos+1, color );
  drawPixel( xpos,   ypos+2, color );
}
开发者ID:EnergyMicro,项目名称:EFM32LG_DK3650,代码行数:18,代码来源:main.c


示例9: makeLine

void makeLine (double x1, double y1, double x2, double y2)
{
	for (double x = x1; x <= x2; x++)
	{
		drawPixel (x,(x-x1)/(x2-x1)*(y2-y1) + y1);
	}
}
开发者ID:geosteffanov,项目名称:lecture-notes,代码行数:7,代码来源:main.cpp


示例10: main

int main ()
{

	for (int count = 0; count <= 9; count++)
	{
		makeLine (count*100,100,(count+1)*100,150);
		//makeLine ()
	}



	for (double x = 0; x <= 1000; x++)
	{
		drawPixel (x/2,150+20.0*sin(x/5.0));
	}


	updateGraphics();

	std::cout << "Press any key to continue...";
	std::cin.get();
	std::cout << std::endl;

	return 0;
}
开发者ID:geosteffanov,项目名称:lecture-notes,代码行数:25,代码来源:main.cpp


示例11: display

void display(void)
{
	int i,k;
	glColor3f(1.0,1.0,1.0) ;
	glClear(GL_COLOR_BUFFER_BIT);

	drawAxis () ;


	glColor3f( 1,0,0);

	for(i=0;i<n;i++)
	{
		y[i] = 0 ;

		for(k=1;k<=i;k++)
		{
			y[i] += - a[k]*y[i-k] ;
		}

		for(k=0;k<=i;k++)
		{
			y[i] += b[k]*U(i-k) ;
		}
	}

	for(i=0;i<n;i++)
		drawPixel(i*10,y[i]*1.0);

	glFlush();
}
开发者ID:Rijul1204,项目名称:Graphics,代码行数:31,代码来源:lab4.cpp


示例12: drawLine

void drawLine(int x1, int y1, int x2, int y2, int color) {
  float u, s, v, d1x, d1y, d2x, d2y, m, n;
  int x = x1, y = y1;

  u = x2-x1;
  v = y2-y1;

  d1x = d2x = _sign(u);
  d1y = _sign(v);
  d2y = 0;
  m = abs(u);
  n = abs(v);

  if (m <= n) {
    d2x = 0;
    d2y = _sign(v);
    m = abs(v);
    n = abs(u);
  }

  s = (int)(m/2);

  for (int i=0; i<round(m); i++) {
    drawPixel(x, y, color);
    s += n;
    if (s >= m) {
      s -= m;
      x += d1x;
      y += d1y;
    } else {
      x += d2x;
      y += d2y;
    }
  }
}
开发者ID:nougad,项目名称:advent2009,代码行数:35,代码来源:draw.c


示例13: defined

void  GxEPD::drawBitmapBM(const uint8_t *bitmap, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color, int16_t mode)
{
  uint16_t inverse_color = (color != GxEPD_WHITE) ? GxEPD_WHITE : GxEPD_BLACK;
  uint16_t fg_color = (mode & bm_invert) ? inverse_color : color;
  uint16_t bg_color = (mode & bm_invert) ? color : inverse_color;
  // taken from Adafruit_GFX.cpp, modified
  int16_t byteWidth = (w + 7) / 8; // Bitmap scanline pad = whole byte
  uint8_t byte = 0;
  for (int16_t j = 0; j < h; j++)
  {
    for (int16_t i = 0; i < w; i++ )
    {
      if (i & 7) byte <<= 1;
      else
      {
#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
        byte = pgm_read_byte(&bitmap[j * byteWidth + i / 8]);
#else
        byte = bitmap[j * byteWidth + i / 8];
#endif
      }
      // keep using overwrite mode
      uint16_t pixelcolor = (byte & 0x80) ? fg_color  : bg_color;
      uint16_t xd = x + i;
      uint16_t yd = y + j;
      if (mode & bm_flip_x) xd = x + w - i;
      if (mode & bm_flip_y) yd = y + h - j;
      drawPixel(xd, yd, pixelcolor);
    }
  }
}
开发者ID:crossgate10,项目名称:HITCON-Badge-2018,代码行数:31,代码来源:GxEPD.cpp


示例14: drawChar

int16_t drawChar(uint8_t c, int16_t x, int16_t y){
	if(c<32 || (c-32) > charcount){
		c=127;
	}

	c-=32;

	uint16_t xc, yc;

	uint8_t fontSize = 7;

	if(x<-fontSize || x> GFX_WIDTH || y<-8 || y>GFX_HEIGHT){
		return x+fontSize;
	}

	for(xc=0;xc<fontSize;xc++){
//		uint8_t slice = (big)?font7x8[c][xc]:font5x7[c][xc];
		uint8_t slice = font7x8[c][xc];
		for(yc=0;yc<8;yc++){
			if(slice & (1<<yc)){
				drawPixel(x+xc, y+yc);
			}
		}
	}

	return x+fontSize;
}
开发者ID:schlafli,项目名称:Hattastic,代码行数:27,代码来源:gfx.c


示例15: init_io

/*********************************************************************************************************
** Function name:           drawLine
** Descriptions:            drawLine
*********************************************************************************************************/
void ePaper::drawLine(int x0, int y0, int x1, int y1)
{

    init_io();
    
    int x = x1-x0;
    int y = y1-y0;
    int dx = abs(x), sx = x0<x1 ? 1 : -1;
    int dy = -abs(y), sy = y0<y1 ? 1 : -1;
    int err = dx+dy, e2;                                              
    for (;;)
    {                                                          
        drawPixel(x0,y0,1);
        e2 = 2*err;
        if (e2 >= dy) 
        {                                                
            if (x0 == x1) break;
            err += dy; x0 += sx;
        }
        if (e2 <= dx) 
        {                                                
            if (y0 == y1) break;
            err += dx; y0 += sy;
        }
    }
}
开发者ID:Seeed-Studio,项目名称:Small_ePaper_Shield,代码行数:30,代码来源:ePaper.cpp


示例16: drawGradient

void drawGradient( SDL_Surface* surface, int x1, int x2, int y, Uint32 color1, Uint32 color2 ) {
    int xDist = x1 - x2;
    if ( xDist == 0 ) {
        printf( "We can only draw horizontal gradients.\n" );
        return;
    }

    Uint8 r1;
    Uint8 r2;
    Uint8 g1;
    Uint8 g2;
    Uint8 b1;
    Uint8 b2;
    SDL_GetRGB( color1, surface->format, &r1, &g1, &b1 );
    SDL_GetRGB( color2, surface->format, &r2, &g2, &b2 );

    int rDiff = r1 - r2;
    int gDiff = g1 - g2;
    int bDiff = b1 - b2;

    float rStep = -rDiff / fabs(xDist);
    float gStep = -gDiff / fabs(xDist);
    float bStep = -bDiff / fabs(xDist);

    int i = 0;
    for ( int x = x1; x <= x2; x++ ) {
        drawPixel( surface, x, y, (Uint8)(r1 + ceil(rStep*i)), (Uint8)(g1 + ceil(gStep*i)), (Uint8)(b1 + ceil(bStep*i)) );
        i++;
    }
}
开发者ID:aranasaurus,项目名称:bamgp-exercises,代码行数:30,代码来源:main.cpp


示例17: main

int main(int argc, char *argv[]){
  glutInit(&argc, argv);  //initialize GL Utility Toolkit(GLUT) and  extract command line arguments for GLUT and keep the counts for the remaining arguments 
  glutInitDisplayMode(GLUT_SINGLE);

  glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
  glutInitWindowPosition(100, 100); 
  int windowID = glutCreateWindow("First Window");
 
  glClearColor(0,0,0,0); 
  glutDisplayFunc(callback_display);
  
  //std::fill(PixelBuffer, PixelBuffer+WINDOW_WIDTH*WINDOW_HEIGHT*3, 0.5); 
  drawPixel(WINDOW_WIDTH/2, WINDOW_HEIGHT/2, 1, 1, 1 );
  int p[] = {0, 100};
  int q[] = {WINDOW_WIDTH/2, 0};
  int r[] = {450, 200};
  drawLine( p, q , (double)0xdc/255, (double)0x14/255, (double)0x3c/255 );
  drawLine( q, r , 0, 0, 1);
  drawLine( r, p , 1, 1, 0);
  
  int s[] = {0, 0};
  int e[] = {50, 220};
  drawLine(s,e, 1,0,1); 

int m_Width = 100, m_Height = 100;
glViewport ( 0, 0, m_Width, m_Height );
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ();
glOrtho ( 0.0f, m_Width, 0.0, m_Height, 1.0, -1.0 );
glMatrixMode ( GL_MODELVIEW );  
glLoadIdentity ();

  glutMainLoop();
  return 0;
}
开发者ID:weidongguo,项目名称:ecs175_computer_graphics,代码行数:35,代码来源:myWindow.cpp


示例18: drawLine

int drawLine(int point1[], int point2[], float r, float g, float b){ 
  int x1, y1, x2, y2;  
  if( point1[0] < point2[0] ){
    x1 = point1[0];
    y1 = point1[1];
    x2 = point2[0];
    y2 = point2[1];
  }
  else {
    x1 = point2[0];
    y1 = point2[1];
    x2 = point1[0];
    y2 = point1[1];
  }

  float m = (float)(y2 - y1) / (float)(x2 - x1);
  
  DPRINT("Slope of the line, m = %.2f \n", m);
  
  int x, y;
  for( x = x1; x <= x2; x++){
    y = lround( m * ( x - x1 ) + y1 );
    drawPixel(x, y, r, g, b);
  }

}
开发者ID:weidongguo,项目名称:ecs175_computer_graphics,代码行数:26,代码来源:myWindow.cpp


示例19: drawLine

// algorithm from http://www.netgraphics.sk/bresenham-algorithm-for-a-line
void SmartMatrix::drawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, const rgb24& color) {
    // if point x1, y1 is on the right side of point x2, y2, change them
    if ((x1 - x2) > 0) {
        drawLine(x2, y2, x1, y1, color);
        return;
    }
    // test inclination of line
    // function Math.abs(y) defines absolute value y
    if (abs(y2 - y1) > abs(x2 - x1)) {
        // line and y axis angle is less then 45 degrees
        // thats why go on the next procedure
        bresteepline(y1, x1, y2, x2, color); return;
    }
    // line and x axis angle is less then 45 degrees, so x is guiding
    // auxiliary variables
    int x = x1, y = y1, sum = x2 - x1, Dx = 2 * (x2 - x1), Dy = abs(2 * (y2 - y1));
    int prirastokDy = ((y2 - y1) > 0) ? 1 : -1;
    // draw line
    for (int i = 0; i <= x2 - x1; i++) {
        drawPixel(x, y, color);
        x++;
        sum -= Dy;
        if (sum < 0) {
            y = y + prirastokDy;
            sum += Dx;
        }
    }
}
开发者ID:GadgetFactory,项目名称:DesignLab_Examples,代码行数:29,代码来源:MatrixGraphics.cpp


示例20: main

void main()
{
  lcdInit();
  spiOn();
  spiOff();
  sendByte(out);
  sendArray(array);
  lcdOn();
  lcdOff();
  sendBuffer();
  sendPart(3, 7, LCD_Buffer);
  clear();
  clearPart(5, 76);
  clearPartColor(5, 76, clBLACK);
  setPenColor(clBLACK);
  setBackColor(clWHITE);
  delay_nsek(40);
  scsOn();
  scsOff();
  i =  getValue(LCD_Buffer, 23, 266);
  setValue(LCD_Buffer, 23, 266, 0x3F);
  setCharge();
  resetCharge();
  drawPixel(5, 5, LCD_Buffer);
  drawVLine(5, 5, 5, LCD_Buffer);
  drawHLine(5, 5, 5, LCD_Buffer);
  drawLine(5, 5, 55, 55, LCD_Buffer);
  drawRect(5, 5, 55, 55, LCD_Buffer);
  drawFillRect(5, 5, 55, 55, clWHITE, LCD_Buffer);
  drawCircle(10, 10, 5, LCD_Buffer);
}
开发者ID:sphincs,项目名称:LCD,代码行数:31,代码来源:main.c



注:本文中的drawPixel函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ drawRect函数代码示例发布时间:2022-05-30
下一篇:
C++ drawObject函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap