void HairyBrush::paintParticle(QPointF pos, const KoColor& color) { // opacity top left, right, bottom left, right memcpy(m_color.data(), color.data(), m_pixelSize); quint8 opacity = color.opacityU8(); int ipx = int (pos.x()); int ipy = int (pos.y()); qreal fx = pos.x() - ipx; qreal fy = pos.y() - ipy; quint8 btl = qRound((1.0 - fx) * (1.0 - fy) * opacity); quint8 btr = qRound((fx) * (1.0 - fy) * opacity); quint8 bbl = qRound((1.0 - fx) * (fy) * opacity); quint8 bbr = qRound((fx) * (fy) * opacity); m_color.setOpacity(btl); plotPixel(ipx , ipy, m_color); m_color.setOpacity(btr); plotPixel(ipx + 1 , ipy, m_color); m_color.setOpacity(bbl); plotPixel(ipx , ipy + 1, m_color); m_color.setOpacity(bbr); plotPixel(ipx + 1 , ipy + 1, m_color); }
void Texture::createFractal(Colour low, Colour high, float roughness, bool conserveHue){ int resolution = (image->w > image->h)?image->w:image->h; // use larger dimension if (conserveHue){ float** data = Math::generateFractal(resolution,0,1,roughness,true); // make tileable texture for (int x=0; x<image->w; x++){ for (int y=0; y<image->h; y++){ int r = int(data[x][y]*(high.r - low.r) + low.r); int g = int(data[x][y]*(high.g - low.g) + low.g); int b = int(data[x][y]*(high.b - low.b) + low.b); plotPixel(x,y,Colour(r,g,b,255)); } } for (int i=0; i<resolution; i++){ delete []data[i]; } delete []data; } else { float** rdata = Math::generateFractal(resolution,0,1,roughness,true); float** gdata = Math::generateFractal(resolution,0,1,roughness,true); float** bdata = Math::generateFractal(resolution,0,1,roughness,true); for (int x=0; x<image->w; x++){ for (int y=0; y<image->h; y++){ int r = int(rdata[x][y]*(high.r - low.r) + low.r); int g = int(gdata[x][y]*(high.g - low.g) + low.g); int b = int(bdata[x][y]*(high.b - low.b) + low.b); plotPixel(x,y,Colour(r,g,b,255)); } } for (int i=0; i<resolution; i++){ delete []rdata[i]; delete []gdata[i]; delete []bdata[i]; } delete []rdata; delete []gdata; delete []bdata; } }
void idle() { float r, g, b, a; float x, y; // This is where your ray-tracing code will go // Please note this is set up to change one pixel at a time. When // you do this assignment, updating the framebuffer every pixel // will be a bottleneck. It is best to do several at once, then // update the screen. if (raster_x < WINDOW_WIDTH && raster_y < WINDOW_HEIGHT) { // first, do a ray trace at raster position (x,y). I made the coordinate system the same as in GLUT. //x = (float)raster_x - (float)WINDOW_WIDTH/2.0f; //y = (float)raster_y - (float)WINDOW_HEIGHT/2.0f; my_raytrace(raster_x,raster_y); b = illu_b; g=illu_g; r=illu_r; // now we must change the color in our buffer plotPixel(screen, raster_x, raster_y, r, g, b, a); // now lets upload the changes to the video card (slow) // Unfortunately, the final parameter of glTexSubImage2D can only be a 1D array // containing the exact pixels you want to transfer (it isn't smart enough to // select a square, for instance) glBindTexture(GL_TEXTURE_2D, texId); glTexSubImage2D(GL_TEXTURE_2D, 0, raster_x, raster_y, 1, 1, GL_RGBA, GL_FLOAT, (void*)(screen + (raster_y*WINDOW_WIDTH+raster_x))); illu_b=0; illu_g=0; illu_r=0; } if (raster_x < WINDOW_WIDTH) raster_x++; if (raster_x == WINDOW_WIDTH) // finished line, increment Y raster { raster_x = 0; raster_y++; glutPostRedisplay(); } // redraw // Note that this function will not be called again until the display // update completes. This limits the number of times this function // is called to you monitor refresh rate. To get around this, you // could calculate several lines and then update, or you can do the // entire thing and update. }
void drawPath( SDL_Surface* screen, int sx, int sy, int dx, int dy, int animate ) { int x,y,/*dx,dy,*/cidx; int num=0; x=boardOffsetX + sx*20; y=boardOffsetY + sy*20; dx=boardOffsetX + dx*20; dy=boardOffsetY + dy*20; if(animate) { graphics.teleColorIndex+=2; if(graphics.teleColorIndex > TELEPATHNUMCOL) graphics.teleColorIndex = 0; } cidx=graphics.teleColorIndex; while(x!=dx || y!=dy) { if(x<dx) x++; if(x>dx) x--; if(y<dy) y++; if(y>dy) y--; if(animate) { cidx--; if(cidx<0) cidx=TELEPATHNUMCOL-1; plotPixel(screen, x+10,y+10, graphics.teleColorTable[cidx]); } else if(num%3==0) { plotPixel(screen, x+10,y+10, graphics.teleColorTable[0]); } num++; } }
void drawPointer(SDL_Surface* screen) { if( inpPointer.timeSinceMoved < POINTER_SHOW_TIMEOUT ) { //Update pointer-holddown time if(inpPointer.isDown) inpPointer.downTime += getTicks(); if( inpPointer.escEnable ) { inpPointer.escEnable=0; SDL_BlitSurface( ptrBackImg, NULL, screen,&backBtnDstRect); } plotPixel(screen, inpPointer.vpX, inpPointer.vpY, inpPointer.colWhite ); plotPixel(screen, inpPointer.vpX, inpPointer.vpY-2, inpPointer.colWhite ); plotPixel(screen, inpPointer.vpX, inpPointer.vpY+2, inpPointer.colWhite ); plotPixel(screen, inpPointer.vpX-2, inpPointer.vpY, inpPointer.colWhite ); plotPixel(screen, inpPointer.vpX+2, inpPointer.vpY, inpPointer.colWhite ); } }
inline void HairyBrush::addBristleInk(Bristle *bristle,const QPointF &pos, const KoColor &color) { Q_UNUSED(bristle); if (m_properties->antialias) { if (m_properties->useCompositing) { paintParticle(pos, color); } else { paintParticle(pos, color, 1.0); } } else { int ix = qRound(pos.x()); int iy = qRound(pos.y()); if (m_properties->useCompositing) { plotPixel(ix, iy, color); } else { darkenPixel(ix, iy, color); } } }
void starField(SDL_Surface* screen, int move) { SDL_FillRect(screen, NULL, 0x00); star_t* star; listItem* it=stars; while( (it=it->next) ) { star=(star_t*)it->data; //Move star if(move) { star->x -= star->sx; //Out of screen? if(star->x < 0) { //Give new y and reset x star->y=rand()%(SCREENH*10)-1; star->x= (SCREENW*10)-1; } } //Draw plotPixel(screen, star->x/10, star->y/10, star->color); } }
void initGL() { int i, j; glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0); resizeWindow(WINDOW_WIDTH, WINDOW_HEIGHT); // erase texture for (i=0;i<sizeof(screen)/sizeof(color_t);i++) { screen[i].r = 0.0f; screen[i].g = 0.0f; screen[i].b = 0.0f; screen[i].a = 1.0f; } // put a red square on the top left for (i=0; i < 32; i++) { for (j=0; j<32;j++) { plotPixel(screen, i, j, 1.0f, 0.0f, 0.0f, 1.0f); } } // put a green square on the top right for (i=WINDOW_WIDTH-32-1; i<WINDOW_WIDTH; i++) { for (j=0; j<32;j++) { plotPixel(screen, i, j, 0.0f, 1.0f, 0.0f, 1.0f); } } // put a blue square on the bottom left for (i=0; i<32; i++) { for (j=WINDOW_HEIGHT-32-1; j<WINDOW_HEIGHT;j++) { plotPixel(screen, i, j, 0.0f, 0.0f, 1.0f, 1.0f); } } // put a white square on the bottom left for (i=WINDOW_WIDTH-32-1; i<WINDOW_WIDTH; i++) { for (j=WINDOW_HEIGHT-32-1; j<WINDOW_HEIGHT;j++) { plotPixel(screen, i, j, 1.0f, 1.0f, 1.0f, 1.0f); } } // create texture for drawing glEnable(GL_TEXTURE_2D); glGenTextures(1, &texId); glBindTexture(GL_TEXTURE_2D, texId); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, WINDOW_WIDTH, WINDOW_HEIGHT, 0, GL_RGBA, GL_FLOAT, (void*)screen); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); }
void fireWorks(SDL_Surface* screen) { rocket_t* tempRocket; star_t* tempStar; listItem* it; uint32_t colWhite = SDL_MapRGB(screen->format, 255,255,255); uint32_t colYellow = SDL_MapRGB(screen->format, 255,255,0); /* New Rockets */ nextExpl -= getTicks(); if(nextExpl < 1) { //Set new timer nextExpl = rand()%2000; //Fire a new rocket tempRocket = malloc(sizeof(rocket_t)); //Set initial position at y 240, and some random x tempRocket->y=(SCREENH*10); tempRocket->x=rand()%(SCREENW*10); //Set a direction that flies towards the middle tempRocket->sx = rand()%5; if(tempRocket->x > (HSCREENW*10) ) { tempRocket->sx *= -1; } tempRocket->sy = 0-rand()%30-20; //Set life tempRocket->life=rand()%1000+250+10; tempRocket->p = initList(); //Init particles for explosion int i, r=rand()%100; for(i=0; i < r; i++) { tempStar = malloc( sizeof(star_t) ); //Set dir to something random tempStar->sx = rand()%500-250; tempStar->sy = rand()%500-250; tempStar->color = SDL_MapRGB( screen->format, rand()%128+128,rand()%256,rand()%128); tempStar->life = rand()%3000+500; //Add to list listAddData( tempRocket->p, (void*)tempStar ); } //Add rocket to list listAddData(rockets, (void*)tempRocket); //Play launch sound sndPlay(SND_ROCKETLAUNCH, tempRocket->x/10); } /* Going through rockets and their particles */ it=rockets; listItem* itt; while( (it=it->next) ) { tempRocket=(rocket_t*)it->data; //If rocket is still alive, fly it if(tempRocket->life > 0) { //Age tempRocket->life -= getTicks(); //Set position for particles if it got too old if(tempRocket->life < 1) { itt=tempRocket->p; while( (itt=itt->next) ) { tempStar=(star_t*)itt->data; tempStar->x = tempRocket->x*10; tempStar->y = tempRocket->y*10; } //Play "Explosion" sound sndPlay(SND_ROCKETBOOM, tempRocket->x/10); } //Fly tempRocket->x += tempRocket->sx; tempRocket->y += tempRocket->sy; //Draw plotPixel(screen, tempRocket->x/10, tempRocket->y/10, colWhite ); plotPixel(screen, tempRocket->x/10, tempRocket->y/10+1, colYellow ); } else { //iterate through stars itt=tempRocket->p; int liveStars=0; while( (itt=itt->next) ) { tempStar=(star_t*)itt->data; //alive? if(tempStar->life > 0) { //Fly tempStar->x += tempStar->sx/10; tempStar->y += tempStar->sy/10; //Gravity if(tempStar->y < 10) tempStar->y += 20; //Draw if(tempStar->life > 1000 || tempStar->life % 2 == 0) plotPixel(screen, tempStar->x/100, tempStar->y/100, tempStar->color); else if(tempStar->life % 3 == 0) plotPixel(screen, tempStar->x/100, tempStar->y/100, colWhite); //age tempStar->life -= getTicks(); liveStars++; } //alive } //Check if it should still survice if(liveStars == 0) { //Remove stars itt=tempRocket->p; while( (itt=itt->next) ) { free(itt->data); } freeList(tempRocket->p); //Remove rocket free(it->data); listRemoveItem(rockets, it); } } //Sim rocket stars } //iterate through rockets }