void Devildog::Paint(MATRIX3X2 matView) { int width = m_BmpDevildogPtr->GetWidth()/6; int height = m_BmpDevildogPtr->GetHeight()/4; RECT clip; clip.left = width * m_MoveTick; clip.right = clip.left + width; clip.top = height * m_StartLine; clip.bottom = clip.top + height; MATRIX3X2 matDirection, matPos; if(m_Direction == 1) matPos.SetAsTranslate(m_Pos); else matPos.SetAsTranslate(m_Pos.x + width, m_Pos.y); matDirection.SetAsScale(m_Direction,1); GAME_ENGINE->SetTransformMatrix(matDirection * matPos * matView); GAME_ENGINE->DrawBitmap(m_BmpDevildogPtr,0,0,clip); GAME_ENGINE->SetColor(COLOR(255,0,0,125)); }
void session_get_line(t_client *client) { char *conf; if (!client->session->conf.file) { if (file_exists(client->session->host)) conf = client->session->host; else conf = "default"; client->session->conf.file = fopen(conf, "r"); VERBOSE(printf("\033[%d;1m<%03d> - conf : %s\033[m\n", COLOR(client->session->id), client->session->id, conf)); } if (!fgets(client->session->conf.line, BUF_SIZE, client->session->conf.file)) { fclose(client->session->conf.file); client->session->conf.file = 0; session_get_line(client); } else if (client->session->conf.line[strlen(client->session->conf.line) - 1] == '\n') client->session->conf.line[strlen(client->session->conf.line) - 1] = 0; }
/* y = f(x) + g(x); */ // === EXCEPTION 1 ============================================================= // Macros is not bad for concatenation and stringification enum Color { Color_Red, Color_Green, Color_Blue }; static const struct { enum Color color; const char *name; } colors[] = { #define COLOR(color) { Color_ ## color, #color } COLOR(Red), COLOR(Green), COLOR(Blue) }; // === EXCEPTION 2 ============================================================= // Macros is not bad for yield a compile-time constants #define ADD_M(a, b) ((a) + (b)) static inline int add_f(int a, int b) { return a + b; } /* === OTHER EXCEPTIONS ======================================================== * Macros is not bad for: * * 3. implement type-generic functions
constexpr char_type const * c_str(mnemocode const _mnemocode) noexcept { switch (_mnemocode) { case mnemocode::ud2 : return "ud2"; case mnemocode::fwait : return "fwait"; case mnemocode::finit : return "finit"; case mnemocode::fninit : return "fninit"; case mnemocode::fstsw : return "fstsw"; case mnemocode::fnstsw : return "fnstsw"; case mnemocode::fstcw : return "fstcw"; case mnemocode::fnstcw : return "fnstcw"; case mnemocode::fldcw : return "fldcw"; case mnemocode::fclex : return "fclex"; case mnemocode::fnclex : return "fnclex"; case mnemocode::fsave : return "fsave"; case mnemocode::fnsave : return "fnsave"; case mnemocode::frstor : return "frstor"; case mnemocode::fstenv : return "fstenv"; case mnemocode::fnstenv : return "fnstenv"; case mnemocode::fldenv : return "fldenv"; case mnemocode::ffree : return "ffree"; case mnemocode::ffreep : return "ffreep"; case mnemocode::fdecstp : return "fdecstp"; case mnemocode::fincstp : return "fincstp"; case mnemocode::fld : return "fld"; case mnemocode::fst : return "fst"; case mnemocode::fstp : return "fstp"; case mnemocode::fxch : return "fxch"; case mnemocode::fcmovb : return "fcmovb"; case mnemocode::fcmove : return "fcmove"; case mnemocode::fcmovbe : return "fcmovbe"; case mnemocode::fcmovu : return "fcmovu"; case mnemocode::fcmovnb : return "fcmovnb"; case mnemocode::fcmovne : return "fcmovne"; case mnemocode::fcmovnbe : return "fcmovnbe"; case mnemocode::fcmovnu : return "fcmovnu"; case mnemocode::fldz : return "fldz"; case mnemocode::fld1 : return "fld1"; case mnemocode::fldpi : return "fldpi"; case mnemocode::fldl2e : return "fldl2e"; case mnemocode::fldl2t : return "fldl2t"; case mnemocode::fldlg2 : return "fldlg2"; case mnemocode::fldln2 : return "fldln2"; case mnemocode::fild : return "fild"; case mnemocode::fist : return "fist"; case mnemocode::fistp : return "fistp"; case mnemocode::fisttp : return "fisttp"; case mnemocode::fbld : return "fbld"; case mnemocode::fbstp : return "fbstp"; case mnemocode::fcom : return "fcom"; case mnemocode::fcomi : return "fcomi"; case mnemocode::fcomip : return "fcomip"; case mnemocode::fcomp : return "fcomp"; case mnemocode::fcompp : return "fcompp"; case mnemocode::ficom : return "ficom"; case mnemocode::ficomp : return "ficomp"; case mnemocode::ftst : return "ftst"; case mnemocode::fucom : return "fucom"; case mnemocode::fucomi : return "fucomi"; case mnemocode::fucomip : return "fucomip"; case mnemocode::fucomp : return "fucomp"; case mnemocode::fucompp : return "fucompp"; case mnemocode::fxam : return "fxam"; case mnemocode::fabs : return "fabs"; case mnemocode::fadd : return "fadd"; case mnemocode::faddp : return "faddp"; case mnemocode::fchs : return "fchs"; case mnemocode::fdiv : return "fdiv"; case mnemocode::fdivp : return "fdivp"; case mnemocode::fdivr : return "fdivr"; case mnemocode::fdivrp : return "fdivrp"; case mnemocode::fmul : return "fmul"; case mnemocode::fmulp : return "fmulp"; case mnemocode::frndint : return "frndint"; case mnemocode::fsqrt : return "fsqrt"; case mnemocode::fsub : return "fsub"; case mnemocode::fsubp : return "fsubp"; case mnemocode::fsubr : return "fsubr"; case mnemocode::fsubrp : return "fsubrp"; case mnemocode::fiadd : return "fiadd"; case mnemocode::fidiv : return "fidiv"; case mnemocode::fidivr : return "fidivr"; case mnemocode::fimul : return "fimul"; case mnemocode::fisub : return "fisub"; case mnemocode::fisubr : return "fisubr"; case mnemocode::fcos : return "fcos"; case mnemocode::fpatan : return "fpatan"; case mnemocode::fptan : return "fptan"; case mnemocode::fsin : return "fsin"; case mnemocode::fsincos : return "fsincos"; case mnemocode::f2xm1 : return "f2xm1"; case mnemocode::fscale : return "fscale"; case mnemocode::fyl2x : return "fyl2x"; case mnemocode::fyl2xp1 : return "fyl2xp1"; case mnemocode::fnop : return "fnop"; case mnemocode::fprem : return "fprem"; case mnemocode::fprem1 : return "fprem1"; case mnemocode::fxtract : return "fxtract"; case mnemocode::trunc : return "trunc"; case mnemocode::sp_inc : return COLOR(3, "sp_inc"); case mnemocode::sp_dec : return COLOR(3, "sp_dec"); case mnemocode::bra : return COLOR(2, "bra" ); case mnemocode::ket : return COLOR(2, "ket" ); case mnemocode::endl : return COLOR(4, "endl" ); case mnemocode::alloca_ : return COLOR(7, "alloca"); case mnemocode::call : return COLOR(1, "call" ); case mnemocode::ret : return COLOR(1, "ret" ); case mnemocode::sahf : return "sahf"; } }
inline COLOR grey(double g) { return COLOR(g,g,g); }
//! \brief create a COLOR from unsigned bytes r, g, b inline COLOR color_ub(unsigned char r, unsigned char g, unsigned char b) { return COLOR(r/255.0, g/255.0, b/255.0); }
// Given a Config variable name and a default COLOR value, // return the corresponding COLOR if the variable is defined, // otherwise return the default value: inline CCOLOR get_var_color(const string& var_name, CCOLOR& default_val) { string col_str = Config::get_var_str(var_name, color_to_str(default_val)); double r, g, b; sscanf(col_str.c_str(), "%lf%lf%lf", &r, &g, &b); return COLOR(r,g,b); }
CAMERA::CAMERA(void){ color=COLOR(0,0,0,0); min=0.001f,max=1000,fovh=angle2rad(60),fovv=angle2rad(60.0f*0.75f); }
void main() { while (1) { COLOR(RND()); draw_circle(RND() & 0xff, RND() & 0xff, (RND() & 0x1f) + 16); } }
static void _tnl_Color4fv( const GLfloat *v ) { GET_IMMEDIATE; COLOR( IM, v[0], v[1], v[2], v[3] ); }
static void _tnl_Color4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha ) { GET_IMMEDIATE; COLOR( IM, red, green, blue, alpha ); }
static void _tnl_Color3f( GLfloat red, GLfloat green, GLfloat blue ) { GET_IMMEDIATE; COLOR( IM, red, green, blue, 1.0 ); }
/* * Parse a string * */ static int config_string_cb(void *params_, const unsigned char *val, size_t _len) { int len = (int)_len; /* The id and socket_path are ignored, we already know them. */ if (!strcmp(cur_key, "id") || !strcmp(cur_key, "socket_path")) return 1; if (!strcmp(cur_key, "mode")) { DLOG("mode = %.*s, len = %d\n", len, val, len); config.hide_on_modifier = (len == 4 && !strncmp((const char *)val, "dock", strlen("dock")) ? M_DOCK : (len == 4 && !strncmp((const char *)val, "hide", strlen("hide")) ? M_HIDE : M_INVISIBLE)); return 1; } if (!strcmp(cur_key, "hidden_state")) { DLOG("hidden_state = %.*s, len = %d\n", len, val, len); config.hidden_state = (len == 4 && !strncmp((const char *)val, "hide", strlen("hide")) ? S_HIDE : S_SHOW); return 1; } if (!strcmp(cur_key, "modifier")) { DLOG("modifier = %.*s\n", len, val); if (len == 5 && !strncmp((const char *)val, "shift", strlen("shift"))) { config.modifier = ShiftMask; return 1; } if (len == 4 && !strncmp((const char *)val, "ctrl", strlen("ctrl"))) { config.modifier = ControlMask; return 1; } if (len == 4 && !strncmp((const char *)val, "Mod", strlen("Mod"))) { switch (val[3]) { case '1': config.modifier = Mod1Mask; return 1; case '2': config.modifier = Mod2Mask; return 1; case '3': config.modifier = Mod3Mask; return 1; /* case '4': config.modifier = Mod4Mask; return 1; */ case '5': config.modifier = Mod5Mask; return 1; } } config.modifier = Mod4Mask; return 1; } if (!strcmp(cur_key, "wheel_up_cmd")) { DLOG("wheel_up_cmd = %.*s\n", len, val); FREE(config.wheel_up_cmd); sasprintf(&config.wheel_up_cmd, "%.*s", len, val); return 1; } if (!strcmp(cur_key, "wheel_down_cmd")) { DLOG("wheel_down_cmd = %.*s\n", len, val); FREE(config.wheel_down_cmd); sasprintf(&config.wheel_down_cmd, "%.*s", len, val); return 1; } if (!strcmp(cur_key, "position")) { DLOG("position = %.*s\n", len, val); config.position = (len == 3 && !strncmp((const char *)val, "top", strlen("top")) ? POS_TOP : POS_BOT); return 1; } if (!strcmp(cur_key, "status_command")) { DLOG("command = %.*s\n", len, val); sasprintf(&config.command, "%.*s", len, val); return 1; } if (!strcmp(cur_key, "font")) { DLOG("font = %.*s\n", len, val); sasprintf(&config.fontname, "%.*s", len, val); return 1; } if (!strcmp(cur_key, "outputs")) { DLOG("+output %.*s\n", len, val); int new_num_outputs = config.num_outputs + 1; config.outputs = srealloc(config.outputs, sizeof(char *) * new_num_outputs); sasprintf(&config.outputs[config.num_outputs], "%.*s", len, val); config.num_outputs = new_num_outputs; return 1; } if (!strcmp(cur_key, "tray_output")) { DLOG("tray_output %.*s\n", len, val); FREE(config.tray_output); sasprintf(&config.tray_output, "%.*s", len, val); return 1; } #define COLOR(json_name, struct_name) \ do { \ if (!strcmp(cur_key, #json_name)) { \ DLOG(#json_name " = " #struct_name " = %.*s\n", len, val); \ sasprintf(&(config.colors.struct_name), "%.*s", len, val); \ return 1; \ } \ } while (0) COLOR(statusline, bar_fg); COLOR(background, bar_bg); COLOR(separator, sep_fg); COLOR(focused_workspace_border, focus_ws_border); COLOR(focused_workspace_bg, focus_ws_bg); COLOR(focused_workspace_text, focus_ws_fg); COLOR(active_workspace_border, active_ws_border); COLOR(active_workspace_bg, active_ws_bg); COLOR(active_workspace_text, active_ws_fg); COLOR(inactive_workspace_border, inactive_ws_border); COLOR(inactive_workspace_bg, inactive_ws_bg); COLOR(inactive_workspace_text, inactive_ws_fg); COLOR(urgent_workspace_border, urgent_ws_border); COLOR(urgent_workspace_bg, urgent_ws_bg); COLOR(urgent_workspace_text, urgent_ws_fg); printf("got unexpected string %.*s for cur_key = %s\n", len, val, cur_key); return 0; }
//------------------------------------------------------------------------------ // ゲームの初期化 //------------------------------------------------------------------------------ // 引数 // なし // 戻り値 // なし //------------------------------------------------------------------------------ void CGame::Init(void) { gamePhase = PHASE_3; gamePhaseCnt = 0; gameEndCount = 0; CSoundAL::Play(CSoundAL::BGM_GAME); //地形生成 Ground = nullptr; Ground = CMeshGround::Create(VECTOR3(0.0f,0.0f,0.0f),VECTOR2(FIELD_PANEL_SIZE,FIELD_PANEL_SIZE),VECTOR2(0,0),1.5f); Ground->SetTex(CTexture::Texture(TEX_FIELD)); // 空生成 Sky = nullptr; Sky = CMeshSphere::Create(VECTOR3(0.0f,0.0f,0.0f),VECTOR2(16.0f,8.0f),RADIUS_SKY); Sky->SetTex(CTexture::Texture(TEX_SKY)); // 境界線生成 CylinderArea = nullptr; CylinderArea = CBattleAreaCylinder::Create(VECTOR3(0.0f,0.0f,0.0f),HEIGHT_WALL,VECTOR2(64.0f,1.0f),RADIUS_AREA_BATTLE,VECTOR2(1,-0.5f)); CylinderArea->SetTex(CTexture::Texture(TEX_WALL)); CylinderArea->SetAlpha(0.5f); Player = new CPlayer*[PLAYER_MAX]; // プレイヤー生成 for (int i = 0; i < PLAYER_MAX; i++) { if (i % 2 == 1) Player[i] = CPlayer::Create(CModel::RINCHAN,PLAYER_POSITION_LIST[i],i); else Player[i] = CPlayer::Create(CModel::YOUJO,PLAYER_POSITION_LIST[i],i); Player[i]->SetTex(CTexture::Texture(TEX_YOUJO_RED + i)); Player[i]->SetDestRot(PLAYER_ROTATION_LIST[i]); Player[i]->SetRot(PLAYER_ROTATION_LIST[i]); Player[i]->setBarrelTex(TEX_YOUJO_RED + i); if (i == CManager::netData.charNum) { Player[i]->SetPlayerFlag(true); Player[i]->CreateBallistic(); } } //プレイヤーカメラ生成 CPlayerCamera::Create(Player[CManager::netData.charNum],35.0f); // 【テスト】各プレイヤーの色をセット for(int i = 0; i < PLAYER_MAX; i++) { switch(i) { // 赤 case 0: Player[i]->SetPlayerColor(RED(0.5f)); break; // 青 case 1: Player[i]->SetPlayerColor(BLUE(0.5f)); break; // 水 case 2: Player[i]->SetPlayerColor(CYAN(0.5f)); break; // 橙 case 3: Player[i]->SetPlayerColor(COLOR(1.0f, 0.7f, 0.0f, 0.5f)); break; // 白 case 4: Player[i]->SetPlayerColor(WHITE(0.5f)); break; // P case 5: Player[i]->SetPlayerColor(YELLOW(0.5f)); break; default: break; } } // プレイヤーの入力を止める for (int i = 0; i < PLAYER_MAX; i++){ Player[i]->SetInputFlag(false); } // UI初期化 UI = new CUI; UI->Init(); UI->setMyID(CManager::netData.charNum); UI->SetPlayer(Player); UI->MiniMap()->SetFieldSize(VECTOR3(RADIUS_AREA_BATTLE*2.25f,0,RADIUS_AREA_BATTLE*2.25f)); // 岩の生成 ppRock_ = new CModel*[MAX_ROCK]; for (int cntRock = 0; cntRock < MAX_ROCK; ++cntRock) { ppRock_[cntRock] = CModel::Create(CModel::ROCK,ROCK_POSITION_LIST[cntRock]); ppRock_[cntRock]->SetRot(ROCK_ROTATION_LIST[cntRock]); ppRock_[cntRock]->SetScl(1,1,1); ppRock_[cntRock]->SetTex(CTexture::Texture(TEX_ROCK)); PushBackObjectByField(ppRock_[cntRock], 10.0f); } // 影生成 Shadow = new CShadow*[2 * PLAYER_MAX]; for (int cntShadow = 0; cntShadow < 2 * PLAYER_MAX; ++cntShadow) { Shadow[cntShadow] = nullptr; Shadow[cntShadow] = CShadow::Create(VECTOR3(0.0f, 0.0f, 0.0f), VECTOR2(1.0f, 1.0f)); if (cntShadow < PLAYER_MAX) { Shadow[cntShadow]->SetScl(30, 30, 30); } else { Shadow[cntShadow]->SetScl(20, 20, 20); } Shadow[cntShadow]->SetTex(CTexture::Texture(TEX_SHADOW)); } CManager::gameStartFlag = true; CManager::sendGameStart(); }
void InitMenu() { /* Reset variables */ TabIndex = TAB_ABOUT; Background = NULL; /* Initialize paths */ sprintf(SaveStatePath, "%ssavedata/", pl_psp_get_app_directory()); sprintf(ScreenshotPath, "%sscreenshot/", pl_psp_get_app_directory()); sprintf(GamePath, "%s", pl_psp_get_app_directory()); if (!pl_file_exists(SaveStatePath)) pl_file_mkdir_recursive(SaveStatePath); /* Initialize options */ LoadOptions(); InitEmulator(); /* Load the background image */ pl_file_path background; snprintf(background, sizeof(background) - 1, "%sbackground.png", pl_psp_get_app_directory()); Background = pspImageLoadPng(background); //Background = pspImageLoadPng("background.png"); /* Init NoSaveState icon image */ NoSaveIcon = pspImageCreate(136, 114, PSP_IMAGE_16BPP); pspImageClear(NoSaveIcon, RGB(0x0c,0,0x3f)); /* Initialize state menu */ int i; pl_menu_item *item; for (i = 0; i < 10; i++) { item = pl_menu_append_item(&SaveStateGallery.Menu, i, NULL); pl_menu_set_item_help_text(item, EmptySlotText); } /* Initialize menus */ pl_menu_create(&SystemUiMenu.Menu, SystemMenuDef); pl_menu_create(&OptionUiMenu.Menu, OptionMenuDef); pl_menu_create(&ControlUiMenu.Menu, ControlMenuDef); /* Load default configuration */ LoadButtonConfig(); /* Initialize UI components */ UiMetric.Background = Background; UiMetric.Font = &PspStockFont; UiMetric.Left = 16; UiMetric.Top = 48; UiMetric.Right = 944; UiMetric.Bottom = 500; UiMetric.OkButton = (!Options.ControlMode) ? PSP_CTRL_CROSS : PSP_CTRL_CIRCLE; UiMetric.CancelButton = (!Options.ControlMode) ? PSP_CTRL_CIRCLE : PSP_CTRL_CROSS; UiMetric.ScrollbarColor = PSP_COLOR_GRAY; UiMetric.ScrollbarBgColor = 0x44ffffff; UiMetric.ScrollbarWidth = 10; UiMetric.TextColor = PSP_COLOR_GRAY; UiMetric.SelectedColor = PSP_COLOR_YELLOW; UiMetric.SelectedBgColor = COLOR(0xff,0xff,0xff,0x44); UiMetric.StatusBarColor = PSP_COLOR_WHITE; UiMetric.BrowserFileColor = PSP_COLOR_GRAY; UiMetric.BrowserDirectoryColor = PSP_COLOR_YELLOW; UiMetric.GalleryIconsPerRow = 5; UiMetric.GalleryIconMarginWidth = 8; UiMetric.MenuItemMargin = 20; UiMetric.MenuSelOptionBg = PSP_COLOR_BLACK; UiMetric.MenuOptionBoxColor = PSP_COLOR_GRAY; UiMetric.MenuOptionBoxBg = COLOR(0, 0, 33, 0xBB); UiMetric.MenuDecorColor = PSP_COLOR_YELLOW; UiMetric.DialogFogColor = COLOR(0, 0, 0, 88); UiMetric.TitlePadding = 4; UiMetric.TitleColor = PSP_COLOR_WHITE; UiMetric.MenuFps = 30; UiMetric.TabBgColor = COLOR(0x74,0x74,0xbe,0xff); UiMetric.BrowserScreenshotPath = ScreenshotPath; UiMetric.BrowserScreenshotDelay = 30; }
static void game_do(game_t *p_game) { item_t turn = p_game->starting_color; int eval = 0; bool_t selected = FALSE; p_game->selected_x = -1; p_game->selected_y = -1; while (1) { fe_point_t where; move_t move; if (abs(eval) > 1000) { game_won(p_game, eval); eval = 0; } if (turn == p_game->computer_color) { game_minimax(p_game, p_game->p_playfield, turn, 0, 1, &move); playfield_do_move(p_game->p_playfield, p_game, move.sx, move.sy, move.dx, move.dy); turn = (turn == PF_BLACK) ? PF_WHITE : PF_BLACK; eval = game_eval_playfield(p_game, p_game->p_playfield, turn); game_draw_status(p_game, turn); continue; } if (fe_get_stylus(&where) == TRUE) { uint8_t field_x = where.x / BRICK_WIDTH; uint8_t field_y = where.y / BRICK_HEIGHT; item_t item = playfield_get_item(p_game->p_playfield, field_x, field_y); rnd += field_x ^ rnd; /* Select something */ if (COLOR(item) == turn) { /* Within field, correct color */ game_draw_one_pos(p_game, p_game->selected_x, p_game->selected_y, 0); game_draw_one_pos(p_game, field_x, field_y, 1); selected = TRUE; p_game->selected_x = field_x; p_game->selected_y = field_y; } else if (selected && item == PF_EMPTY) { /* Destination - move to! */ if (playfield_can_move(p_game->p_playfield, p_game->selected_x, p_game->selected_y, field_x, field_y)) { playfield_do_move(p_game->p_playfield, p_game, p_game->selected_x, p_game->selected_y, field_x, field_y); turn = (turn == PF_BLACK) ? PF_WHITE : PF_BLACK; } game_draw_status(p_game, turn); selected = FALSE; eval = game_eval_playfield(p_game, p_game->p_playfield, turn); } else { /* Pressed outside the playfield */ game_draw_one_pos(p_game, p_game->selected_x, p_game->selected_y, 0); selected = FALSE; /* Handle the buttons */ if (IN_RECT(where.x, where.y, RESTART_BUTTON_X, RESTART_BUTTON_Y, 34, 13)) { p_game->restart = 1; game_won(p_game, 0); p_game->restart = 0; } if (IN_RECT(where.x, where.y, HUMAN_BUTTON_X, HUMAN_BUTTON_Y, 13, 13)) p_game->computer_color = PF_INVALID; else if (IN_RECT(where.x, where.y, BLACK_BUTTON_X, BLACK_BUTTON_Y, 13, 13)) p_game->computer_color = PF_BLACK; else if (IN_RECT(where.x, where.y, WHITE_BUTTON_X, WHITE_BUTTON_Y, 13, 13)) p_game->computer_color = PF_WHITE; game_draw_status(p_game, turn); } } if ( fe_get_buttons() == FE_EVENT_EXIT) break; } }
void print_label(int n) { ft_printf(C_256 "%d " RESET_ANSI, COLOR(n), n); }
int main() { /* give range of X axis, then define Y as x^2 + 3x + 3 */ plotdata x(-5.0, 2.0), y = x*x + 3*x + 3; /* Plot the graph */ plot(x, y); /**********************************************************/ /* Points may be entered one at a time into the axes data */ /* .. a "point-by-point" data entry method. */ /* Erase previous data in axes X and Y so they can be re-used.*/ clear(x); clear(y); /* * Enter each curve point as a coordinate pair using the plotdata * insertion operator "<<" ( or use the "point" function instead). */ for (int i = -180 ; i <= 180; i++) { double y_value = i / 180.0 + cos(DEG_TO_RAD * i); x << i; y << y_value; /* "<<" inserts a new value into the plot data. * You could instead use the point function, with * point(x, y, x_value, y_value); if you prefer. */ } /* Graph drawn in blue colour (Each data point is joined to * the preceding and following points, forming the curve.). */ plot(x, y, BLUE); /**********************************************/ /* Plot function y = sin(x) between 0 and 360 */ x = plotdata(0.0, 360.0); y = sin(x * DEG_TO_RAD); /* Give the function name to be printed as the window label */ plot(x, y, CRIMSON, "sin(x)"); /*****************************************************************/ /* Plot user-defined unary function f(x) = sinc between -6 and 6 */ x = plotdata(-6.0, 6.0); f(x) = sinc; /* sinc is defined at the bottom of this file. */ plot(x, f(x), "sinc(x)"); /*****************************************************************/ /* Plot user-defined binary function y = tanLessThan(x, max) */ /* Read tanLessThan code to see how values > max are not plotted */ x = plotdata(-270.0, 270.0); f2(x) = tanLessThan; /* Do not plot y values greater than 20 */ plot(x, f2(x, 20), "tan(x)", REDRED); /*********************************************************************/ /* Plot 2 functions on same graph (could be any number of functions) */ /* Define Y as two functions */ clear(x); /* Re-use old X, but change its range to -75..245 degrees */ x << plotdata(-80.0, 255.0); y = f2(x, 3); /* First function */ breakplot(x, y); /* Break the plot between functions */ /* You could also use x << NOPLOT; y << NOPLOT; instead.*/ /* Define second function (2cos(2x)) on same range "point-by-point" */ for(int i = -80; i <= 255; i++) { x << i; y << 2 * cos(2 * i * DEG_TO_RAD); } plot(x, y, "tan(x) and 2cos(2x)", BLUEBLUE); /*********************************************************** * You can also use the << operator to insert data at the end * of already entered plot data in order to draw 2 or more * functions. * * Use NOPLOT to separate different function data in both X * and Y, but be careful of the order of insertion! Each NOPLOT * in X must correspond to a NOPLOT in Y. * * Koolplot does not plot NOPLOT values. */ x = plotdata(-315.0, 45.0); y = sin(x * DEG_TO_RAD); plotdata z = cos(x * DEG_TO_RAD); plotdata p = sin(2 * (x - 45) * DEG_TO_RAD); plotdata q = cos(2 * x * DEG_TO_RAD); setColor(x, y, CRIMSON); // Will also break the plot x << plotdata(-315.0, 45.0); y << z; setColor(x, y, DARKORANGE ); x << plotdata(-315.0, 45.0); y << p; setColor(x, y, BLUEBLUE ); x << plotdata(-315.0, 45.0); y << q; // Default plot colour is green plot(x, y, COLOR(0,160,0), " sin(x) -green-, cos(x) -red-, sin(2x - 45) -orange-, cos(2x) -blue-"); /*************************************************/ return 0; }
void fromRGBA32(Comp32 rgba) { RGBA32 tmp; tmp.rgba = COLOR(rgba); fromRGBA8(tmp.r, tmp.g, tmp.b, tmp.a); }
void fill_profile_color() { #define COLOR(x, y, z) QVector<QColor>() << x << y << z; profile_color[SAC_1] = COLOR(FUNGREEN1, BLACK1_LOW_TRANS, FUNGREEN1); profile_color[SAC_2] = COLOR(APPLE1, BLACK1_LOW_TRANS, APPLE1); profile_color[SAC_3] = COLOR(ATLANTIS1, BLACK1_LOW_TRANS, ATLANTIS1); profile_color[SAC_4] = COLOR(ATLANTIS2, BLACK1_LOW_TRANS, ATLANTIS2); profile_color[SAC_5] = COLOR(EARLSGREEN1, BLACK1_LOW_TRANS, EARLSGREEN1); profile_color[SAC_6] = COLOR(HOKEYPOKEY1, BLACK1_LOW_TRANS, HOKEYPOKEY1); profile_color[SAC_7] = COLOR(TUSCANY1, BLACK1_LOW_TRANS, TUSCANY1); profile_color[SAC_8] = COLOR(CINNABAR1, BLACK1_LOW_TRANS, CINNABAR1); profile_color[SAC_9] = COLOR(REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1); profile_color[VELO_STABLE] = COLOR(CAMARONE1, BLACK1_LOW_TRANS, CAMARONE1); profile_color[VELO_SLOW] = COLOR(LIMENADE1, BLACK1_LOW_TRANS, LIMENADE1); profile_color[VELO_MODERATE] = COLOR(RIOGRANDE1, BLACK1_LOW_TRANS, RIOGRANDE1); profile_color[VELO_FAST] = COLOR(PIRATEGOLD1, BLACK1_LOW_TRANS, PIRATEGOLD1); profile_color[VELO_CRAZY] = COLOR(RED1, BLACK1_LOW_TRANS, RED1); profile_color[PO2] = COLOR(APPLE1, BLACK1_LOW_TRANS, APPLE1); profile_color[PO2_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1); profile_color[PN2] = COLOR(BLACK1_LOW_TRANS, BLACK1_LOW_TRANS, BLACK1_LOW_TRANS); profile_color[PN2_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1); profile_color[PHE] = COLOR(PEANUT, BLACK1_LOW_TRANS, PEANUT); profile_color[PHE_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1); profile_color[PP_LINES] = COLOR(BLACK1_HIGH_TRANS, BLACK1_LOW_TRANS, BLACK1_HIGH_TRANS); profile_color[TEXT_BACKGROUND] = COLOR(CONCRETE1_LOWER_TRANS, WHITE1, CONCRETE1_LOWER_TRANS); profile_color[ALERT_BG] = COLOR(BROOM1_LOWER_TRANS, BLACK1_LOW_TRANS, BROOM1_LOWER_TRANS); profile_color[ALERT_FG] = COLOR(BLACK1_LOW_TRANS, WHITE1, BLACK1_LOW_TRANS); profile_color[EVENTS] = COLOR(REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1); profile_color[SAMPLE_DEEP] = COLOR(QColor(Qt::red).darker(), BLACK1, PERSIANRED1); profile_color[SAMPLE_SHALLOW] = COLOR(QColor(Qt::red).lighter(), BLACK1_LOW_TRANS, PERSIANRED1); profile_color[SMOOTHED] = COLOR(REDORANGE1_HIGH_TRANS, BLACK1_LOW_TRANS, REDORANGE1_HIGH_TRANS); profile_color[MINUTE] = COLOR(MEDIUMREDVIOLET1_HIGHER_TRANS, BLACK1_LOW_TRANS, MEDIUMREDVIOLET1_HIGHER_TRANS); profile_color[TIME_GRID] = COLOR(WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS); profile_color[TIME_TEXT] = COLOR(FORESTGREEN1, BLACK1, FORESTGREEN1); profile_color[DEPTH_GRID] = COLOR(WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS); profile_color[MEAN_DEPTH] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS); profile_color[DEPTH_BOTTOM] = COLOR(GOVERNORBAY1_MED_TRANS, BLACK1_HIGH_TRANS, GOVERNORBAY1_MED_TRANS); profile_color[DEPTH_TOP] = COLOR(MERCURY1_MED_TRANS, WHITE1_MED_TRANS, MERCURY1_MED_TRANS); profile_color[TEMP_TEXT] = COLOR(GOVERNORBAY2, BLACK1_LOW_TRANS, GOVERNORBAY2); profile_color[TEMP_PLOT] = COLOR(ROYALBLUE2_LOW_TRANS, BLACK1_LOW_TRANS, ROYALBLUE2_LOW_TRANS); profile_color[SAC_DEFAULT] = COLOR(WHITE1, BLACK1_LOW_TRANS, FORESTGREEN1); profile_color[BOUNDING_BOX] = COLOR(WHITE1, BLACK1_LOW_TRANS, TUNDORA1_MED_TRANS); profile_color[PRESSURE_TEXT] = COLOR(KILLARNEY1, BLACK1_LOW_TRANS, KILLARNEY1); profile_color[BACKGROUND] = COLOR(SPRINGWOOD1, WHITE1, SPRINGWOOD1); profile_color[CEILING_SHALLOW] = COLOR(REDORANGE1_HIGH_TRANS, BLACK1_HIGH_TRANS, REDORANGE1_HIGH_TRANS); profile_color[CEILING_DEEP] = COLOR(RED1_MED_TRANS, BLACK1_HIGH_TRANS, RED1_MED_TRANS); profile_color[CALC_CEILING_SHALLOW] = COLOR(FUNGREEN1_HIGH_TRANS, BLACK1_HIGH_TRANS, FUNGREEN1_HIGH_TRANS); profile_color[CALC_CEILING_DEEP] = COLOR(APPLE1_HIGH_TRANS, BLACK1_HIGH_TRANS, APPLE1_HIGH_TRANS); #undef COLOR }
inline COLOR get_max(CCOLOR& a, CCOLOR& b) { return COLOR(max(a[0],b[0]), max(a[1],b[1]), max(a[2],b[2])); }
int SwapOff(struct Position *p, int move) { int to = M_TO(move); int fr = M_FROM(move); int side = COLOR(p->piece[fr]); int oside = !side; int swaplist[32]; int swapcnt = 0; int swapval, swapside; int swapsign = -1; BitBoard atks[2]; BitBoard exclude; if(move & M_PANY) { swapval = SwapValue[PromoType(move)]; swaplist[0] = SwapValue[TYPE(p->piece[to])] - SwapValue[Pawn] + swapval; } else { swapval = SwapValue[TYPE(p->piece[fr])]; swaplist[0] = SwapValue[TYPE(p->piece[to])]; } swapside = oside; atks[White] = p->mask[White][0] & p->atkFr[to]; atks[Black] = p->mask[Black][0] & p->atkFr[to]; exclude = p->mask[White][0] | p->mask[Black][0]; SwapReRay(p, side, atks, fr, to, &exclude); while(atks[swapside]) { int at; BitBoard tmp; /* find last valuable attacker */ tmp = p->mask[swapside][Pawn] & atks[swapside]; if(tmp) at = FindSetBit(tmp); else { tmp = (p->mask[swapside][Knight] | p->mask[swapside][Bishop]) & atks[swapside]; if(tmp) at = FindSetBit(tmp); else { tmp = p->mask[swapside][Rook] & atks[swapside]; if(tmp) at = FindSetBit(tmp); else { tmp = p->mask[swapside][Queen] & atks[swapside]; if(tmp) at = FindSetBit(tmp); else at = FindSetBit(p->mask[swapside][King]); } } } swapcnt++; swaplist[swapcnt] = swaplist[swapcnt-1] + swapsign*swapval; swapval = SwapValue[TYPE(p->piece[at])]; swapsign = -swapsign; SwapReRay(p, swapside, atks, at, to, &exclude); swapside = !swapside; } if(swapcnt & 1) swapsign = -1; else swapsign = 1; while(swapcnt) { if(swapsign < 0) { if(swaplist[swapcnt] <= swaplist[swapcnt-1]) swaplist[swapcnt-1]=swaplist[swapcnt]; } else { if(swaplist[swapcnt] >= swaplist[swapcnt-1]) swaplist[swapcnt-1]=swaplist[swapcnt]; } swapcnt--; swapsign = -swapsign; } return (swaplist[0]); }
//! \brief create a COLOR from an rgba unsigned int // (ignores alpha) inline COLOR rgba_to_color(uint rgba) { return COLOR(rgba_to_r(rgba)/255.0, rgba_to_g(rgba)/255.0, rgba_to_b(rgba)/255.0); }
/****************************************************************************** Write out a jot .sm file. ******************************************************************************/ void write_sm() { LMESHptr mesh = make_shared<LMESH>(); int i=0; //******** Build the mesh ******** err_adv(debug, "read ply file: %d vertices, %d faces\n", nverts, nfaces); err_adv(debug, "building mesh:"); // Add vertices to mesh err_adv(debug, " adding vertices..."); for (i = 0; i < nverts; i++) mesh->add_vertex(Wpt(vlist[i]->x, vlist[i]->y, vlist[i]->z)); err_adv(debug, " done\n"); // Add per-vertex colors if needed if (per_vertex_color) { err_adv(debug, " adding colors..."); for (i = 0; i < nverts; i++) mesh->bv(i)->set_color(COLOR(vlist[i]->r, vlist[i]->g, vlist[i]->b)); err_adv(debug, " done\n"); } // Add faces err_adv(debug, " adding faces..."); for (i = 0; i < nfaces; i++) add_face(mesh, flist[i]); err_adv(debug, " done\n"); //******** Filter the mesh ******** err_adv(debug, "filtering mesh..."); // Remove any isolated vertices for (i=mesh->nverts()-1; i>=0; i--) { if (mesh->bv(i)->degree() == 0) { mesh->remove_vertex(mesh->bv(i)); } } mesh->changed(); // Remove duplicate vertices while we're at it mesh->remove_duplicate_vertices(false); // don't keep the bastards // Check for consistent orientation of normals bool is_bad = false; for (i=0; i<mesh->nedges(); i++) if (!mesh->be(i)->consistent_orientation()) is_bad = true; if (is_bad) err_msg("Warning: inconsistently oriented triangles -- can't fix"); // Optional: recenter mesh if (Config::get_var_bool("JOT_RECENTER")) mesh->recenter(); // Optional: print stats if (Config::get_var_bool("JOT_PRINT_MESH")) mesh->print(); err_adv(debug, "done\n"); //******** Write mesh ******** err_adv(debug, "writing mesh..."); mesh->write_stream(cout); err_adv(debug, "done\n"); }
void OsuCircle::drawHitCircleNumber(Graphics *g, OsuSkin *skin, float numberScale, float overlapScale, Vector2 pos, int number, float numberAlpha) { if (!osu_draw_numbers.getBool()) return; class DigitWidth { public: static float getWidth(OsuSkin *skin, int digit) { switch (digit) { case 0: return skin->getDefault0()->getWidth(); case 1: return skin->getDefault1()->getWidth(); case 2: return skin->getDefault2()->getWidth(); case 3: return skin->getDefault3()->getWidth(); case 4: return skin->getDefault4()->getWidth(); case 5: return skin->getDefault5()->getWidth(); case 6: return skin->getDefault6()->getWidth(); case 7: return skin->getDefault7()->getWidth(); case 8: return skin->getDefault8()->getWidth(); case 9: return skin->getDefault9()->getWidth(); } return skin->getDefault0()->getWidth(); } }; // generate digits std::vector<int> digits; while (number >= 10) { digits.push_back(number % 10); number = number / 10; } digits.push_back(number); int digitOffsetMultiplier = digits.size()-1; // set color g->setColor(0xffffffff); if (osu_circle_number_rainbow.getBool()) { float frequency = 0.3f; float time = engine->getTime()*20; char red1 = std::sin(frequency*time + 0 + rainbowNumber*rainbowNumber*rainbowNumber*rainbowColorCounter) * 127 + 128; char green1 = std::sin(frequency*time + 2 + rainbowNumber*rainbowNumber*rainbowNumber*rainbowColorCounter) * 127 + 128; char blue1 = std::sin(frequency*time + 4 + rainbowNumber*rainbowNumber*rainbowNumber*rainbowColorCounter) * 127 + 128; g->setColor(COLOR(255, red1, green1, blue1)); } g->setAlpha(numberAlpha); // draw digits, start at correct offset g->pushTransform(); g->scale(numberScale, numberScale); g->translate(pos.x, pos.y); g->translate(-DigitWidth::getWidth(skin, (digits.size() > 0 ? digits[digits.size()-1] : 0))*digitOffsetMultiplier*numberScale*0.5f + skin->getHitCircleOverlap()*digitOffsetMultiplier*overlapScale*0.5f, 0); for (int i=digits.size()-1; i>=0; i--) { switch (digits[i]) { case 0: g->drawImage(skin->getDefault0()); break; case 1: g->drawImage(skin->getDefault1()); break; case 2: g->drawImage(skin->getDefault2()); break; case 3: g->drawImage(skin->getDefault3()); break; case 4: g->drawImage(skin->getDefault4()); break; case 5: g->drawImage(skin->getDefault5()); break; case 6: g->drawImage(skin->getDefault6()); break; case 7: g->drawImage(skin->getDefault7()); break; case 8: g->drawImage(skin->getDefault8()); break; case 9: g->drawImage(skin->getDefault9()); break; } g->translate(DigitWidth::getWidth(skin, digits[i])*numberScale - skin->getHitCircleOverlap()*overlapScale, 0); } g->popTransform(); }
Box2DDebugRenderer::Box2DDebugRenderer() { m_Color = COLOR(255, 255, 255, 187); m_MatScale = MATRIX3X2::CreateScalingMatrix(PhysicsActor::SCALE); }
/* unsigned char buttonleft[8], */ {0x03,0x0f,0x1f,0x1f,0x1f,0x1f,0x0f,0x03}, /* buttonright[8]; */ {0xc0,0xf0,0xf8,0xf8,0xf8,0xf8,0xf0,0xc0}, /* Menu border patterns. */ /* unsigned char menuleftpattern[8], */ {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}, /* menurightpatterns[8]; */ {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}, /* Window and widget colors. */ /* unsigned char windowcolors[6], */ {COLOR(COLOR_BLACK, COLOR_BLACK), COLOR(COLOR_BLACK, COLOR_BLACK), COLOR(COLOR_BLUE, COLOR_BLACK), COLOR(COLOR_BLUE, COLOR_BLACK), COLOR(COLOR_LIGHTBLUE, COLOR_BLUE), COLOR(COLOR_LIGHTBLUE, COLOR_BLUE)}, /* separatorcolors[6], */ {COLOR(COLOR_BLACK, COLOR_BLUE), COLOR(COLOR_BLACK, COLOR_BLUE), COLOR(COLOR_BLUE, COLOR_BLACK), COLOR(COLOR_BLUE, COLOR_BLACK), COLOR(COLOR_LIGHTBLUE, COLOR_BLUE), COLOR(COLOR_LIGHTBLUE, COLOR_BLUE)}, /* labelcolors[6], */
/*-<==>----------------------------------------------------------------- / Defines the scene /----------------------------------------------------------------------*/ void CRayTracer::load () { // Add the camera looking at the origin camera.setView (VECTOR(0, 50, 400), VECTOR (0,0,0)); camera.setRenderParameters (640,480,60); // Define some materials materials["orange"] = new CSolidMaterial (COLOR (1, 0.301, 0.074), 0.1); materials["blue"] = new CSolidMaterial (COLOR (0.0, 0.2, 0.8), 0.0); // materials["red"] = new CSolidMaterial (COLOR (0.8, 0.2, 0.0), 0.5); materials["green"] = new CSolidMaterial (COLOR (0.1, 0.8, 0.0), 0.7); materials["grey"] = new CSolidMaterial (COLOR (0.5, 0.5, 0.5), 0.5); materials["escacs"] = new CCheckerMaterial(materials["red"], materials["green"],100); materials["glass"] = new CTransparentMaterial(COLOR(0.1,0.1,0.2),1.0); // Add a sphere CSphere *sph = new CSphere(50); sph->setLocation (VECTOR(0,-100,0)); sph->setMaterial (materials["grey"]); objects.push_back (sph); // Add a sphere sph = new CSphere(50); sph->setLocation (VECTOR(0,100,0)); sph->setMaterial (materials["blue"]); objects.push_back (sph); // Add a sphere sph = new CSphere(50); sph->setLocation (VECTOR(0,210,0)); sph->setMaterial (materials["red"]); objects.push_back (sph); // Add a sphere sph = new CSphere(50); sph->setLocation (VECTOR(200,50,100)); sph->setMaterial (materials["glass"]); //sph->setMaterial (materials["green"]); objects.push_back (sph); // Add a sphere sph = new CSphere(50); sph->setLocation (VECTOR(200,50,0)); sph->setMaterial (materials["orange"]); objects.push_back (sph); // And now for something completely different // CCylinder* cyl = new CCylinder(100,50); // cyl->setLocation (VECTOR(85,0,120)); // cyl->setMaterial (materials["grey"]); // objects.push_back(cyl); /*CCylinder* cyl = new CCylinder(100,50); cyl->setLocation (VECTOR(150,0,100)); cyl->setMaterial (materials["green"]); objects.push_back(cyl);*/ // Add the ground CPlane *plane = new CPlane (VECTOR(0,1,0), 0); plane->setMaterial (materials["escacs"]); objects.push_back (plane); // Add a single white light CLight *light = new CLight(VECTOR (400,200,50), COLOR (1,1,1)); lights.push_back (light); }
// returns a color value that represents an RGB triple xmas_color_t xmas_color(uint8_t r, uint8_t g, uint8_t b) { return COLOR(r, g, b); }
/* Implementation of the minimax algorithm. Once was a alpha-beta * implementation, but since the REX only evaluates one ply down I * think this can be skipped. It's available in subversion. */ static int16_t game_minimax(game_t *p_game, playfield_t *p_playfield, item_t turn, int depth, int maxdepth, move_t *p_out) { item_t next_turn; uint8_t x,y; int16_t best_eval; /* End the recursion */ if (depth >= maxdepth) return game_eval_playfield(p_game, p_playfield, turn); best_eval = (turn == PF_BLACK) ? -PF_INF : PF_INF; next_turn = (turn == PF_WHITE) ? PF_BLACK : PF_WHITE; for (y = 0; y < PF_HEIGHT; y++) { for (x = 0; x < PF_WIDTH; x++) { item_t cur = playfield_get_item(p_playfield, x, y); dir_t i; if (COLOR(cur) != turn) continue; for (i = 0; i < N_NEIGHBORS/2; i++) { move_t move; uint8_t dist; /* Generate all possible moves in the current dir */ for (dist = 1; dist < PF_WIDTH; dist++) { playfield_t next_playfield; int16_t eval; int dx = x + dir_to_dx(i)*dist; int dy = y + dir_to_dy(i)*dist; /* Hit an obstacle, no need to check the rest */ if (!playfield_can_move(p_playfield, x, y, dx, dy)) break; /* Execute move on a new playfield */ memcpy(&next_playfield, p_playfield, sizeof(playfield_t)); playfield_do_move(&next_playfield, NULL, x, y, dx, dy); /* Evaluate recursively */ eval = game_minimax(p_game, &next_playfield, next_turn, depth + 1, maxdepth, &move); if ( (turn == PF_BLACK && eval >= best_eval) || (turn == PF_WHITE && eval <= best_eval) ) { if (eval == best_eval && (rnd & 4) != 0) continue; p_out->sx = x; p_out->sy = y; p_out->dx = dx; p_out->dy = dy; best_eval = eval; } } } } } return best_eval; }