void RIBBON_GRAPH::draw(float* d, int ln, bool with_ticks) { int i; data = d; len = ln; dmax = 0; for (i=0; i<len; i++) { if (data[i] > dmax) dmax = data[i]; } if (dmax ==0) dmax = 1; mode_shaded(color); glBegin(GL_QUADS); draw_x(0); for (i=1; i<len-1; i++) { draw_y(i); draw_x(i); } draw_x(len-1); if (with_ticks) { mode_shaded(tick_color); for (i=0; i<3; i++) { draw_tick(i); } } glEnd(); }
/** * @brief Draw the detected corners with intensity equal to the min value * in the input image * @param in input image float * @param checkerboard arrat containing the 12 locations of the X-checkerboards * @return float image with X's where the points are located */ ImageFloat draw_detected_corners_image_minval(ImageFloat in, float *checkerboard) { /*Checkpoints */ /*O O1 O2 P P1 P2 Q Q1 Q2 R R1 R2 pattern location */ int length = 4; int i; float min_val = BIG_NUMBER; ImageFloat in_detected; in_detected = new_imageFloat(in->ncol,in->nrow); for(i=0;i<in->nrow*in->ncol;i++) { in_detected->val[i] = in->val[i]; if(in->val[i]<min_val) min_val = in->val[i]; } for(i=0; i<12;i++) /*0.5 is added to draw the segment in the center of the pixel*/ draw_x(roundfi(checkerboard[2*i]+0.5), roundfi(checkerboard[2*i+1]+0.5), length, min_val, in_detected); return in_detected; }
void Cartesian::draw_axis(Drawable* drawable) { draw_x(drawable, -15, 15); draw_y(drawable, -15, 15); draw_x_serif(drawable, -15, 15, 1); draw_y_serif(drawable, -15, 15, 1); };
int main(int argc, char **argv) { struct Cell_head window; RASTER_MAP_TYPE raster_type, mag_raster_type = -1; int layer_fd; void *raster_row, *ptr; int nrows, ncols; int aspect_c = -1; float aspect_f = -1.0; double scale; int skip, no_arrow; char *mag_map = NULL; void *mag_raster_row = NULL, *mag_ptr = NULL; double length = -1; int mag_fd = -1; struct FPRange range; double mag_min, mag_max; struct GModule *module; struct Option *opt1, *opt2, *opt3, *opt4, *opt5, *opt6, *opt7, *opt8, *opt9; struct Flag *align; double t, b, l, r; G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("display")); G_add_keyword(_("raster")); module->description = _("Draws arrows representing cell aspect direction " "for a raster map containing aspect data."); opt1 = G_define_standard_option(G_OPT_R_MAP); opt1->description = _("Name of raster aspect map to be displayed"); opt2 = G_define_option(); opt2->key = "type"; opt2->type = TYPE_STRING; opt2->required = NO; opt2->answer = "grass"; opt2->options = "grass,compass,agnps,answers"; opt2->description = _("Type of existing raster aspect map"); opt3 = G_define_option(); opt3->key = "arrow_color"; opt3->type = TYPE_STRING; opt3->required = NO; opt3->answer = "green"; opt3->gisprompt = "old_color,color,color"; opt3->description = _("Color for drawing arrows"); opt3->guisection = _("Colors"); opt4 = G_define_option(); opt4->key = "grid_color"; opt4->type = TYPE_STRING; opt4->required = NO; opt4->answer = "gray"; opt4->gisprompt = "old_color,color,color_none"; opt4->description = _("Color for drawing grid or \"none\""); opt4->guisection = _("Colors"); opt5 = G_define_option(); opt5->key = "x_color"; opt5->type = TYPE_STRING; opt5->required = NO; opt5->answer = DEFAULT_FG_COLOR; opt5->gisprompt = "old_color,color,color_none"; opt5->description = _("Color for drawing X's (null values)"); opt5->guisection = _("Colors"); opt6 = G_define_option(); opt6->key = "unknown_color"; opt6->type = TYPE_STRING; opt6->required = NO; opt6->answer = "red"; opt6->gisprompt = "old_color,color,color_none"; opt6->description = _("Color for showing unknown information"); opt6->guisection = _("Colors"); opt9 = G_define_option(); opt9->key = "skip"; opt9->type = TYPE_INTEGER; opt9->required = NO; opt9->answer = "1"; opt9->description = _("Draw arrow every Nth grid cell"); opt7 = G_define_option(); opt7->key = "magnitude_map"; opt7->type = TYPE_STRING; opt7->required = NO; opt7->multiple = NO; opt7->gisprompt = "old,cell,raster"; opt7->description = _("Raster map containing values used for arrow length"); opt8 = G_define_option(); opt8->key = "scale"; opt8->type = TYPE_DOUBLE; opt8->required = NO; opt8->answer = "1.0"; opt8->description = _("Scale factor for arrows (magnitude map)"); align = G_define_flag(); align->key = 'a'; align->description = _("Align grids with raster cells"); /* Check command line */ if (G_parser(argc, argv)) exit(EXIT_FAILURE); layer_name = opt1->answer; arrow_color = D_translate_color(opt3->answer); x_color = D_translate_color(opt5->answer); unknown_color = D_translate_color(opt6->answer); if (strcmp("none", opt4->answer) == 0) grid_color = -1; else grid_color = D_translate_color(opt4->answer); if (strcmp("grass", opt2->answer) == 0) map_type = 1; else if (strcmp("agnps", opt2->answer) == 0) map_type = 2; else if (strcmp("answers", opt2->answer) == 0) map_type = 3; else if (strcmp("compass", opt2->answer) == 0) map_type = 4; scale = atof(opt8->answer); if (scale <= 0.0) G_fatal_error(_("Illegal value for scale factor")); skip = atoi(opt9->answer); if (skip <= 0) G_fatal_error(_("Illegal value for skip factor")); if (opt7->answer) { if (map_type != 1 && map_type != 4) G_fatal_error(_("Magnitude is only supported for GRASS and compass aspect maps.")); mag_map = opt7->answer; } else if (scale != 1.0) G_warning(_("Scale option requires magnitude_map")); /* Setup driver and check important information */ if (D_open_driver() != 0) G_fatal_error(_("No graphics device selected. " "Use d.mon to select graphics device.")); D_setup(0); /* Read in the map window associated with window */ G_get_window(&window); if (align->answer) { struct Cell_head wind; Rast_get_cellhd(layer_name, "", &wind); /* expand window extent by one wind resolution */ wind.west += wind.ew_res * ((int)((window.west - wind.west) / wind.ew_res) - (window.west < wind.west)); wind.east += wind.ew_res * ((int)((window.east - wind.east) / wind.ew_res) + (window.east > wind.east)); wind.south += wind.ns_res * ((int)((window.south - wind.south) / wind.ns_res) - (window.south < wind.south)); wind.north += wind.ns_res * ((int)((window.north - wind.north) / wind.ns_res) + (window.north > wind.north)); wind.rows = (wind.north - wind.south) / wind.ns_res; wind.cols = (wind.east - wind.west) / wind.ew_res; Rast_set_window(&wind); nrows = wind.rows; ncols = wind.cols; t = (wind.north - window.north) * nrows / (wind.north - wind.south); b = t + (window.north - window.south) * nrows / (wind.north - wind.south); l = (window.west - wind.west) * ncols / (wind.east - wind.west); r = l + (window.east - window.west) * ncols / (wind.east - wind.west); } else { nrows = window.rows; ncols = window.cols; t = 0; b = nrows; l = 0; r = ncols; } D_set_src(t, b, l, r); D_update_conversions(); /* figure out arrow scaling if using a magnitude map */ if (opt7->answer) { Rast_init_fp_range(&range); /* really needed? */ if (Rast_read_fp_range(mag_map, "", &range) != 1) G_fatal_error(_("Problem reading range file")); Rast_get_fp_range_min_max(&range, &mag_min, &mag_max); scale *= 1.5 / fabs(mag_max); G_debug(3, "scaling=%.2f rast_max=%.2f", scale, mag_max); } if (grid_color > 0) { /* ie not "none" */ /* Set color */ D_use_color(grid_color); /* Draw vertical grids */ for (col = 0; col < ncols; col++) D_line_abs(col, 0, col, nrows); /* Draw horizontal grids */ for (row = 0; row < nrows; row++) D_line_abs(0, row, ncols, row); } /* open the raster map */ layer_fd = Rast_open_old(layer_name, ""); raster_type = Rast_get_map_type(layer_fd); /* allocate the cell array */ raster_row = Rast_allocate_buf(raster_type); if (opt7->answer) { /* open the magnitude raster map */ mag_fd = Rast_open_old(mag_map, ""); mag_raster_type = Rast_get_map_type(mag_fd); /* allocate the cell array */ mag_raster_row = Rast_allocate_buf(mag_raster_type); } /* loop through cells, find value, determine direction (n,s,e,w,ne,se,sw,nw), and call appropriate function to draw an arrow on the cell */ for (row = 0; row < nrows; row++) { Rast_get_row(layer_fd, raster_row, row, raster_type); ptr = raster_row; if (opt7->answer) { Rast_get_row(mag_fd, mag_raster_row, row, mag_raster_type); mag_ptr = mag_raster_row; } for (col = 0; col < ncols; col++) { if (row % skip != 0) no_arrow = TRUE; else no_arrow = FALSE; if (col % skip != 0) no_arrow = TRUE; /* find aspect direction based on cell value */ if (raster_type == CELL_TYPE) aspect_f = *((CELL *) ptr); else if (raster_type == FCELL_TYPE) aspect_f = *((FCELL *) ptr); else if (raster_type == DCELL_TYPE) aspect_f = *((DCELL *) ptr); if (opt7->answer) { if (mag_raster_type == CELL_TYPE) length = *((CELL *) mag_ptr); else if (mag_raster_type == FCELL_TYPE) length = *((FCELL *) mag_ptr); else if (mag_raster_type == DCELL_TYPE) length = *((DCELL *) mag_ptr); length *= scale; if (Rast_is_null_value(mag_ptr, mag_raster_type)) { G_debug(5, "Invalid arrow length [NULL]. Skipping."); no_arrow = TRUE; } else if (length <= 0.0) { /* use fabs() or theta+=180? */ G_debug(5, "Illegal arrow length [%.3f]. Skipping.", length); no_arrow = TRUE; } } if (no_arrow) { ptr = G_incr_void_ptr(ptr, Rast_cell_size(raster_type)); if (opt7->answer) mag_ptr = G_incr_void_ptr(mag_ptr, Rast_cell_size(mag_raster_type)); no_arrow = FALSE; continue; } /* treat AGNPS and ANSWERS data like old zero-as-null CELL */ /* TODO: update models */ if (map_type == 2 || map_type == 3) { if (Rast_is_null_value(ptr, raster_type)) aspect_c = 0; else aspect_c = (int)(aspect_f + 0.5); } /** Now draw the arrows **/ /* case switch for standard GRASS aspect map measured in degrees counter-clockwise from east */ if (map_type == 1) { D_use_color(arrow_color); if (Rast_is_null_value(ptr, raster_type)) { D_use_color(x_color); draw_x(); D_use_color(arrow_color); } else if (aspect_f >= 0.0 && aspect_f <= 360.0) { if (opt7->answer) arrow_mag(aspect_f, length); else arrow_360(aspect_f); } else { D_use_color(unknown_color); unknown_(); D_use_color(arrow_color); } } /* case switch for AGNPS type aspect map */ else if (map_type == 2) { D_use_color(arrow_color); switch (aspect_c) { case 0: D_use_color(x_color); draw_x(); D_use_color(arrow_color); break; case 1: arrow_n(); break; case 2: arrow_ne(); break; case 3: arrow_e(); break; case 4: arrow_se(); break; case 5: arrow_s(); break; case 6: arrow_sw(); break; case 7: arrow_w(); break; case 8: arrow_nw(); break; default: D_use_color(unknown_color); unknown_(); D_use_color(arrow_color); break; } } /* case switch for ANSWERS type aspect map */ else if (map_type == 3) { D_use_color(arrow_color); if (aspect_c >= 15 && aspect_c <= 360) /* start at zero? */ arrow_360((double)aspect_c); else if (aspect_c == 400) { D_use_color(unknown_color); unknown_(); D_use_color(arrow_color); } else { D_use_color(x_color); draw_x(); D_use_color(arrow_color); } } /* case switch for compass type aspect map measured in degrees clockwise from north */ else if (map_type == 4) { D_use_color(arrow_color); if (Rast_is_null_value(ptr, raster_type)) { D_use_color(x_color); draw_x(); D_use_color(arrow_color); } else if (aspect_f >= 0.0 && aspect_f <= 360.0) { if (opt7->answer) arrow_mag(90 - aspect_f, length); else arrow_360(90 - aspect_f); } else { D_use_color(unknown_color); unknown_(); D_use_color(arrow_color); } } ptr = G_incr_void_ptr(ptr, Rast_cell_size(raster_type)); if (opt7->answer) mag_ptr = G_incr_void_ptr(mag_ptr, Rast_cell_size(mag_raster_type)); } } Rast_close(layer_fd); if (opt7->answer) Rast_close(mag_fd); D_save_command(G_recreate_command()); D_close_driver(); exit(EXIT_SUCCESS); }
void main() { int gd=DETECT,gm,x,y,res=-1,clk,chk[3][3],cnt; char *n1,*n2; clrscr(); in.x.ax=8; in.x.cx=0; in.x.dx=480; int86(51,&in,&out); start: cnt=0; for(int i=0;i<3;i++) for(int j=0;j<3;j++) chk[i][j]=0; initgraph(&gd,&gm,"c:\\tc\\bgi"); settextstyle(7,HORIZ_DIR,1); cleardevice(); draw_grid(); callmouse(); while(1) { if(cnt==9) break; back: delay(150); getmouse(x,y,clk); if(clk==1) { if(x>175 && x<240) //1st col { if(y>100 && y<166) //1st row { if(cnt%2==0) { if(chk[0][0]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[0][0]=1; draw_x(175,100); } else { if(chk[0][0]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[0][0]=2; draw_o(175,100); } } else if(y>166 && y<232) //2nd row { if(cnt%2==0) { if(chk[1][0]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[1][0]=1; draw_x(175,166); } else { if(chk[1][0]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[1][0]=2; draw_o(175,166); } } else if(y>232 && y<300) //3rd row { if(cnt%2==0) { if(chk[2][0]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[2][0]=1; draw_x(175,232); } else { if(chk[2][0]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[2][0]=2; draw_o(175,232); } } } else if(x>240 && x<306) //2nd col { if(y>100 && y<166) //1st row { if(cnt%2==0) { if(chk[0][1]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[0][1]=1; draw_x(240,100); } else { if(chk[0][1]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[0][1]=2; draw_o(240,100); } } else if(y>166 && y<232) //2nd row { if(cnt%2==0) { if(chk[1][1]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[1][1]=1; draw_x(240,166); } else { if(chk[1][1]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[1][1]=2; draw_o(240,166); } } else if(y>232 && y<300) //3rd row { if(cnt%2==0) { if(chk[2][1]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[2][1]=1; draw_x(240,232); } else { if(chk[2][1]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[2][1]=2; draw_o(240,232); } } } else if(x>306 && x<375) //3rd col { if(y>100 && y<166) //1st row { if(cnt%2==0) { if(chk[0][2]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[0][2]=1; draw_x(306,100); } else { if(chk[0][2]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[0][2]=2; draw_o(306,100); } } else if(y>166 && y<232) //2nd row { if(cnt%2==0) { if(chk[1][2]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[1][2]=1; draw_x(306,166); } else { if(chk[1][2]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[1][2]=2; draw_o(306,166); } } else if(y>232 && y<300) //3rd row { if(cnt%2==0) { if(chk[2][2]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[2][2]=1; draw_x(306,232); } else { if(chk[2][2]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[2][2]=2; draw_o(306,232); } } } cnt++; } res=win(chk); if(res==1) { settextstyle(7,HORIZ_DIR,1); outtextxy(220,330,"PLAYER_X has WON the Game !!!"); break; } if(res==2) { settextstyle(7,HORIZ_DIR,1); outtextxy(220,330,"PLAYER_O has WON the Game !!!"); break; } } if(res==-1) { settextstyle(7,HORIZ_DIR,1); outtextxy(220,330,"HEY !!! NO ONE WON...."); outtextxy(225,355,"ONE MORE GAME ??? "); if(getche()=='y') { cleardevice(); goto start; } exit(0); } getch(); }
int xpose_hook(t_all *all) { draw_y(all); draw_x(all); return (0); }
static void draw_pin_to_chan_edge (int pin_node, int chan_node, int itrack, boolean mark_conn) { /* This routine draws an edge from the pin_node to the chan_node (CHANX or * * CHANY). The track number of the channel is passed in itrack, rather than * * taken from chan_node's ptc_num to allow this routine to draw global * * routings (where the track number isn't in the rr_graph). If mark_conn is * * TRUE, draw a box where the pin connects to the track (useful for drawing * * the rr graph). */ t_rr_type chan_type; int pin_x, pin_y, pin_num, chan_xlow, chan_ylow; float x1, x2, y1, y2; pin_x = rr_node[pin_node].xlow; pin_y = rr_node[pin_node].ylow; pin_num = rr_node[pin_node].ptc_num; chan_type = rr_node[chan_node].type; switch (chan_type) { case CHANX: chan_ylow = rr_node[chan_node].ylow; if (pin_y == chan_ylow) { get_rr_pin_draw_coords (pin_node, TOP, &x1, &y1); y1 += pin_size; /* Don't overdraw pin number. */ } else { get_rr_pin_draw_coords (pin_node, BOTTOM, &x1, &y1); y1 -= pin_size; } y2 = y_clb_bottom[chan_ylow] + clb_width + 1 + itrack; x2 = x1; break; case CHANY: chan_xlow = rr_node[chan_node].xlow; if (pin_x == chan_xlow) { get_rr_pin_draw_coords (pin_node, RIGHT, &x1, &y1); x1 += pin_size; } else { get_rr_pin_draw_coords (pin_node, LEFT, &x1, &y1); x1 -= pin_size; } x2 = x_clb_left[chan_xlow] + clb_width + 1 + itrack; y2 = y1; break; default: printf ("Error in draw_pin_to_chan_edge: invalid channel node %d.\n", chan_node); exit (1); } drawline (x1, y1, x2, y2); if (mark_conn) draw_x (x2, y2, 0.7 * pin_size); }