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; }
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); }
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); } } }
// 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; } } }
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; }
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 ); } }
// 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); } } }
/**************************************************************************//** * @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 ); }
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); } }
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; }
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(); }
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; } } }
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); } } }
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; }
/********************************************************************************************************* ** 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; } } }
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++; } }
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; }
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); } }
// 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; } } }
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); }
void drawVLine(screen scr, u16 col, u16 y1, u16 y2, color clr) { if (y1 > y2) swap_u16(&y1, &y2); u16 i; for (i = y1; i <= y2; i++) drawPixel(scr, col, i, clr); }
void drawHLine(screen scr, u16 row, u16 x1, u16 x2, color clr) { if (x1 > x2) swap_u16(&x1, &x2); u16 i; for (i = x1; i <= x2; i++) drawPixel(scr, i, row, clr); }
void drawFillRect(int x1, int x2, int y1, int y2, char r, char g, char b, u8* screen) { int X1, X2, Y1, Y2; if (x1 < x2) { X1 = x1; X2 = x2; } else { X1 = x2; X2 = x1; } if (y1 < y2) { Y1 = y1; Y2 = y2; } else { Y1 = y2; Y2 = y1; } for (int i = X1; i <= X2; i++) { for (int j = Y1; j <= Y2; j++) { drawPixel(i, j, r, g, b, screen); } } }
void Screen::draw(Drawable *drawable,bool isflip){ if(!isflip){ draw(drawable); } else{ vector<Pixel> result; //Hitung sumbu vertikal vector<Pixel> group_of_point=drawable->getPixels(); vector<Pixel>::iterator it; int vertical_axis=0; int numb=0; for(it=group_of_point.begin();it!=group_of_point.end();it++){ vertical_axis+=(it->getPosition()).x;numb++; } vertical_axis/=numb; //transformasi for(it=group_of_point.begin();it!=group_of_point.end();it++){ int temp=(it->getPosition()).x; temp=2*vertical_axis-temp; Point pt(temp,(it->getPosition()).y); Pixel px(pt,it->getColor()); result.push_back(px); } for(it=result.begin();it!=result.end();it++) drawPixel(*it); } }
void fillCircle(int x, int y, int radius){ int x1, y1; for(y1=-radius; y1<=radius; y1++) for(x1=-radius; x1<=radius; x1++) if(x1*x1+y1*y1 <= radius*radius) drawPixel(x+x1, y+y1); }
// draw a character void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size) { if( (x >= _width) || // Clip right (y >= _height) || // Clip bottom ((x + 5 * size - 1) < 0) || // Clip left ((y + 8 * size - 1) < 0) // Clip top ) return; for (int8_t i=0; i<6; i++ ) { uint8_t line = 0; if (i == 5) line = 0x0; else line = font[(c*5)+i]; for (int8_t j = 0; j<8; j++) { if (line & 0x1) { #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT) if (size == 1) // default size drawPixel(x+i, y+j, color); else // big size fillRect(x+(i*size), y+(j*size), size, size, color); #else drawPixel(x+i, y+j, color); #endif } else if (bg != color) { #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT) if (size == 1) // default size drawPixel(x+i, y+j, bg); else // big size fillRect(x+i*size, y+j*size, size, size, bg); #else drawPixel(x+i, y+j, bg); #endif } line >>= 1; } } }
// Bresenham's algorithm - borrowed from Adafruit's GFX Library void Piccolino_OLED::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) { int16_t steep = abs(y1 - y0) > abs(x1 - x0); if (steep) { swap(x0, y0); swap(x1, y1); } if (x0 > x1) { swap(x0, x1); swap(y0, y1); } int16_t dx, dy; dx = x1 - x0; dy = abs(y1 - y0); int16_t err = dx / 2; int16_t ystep; if (y0 < y1) { ystep = 1; } else { ystep = -1; } for (; x0<=x1; x0++) { if (steep) { if(color==GRAY) drawPixel(y0, x0, !(x0%2)); else drawPixel(y0, x0, color); } else { if(color==GRAY) drawPixel(x0, y0, !(x0%2)); else drawPixel(x0, y0, color); } err -= dy; if (err < 0) { y0 += ystep; err += dx; } } }
void SmartMatrix::drawRoundRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t radius, const rgb24& outlineColor) { if (x1 < x0) SWAPint(x1, x0); if (y1 < y0) SWAPint(y1, y0); // decrease large radius that would break shape if(radius > (x1-x0)/2) radius = (x1-x0)/2; if(radius > (y1-y0)/2) radius = (y1-y0)/2; int a = radius, b = 0; int radiusError = 1 - a; // draw straight part of outline drawFastHLine(x0 + radius, x1 - radius, y0, outlineColor); drawFastHLine(x0 + radius, x1 - radius, y1, outlineColor); drawFastVLine(x0, y0 + radius, y1 - radius, outlineColor); drawFastVLine(x1, y0 + radius, y1 - radius, outlineColor); // convert coordinates to point at center of rounded sections x0 += radius; x1 -= radius; y0 += radius; y1 -= radius; while (a >= b) { // this pair sweeps from far left towards right drawPixel(-a + x0, -b + y0, outlineColor); drawPixel(-a + x0, b + y1, outlineColor); // this pair sweeps from far right towards left drawPixel(a + x1, -b + y0, outlineColor); drawPixel(a + x1, b + y1, outlineColor); // this pair sweeps from very top towards bottom drawPixel(-b + x0, -a + y0, outlineColor); drawPixel(b + x1, -a + y0, outlineColor); // this pair sweeps from bottom up drawPixel(-b + x0, a + y1, outlineColor); drawPixel(b + x1, a + y1, outlineColor); b++; if (radiusError < 0) { radiusError += 2 * b + 1; } else { a--; radiusError += 2 * (b - a + 1); } } }
void screen::updateScreen() { for(int i=0;i<l;i++) { for(int j=0;j<L;j++) { drawPixel(ecran[i][j]); } } SDL_Flip(surf); }
int main() { double x = 0.0; while (x < M_PI * 2) { drawPixel((int)(x*50),100 + (int)(sin(x)*100)); x += 0.01; } }