void draw_numeral( int x, int y, int n, int height, int width) { switch(n) { case 1: draw_one(x, y, height, width) ; break ; case 2: draw_two(x, y, height, width) ; break ; case 3: draw_three(x, y, height, width) ; break ; case 4: draw_four(x, y, height, width) ; break ; case 5: draw_five(x, y, height, width) ; break ; case 6: draw_six(x, y, height, width) ; break ; case 7: draw_seven(x, y, height, width) ; break ; case 8: draw_eight(x, y, height, width) ; break ; case 9: draw_nine(x, y, height, width) ; break ; case 0: draw_zero(x, y, height, width) ; break ; } }
int main (void) { int xSize=600, ySize=600, xMouse, yMouse, j; float h=100; char c; gfx_open(xSize, ySize, "Window"); while (1) { c = gfx_wait(); xMouse = gfx_xpos(); yMouse = gfx_ypos(); switch (c) { case '0': draw_zero(xMouse, yMouse, h); break; case '1': draw_one(xMouse, yMouse, h); break; case '2': draw_two(xMouse, yMouse, h); break; case '3': draw_three(xMouse, yMouse, h); break; case '4': draw_four(xMouse, yMouse, h); break; case '5': draw_five(xMouse, yMouse, h); break; case '6': draw_six(xMouse, yMouse, h); break; case '7': draw_seven(xMouse, yMouse, h); break; case '8': draw_eight(xMouse, yMouse, h); break; case '9': draw_nine(xMouse, yMouse, h); break; case '-': h = h/2; break; case '=': h = h*2; break; case 'q': return 0; } } return 0; }
void draw_ten(int x, int y, int height, int width) { //draw 1 draw_one(x, y, height, width/2) ; //draw 0 draw_zero(x+width, y, height, width/2) ; }
void draw_map() { int i, j; for(i = 0; i < ROW; i++) { for(j = 0; j < COL; j++) { if((i % 2) == 0) { move(i, 2*j); draw_one(map[i][j].type); } else { move(i, 2*j+1); draw_one(map[i][j].type); } } } }
/*F****************************************************************** * draw_digit(float x_position, float y_position, unsigned int digit, float size) * * PURPOSE : Draws the specified digit to the specified coordinates * at the specified size * * RETURN : void * * NOTES : *F*/ void draw_digit(float x_position, float y_position, unsigned int digit, float size) { glClearColor(255, 255, 255, 1); glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_LINES); switch(digit) { case 0: draw_zero(x_position, y_position, size); return; case 1: draw_one(x_position, y_position, size); return; case 2: draw_two(x_position, y_position, size); return; case 3: draw_three(x_position, y_position, size); return; case 4: draw_four(x_position, y_position, size); return; case 5: draw_five(x_position, y_position, size); return; case 6: draw_six(x_position, y_position, size); return; case 7: draw_seven(x_position, y_position, size); return; case 8: draw_eight(x_position, y_position, size); return; case 9: draw_nine(x_position, y_position, size); return; default: return; } glEnd(); glutSwapBuffers(); }
void line(t_crd *pt1, t_crd *pt2, t_mlx ml) { t_lne lne; lne.dx = ft_abs(pt2->x - pt1->x); lne.dy = ft_abs(pt2->y - pt1->y); lne.x = pt1->x; lne.y = pt1->y; if (pt1->x < pt2->x) lne.x_incr = 1; else lne.x_incr = -1; if (pt1->y < pt2->y) lne.y_incr = 1; else lne.y_incr = -1; if (lne.dx > lne.dy) draw_one(&lne, ml); else draw_two(&lne, ml); }
//---------------------------------------------------------------------- void CS::draw() { const Vector &mu(mod_->mu()); int n = mu.size(); Sumsq_ = mod_->suf()->center_sumsq(mu); df_ = mod_->suf()->n(); Vector sigma = sqrt(diag(mod_->Sigma())); R_ = var2cor(mod_->Sigma()); for (int i = 0; i < n; ++i) { Sumsq_.row(i) /= sigma[i]; Sumsq_.col(i) /= sigma[i]; } for (int i = 1; i < n; ++i) { i_ = i; for (int j = 0; j < i; ++j) { j_ = j; draw_one(); } } for (int i = 0; i < sigma.size(); ++i) { R_.row(i) *= sigma[i]; R_.col(i) *= sigma[i]; } mod_->set_Sigma(R_); }
// draw绘制方格和数字 void draw() { int n, m, x, y; clear(); for (n = 0; n < 9; n += 2) //横线 for (m = 0; m < 21; m++) { move(n, m); addch('-'); refresh(); } for (m = 0; m < 22; m += 5) //竖线 for (n = 1; n < 8; n++) { move(n, m); addch('|'); refresh(); } for (y = 0; y < 4; y++) //数字 for (x = 0; x < 4; x++) { draw_one(y, x); if (a[y][x] == 2048) { // 胜利条件,出现2048 endflag = win; } } }
void draw(ID3D11DeviceContext* ctx, ID3D11RenderTargetView* rtv, unsigned width, unsigned height, double time) { D3D11_VIEWPORT vp; memset(&vp, 0, sizeof(vp)); vp.Width = (float)width; vp.Height = (float)height; vp.MaxDepth = 1.0f; if((int)width != cur_width || (int)height != cur_height) init_for_dimensions(width, height); float4 lightpos = vec(5.0f, 5.0f, 10.0f, 0.0f); float black[4] = {0.0, 0.0, 0.0, 0}; float4x4 proj; float4x4 m; float xr = (float)width / (float)height; float yr = 1.0f; if(xr < 1.0f) { yr /= xr; xr = 1.0f; } proj = mat4x4_frustum(-xr, xr, -yr, yr, 5.0f, 60.0f); m = mat4x4_diag(1.0f); m = mat_push_translate(m, 0.0f, 0.0f, -40.0f); m = mat_push_rotate(m, 0, view_rotx); m = mat_push_rotate(m, 1, view_roty); m = mat_push_rotate(m, 2, view_rotz); cbuf_t cbd; cbd.projection = proj; cbd.light = lightpos; float blend_factor[4] = {1.0f / (float)impressions, 1.0f / (float)impressions, 1.0f / (float)impressions, 1.0f / (float)impressions}; ID3D11RenderTargetView* render_rtv; if(impressions == 1) render_rtv = rtv; else render_rtv = offscreen_rtv; ctx->RSSetViewports(1, &vp); ctx->ClearRenderTargetView(render_rtv, black); ctx->PSSetShader(ps, 0, 0); ctx->VSSetShader(vs, 0, 0); ctx->PSSetConstantBuffers(0, 1, &cb); ctx->VSSetConstantBuffers(0, 1, &cb); if(impressions == 1) { ctx->OMSetBlendState(0, 0, ~0); ctx->OMSetDepthStencilState(0, 0); ctx->OMSetRenderTargets(1, &rtv, zsv); ctx->ClearDepthStencilView(zsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0, 0); draw_one(ctx, cbd, m, get_angle(time)); } else { ctx->OMSetBlendState(blend, blend_factor, ~0); float time_delta = (float)time - last_time; float time_delta_per_impression = time_delta / impressions; float base_time = last_time + time_delta_per_impression / 2; for(unsigned impression = 0; impression < impressions; ++impression) { float impression_time = base_time + time_delta_per_impression * impression; ctx->ClearDepthStencilView(zsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0, 0); // do early z-pass since we must not write any pixel more than once due to blending for(unsigned pass = 0; pass < 2; ++pass) { if(pass == 0) { ctx->OMSetRenderTargets(0, 0, zsv); ctx->OMSetDepthStencilState(0, 0); } else { ctx->OMSetRenderTargets(1, &render_rtv, zsv); ctx->OMSetDepthStencilState(zsa, 0); } draw_one(ctx, cbd, m, get_angle(impression_time)); } } blitter->bind_draw_and_unbind(ctx, offscreen_srv, rtv, 0, 0, (float)width, (float)height, false); } last_time = (float)time; }
/* @brief loads the path onto the board and generates the relevant display list * * see level_data.c for path format description */ void path_load(state_t *state, map_t *map) { int cur_x = map->x_start, cur_y = map->y_start, i; int new_x, new_y; int length = map->length; int *path = map->path; float x, y; path_t *cur, *prev = NULL; cur = state->path = path_new(map->x_start, map->y_start); for(i = 0; i < length; i+=2) { /* do x */ new_x = cur_x + path[i]; if(path[i] > 0) { for(; cur_x < new_x; cur_x++) { cur->next = path_new(cur_x, cur_y); cur = cur->next; } } else if(path[i] < 0) { for(; cur_x > new_x; cur_x--) { cur->next = path_new(cur_x, cur_y); cur = cur->next; } } if(i == length - 1) break; /* do y */ new_y = cur_y + path[i+1]; if(path[i + 1] > 0) { for(; cur_y < new_y; cur_y++) { cur->next = path_new(cur_x, cur_y); cur = cur->next; } } else if(path[i + 1] < 0) { for(; cur_y > new_y; cur_y--) { cur->next = path_new(cur_x, cur_y); cur = cur->next; } } } cur->next = NULL; glNewList(DISPLAY_LIST_PATH, GL_COMPILE); glBegin(GL_QUADS); for(cur = state->path; cur != NULL; cur = cur->next) { x = cur->pos.x; y = cur->pos.y; if(cur->next == NULL) glColor3f(0.9, 0.2, 0.2); else if(cur == state->path) glColor3f(0.1, 0.5, 0.1); else glColor3f(0.2, 0.2, 0.2); glVertex2f(x - GRID_SIZE/2, y - GRID_SIZE/2); glVertex2f(x + GRID_SIZE/2, y - GRID_SIZE/2); glVertex2f(x + GRID_SIZE/2, y + GRID_SIZE/2); glVertex2f(x - GRID_SIZE/2, y + GRID_SIZE/2); } glEnd(); cur = state->path; cur_x = map->x_start; cur_y = map->y_start; glBegin(GL_LINES); for(i = 0; i < length; i+=2) { new_x = cur_x + path[i]; if(path[i] > 0) { for(; cur_x < new_x; cur_x++) { draw_one(cur_x, cur_y, cur, prev); prev = cur; cur = cur->next; } } else if(path[i] < 0) { for(; cur_x > new_x; cur_x--) { draw_one(cur_x, cur_y, cur, prev); prev = cur; cur = cur->next; } } if(i == length - 1) break; new_y = cur_y + path[i+1]; if(path[i + 1] > 0) { for(; cur_y < new_y; cur_y++) { draw_one(cur_x, cur_y, cur, prev); prev = cur; cur = cur->next; } } else if(path[i + 1] < 0) { for(; cur_y > new_y; cur_y--) { draw_one(cur_x, cur_y, cur, prev); prev = cur; cur = cur->next; } } } glEnd(); glEndList(); }
void go_player() { int oldx, oldy; enum Type oldType; char ch; oldx = player.x; oldy = player.y; oldType = map[player.x][player.y].type; while(ch = getch()) { switch(ch) { case 'w': case 'W': if(player.x == 0) player.x = 8; else player.x--; break; case 's': case 'S': if(player.x == 8) player.x = 0; else player.x++; break; case 'a': case 'A': if(player.y == 0) player.y = 8; else player.y--; break; case 'd': case 'D': if(player.y == 8) player.y = 0; else player.y++; break; case ' ': if((player.x % 2) == 0) move(player.x, player.y*2); else move(player.x, player.y*2+1); if(map[player.x][player.y].type != CAT) { attron(A_STANDOUT); draw_one(STONE); attroff(A_STANDOUT); map[player.x][player.y].type = STONE; } break; default: break; }//end switch if(ch == ' ') { cal_allPath(); cal_allOut(); return; } if((oldx % 2) == 0) move(oldx, oldy*2); else move(oldx, oldy*2+1); draw_one(oldType); oldType = map[player.x][player.y].type; if((player.x % 2) == 0) move(player.x, player.y*2); else move(player.x, player.y*2+1); attron(A_STANDOUT); draw_one(oldType); attroff(A_STANDOUT); oldx = player.x; oldy = player.y; } //end while }
void go_computer() { int i; int oldx = computer.x; int oldy = computer.y; Location buf[6]; if(is_boundary(computer)) who_win(COMPUTER); if(is_inCircle(computer)) { i = max_cost(computer); inCircle = 1; } else i = min_path(computer); switch(i) { case 0: computer.y--; break; case 1: if((computer.x % 2) == 0) { computer.x--; computer.y--; } else { computer.x--; } break; case 2: if((computer.x % 2) == 0) { computer.x--; } else { computer.x--; computer.y++; } break; case 3: computer.y++; break; case 4: if((computer.x % 2) == 0) { computer.x++; } else { computer.x++; computer.y++; } break; case 5: if((computer.x % 2) == 0) { computer.x++; computer.y--; } else { computer.x++; } break; } //end switch if((oldx % 2) == 0) move(oldx, oldy*2); else move(oldx, oldy*2+1); draw_one(WAY); map[oldx][oldy].type = WAY; if((computer.x % 2) == 0) move(computer.x, computer.y*2); else move(computer.x, computer.y*2+1); draw_one(CAT); map[computer.x][computer.y].type = CAT; }