int main(int argc, char *argv[]) { int i=0; int x=40,y=20; srandom(time(NULL)); while(1) { if (i==0) { x=rand()%XSIZE; y=rand()%YSIZE; clearscreen(); } printf("fljsdf\n"); i=(i+1)%1000; x=XSIZE+(x-1+rand()%2) % XSIZE; y=YSIZE+(y-1+rand()%2) % YSIZE; setpixel(x,y); setpixel(x+1,y); setpixel(x+1,y+1); setpixel(x,y+1); writescreen(); usleep(15000); } return 0; }
void draw_preview_block(char x, char y) { byte x_start, y_start, x1, y1; byte i; x_start = PREVIEW_X + BLOCK_SIZE * x; y_start = PREVIEW_Y + BLOCK_SIZE * y; x1 = x_start; y1 = y_start + BLOCK_SIZE - 1; for (i = 0; i < BLOCK_SIZE; i++) { setpixel(x1, y_start); setpixel(x1, y1); x1++; } x1 = x_start + BLOCK_SIZE - 1; y1 = y_start + 1; for (i = 0; i < BLOCK_SIZE - 2; i++) { setpixel(x_start, y1); setpixel(x1, y1); y1++; } setpixel(x_start + 2, y_start + 2); }
void seg7_img_draw (struct seg7_img_t *img, int value) { int i,j; int pixel; pixel = (img->x + img->y*machine.ui.width)*machine.ui.bpp; for(i=0; i < img->h; i++) { int pii = pixel; for(j=0; j < img->w; j++) { if ((value & img->img[j][i]) != 0) { setpixel(pii,0xee,0x00,0x00); /* on */ } else if (img->img[j][i] > 0) { setpixel(pii,0x30,0x30,0x30); /* off */ } else { setpixel(pii,0x00,0x00,0x00); /* bkg */ } pii += 3; } pixel += machine.ui.width * machine.ui.bpp; } }
// draw a circle void fillcircle(uint8_t *buff, uint8_t x0, uint8_t y0, uint8_t r, uint8_t color) { int8_t f = 1 - r; int8_t ddF_x = 1; int8_t ddF_y = -2 * r; int8_t x = 0; int8_t y = r; for (uint8_t i=y0-r; i<=y0+r; i++) { setpixel(buff, x0, i, color); } while (x<y) { if (f >= 0) { y--; ddF_y += 2; f += ddF_y; } x++; ddF_x += 2; f += ddF_x; for (uint8_t i=y0-y; i<=y0+y; i++) { setpixel(buff, x0+x, i, color); setpixel(buff, x0-x, i, color); } for (uint8_t i=y0-x; i<=y0+x; i++) { setpixel(buff, x0+y, i, color); setpixel(buff, x0-y, i, color); } } }
void write_text_to_buffer(char* textbuffer) { for(int i = 0; i < COLUMNS; i++) { // CLEAR FRAME FIRST for(int x = 0; x < ROWS; x++) { setpixel(i, x, bckred, bckgreen, bckblue); } } for(int i = 0; i < COLUMNS; i++) { for(int x = 0; x < ROWS; x++) { if(i < TEXTWIDTH) { bool pix = font8x8_basic[textbuffer[0]][x] & (1 << (i)); if(pix) { setpixel(i, x, txtred, txtgreen, txtblue); } else { setpixel(i, x, bckred, bckgreen, bckblue); } int columnplace = i + TEXTWIDTH + TEXTOFFSET; pix = font8x8_basic[textbuffer[1]][x] & (1 << (i)); if(pix) { setpixel(columnplace, x, txtred, txtgreen, txtblue); } else { setpixel(columnplace, x, bckred, bckgreen, bckblue); } } } } }
static void overlay_one_inplace( float *ox, float *oy, float *of, // background images and flow int w, int h, int pd, // dimensions of background float *ppx, int pw, int ph, // overlaid image and its size float posx, float posy, // overlay position float zoom, float angle, // overlay transformation float dx, float dy // overlay displacement ) { float (*px)[pw][pd] = (void*)ppx; float dxy[2] = {dx, dy}; float sina = sin(angle*M_PI/180.0); float cosa = cos(angle*M_PI/180.0); for (int j = 0; j < ph; j++) for (int i = 0; i < pw; i++) { float cij[2] = {i - pw/2.0, j - ph/2.0}; float ai = pw/2.0 + zoom * ( cosa * cij[0] + sina * cij[1]); float aj = ph/2.0 + zoom * (-sina * cij[0] + cosa * cij[1]); ai = round(ai); aj = round(aj); float adxy[2] = {dx + ai - i, dy + aj - j}; // TODO: correct re-sampling (!) setpixel(ox,w,h,pd, posx + i , posy + j , px[j][i]); setpixel(oy,w,h,pd, posx + dx + ai, posy + dy + aj, px[j][i]); setpixel(of,w,h,2 , posx + i , posy + j , adxy); } }
void filter_threshold(struct image *img, int threshold) { struct image *dst; int x, y; int r, g, b; int min = 0, max = 255; dst = image_new(img->width, img->height); if(threshold < 0) { min = 255; max = 0; threshold = -threshold; } threshold *= 3; for(y = 0; y < img->height; y++) for(x = 0; x < img->width; x++) { getpixel(img, x, y, &r, &g, &b); if(r + g + b < threshold) setpixel(dst, x, y, min, min, min); else setpixel(dst, x, y, max, max, max); } image_swap(img, dst); image_free(dst); }
void ez430_lcd_img_draw(struct ez430_lcd_img_t *img, uint8_t mem[15], uint8_t bmem[15]) { int i, j, k; int pixel; pixel = (img->x + img->y * machine.ui.width) * machine.ui.bpp; for (i = 0; i < img->h; i++) { int pii = pixel; for (j = 0; j < img->w; j++) { setpixel(pii, 0x00, 0x00, 0x00); // bkg for (k = 0; k < 12; k++) { if ((mem[k] & img->img[j][i][k]) != 0) { if ((bmem[k] & img->img[j][i][k]) != 0) { setpixel(pii, 0x00, 0xee, 0x00); // blink break; } else { setpixel(pii, 0xee, 0x00, 0x00); // on break; } } else if (img->img[j][i][k] > 0) { setpixel(pii, 0x30, 0x30, 0x30); // off } } pii += 3; } pixel += machine.ui.width * machine.ui.bpp; } }
void linebres(int xa, int ya, int xb, int yb) { int dx = abs(xa-xb), dy = abs(ya-yb); int p= 2*dy-dx; int twody = 2*dy, twodydx = 2*(dy-dx); int x,y,xEnd; if(xa>xb) { x=xb; y=yb; xEnd = xa; } else{ x=xa; y=ya; xEnd =xb; } setpixel (x,y); while(x<xEnd){ x++; if(p<0) p+=twody; else{ y++; p+=twodydx; } setpixel(x,y); } }
// draw a rectangle void drawrect(unsigned char *buff, unsigned char x, unsigned char y, unsigned char w, unsigned char h, unsigned char color) { // stupidest version - just pixels - but fast with internal buffer! for (uint8_t i=x; i<x+w; i++) { setpixel(buff, i, y, color); setpixel(buff, i, y+h-1, color); } for (uint8_t i=y; i<y+h; i++) { setpixel(buff, x, i, color); setpixel(buff, x+w-1, i, color); } }
// draw a rectangle void SSD1306::drawrect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t color) { // stupidest version - just pixels - but fast with internal buffer! for (uint8_t i=x; i<x+w; i++) { setpixel(i, y, color); setpixel(i, y+h-1, color); } for (uint8_t i=y; i<y+h; i++) { setpixel(x, i, color); setpixel(x+w-1, i, color); } }
void ICACHE_FLASH_ATTR write_texttowall(int buffer, int textbuffer, long offset, int fR, int fG, int fB, int fbR, int fbG, int fbB) { for(int i = 0; i < COLUMNS; i++) { for(int x = 0; x < ROWS; x++) { char pix = get_textpixel(textbuffer, i, x, offset); if(pix > 0) { setpixel(buffer, i, x, fR, fG, fB); } else { setpixel(buffer, i, x, fbR, fbG, fbB); } } } }
void filter_fill_holes(struct image *img) { struct image *dst; int x, y; int r, g, b; dst = image_new(img->width, img->height); for(y = 0; y < img->height; y++) for(x = 0; x < img->width; x++) { getpixel(img, x, y, &r, &g, &b); setpixel(dst, x, y, r, g, b); } for(y = 0; y < dst->height; y++) for(x = 2; x < dst->width - 2; x++) { int c1, c2, c3, c4, c5; getpixel(img, x-2, y, &c1, &g, &b); getpixel(img, x-1, y, &c2, &g, &b); getpixel(img, x, y, &c3, &g, &b); getpixel(img, x+1, y, &c4, &g, &b); getpixel(img, x+2, y, &c5, &g, &b); if(c1 < 127 && c2 < 127 && c3 > 128 && c4 < 127) c3 = (c1 + c2 + c4) / 3; else if(c2 < 127 && c3 > 128 && c4 < 127 && c5 < 127) c3 = (c2 + c4 + c5) / 3; setpixel(dst, x, y, c3, c3, c3); } for(x = 0; x < dst->width; x++) for(y = 2; y < dst->height - 2; y++) { int c1, c2, c3, c4, c5; getpixel(img, x, y-2, &c1, &g, &b); getpixel(img, x, y-1, &c2, &g, &b); getpixel(img, x, y, &c3, &g, &b); getpixel(img, x, y+1, &c4, &g, &b); getpixel(img, x, y+2, &c5, &g, &b); if(c1 < 127 && c2 < 127 && c3 > 128 && c4 < 127) c3 = (c1 + c2 + c4) / 3; else if(c2 < 127 && c3 > 128 && c4 < 127 && c5 < 127) c3 = (c2 + c4 + c5) / 3; setpixel(dst, x, y, c3, c3, c3); } image_swap(img, dst); image_free(dst); }
// Bresenham's algorithm - From wikipedia void drawline(uint8_t *buff, uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color) { uint8_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); } uint8_t dx, dy; dx = x1 - x0; dy = abs(y1 - y0); int8_t err = dx / 2; int8_t ystep; if (y0 < y1) { ystep = 1; } else { ystep = -1; } for (; x0<x1; x0++) { if (steep) { setpixel(buff, y0, x0, color); } else { setpixel(buff, x0, y0, color); } err -= dy; if (err < 0) { y0 += ystep; err += dx; } } }
void render(){ int i, j; int color[3]; int pos[2]; for(i = 0; i < lastBlock; i++){ color[0] = blockList[i].program[0] / 8.0 * 255; color[1] = blockList[i].program[INSTRUCTIONS / 2] / 8.0 * 255; color[2] = blockList[i].program[INSTRUCTIONS - 1] / 8.0 * 255; if(blockList[i].die){ if(blockList[i].energy < 1){ color[0] = color[0] - 70 < 0?0:color[0] - 70; color[1] = color[1] - 70 < 0?0:color[1] - 70; color[2] = color[2] - 70 < 0?0:color[2] - 70; }else{ color[0] = color[0] - 90 < 0?0:color[0] - 70; color[1] = color[1] - 90 < 0?0:color[1] - 70; color[2] = color[2] - 90 < 0?0:color[2] - 70; } } pos[0] = blockList[i].x; pos[1] = blockList[i].y; setpixel(pos[0], pos[1], color[0], color[1], color[2]); } SDL_Flip(screen); SDL_FillRect(screen, NULL, 0x000000); }
/* Functions */ void filter_flood_fill(struct image *img, int x, int y, int r, int g, int b) { int oldr, oldg, oldb; int nextr, nextg, nextb; if(x < 0 || y < 0 || x >= img->width || y >= img->height) return; getpixel(img, x, y, &oldr, &oldg, &oldb); setpixel(img, x, y, r, g, b); getpixel(img, x + 1, y, &nextr, &nextg, &nextb); if(nextr == oldr && nextg == oldg && nextb == oldb) filter_flood_fill(img, x + 1, y, r, g, b); getpixel(img, x - 1, y, &nextr, &nextg, &nextb); if(nextr == oldr && nextg == oldg && nextb == oldb) filter_flood_fill(img, x - 1, y, r, g, b); getpixel(img, x, y + 1, &nextr, &nextg, &nextb); if(nextr == oldr && nextg == oldg && nextb == oldb) filter_flood_fill(img, x, y + 1, r, g, b); getpixel(img, x, y - 1, &nextr, &nextg, &nextb); if(nextr == oldr && nextg == oldg && nextb == oldb) filter_flood_fill(img, x, y - 1, r, g, b); }
void floodFill(int x, int y,struct fill fillColor,struct fill old) { struct fill tmp; tmp=getpixcol(x,y); printf("r:%f g:%f b:%f\n",tmp.r,tmp.g,tmp.b); if(tmp.r * 1000!=old.r * 1000 || tmp.g*1000!=old.g*1000 || tmp.b*1000!=old.b*1000) { puts("RETURN"); return; } setpixel(fillColor,x,y); int dx[4]= {1,0,-1}; int dy[4]= {-1,0,1}; for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { //mrnd=(mrnd*7)%8; //int ind = mrnd>>1; //mrnd=ind; if(i==1 && j==1) continue; floodFill(x+dx[i],y+dy[j],fillC,old); } } glFlush(); Sleep(2); }
static void menu_setpixel(uint8_t x, uint8_t y, uint8_t isSet) { uint8_t nColor; // mirror mirror on the wall, what's the quirkiest API of them all... x = NUM_COLS - 1 - x; uint8_t nMiddle = (NUM_COLS - MENU_WIDTH_ICON) / 2; if (isSet != 0) { if ((x >= nMiddle - MENU_WIDTH_DELIMITER) && (x < (nMiddle + MENU_WIDTH_ICON + MENU_WIDTH_DELIMITER))) { nColor = 3; } else if ((x == (nMiddle - MENU_WIDTH_DELIMITER - 1)) || (x == (nMiddle + MENU_WIDTH_ICON + MENU_WIDTH_DELIMITER))) { nColor = 2; } else { nColor = 1; } } else { nColor = 0; } setpixel((pixel){x, y}, nColor); }
void ICACHE_FLASH_ATTR clear_buffer(int buffer) { for(int i = 0; i < COLUMNS; i++) { for(int x = 0; x < ROWS; x++) { setpixel(buffer, i, x, 0x00, 0x00, 0x00); } } }
/* this is the actual draw function for a single field */ static void draw_single_field (uint8_t in_x, uint8_t in_y, game_field_t in_f) { pixel tmp; uint8_t b; switch (in_f) { case b1: b = 1; break; case rb: case b2: b = 2; break; case b3: case bl: case bs: b = 3; break; default: /* this includes freespace */ b = 0; break; } tmp.x = in_x; tmp.y = in_y; setpixel (tmp, b); }
void drawBuffered(SDL_Surface *screen){ if(SDL_MUSTLOCK(screen)) { if(SDL_LockSurface(screen) < 0){ return; } } int i = 0; int x,y=0; int drawnY,drawnX; int ylimit = SCREENHEIGHT*screen->pitch/BITSPERPIXEL; //ylimit is307200 for(; i < bufferPointer && i < CLICKBUFFERSIZE; i=i+2){ //Each odd number is an x, each even is a y for(x=0; x < brushSize; x++ ){ for(y=0; y < brushSize; y++){ drawnY=(buffered[i+1]+y)*screen->pitch/BITSPERPIXEL; drawnX=buffered[i]+x; if(drawnY < ylimit && drawnX < SCREENWIDTH) setpixel(screen, drawnX,drawnY,0,0,0); } } } //Done drawing reset: bufferPointer=0; if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); SDL_Flip(screen); }
void filter_contrast(struct image *img) { struct image *dst; int histo[256]; int x, y, i, min = 255, max = 0; int r, g, b; dst = image_new(img->width, img->height); for(y = 0; y < img->height; y++) for(x = 0; x < img->width; x++) { getgray(img, x, y, &r); if(r < min) min = r; if(r > max) max = r; } if(min == max) histo[min] = 127; else for(i = min; i < max + 1; i++) histo[i] = (i - min) * 255 / (max - min); for(y = 0; y < img->height; y++) for(x = 0; x < img->width; x++) { getgray(img, x, y, &r); setpixel(dst, x, y, histo[r], histo[r], histo[r]); } image_swap(img, dst); image_free(dst); }
void filter_crop(struct image *img, int xmin, int ymin, int xmax, int ymax) { struct image *dst; int x, y; int r, g, b; if(xmin < 0) xmin = 0; if(ymin < 0) ymin = 0; if(xmax >= img->width) xmax = img->width - 1; if(ymax >= img->height) ymax = img->height - 1; if(xmin >= xmax || ymin >= ymax) return; dst = image_new(xmax - xmin, ymax - ymin); for(y = 0; y < dst->height; y++) for(x = 0; x < dst->width; x++) { getpixel(img, xmin + x, ymin + y, &r, &g, &b); setpixel(dst, x, y, r, g, b); } image_swap(img, dst); image_free(dst); }
static void in_render() { void *buf2 = lock(logo, logo->format->BitsPerPixel); void *buf = lock(start, start->format->BitsPerPixel); void *buf3 = lock(front, front->format->BitsPerPixel); int i,z; static float alpha = 0.0f; for(i = 0; i < front->w; i++) { for(z = 0; z < front->h; z++) { SDL_Color col1, col2; Uint32 color = 0; getpixel(logo, i, z, logo->format->BitsPerPixel, logo->pitch, &col2); getpixel(start, i, z, start->format->BitsPerPixel, start->pitch, &col1); color = SDL_MapRGB(front->format, ((Uint8)(alpha * col1.r) + (1-alpha) * col2.r), (Uint8)(alpha * col1.g) + (1-alpha) * col2.g , (Uint8) (alpha * col1.b) + (1-alpha) * col2.b); setpixel(buf3, i , z, color, front->format->BitsPerPixel, front->pitch); } } alpha += 0.1f; if(alpha > 3.0) { //start_game(); scr = ID_START; } unlock(front); unlock(start); unlock(logo); }
void ICACHE_FLASH_ATTR set_buffer(int buffer, int val1, int val2, int val3) { for(int i = 0; i < COLUMNS; i++) { for(int x = 0; x < ROWS; x++) { setpixel(buffer, i, x, val1, val2, val3); } } }
void LCDST7565::drawOffsetBar(control_type_e control) { int fillw; float value = 1.f;//midi->offset( CT_PITCH ); int y; if( control == CT_PITCH ) { value = 0.77f; y = 12; } else { value = -0.2f; y = 34; } drawrect(GUI_VALBAR_X-2, y, GUI_VALBAR_WIDTH+3, GUI_VALBAR_HEIGHT, BLACK); if(value >= 0) { fillw = (int) ((GUI_VALBAR_WIDTH * value) / 2.f) + 1; float x = GUI_VALBAR_X + GUI_VALBAR_WIDTH / 2.f - 1; fillrect((int)x, y, fillw, GUI_VALBAR_HEIGHT, BLACK); } else { value *= -1; fillw = (int) ((GUI_VALBAR_WIDTH * value) / 2.f) + 1; float x = GUI_VALBAR_X + GUI_VALBAR_WIDTH / 2.f - fillw; fillrect((int)x, y, fillw, GUI_VALBAR_HEIGHT, BLACK); //fillrect(GUI_VALBAR_X-1, y, GUI_VALBAR_WIDTH+2, GUI_VALBAR_HEIGHT, BLACK); } for(int x = GUI_VALBAR_X + 4; x < GUI_VALBAR_X+GUI_VALBAR_WIDTH-1; x += 5) { setpixel(x, y-1, BLACK); setpixel(x, y + GUI_VALBAR_HEIGHT, BLACK); } //draw left marker drawline(GUI_VALBAR_X-2, y-2, GUI_VALBAR_X-2, y + GUI_VALBAR_HEIGHT+1, BLACK); //draw right marker drawline(GUI_VALBAR_X + GUI_VALBAR_WIDTH, y-2, GUI_VALBAR_X + GUI_VALBAR_WIDTH, y + GUI_VALBAR_HEIGHT+1, BLACK); //draw middle marker //setpixel(GUI_VALBAR_HALF, y-1,BLACK); setpixel(GUI_VALBAR_HALF+1, y-1, BLACK); setpixel(GUI_VALBAR_HALF+1, y + GUI_VALBAR_HEIGHT, BLACK); }
void pfprint(field_t pf) { coord_t x,y; for(y=YSIZE; y--;) { for(x=XSIZE; x--;) { setpixel((pixel){x,y},getcell(pf,x,y)*3); } } }
// blink a specific LED (at x,y) "n" times void blinkn(uint8_t n) { uint8_t del; uint8_t x = 0; uint8_t y = 1; uint8_t i; /* blink LED6 (at 0,1) "n" times */ del = 25; for (i = 0; i < n; i++) { setpixel(x, y, 1); // LED(x,y) on mydelay10(del); setpixel(x, y, 0); // LED(x,y) off mydelay10(del); } }
void filter_trick(struct image *img) { #define TSIZE 3 struct image *dst; int x, y, i, j, val, m, more, l, less; int r, g, b; dst = image_new(img->width, img->height); for(y = 0; y < img->height; y++) for(x = 0; x < img->width; x++) setpixel(dst, x, y, 255, 255, 255); for(y = TSIZE/2; y < img->height - TSIZE/2; y++) for(x = TSIZE/2; x < img->width - TSIZE/2; x++) { getpixel(img, x + TSIZE - TSIZE/2, y + TSIZE - TSIZE/2, &val, &g, &b); m = more = l = less = 0; for(i = 0; i < TSIZE; i++) for(j = 0; j < TSIZE; j++) { getpixel(img, x + j - TSIZE/2, y + i - TSIZE/2, &r, &g, &b); if(r > val) { more += r; m++; } else if(r < val) { less += r; l++; } } if(l >= 6) i = less / l; else if(m >= 6) i = more / m; else i = val; setpixel(dst, x, y, i, i, i); } image_swap(img, dst); image_free(dst); }
const bool mxSurfacePainter::setPixel(int x, int y, Uint32 color) { if(locked == false) return false; setpixel(pbuf, x, y, color, surface->getSurface()->format->BytesPerPixel, surface->getSurface()->pitch); return true; }