void desactivar_actuador(int x, int y, TipoActuador actuador, string nombre){ std::swap( x,y); SDL_Rect rect; rect.x = x; rect.y = y; rect.w = 100; rect.h = 100; SDL_SetRenderDrawColor(renderer,0xFF,0xFF,0xFF,0xFF); SDL_RenderFillRect(renderer, &rect); SDL_RenderPresent(renderer); switch (actuador){ case Alarma: filledCircleRGBA( renderer, ORIGEN_X + x, ORIGEN_Y + y, 6, 0xFF,0xFF,0xFF,0xFF); circleRGBA(renderer, ORIGEN_X + x, ORIGEN_Y + y, 6 , 0xFF,0x00,0x00,0xFF); renderString(nombre.c_str(), x +ORIGEN_X-3 ,y+ORIGEN_Y-18, 0xFF,0x00,0x00); renderString("OFF", x +ORIGEN_X-6 ,y+ORIGEN_Y+10, 0xFF,0x00,0x00); break; case Luz: filledCircleRGBA( renderer, ORIGEN_X + x, ORIGEN_Y + y, 6, 0xFF,0xFF,0xFF,0xFF); circleRGBA(renderer, ORIGEN_X + x, ORIGEN_Y + y, 6 , 0xFF,0xB4,0x00,0xFF); renderString(nombre.c_str(), x +ORIGEN_X-3 ,y+ORIGEN_Y-18,0xFF,0xB4,0x00); renderString("OFF", x +ORIGEN_X-6 ,y+ORIGEN_Y+10,0xFF,0xB4,0x00); break; }; SDL_RenderPresent(renderer); }
void DamageAction::render() { // Damage int rad = 26; filledCircleRGBA( Game::getGlobalGame()->getRenderer(), position.x + (rand()%rad-rand()%rad), position.y + (rand()%rad-rand()%rad), (rand()%3+1)/(timer/5+1), 168+rand()%88, 50+rand()%128, 50+rand()%128, 190+rand()%55 ); filledCircleRGBA( Game::getGlobalGame()->getRenderer(), position.x + (rand()%rad-rand()%rad), position.y + (rand()%rad-rand()%rad), (rand()%3+1)/(timer/5+1), 168+rand()%88, 50+rand()%128, 50+rand()%128, 190+rand()%55 ); filledCircleRGBA( Game::getGlobalGame()->getRenderer(), position.x + (rand()%rad-rand()%rad), position.y + (rand()%rad-rand()%rad), (rand()%3+1)/(timer/5+1), 168+rand()%88, 50+rand()%128, 50+rand()%128, 190+rand()%55 ); filledCircleRGBA( Game::getGlobalGame()->getRenderer(), position.x + (rand()%rad-rand()%rad), position.y + (rand()%rad-rand()%rad), (rand()%3+1)/(timer/5+1), 168+rand()%88, 50+rand()%128, 50+rand()%128, 190+rand()%55 ); filledCircleRGBA( Game::getGlobalGame()->getRenderer(), position.x + (rand()%rad-rand()%rad), position.y + (rand()%rad-rand()%rad), (rand()%3+1)/(timer/5+1), 168+rand()%88, 50+rand()%128, 50+rand()%128, 190+rand()%55 ); }
bool PowerUp::render() { double throughLife = (double)(SDL_GetTicks()-birthTime)/(double)LIFE_TIME; int color = (double)0xff * throughLife; int end = (1.0f-throughLife)*360.0f; arcRGBA(SDL_GetVideoSurface(), X(), Y(), getRadius(), 0, end, 0xff, 0xff, 0xff, 0xff-color); if(type == 10) { // Spray power up filledCircleRGBA(SDL_GetVideoSurface(), X()-10, Y()+3, 4, 0xff, 0xff, 0xff, 0xff-color); filledCircleRGBA(SDL_GetVideoSurface(), X(), Y()-3, 4, 0xff, 0xff, 0xff, 0xff-color); filledCircleRGBA(SDL_GetVideoSurface(), X()+10, Y()+3, 4, 0xff, 0xff, 0xff, 0xff-color); } else if(type == 11) { // Cluster bullet filledCircleRGBA(SDL_GetVideoSurface(), X(), Y(), 4, 0xff, 0xff, 0xff, 0xff-color); filledCircleRGBA(SDL_GetVideoSurface(), X()-10, Y()-4, 2, 0xff, 0xff, 0xff, 0xff-color); filledCircleRGBA(SDL_GetVideoSurface(), X(), Y()-8, 2, 0xff, 0xff, 0xff, 0xff-color); filledCircleRGBA(SDL_GetVideoSurface(), X()+10, Y()-4, 2, 0xff, 0xff, 0xff, 0xff-color); filledCircleRGBA(SDL_GetVideoSurface(), X()-8, Y()+6, 2, 0xff, 0xff, 0xff, 0xff-color); filledCircleRGBA(SDL_GetVideoSurface(), X()+8, Y()+6, 2, 0xff, 0xff, 0xff, 0xff-color); } else if(type == 12) { // Shield aacircleColor(SDL_GetVideoSurface(), X(), Y(), getRadius()-10+(cos((double)SDL_GetTicks()/100.0f)*3), 0xffffffff); } return isAlive(); }
void MotionControl::drawMap(SDL_Surface* screen, int sx, int sy) const { #if 0 //pixelRGBA(screen, sx, sy, 255, 255, 255, 255); lineRGBA(screen, sx, sy, sx, sy-100, 255, 255, 0, 255); lineRGBA(screen, sx, sy, sx+100, sy, 255, 255, 0, 255); float pxl_per_m = 100; filledCircleRGBA(screen, sx + lastPose.x * pxl_per_m, sy - lastPose.y * pxl_per_m, 5, 0, 255, 255, 255); lineRGBA(screen, sx + lastPose.x * pxl_per_m, sy - lastPose.y * pxl_per_m, sx + (lastPose.x + cos(lastPose.theta)) * pxl_per_m, sy - (lastPose.y + sin(lastPose.theta)) * pxl_per_m, 255, 0, 0, 255); PoseList poles{ Pose(3, 3.1, 0), Pose(3, 2.3, 0), Pose(3.2, 1.2, 0), Pose(4, 1.2, 0), Pose(2.2, 1.9, 0), Pose(2.2, 1.1, 0), Pose(1, 0.3, 0), Pose(1, 1.1, 0), Pose(1.5, 2.8, 0), Pose(1.5, 2, 0) }; for (auto it = poles.begin(); it != poles.end(); ++it) { filledCircleRGBA(screen, sx + it->x * pxl_per_m, sy - it->y * pxl_per_m, 5, 255, 0, 0, 255); } for (auto it = waypoints.begin(); it != waypoints.end(); ++it) { filledCircleRGBA(screen, sx + it->x * pxl_per_m, sy - it->y * pxl_per_m, 5, 0, 0, 255, 255); } auto last = midpoints.begin(); //cout << endl << "Starting le draw" << endl; if (last != midpoints.end()) { int i=1; auto next = last; lineRGBA(screen, sx + lastPose.x * pxl_per_m, sy - lastPose.y * pxl_per_m, sx + last->x * pxl_per_m, sy - last->y * pxl_per_m, 255, 255, 0, 255); for (++next; ; ++next) { float arrowx = cos(last->theta), arrowy = sin(last->theta); lineRGBA(screen, sx + last->x * pxl_per_m, sy - last->y * pxl_per_m, sx + (last->x+arrowx) * pxl_per_m, sy - (last->y+arrowy) * pxl_per_m, 255-255*i/midpoints.size(), 255*i/midpoints.size(), 0, 255); if (next == midpoints.end()) break; lineRGBA(screen, sx + last->x * pxl_per_m, sy - last->y * pxl_per_m, sx + next->x * pxl_per_m, sy - next->y * pxl_per_m, 255, 255, 255, 255); last = next; i++; } } #endif }
void DrawHand(SDL_Renderer *renderer, int hour, int minute, int second) { double a_hour, a_min, a_sec, a_sec1; int x_hour, y_hour, x_min, y_min, x_sec, y_sec, x1_sec, y1_sec; a_sec = second * 2 * M_PI / 60; a_sec1 = (second > 30 ? second-30 : second+30) * 2 * M_PI / 60; a_min = minute * 2 * M_PI / 60 + a_sec / 60; a_hour = hour * 2 * M_PI / 12 + a_min / 12; x_sec = WIDTH/2 + (int)(HEIGHT/2 * 0.95 * sin(a_sec)); y_sec = HEIGHT/2 - (int)(HEIGHT/2 * 0.95 * cos(a_sec)); x1_sec = WIDTH/2 + (int)(HEIGHT/2 * 0.20 * sin(a_sec1)); y1_sec = HEIGHT/2 - (int)(HEIGHT/2 * 0.20 * cos(a_sec1)); x_min = WIDTH/2 + (int)(HEIGHT/2 * 0.85 * sin(a_min)); y_min = HEIGHT/2 - (int)(HEIGHT/2 * 0.85 * cos(a_min)); x_hour = WIDTH/2 + (int)(HEIGHT/2 * 0.65 * sin(a_hour)); y_hour = HEIGHT/2 - (int)(HEIGHT/2 * 0.65 * cos(a_hour)); thickLineRGBA(renderer, WIDTH/2, HEIGHT/2, x_hour, y_hour, I_ZOOM*5, 0, 0, 255, 255); thickLineRGBA(renderer, WIDTH/2, HEIGHT/2, x_min, y_min, I_ZOOM*4, 0, 255, 0, 255); thickLineRGBA(renderer, x1_sec, y1_sec, x_sec, y_sec, I_ZOOM*1, 255, 0, 0, 255); filledCircleRGBA(renderer, WIDTH/2, HEIGHT/2, I_ZOOM*8, 255, 160, 255, 240); }
void CirculoR(int x, int y, int rad, unsigned char r, unsigned char g, unsigned char b, GRF_Imagen img) { GRF_Imagen ptr = ((img==0) ? ventana : img); filledCircleRGBA(ptr, x, y, rad, r, g, b,255); if (img==0 && dibujo_activo) SDL_UpdateRect(ptr, x-rad, y-rad, rad*2+1, rad*2+1); }
void draw_tank (Sint16 x, Sint16 y, Uint8 color, Sint16 tank_cannon_angle, Sint16 zoom) { Sint16 x_rel = x - world_up_x; Sint16 y_rel = y - world_up_y; Sint16 tank_x1 = (x_rel * zoom) + (zoom / 4); Sint16 tank_y1 = (y_rel * zoom) + (zoom / 4); Sint16 tank_x2 = (x_rel * zoom) + (zoom - (zoom / 4)); Sint16 tank_y2 = (y_rel * zoom) + (zoom - (zoom / 4)); Sint16 tank_left_chain_x = tank_x1 - (zoom / 8); Sint16 tank_right_chain_x = tank_x2 + (zoom / 8); Sint16 tank_cannon_x = tank_x1 + (tank_x2 - tank_x1) / 2; Sint16 tank_cannon_y = tank_y1 + (tank_y2 - tank_y1) / 2; Sint16 tank_cannon_width = zoom / 8; Sint16 tank_cannon_length = zoom; /* draw tank */ boxRGBA (screen, tank_x1, tank_y1, tank_x2, tank_y2, unit_color[color].r, unit_color[color].g, unit_color[color].b, 255); boxRGBA (screen, tank_left_chain_x, tank_y1, tank_x1, tank_y2, 0, 0, 0, 255); boxRGBA (screen, tank_right_chain_x, tank_y1, tank_x2, tank_y2, 0, 0, 0, 255); filledCircleRGBA (screen, tank_cannon_x, tank_cannon_y, tank_cannon_width, 0, 0, 0, 255); draw_line_rotated (screen, tank_cannon_x, tank_cannon_y, tank_cannon_length, tank_cannon_angle, tank_cannon_width / 2, 0, 0, 0); update_screen (); }
/** * @brief Draws the lines. */ void LineApp::draw_line_points() { for (unsigned int i = 0; i < line_points.size(); i++) { filledCircleRGBA(surf, line_points[i]->x, line_points[i]->y, LINEPOINTSIZE, 255, 0, 0, 255); } }
void CPhysicsDebugDraw::DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) { filledCircleRGBA(g_app->sdlRenderer,(Sint16)(center.x*C_RATIO),(Sint16)(center.y*C_RATIO),(Sint16)(radius*C_RATIO),(Uint8)(color.r * 255),(Uint8)(color.g * 255),(Uint8)(color.b * 255),200); b2Vec2 p = center + radius * axis; lineRGBA(g_app->sdlRenderer,(Sint16)(center.x*C_RATIO),(Sint16)(center.y*C_RATIO),(Sint16)(p.x*C_RATIO),(Sint16)(p.y*C_RATIO),(Uint8)(color.r * 255),(Uint8)(color.g * 255),(Uint8)(color.b * 255),255); }
void Draw(SDL_Surface *screen) { int i,rate,x,y,dx,dy,r,g,b; FPSmanager fpsm; /* Initialize variables */ srand(time(NULL)); i=0; x=screen->w/2; y=screen->h/2; dx=7; dy=5; r=g=b=255; SDL_initFramerate(&fpsm); while (1) { /* Set/switch framerate */ i -= 1; if (i<0) { /* Set new rate */ rate=5+5*(rand() % 10); SDL_setFramerate(&fpsm,rate); printf ("\nFramerate set to %i Hz ...\n\n",rate); /* New timeout */ i=2*rate; /* New Color */ r=rand() & 255; g=rand() & 255; b=rand() & 255; } HandleEvent(); /* Black screen */ ClearScreen(screen); /* Move */ x += dx; y += dy; /* Reflect */ if ((x<0) || (x>screen->w)) { dx=-dx; } if ((y<0) || (y>screen->h)) { dy=-dy; } /* Draw */ filledCircleRGBA (screen,x,y,30,r,g,b,255); circleRGBA(screen,x,y,30,255,255,255,255); /* Display by flipping screens */ SDL_UpdateRect(screen,0,0,0,0); /* Delay to fix rate */ SDL_framerateDelay(&fpsm); } }
void MotionControl::drawInfo(SDL_Surface* screen, int sx, int sy) const { filledCircleRGBA(screen, sx, sy, 5, 255, 255, 255, 255); if (history.size()) { float a = history.back().ata; int dx = 20 * cos(a); int dy = 20 * sin(a); lineRGBA(screen, sx, sy, sx + dx, sy - dy, 255, 0, 0, 255); } }
void Renderer::drawCircle(const b2Vec2& center, float32 radius, Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha, bool filled){ b2Vec2 coords = toScreenCoords(center); if(filled){ filledCircleRGBA(renderer, (Sint16) coords.x, (Sint16) coords.y, (Sint16) metersToPixels(radius), red, green, blue, alpha); }else{ circleRGBA(renderer, (Sint16) coords.x, (Sint16) coords.y, (Sint16) metersToPixels(radius), red, green, blue, alpha); } }
void Draw(SDL_Renderer *renderer, FPSmanager *fpsm) { int newRate; int currentRate; /* FPSmanager: get current rate */ currentRate = SDL_getFramerate(fpsm); /* Set/switch framerate */ timeout--; if (timeout < 0) { /* New rate */ newRate = 5 + 5 * (rand() % 10); /* Update timeout */ timeout = 2 * newRate; /* New Color */ r = rand() & 255; g = rand() & 255; b = rand() & 255; /* FPSmanager: set new rate */ SDL_setFramerate(fpsm, newRate); } /* Black screen */ ClearScreen(renderer); /* Move */ x += dx; y += dy; /* Reflect */ if ((x<0) || (x>WIDTH)) { dx=-dx; } if ((y<0) || (y>HEIGHT)) { dy=-dy; } /* Draw */ filledCircleRGBA (renderer,x,y,30,r,g,b,255); circleRGBA(renderer,x,y,30,255,255,255,255); /* Report set rate and current delay (from last iteration) */ if (time_passed > 0) { SDL_snprintf(messageText, 1024, "Set rate: %4iHz Last delay=%4ims / Calc.Rate=%4iHz", currentRate, time_passed, 1000 / time_passed); stringRGBA (renderer, WIDTH/2 - 4*strlen(messageText),HEIGHT-24,messageText,255,255,255,255); } /* Simulate some random delay from drawing, business logic, network interaction, etc. */ SDL_Delay(1 + rand() % 10); /* Display */ SDL_RenderPresent(renderer); /* FPSmanager: Delay to a fixed rate */ time_passed = SDL_framerateDelay(fpsm); }
void marca_sensor(int x, int y, TipoSensor sensor, string nombre){ SDL_RenderPresent(renderer); std::swap(x,y); switch (sensor){ case Temperatura: filledCircleRGBA(renderer, ORIGEN_X + x, ORIGEN_Y + y, 6, 0,0xFF,0,0xFF); renderString(nombre.c_str(), x+ORIGEN_X-3, y+ORIGEN_Y-18,0,0xFF,0); break; case Luminosidad: filledCircleRGBA(renderer, ORIGEN_X + x, ORIGEN_Y + y, 6,0xFF,0xFF,0xFF,0xFF); renderString(nombre.c_str(), x+ORIGEN_X-3, y+ORIGEN_Y-18, 0xFF,0xFF,0xFF); break; case Humo: filledCircleRGBA(renderer, ORIGEN_X + x, ORIGEN_Y + y, 6, 0,0,0xFF,0xFF); renderString(nombre.c_str(), x+ORIGEN_X-3, y+ORIGEN_Y-18,0,0,0xFF); break; }; SDL_RenderPresent(renderer); }
void Simulation::Render() { SDL_Renderer *renderer = Game::getGlobalGame()->getRenderer(); Game::getGlobalGame()->setBackgroundColor(0, 0, 0); // Render do Fundo // SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_ADD); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); drawBG(background[0], bgOffsetX, bgOffsetY, -0.1, renderer); drawBG(background[1], bgOffsetX, bgOffsetY, -0.13, renderer); drawBG(background[2], bgOffsetX, bgOffsetY, -0.2, renderer); drawBG(background[3], bgOffsetX, bgOffsetY, -0.28, renderer); // background[0]->DrawImage(bgOffsetX*0.10, bgOffsetY*0.10, renderer); // background[1]->DrawImage(bgOffsetX*0.13, bgOffsetY*0.13, renderer); // background[2]->DrawImage(bgOffsetX*0.20, bgOffsetY*0.20, renderer); // background[3]->DrawImage(bgOffsetX*0.28, bgOffsetY*0.28, renderer); // background->DrawImage(bgOffsetX, bgOffsetY, renderer); // background->DrawImage(bgOffsetX + Game::getGlobalGame()->getWidth(), // bgOffsetY + Game::getGlobalGame()->getHeight(), renderer); // // background->DrawImage(bgOffsetX + Game::getGlobalGame()->getWidth(), bgOffsetY, renderer); // background->DrawImage(bgOffsetX, bgOffsetY + Game::getGlobalGame()->getHeight(), renderer); //Just TESTING SDL_SetRenderTarget(renderer, renderCombat); // Limpar textura SDL_SetTextureBlendMode(renderCombat, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); SDL_RenderClear(renderer); SDL_SetRenderDrawBlendMode(renderer, SDL_BlendMode::SDL_BLENDMODE_NONE); SDL_SetTextureBlendMode(renderCombat, SDL_BLENDMODE_BLEND); simulationWorld->render(); SDL_SetRenderTarget(renderer, 0); // Renderizar imagem de combate na tela SDL_Rect rect; rect.x = -camera->getX(); rect.w = 2048; rect.y = -camera->getY(); rect.h = 2048; SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_SetRenderDrawBlendMode(renderer, SDL_BlendMode::SDL_BLENDMODE_NONE); SDL_RenderCopy( renderer, renderCombat, 0, &rect); if(selectedUnit) { filledCircleRGBA( renderer, selectedUnit->getAvgX(), selectedUnit->getAvgY(), 64, 0, 0, 255, 128 ); } }
int Sprite::drawFilledCircle(Vector2 *center, int radius, int r, int g, int b, int a, int translation, Screen *screen) { Vector2 *scrolledCenter; scrolledCenter = ScrollManager::getInstance()->scrollVector(center); int ret = filledCircleRGBA(screen->getTopScreen(), scrolledCenter->x + translation, scrolledCenter->y + translation, radius, r, g, b, a); delete scrolledCenter; return ret; }
void Tower::DrawRange() { int r = 255; int g = 0; int b = 0; int x = (gridX + .5)*TILESIZE + Surface::Padding; int y = (gridY + .5)*TILESIZE + Surface::Padding; filledCircleRGBA(Surface::Display, x, y, range, r, g, b, 64); circleRGBA(Surface::Display, x, y, range, r, g, b, 255); };
CAMLprim value ml_filledCircleRGBA(value dst,value p,value ra, value col,value alpha) { SDL_Surface *sur= SDL_SURFACE(dst); SDL_Rect prect; SDL_Color c; int r; SDLRect_of_value(&prect,p); SDLColor_of_value(&c,col); r=filledCircleRGBA(sur,prect.x,prect.y,Int_val(ra),c.r,c.g,c.b, Int_val(alpha)); return Val_bool(r); }
void affichage(){ cpFloat timeStep = 1.0/60.0; SDL_Color white={255,255,255}; for(cpFloat time = 0; time < 25; time += timeStep){ SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format,0,0,0)); for(int i=0;i<50;i++){ if(lesBoules[i].del==FALSE){ cpVect pos = cpBodyGetPos(lesBoules[i].body); cpVect vel = cpBodyGetVel(lesBoules[i].body); rectangleColor(ecran,10, 0, 630, 420,SDL_MapRGB(ecran->format,255,255,255)); circleRGBA(ecran, pos.y, pos.x, lesBoules[i].radius, lesBoules[i].r,lesBoules[i].g,lesBoules[i].b,lesBoules[i].a); filledCircleRGBA(ecran,pos.y,pos.x,lesBoules[i].radius, lesBoules[i].r,lesBoules[i].g,lesBoules[i].b,lesBoules[i].a); //lettre SDL_Surface *lettre= TTF_RenderText_Solid(police, lesBoules[i].lettre, white); SDL_Rect position; position.y=pos.x; position.x=pos.y; lesBoules[i].x=pos.x; lesBoules[i].y=pos.y; SDL_BlitSurface(lettre, NULL, ecran, &position); } } SDL_Surface *pointsTexte=TTF_RenderText_Solid(police,"Score:" , white); SDL_Rect position_pointsTexte; position_pointsTexte.y=435; position_pointsTexte.x=10; SDL_BlitSurface(pointsTexte, NULL, ecran, &position_pointsTexte); char scoreChar[15]={"0"}; snprintf(scoreChar, 15, "%d", score); SDL_Surface *points=TTF_RenderText_Solid(police,scoreChar, white); SDL_Rect position_points; position_points.y=435; position_points.x=100; SDL_BlitSurface(points, NULL, ecran, &position_points); cpSpaceStep(espace, timeStep); SDL_Flip(ecran); } //affichage points SDL_Flip(ecran); }
static void drawDIPS(SDL_Surface* surf, state* s, unsigned char r, unsigned char g, unsigned char b, unsigned char a, double ratioPixels) { double distance = (fabs(s->xPosition2 - s->xPosition1) * ratioPixels) - 14; double inter = (distance) / (double)NB_SPRING; unsigned int i = 1; int sign = 1; double x1 = (screenWidth / 4.0) + (s->xPosition1 * ratioPixels); double y1 = screenHeight / 2.0; double x2 = x1 - (ratioPixels * sin(M_PIl - s->angularPosition1) * 2.0 * parameters[2]); double y2 = y1 + (ratioPixels * cos(M_PIl - s->angularPosition1) * 2.0 * parameters[2]); aalineRGBA(surf, x1, y1, x2, y2, r, g, b, a); filledCircleRGBA(surf, x1, y1, 5, r, g, b, a); filledCircleRGBA(surf, x2, y2, 5, r, g, b, a); rectangleRGBA(surf, x1 - 7, y1 - 7, x1 + 7, y1 + 7, r, g, b, a); x1 = (screenWidth / 4.0) + (s->xPosition2 * ratioPixels); y1 = (screenHeight / 2.0); x2 = x1 - (ratioPixels * sin(M_PIl - s->angularPosition2) * 2.0 * parameters[3]); y2 = y1 + (ratioPixels * cos(M_PIl - s->angularPosition2) * 2.0 * parameters[3]); aalineRGBA(surf, x1, y1, x2, y2, r, g, b, a); filledCircleRGBA(surf, x1, y1, 5, r, g, b, a); filledCircleRGBA(surf, x2, y2, 5, r, g, b, a); rectangleRGBA(surf, x1 - 7, y1 - 7, x1 + 7, y1 + 7, r, g, b, a); x1 = (screenWidth / 4.0) + (s->xPosition1 * ratioPixels) + 7; y1 = (screenHeight / 2.0); for(; i <= NB_SPRING; i++) { if(sign > 0) sign = -7; else sign = 7; aalineRGBA(surf, x1+((i-1)*inter), y1+sign, x1+(i*inter), y1-sign, r, g, b, a); } }
static void drawPendulum(state* s, unsigned char r, unsigned char g, unsigned char b, unsigned char a, double ratioPixels) { double x1 = (screenWidth / 4.0) + (s->xPosition * ratioPixels); double y1 = screenHeight / 2.0; double x2 = x1 - (ratioPixels * sin(M_PIl - s->angularPosition) * 2.0 * parameters[2]); double y2 = y1 + (ratioPixels * cos(M_PIl - s->angularPosition) * 2.0 * parameters[2]); aalineRGBA(screen, x1, y1, x2, y2, r, g, b, a); filledCircleRGBA(screen, x1, y1, 3, r, g, b, a); x2 = x1 - (int)(ratioPixels * sin(M_PIl - s->angularPosition) * ((2.0 * parameters[2]) + (3.0/ratioPixels))); y2 = y1 + (int)(ratioPixels * cos(M_PIl - s->angularPosition) * ((2.0 * parameters[2]) + (3.0/ratioPixels))); filledCircleRGBA(screen, x2, y2, 3, r, g, b, a); rectangleRGBA(screen, x1 - 10, y1 - 5, x1 + 10, y1 + 5, r, g, b, a); }
void DrawPlate(SDL_Renderer *renderer) { int w, l, x1, x2, y1, y2; filledCircleRGBA(renderer, WIDTH/2, HEIGHT/2, HEIGHT/2, 255, 154, 69, 255); filledCircleRGBA(renderer, WIDTH/2, HEIGHT/2, HEIGHT/2-I_ZOOM*10, 0, 0, 0, 255); for(int i=0; i<60; i++) { if(i%5==0) { w=4*I_ZOOM; l=15*I_ZOOM; } else { w=2*I_ZOOM; l=10*I_ZOOM; } x1=HEIGHT/2*sin(i*6*M_PI/180)+WIDTH/2; y1=HEIGHT/2*cos(i*6*M_PI/180)+HEIGHT/2; x2=(HEIGHT/2-l)*sin(i*6*M_PI/180)+WIDTH/2; y2=(HEIGHT/2-l)*cos(i*6*M_PI/180)+HEIGHT/2; thickLineRGBA(renderer, x1, y1, x2, y2, w, 111, 123, 75, 255); } }
int cSleeperGuard::render(SDL_Surface* dst, cLevel* level, bool los) { coord tc = {x, y}; tc = level->toScreen(tc); switch (state) { case SleeperGuardStates_ALARM: drawLOS(dst, level, x, y, angle, GUARD_FOV, 100); applySurface(sGuard, dst, tc.x - sGuard->w/2, tc.y - sGuard->h/2); break; case SleeperGuardStates_SLEEP: circleRGBA(dst, tc.x, tc.y, range, 255, 0, 0, 255); filledCircleRGBA(dst, tc.x, tc.y, range, 255, 0, 0, 80); applySurface(sGuard, dst, tc.x - sGuard->w/2, tc.y - sGuard->h/2); break; } return 0; }
// ML type: surface -> circle -> color -> unit // Draws a circle of the given color on the surface. EXTERNML value draw_draw_circle(value wScreen, value wCircle, value wColor) { SDL_Surface *screen = (SDL_Surface *)Addr_val(wScreen); int x = Long_val(Field(Field(wCircle, 0), 0)), y = Long_val(Field(Field(wCircle, 0), 1)), r = Long_val(Field(wCircle, 1)), colorr = Long_val(Field(wColor, 0)), colorg = Long_val(Field(wColor, 1)), colorb = Long_val(Field(wColor, 2)), colora = Tag_val(wColor) == RGBA ? Long_val(Field(wColor, 3)) : 255; if (Tag_val(wCircle) == FilledCircle) { filledCircleRGBA(screen, x, y, r, colorr, colorg, colorb, colora); } else if (Tag_val(wCircle) == AntiAliasedCircle) { aacircleRGBA(screen, x, y, r, colorr, colorg, colorb, colora); } else { circleRGBA(screen, x, y, r, colorr, colorg, colorb, colora); } return Val_unit; }
void render_pixel(uint16_t index, uint8_t r, uint8_t g, uint8_t b) { //printf("[0] render_pixel(%u, {%u,%u,%u})\n", index, r, g, b); uint16_t view = fauxel_leds[index]; uint16_t view_led_count = fauxel_view_size[view]; uint16_t view_led_position = index - fauxel_view_start[view]; uint16_t center_x = (SCREEN_WIDTH / fauxel_view_count) * view - (SCREEN_WIDTH / fauxel_view_count / 2) ; uint16_t center_y = SCREEN_HEIGHT / 2; uint16_t x = sin((360.0/view_led_count * view_led_position) * (M_PI/180)) * (SCREEN_WIDTH / fauxel_view_count / 2 - 25) + center_x; uint16_t y = cos((360.0/view_led_count * view_led_position) * (M_PI/180)) * (SCREEN_WIDTH / fauxel_view_count / 2 - 25) + center_y; // Could derive from # of views and led count to squeeze into space uint16_t radius = 20; filledCircleRGBA( renderer, x, y, radius, r, g, b, 0xFF ); // Alpha might be useful for simulating low color on leds (since its not black). // Could also draw overlapping alpha shapes since leds are individual colors. //SDL_SetRenderDrawColor( renderer, r, g, b, 0xFF ); //SDL_Rect fillRect = { (SCREEN_WIDTH / 40) * index, SCREEN_HEIGHT / 2, 15, 15}; //SDL_RenderFillRect( renderer, &fillRect ); }
void drawfilledcircle(int x1, int y1, int radius){ filledCircleRGBA(screen, x1, y1, radius, foreground_color.r, foreground_color.g, foreground_color.b , 255); /* SDL_Flip(screen); */ }
void Renderer::FilledCircle(Point p0, int radius, Uint8 rr, Uint8 gg, Uint8 bb, Uint8 aa){ filledCircleRGBA(_renderer, p0.x(), p0.y(), radius, rr, gg, bb, aa); }
int main(int argc, char *argv[]) { int seed = time(NULL); srand(seed); int ret = 0; // only the application runs in a thread, all others don't allow SDL in thread std::thread t1( logic_thread ); /* Init SDL */ if( SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO ) < 0 ) { std::cerr << "Couldn't initialize SDL: " << SDL_GetError() << std::endl; exit( 1 ); } atexit( SDL_Quit ); /* Initialize the display */ SDL_Window *sdlWindow = SDL_CreateWindow( "HEXXX simulator", // SDL2 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 400, 400, SDL_WINDOW_OPENGL ); SDL_Renderer *sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, 0); int button_0_left_state = 1; int button_0_right_state = 1; int button_1_left_state = 1; int button_1_right_state = 1; int button_2_left_state = 1; int button_2_right_state = 1; while( 1 ) { // render HEXXX on screen SDL_SetRenderDrawColor(sdlRenderer, 64, 64, 64, 255); SDL_RenderClear(sdlRenderer); for( int i = 0; i < HEXAGON_LED_COUNT; i++ ) { // we'll simulate gamma error of ws2811 LEDs by applying "gamma error" functions which are inverted of gamma correction int red = applyGammaError( getRed( simulated_ledstring[ i ] ) ); int green = applyGammaError( getGreen( simulated_ledstring[ i ] ) ); int blue = applyGammaError( getBlue( simulated_ledstring[ i ] ) ); filledCircleRGBA( sdlRenderer, 200 + 180 * led2unitx(i), 200 - 180 * led2unity(i), 5, // radius red, green, blue, 255 ); } SDL_RenderPresent(sdlRenderer); // check for button presses SDL_Event event; while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_QUIT: exit(0); break; } } const Uint8 *keystate = SDL_GetKeyboardState(NULL); set_button_state( 0, !keystate[ SDL_SCANCODE_V ] ); set_button_state( 1, !keystate[ SDL_SCANCODE_B ] ); set_button_state( 2, !keystate[ SDL_SCANCODE_Q ] ); set_button_state( 3, !keystate[ SDL_SCANCODE_W ] ); set_button_state( 4, !keystate[ SDL_SCANCODE_O ] ); set_button_state( 5, !keystate[ SDL_SCANCODE_P ] ); if( keystate[ SDL_SCANCODE_ESCAPE ] ) exit( 0 ); usleep(15000); // slow down to about 50FPS on a raspberry pi 2 } return ret; }
int main( int argc, char* args[]) { //******************************************************************************************** //* **************************************************************************************** * //* *//////////////////////////////////////////////////////////////////////////////////////* * //* */////////////////////////////////Variable Declaration/////////////////////////////////* * //* *//////////////////////////////////////////////////////////////////////////////////////* * //* **************************************************************************************** * //******************************************************************************************** SDL_Event event; // ------------------------- Maze setup ----------------------------------------- const int MAP_WIDTH = 20; const int MAP_HEIGHT = 20; const int TILE_SIZE = 20; int MAZE[ MAP_WIDTH] [MAP_HEIGHT ] = { // 0001020304050607080910111213141516171819 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 00 1,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,1, // 01 1,9,9,1,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1, // 02 1,9,9,1,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1, // 03 1,9,1,1,1,1,9,9,1,9,1,9,1,1,1,1,9,9,1,1, // 04 1,9,1,1,9,1,1,1,1,9,1,1,1,1,9,1,1,1,1,1, // 05 1,9,9,9,9,1,1,1,1,1,1,9,9,9,9,1,1,1,1,1, // 06 1,9,9,9,9,9,9,9,9,1,1,1,9,9,9,9,9,9,9,1, // 07 1,9,1,1,1,1,1,1,1,1,1,9,1,1,1,1,1,1,1,1, // 08 1,9,1,9,9,9,9,9,9,9,1,1,9,9,9,9,9,9,9,1, // 09 1,9,1,1,1,1,9,1,1,9,1,1,1,1,1,1,1,1,1,1, // 10 1,9,9,9,9,9,1,9,1,9,1,9,9,9,9,9,1,1,1,1, // 11 1,9,1,9,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1, // 12 1,9,1,9,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1, // 13 1,9,1,1,1,1,9,9,1,9,1,9,1,1,1,1,9,9,1,1, // 14 1,9,1,1,9,1,1,1,1,9,1,1,1,1,9,1,1,1,1,1, // 15 1,9,9,9,9,1,1,1,1,1,1,9,9,9,9,1,1,1,1,1, // 16 1,1,9,9,9,9,9,9,9,1,1,1,9,9,9,1,9,9,9,9, // 17 1,9,1,1,1,1,1,1,1,1,1,9,1,1,1,1,1,1,1,1, // 18 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 19 }; // --------------------------endof maze --------------------------------- //************************** //*////////integers////////* //************************** int PlayerX = 10; int PlayerY = 10; int EnemyX = 390; int EnemyY = 390; int i = 0; int MapX = 0; int MapY = 0; //************************** //*///////Characters///////* //************************** //************************** //*////////Booleans////////* //************************** bool GameRunning = true; //Up bool RightSideUp = false; bool LeftSideUp = false; //Left bool UpSideLeft = false; bool DownSideLeft = false; //Down bool RightSideDown = false; bool LeftSideDown = false; //Right bool UpSideRight = false; bool DownSideRight = false; //************************** //*/////////Arrays/////////* //************************** bool keysHeld [323] = {false}; //************************** //*////////Integers////////* //************************** //SCREEN SETUP int LeftBorder = 0; int RightBorder = MAP_WIDTH; int TopBorder = 0; int BottomBorder = MAP_HEIGHT; //mouse int MouseX = 0; int MouseY = 0; //BACKGROUND int MultiX = 1; int MultiY = 1; //************************** //*////////Booleans////////* //************************** bool drawscreen = true; bool LEFTMOUSEDOWN = false; bool RIGHTMOUSEDOWN = false; //******************************************************************************************** //* **************************************************************************************** * //* *//////////////////////////////////////////////////////////////////////////////////////* * //* *//////////////////////////////////////SDL SETUP///////////////////////////////////////* * //* *//////////////////////////////////////////////////////////////////////////////////////* * //* **************************************************************************************** * //******************************************************************************************** //Surfaces SDL_Surface* Screen = NULL ; SDL_Surface* Map = NULL ; SDL_Surface* Player = NULL ; SDL_Surface* Enemy = NULL; //Start SDL SDL_Init ( SDL_INIT_EVERYTHING ) ; //Set up screen Screen = SDL_SetVideoMode ( 400, 400, 32, SDL_SWSURFACE ); Map = SDL_SetVideoMode ( 400, 400, 32, SDL_SWSURFACE ); //******************************************************************************************** //* **************************************************************************************** * //* *//////////////////////////////////////////////////////////////////////////////////////* * //* *//////////////////////////////////////User Input//////////////////////////////////////* * //* *//////////////////////////////////////////////////////////////////////////////////////* * //* **************************************************************************************** * //******************************************************************************************** //inint tile positions while (GameRunning) { //*************************** // input //*************************** if (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { GameRunning = false; } if (event.type == SDL_KEYDOWN) { keysHeld[event.key.keysym.sym] = true; } if (event.type == SDL_KEYUP) { keysHeld[event.key.keysym.sym] = false; } if (event.type == SDL_MOUSEBUTTONDOWN) { if (event.button.button == SDL_BUTTON_LEFT) { LEFTMOUSEDOWN = true; } if (event.button.button == SDL_BUTTON_RIGHT) { RIGHTMOUSEDOWN = true; } } if (event.type == SDL_MOUSEBUTTONUP) { if (event.button.button == SDL_BUTTON_LEFT) { LEFTMOUSEDOWN = false; } if (event.button.button == SDL_BUTTON_RIGHT) { RIGHTMOUSEDOWN = false; } } } //*************************** // movement //*************************** if ( keysHeld[SDLK_ESCAPE] ) { GameRunning = false; } if ( keysHeld[SDLK_w] ) // up { RightSideUp = CollisionAtPixel (PlayerX+6, PlayerY-6, Map,1); LeftSideUp = CollisionAtPixel (PlayerX-6, PlayerY-6, Map,1); if (RightSideUp && LeftSideUp && PlayerY >= 8) { RightSideUp = false; LeftSideUp = false; PlayerY --; printf("Player X - Y: %d - %d\n",PlayerX,PlayerY); } } if ( keysHeld[SDLK_a] ) // left { UpSideLeft = CollisionAtPixel (PlayerX-6, PlayerY-6, Map,2); DownSideLeft = CollisionAtPixel (PlayerX-6, PlayerY+6, Map,2); if (UpSideLeft && DownSideLeft && PlayerX >= 8) { UpSideLeft = false; DownSideLeft = false; PlayerX --; printf("Player X - Y: %d - %d\n",PlayerX,PlayerY); } } if ( keysHeld[SDLK_s] ) // down { RightSideDown = CollisionAtPixel (PlayerX+6, PlayerY+6, Map,3); LeftSideDown = CollisionAtPixel (PlayerX-6, PlayerY+6, Map,3); if (RightSideDown && LeftSideDown && PlayerY <= 392) { RightSideDown = false; LeftSideDown = false; PlayerY ++; printf("Player X - Y: %d - %d\n",PlayerX,PlayerY); } } if (keysHeld[SDLK_d]) // right { UpSideRight = CollisionAtPixel (PlayerX+6, PlayerY-6, Map,4); DownSideRight = CollisionAtPixel (PlayerX+6, PlayerY+6, Map,4); if (UpSideRight && DownSideRight && PlayerX <= 392) { UpSideRight = false; DownSideRight = false; PlayerX ++; printf("Player X - Y: %d - %d\n",PlayerX,PlayerY); } } //mouse click to place player if (LEFTMOUSEDOWN) { MouseX = event.motion.x/20; MouseY = event.motion.y/20; printf("Left mouse click at X - Y: %d - %d\n",MouseX,MouseY); if (MAZE[MouseX][MouseY] == 1) { PlayerX = (MouseX*20) + 10; PlayerY = (MouseY*20) + 10; } } //mouse click to place enemy if (RIGHTMOUSEDOWN) { MouseX = event.motion.x/20; MouseY = event.motion.y/20; printf("Right mouse click at X - Y: %d - %d\n",MouseX,MouseY); if (MAZE[MouseX][MouseY] == 1) { EnemyX = (MouseX*20) + 10; EnemyY = (MouseY*20) + 10; } } //*************************** // drawing //*************************** SDL_FillRect(Screen, &Screen->clip_rect,SDL_MapRGB(Screen->format, 255, 255, 255)); for(MapX = 0; MapX < 20; MapX++) { for(MapY = 0; MapY < 20; MapY++) { if ( MAZE[MapX][MapY] == 9) { boxRGBA(Screen, MapX*20, MapY*20, (MapX*20)+20, (MapY*20)+20, 0, 0, 0, 255); } if ( MAZE[MapX][MapY] == 1) { boxRGBA(Screen, MapX*20, MapY*20, (MapX*20)+20, (MapY*20)+20, 255, 255, 255, 255); } } } //ENEMY DRAWING filledCircleRGBA(Screen, EnemyX, EnemyY, 5, 255, 0, 0, 255); //PLAYER DRAWING filledCircleRGBA(Screen, PlayerX, PlayerY, 5, 0, 0, 255, 255); SDL_Delay(10); //screen flip if (SDL_Flip(Screen) == -1) { return 1; } } //Quit Delay SDL_Delay ( 1000 ); //Free the loaded image SDL_FreeSurface( Player ); SDL_FreeSurface( Enemy ); //Quit SDL SDL_Quit(); return 0; }
void ConvexHullApp::draw_points() { for (int i = 0; i < NPOINTS; i++) filledCircleRGBA(surf, points[i]->x, points[i]->y, POINTSIZE, 0, 0, 255, 255); }