void ArrowMarker::setBoundingRect(double xs, double ys, double xe, double ye) { if (d_rect.left() == xs && d_rect.top() == ys && d_rect.right() == xe && d_rect.bottom() == ye) return; d_rect.setLeft(xs); d_rect.setTop(ys); d_rect.setRight(xe); d_rect.setBottom(ye); if (!plot()) return; plot()->updateLayout(); d_start = QPoint(plot()->transform(xAxis(), xs), plot()->transform(yAxis(), ys)); d_end = QPoint(plot()->transform(xAxis(), xe), plot()->transform(yAxis(), ye)); }
function run() { set(PLOTNOW); NumYears = 1; MaxBars = 210; PlotScale = 8; PlotWidth = 800; PlotHeight1 = 350; PlotHeight2 = 80; vars Price = series(price()); // plot Bollinger bands BBands(Price,30,2,2,MAType_SMA); plot("Bollinger1",rRealUpperBand,BAND1,0x00CC00); plot("Bollinger2",rRealLowerBand,BAND2,0xCC00FF00); plot("SAR",SAR(0.02,0.02,0.2),DOT,RED); ZigZag(Price,20*PIP,5,BLUE); // plot some other indicators plot("ATR (PIP)",ATR(20)/PIP,NEW,RED); plot("Doji",CDLDoji(),NEW+BARS,BLUE); plot("FractalDim",FractalDimension(Price,30),NEW,RED); plot("ShannonGain",ShannonGain(Price,40),NEW,RED); }
void QtDensity::runRandomDataCmd(void) { std::string cmd = "y <- " + m_cmd.toStdString(); m_R.parseEvalQ(cmd); plot(); // after each random draw, update plot with estimate }
void QtDensity::getBandwidth(int bw) { if (bw != m_bw) { m_bw = bw; plot(); } }
void Mandelbrot::generate(int maxIterations, unsigned int ty, unsigned int height) { double real = (m_maxReal - m_minReal) / m_width; double imag = (m_maxImag - m_minImag) / m_height; for(unsigned int x = 0; x < m_width; x++) { for(unsigned int y = ty; y < height; y++) { double cx = m_minReal + x * real + m_center.x * real; double cy = m_maxImag - y * imag - m_center.y * imag; double zx = cx; double zy = cy; int iteration = 0; while(zx*zx + zy*zy < 4 && iteration < maxIterations) { double tempX = zx*zx - zy*zy + cx; double tempY = 2 * zx * zy + cy; if(zx == tempX && zy == tempY) { iteration = maxIterations; break; } zx = tempX; zy = tempY; iteration++; } if(iteration == maxIterations) plot(x, y, sf::Color::Black); else { sf::Color color; if (iteration == maxIterations) { color = sf::Color(0, 0, 0); } else if (iteration < 64) { color = sf::Color(iteration * 2, 0, 0); } else if (iteration < 128) { color = sf::Color((((iteration - 64) * 128) / 126) + 128, 0, 0); } else if (iteration < 256) { color = sf::Color((((iteration - 128) * 62) / 127) + 193, 0, 0); } else if (iteration < 512) { color = sf::Color(255, (((iteration - 256) * 62) / 255) + 1, 0); } else if (iteration < 1024) { color = sf::Color(255, (((iteration - 512) * 63) / 511) + 64, 0); } else if (iteration < 2048) { color = sf::Color(255, (((iteration - 1024) * 63) / 1023) + 128, 0); } else if (iteration < 4096) { color = sf::Color(255, (((iteration - 2048) * 63) / 2047) + 192, 0); } else { color = sf::Color(iteration, iteration, 0); } plot(x, y, color); } } } m_texture.update(m_pixels); }
void LegendItem::paint(QPainter *painter) { if (!isVisible()) { return; } RelationList legendItems; if (_auto) { legendItems = plot()->renderItem(PlotRenderItem::Cartesian)->relationList(); } else { legendItems = _relations; } int count = legendItems.count(); if (count <= 0) { // no legend or box if there are no legend items return; } QFont font(_font); font.setPointSizeF(view()->scaledFontSize(_fontScale, *painter->device())); painter->setFont(font); // generate string list of relation names QStringList names; bool allAuto = true; bool sameX = true; bool sameYUnits = true; LabelInfo label_info = legendItems.at(0)->xLabelInfo(); QString yUnits = legendItems.at(0)->yLabelInfo().units; for (int i = 0; i<count; i++) { RelationPtr relation = legendItems.at(i); if (relation->descriptiveNameIsManual()) { allAuto = false; } if (relation->xLabelInfo() != label_info) { sameX = false; } // sameYUnits is false if any non empty units are defined differently. if (yUnits.isEmpty()) { yUnits = relation->yLabelInfo().units; } else if (relation->yLabelInfo().units != yUnits) { if (!relation->yLabelInfo().units.isEmpty()) { sameYUnits = false; } } } if (!allAuto) { for (int i = 0; i<count; i++) { names.append(legendItems.at(i)->descriptiveName()); } } else { for (int i = 0; i<count; i++) { RelationPtr relation = legendItems.at(i); QString label = relation->titleInfo().singleRenderItemLabel(); if (label.isEmpty()) { label_info = relation->yLabelInfo(); QString y_label = label_info.name; if (!sameYUnits) { if (!label_info.units.isEmpty()) { y_label = tr("%1 \\[%2\\]", "axis labels. %1 is quantity, %2 is units. eg Time [s]. '[' must be escaped.").arg(y_label).arg(label_info.units); } } if (!y_label.isEmpty()) { LabelInfo xlabel_info = relation->xLabelInfo(); if (!sameX) { label = tr("%1 vs %2", "describes a plot. %1 is X axis. %2 is Y axis").arg(y_label).arg(xlabel_info.name); } else if (xlabel_info.quantity.isEmpty()) { label = y_label; } else if (xlabel_info.quantity != xlabel_info.name) { label = tr("%1 vs %2", "describes a plot. %1 is X axis. %2 is Y axis").arg(y_label).arg(xlabel_info.name); } else { label = y_label; } } else { label = relation->descriptiveName(); } } int i_dup = names.indexOf(label); if (i_dup<0) { names.append(label); } else { RelationPtr dup_relation = legendItems.at(i_dup); if (!dup_relation->yLabelInfo().file.isEmpty()) { names.replace(i_dup, label + " (" + dup_relation->yLabelInfo().escapedFile() + ')'); } if (!relation->yLabelInfo().file.isEmpty()) { names.append(label + " (" + relation->yLabelInfo().escapedFile() + ')'); } } } } QSize legendSize(0, 0); QSize titleSize(0,0); Label::Parsed *parsed = Label::parse(_title); int pad = painter->fontMetrics().ascent()/4; Label::RenderContext rc(painter->font(), painter); Label::renderLabel(rc, parsed->chunk, false, false); if (!_title.isEmpty()) { titleSize.setWidth(rc.x+3*pad); titleSize.setHeight(painter->fontMetrics().height()+pad); } QList<QSize> sizes; int max_w = 0; int max_h = 0; for (int i = 0; i<count; i++) { RelationPtr relation = legendItems.at(i); QSize size; painter->save(); size = paintRelation(names.at(i), relation, painter, false); painter->restore(); sizes.append(size); max_w = qMax(max_w, size.width()); max_h = qMax(max_h, size.height()); } // determine number of rows and number of columns int n_rows = 0; int n_cols = 0; if (_verticalDisplay) { int h=titleSize.height(); for (int i = 0; i<count; i++) { h+=sizes.at(i).height(); } int max_legend_height = _plotItem->plotRect().height()*0.6+1; n_cols = qMin(count, h / max_legend_height + 1); n_rows = count / n_cols; while (n_rows*n_cols<count) { n_rows++; } } else { int w = 0; for (int i = 0; i<count; i++) { w+=sizes.at(i).width(); } int max_legend_width = _plotItem->plotRect().width()*0.8+1; n_rows = qMin(count, w / max_legend_width+1); n_cols = count/n_rows; while (n_rows*n_cols<count) { n_cols++; } } // determine the dimensions of each column QList<QSize> col_sizes; for (int i=0; i<n_cols; i++) { col_sizes.append(QSize(0,0)); } for (int i = 0; i<count; i++) { int col = i/n_rows; col_sizes[col].rheight()+= sizes.at(i).height(); col_sizes[col].setWidth(qMax(sizes.at(i).width(), col_sizes.at(col).width())); } // determine the dimensions of the legend int w = 0; int h = 0; for (int col = 0; col < n_cols; col++) { w += col_sizes.at(col).width(); h = qMax(h, col_sizes.at(col).height()); } legendSize.setHeight(h + titleSize.height()); legendSize.setWidth(qMax(titleSize.width(), w)); setViewRect(rect().x(), rect().y(), legendSize.width()+pad, legendSize.height()+pad); // Now paint everything painter->drawRect(rect()); int x=rect().x(); int y=rect().y(); if (!_title.isEmpty()) { rc.y = rect().y() + titleSize.height()-pad; rc.x = qMax(rect().x()+pad, rect().x() + legendSize.width()/2 - titleSize.width()/2); Label::renderLabel(rc, parsed->chunk, false, true); y+= titleSize.height(); } legendSize.setWidth(0); legendSize.setHeight(0); for (int i = 0; i<count; i++) { RelationPtr relation = legendItems.at(i); painter->save(); painter->translate(x,y); paintRelation(names.at(i), relation, painter, true); painter->restore(); int col = i/n_rows; int row = i%n_rows; if (row == n_rows-1) { // end of a column x += col_sizes.at(col).width(); y = rect().y() + titleSize.height(); } else { y += sizes.at(i).height(); } } delete parsed; }
int main ( int argc, char **argv ) { srand(time(NULL)); if ( argc<=1 ) { // printf ( "neuro num\r\n" ); // exit ( 0 ); } if (argc>2) { //desired_error=atof(argv[2]); numn=atoi(argv[1]); l1n=atoi(argv[2]); if (argc>3) l2n=atoi(argv[3]); if (argc>4) l3n=atoi(argv[4]); if (argc>5) l4n=atoi(argv[5]); if (argc>6) l5n=atoi(argv[6]); if (argc>7) l6n=atoi(argv[7]); } signal ( 2, sig_term ); srand ( time ( NULL ) ); printf("loading training data..."); train_data = fann_read_train_from_file ( "train.dat" ); test_data = fann_read_train_from_file ( "test.dat" ); weight_data=fann_merge_train_data(train_data,test_data); cln_weight_data=fann_duplicate_train_data(weight_data); cln_test_data=fann_duplicate_train_data(test_data); cln_train_data=fann_duplicate_train_data(train_data); //num_neurons_hidden = atoi ( argv[1] ); srand(time(NULL)); y=atoi(argv[2]); lay=atoi(argv[1]); ln=lay+2; if (lay==1) y2=train_data->num_output; best_perc=1; printf("\r\ndoing %ux%u [layers=%u,out=%u]",lay,y,ln, train_data->num_output); while (true) { neur1=1+(rand()%y); neur2=1+(rand()%y); conn_rate=0.5f+((rand()%50)*0.01f); printf("\r\n%2dx%-4d: ",neur1,neur2); // printf("create network: layers=%d l1n=%d l2n=%d l3n=%d l4n=%d\ l5n=%d l6n=%dr\n",numn,l1n,l2n,l3n,l4n,l5n,l6n); ann = fann_create_standard (//conn_rate, ln, train_data->num_input, neur1, neur2, train_data->num_output ); //fann_init_weights ( ann, train_data ); printf(" [%p] ",ann); if ( ( int ) ann==NULL ) { printf ( "error" ); exit ( 0 ); } fann_set_activation_function_hidden(ann,FANN_SIGMOID); fann_set_activation_function_output(ann,FANN_SIGMOID); rebuild_functions(neur1); fann_set_training_algorithm ( ann, FANN_TRAIN_RPROP ); fann_set_sarprop_temperature(ann,15000.0f); //fann_randomize_weights ( ann, -((rand()%10)*0.1f), ((rand()%10)*0.1f) ); fann_init_weights(ann,train_data); got_inc=0; prev_epoch_mse=1; // epochs=0; unsigned last_best_perc_epoch=0; unsigned last_sync_epoch=0; unsigned last_ftest_secs=0; last_sync_epoch=0; last_best_perc_epoch=0; if (good_ann) fann_destroy(good_ann); good_ann=fann_copy(ann); unlink(histfile); for (u=0;u<1000;u++) { fflush(NULL); train_mse=fann_train_epoch(ann, train_data); if (jitter_train) apply_jjit(train_data,cln_train_data); if (time(NULL)-last_ftest_secs>=1) { //printf("\r\n%5u %9.6f %5.2f ",epochs,train_mse,test_perc); //printf(" %4.2f",test_perc); printf("."); last_ftest_secs=time(NULL); } ftest_data(); plot(epochs,train_mse,test_mse); /* if (epochs>10&&((int)test_perc==43||(int)test_perc==57)) { printf(" [excluded %.2f] ",test_perc); break; } else { } */ //printf("excluded %f ",test_perc); double prev_test_perc; // if (prev_epoch_mse==best_perc) // printf("o"); if ((int)test_perc>(int)train_perc&&epochs-last_stat_epoch>10) { fann_destroy(good_ann); good_ann=fann_copy(ann); if (test_perc!=prev_test_perc) printf("%.2f [%f]",test_perc,train_mse); //printf(" sync[%4.2f]",test_perc); last_stat_epoch=epochs; } else if (epochs-last_sync_epoch>111500) { last_sync_epoch=epochs; } if (epochs>210&&test_perc>best_perc) { // u--; // fann_destroy(good_ann); // good_ann=fann_copy(ann); printf(" [saved best %.0f] ",test_perc); last_stat_epoch=epochs; // printf("%f",test_perc); // fann_destroy(ann); // ann=fann_copy(good_ann); fann_save(ann,"mutate-best.net"); best_perc=test_perc; printf(" %6.2f [%f]",test_perc,train_mse); last_best_perc_epoch=epochs; } else if (epochs>11100&&((int)test_perc<=63||(int)test_perc==(int)prev_test_perc)) { //best_perc=test_perc; // printf("x"); // printf("."); //printf("\r%6.8f",train_mse); // printf("done\r\n"); break; } static unsigned last_restore_epoch=0; if (epochs>100&&test_mse-train_mse>=0.25f&&epochs-last_restore_epoch>=120) { /* fann_set_learning_rate ( ann,0.31f+(rand()%90)*0.01f); fann_set_learning_momentum(ann,(rand()%90)*0.01f); printf(" [restored @ %u lr %.2f mm %.2f]",epochs,fann_get_learning_rate(ann), fann_get_learning_momentum(ann)); fann_destroy(ann); ann=fann_copy(good_ann); last_stat_epoch=epochs; last_restore_epoch=epochs; */ double rdec,rinc; rdec=0.0101f+((rand()%100)*0.00001f); if (!rdec) rdec=0.01f; rinc=1.0001f+((rand()%90)*0.00001f); if (!rinc) rinc=1.1f; static double prev_test_epoch_mse; // rinc+=diff_mse*0.000001f; // fann_set_rprop_increase_factor(ann,rinc ); // fann_set_rprop_decrease_factor(ann, rdec); } else if (test_mse-train_mse<=0.1f) { fann_destroy(good_ann); good_ann=fann_copy(ann); // printf("s"); } else { fann_set_sarprop_temperature(ann,fann_get_sarprop_temperature(ann)-0.0001f); } static unsigned last_train_change_epoch=0; if (test_mse>=train_mse&&epochs-last_train_change_epoch>=100) { last_train_change_epoch=epochs; //fann_set_training_algorithm(ann,FANN_TRAIN_SARPROP); jitter_train=0; } else { //fann_set_training_algorithm(ann,FANN_TRAIN_RPROP); jitter_train=0; } got_inc=test_perc-prev_epoch_mse; prev_epoch_mse=test_perc; prev_test_perc=test_perc; epochs++; if (epochs-last_best_perc_epoch>511500) { printf(" failed"); break; } if (epochs>2200&&(int)train_perc<40) { printf("skip 1\r\n"); break; } if ((int)test_perc>=80) { printf("\r\ngot it %f\r\n",test_perc); fann_save(ann,"good.net"); exit(0); } // printf("\n%6u ",epochs); } printf(" %6.2f inc: %.2f",test_perc,got_inc); // printf("%6.2f %6.2f",train_perc,test_perc); fann_destroy ( ann ); } fann_destroy_train ( train_data ); fann_destroy_train ( test_data ); fann_destroy ( ann ); return 0; }
void GeomGlut::plot( GLfloat x, GLfloat y ) { plot(x, y, DEFAULT_SIZE_POINT); }
void compare_Mtt_distribution_fitting(){ gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetPadRightMargin(0.03); gStyle->SetPadLeftMargin(0.16); TFile *file; TH1F* h_vbf_tight[3]; TH1F* h_vbf_loose[3]; TH1F* h_1jet[3]; TH1F* h_vbf_tight_signal[3]; TH1F* h_vbf_loose_signal[3]; TH1F* h_1jet_signal[3]; /* * VBF tight category for 8TeV */ for(int ichannel=0; ichannel < 3; ichannel++){ TString fname = file_8TeV[ichannel]; file = new TFile(fname); TString getname = ch_name[ichannel]; getname += "_vbf_tight/"; TString name = getname + process_name[ichannel]; h_vbf_tight[ichannel] = (TH1F*) file->Get(name); // signal TString sname = getname; sname += "ggH125"; h_vbf_tight_signal[ichannel] = (TH1F*) file->Get(sname); sname = getname; sname += "qqH125"; h_vbf_tight_signal[ichannel]->Add((TH1F*) file->Get(sname)); sname = getname; sname += "VH125"; h_vbf_tight_signal[ichannel]->Add((TH1F*) file->Get(sname)); ////////////////////////// getname = ch_name[ichannel]; getname += "_vbf_loose/"; TString name = getname + process_name[ichannel]; h_vbf_loose[ichannel] = (TH1F*) file->Get(name); // signal sname = getname; sname += "ggH125"; h_vbf_loose_signal[ichannel] = (TH1F*) file->Get(sname); sname = getname; sname += "qqH125"; h_vbf_loose_signal[ichannel]->Add((TH1F*) file->Get(sname)); sname = getname; sname += "VH125"; h_vbf_loose_signal[ichannel]->Add((TH1F*) file->Get(sname)); ///////////////////////// getname = ch_name[ichannel]; if(ichannel==2) getname += "_1jet_high/"; else getname += "_1jet_high_mediumhiggs/"; TString name = getname + process_name[ichannel]; h_1jet[ichannel] = (TH1F*) file->Get(name); // signal sname = getname; sname += "ggH125"; h_1jet_signal[ichannel] = (TH1F*) file->Get(sname); sname = getname; sname += "qqH125"; h_1jet_signal[ichannel]->Add((TH1F*) file->Get(sname)); sname = getname; sname += "VH125"; h_1jet_signal[ichannel]->Add((TH1F*) file->Get(sname)); } plot(h_vbf_tight_signal, h_vbf_tight, "VBF_tight","8TeV"); plot(h_vbf_loose_signal, h_vbf_loose, "VBF_loose","8TeV"); plot(h_1jet_signal, h_1jet, "1jet_high","8TeV"); /////////////////// 7 TeV //////////////////////////// TH1F* hh_vbf[3]; TH1F* hh_1jet[3]; TH1F* hh_vbf_signal[3]; TH1F* hh_1jet_signal[3]; /* * VBF tight category for 8TeV */ for(int ichannel=0; ichannel < 3; ichannel++){ TString fname = file_7TeV[ichannel]; file = new TFile(fname); TString getname = ch_name[ichannel]; if(ichannel==2) getname += "_vbf_loose/"; else getname += "_vbf/"; TString name = getname + process_name[ichannel]; hh_vbf[ichannel] = (TH1F*) file->Get(name); // signal TString sname = getname; sname += "ggH125"; hh_vbf_signal[ichannel] = (TH1F*) file->Get(sname); sname = getname; sname += "qqH125"; hh_vbf_signal[ichannel]->Add((TH1F*) file->Get(sname)); sname = getname; sname += "VH125"; hh_vbf_signal[ichannel]->Add((TH1F*) file->Get(sname)); ////////////////////////// getname = ch_name[ichannel]; if(ichannel==2) getname += "_1jet_high/"; else getname += "_1jet_high_mediumhiggs/"; TString name = getname + process_name[ichannel]; hh_1jet[ichannel] = (TH1F*) file->Get(name); // signal sname = getname; sname += "ggH125"; hh_1jet_signal[ichannel] = (TH1F*) file->Get(sname); sname = getname; sname += "qqH125"; hh_1jet_signal[ichannel]->Add((TH1F*) file->Get(sname)); sname = getname; sname += "VH125"; hh_1jet_signal[ichannel]->Add((TH1F*) file->Get(sname)); } plot(hh_vbf_signal, hh_vbf, "VBF","7TeV"); plot(hh_1jet_signal, hh_1jet, "1jet","7TeV"); }
static int drawvect(int zoomit, /* -1 = refresh, 0 = new image, 1 = zoom, 2 = warp */ View * zoom_view, double E[], double N[], int trans_order) { /* order of transformation if warping vectors */ int stat = 0; int i; char name[GNAME_MAX], mapset[GMAPSET_MAX]; struct Cell_head cellhd; struct line_pnts *Points; char msg[100], win_name[100]; int t, b, l, r; int blank = 0; View *active_view; int left, top, nrows, ncols; static int vectclr[VFILES]; /* if refresh screen or overlay & no displayed vector maps return */ if ((zoomit == DO_REFRESH || zoomit == DO_WARP) && !numfiles) { if (zoomit == DO_REFRESH) display_points(1); return 0; } /* numfiles stays at 0 until the end of the first vector map init */ if (numfiles >= VFILES) { G_warning ("Can't display another map; reached maximum number of files"); return 0; } select_target_env(); if (zoomit == DO_REFRESH || zoomit == DO_NEW) { /* New Map File or Refresh Screen */ if (zoomit == DO_NEW) { /* zoomit==0, Draw New Map File */ if (!choose_vectfile(name, mapset)) return 0; strcpy(vect_file[numfiles], name); strcpy(vect_mapset[numfiles], mapset); get_vector_color(); /* ask line_color to draw map */ if (!numfiles) { /* first map: SET VECTOR WINDOW BY WIND */ G_get_window(&cellhd); G_copy(&VIEW_MAP2->cell.head, &cellhd, sizeof(cellhd)); } else /* not the first map */ G_copy(&cellhd, &VIEW_MAP2->cell.head, sizeof(VIEW_MAP2->cell.head)); numfiles++; } else { /* zoomit=-1 Refresh Screen */ G_copy(&cellhd, &VIEW_MAP2->cell.head, sizeof(VIEW_MAP2->cell.head)); if (!cellmap_present) Erase_view(VIEW_MAP2_ZOOM); VIEW_MAP2_ZOOM->cell.configured = 0; blank = BLACK; } strcpy(win_name, "vect_map"); if (!view2on) { t = VIEW_MAP2->top; b = VIEW_MAP2->bottom; l = VIEW_MAP2->left; r = VIEW_MAP2->right; D_new_window(win_name, t, b, l, r); if (!cellmap_present) blank = BLACK; else blank = 0; /* don't erase viewport */ view2on = 1; } active_view = VIEW_MAP2; } else { /* zoomit>0 Zoom or Warp */ G_copy(&cellhd, &zoom_view->cell.head, sizeof(zoom_view->cell.head)); if (!(zoom_view == VIEW_MAP1)) { /* target side */ VIEW_MAP2_ZOOM->cell.configured = 0; strcpy(win_name, "zoom_map"); if (!view2zoomon) { t = VIEW_MAP2_ZOOM->top; b = VIEW_MAP2_ZOOM->bottom; l = VIEW_MAP2_ZOOM->left; r = VIEW_MAP2_ZOOM->right; D_new_window(win_name, t, b, l, r); view2zoomon = 1; } active_view = VIEW_MAP2_ZOOM; blank = BLACK; } else { strcpy(win_name, "warp_map"); /* defined in drawcell routine */ active_view = VIEW_MAP1; blank = 0; /* don't erase viewport */ } } nrows = active_view->nrows; ncols = active_view->ncols; left = active_view->left; top = active_view->top; D_set_cur_wind(win_name); R_standard_color(YELLOW); Outline_box(top, top + nrows - 1, left, left + ncols - 1); Points = Vect_new_line_struct(); if (zoomit != DO_WARP) { Curses_clear_window(INFO_WINDOW); Curses_write_window(INFO_WINDOW, 1, 13, "COORDINATES"); Curses_write_window(INFO_WINDOW, 3, 2, "MAIN WINDOW"); sprintf(msg, "N = %10.2f E = %10.2f", VIEW_MAP2->cell.head.north, VIEW_MAP2->cell.head.east); Curses_write_window(INFO_WINDOW, 5, 4, msg); sprintf(msg, "S = %10.2f W = %10.2f", VIEW_MAP2->cell.head.south, VIEW_MAP2->cell.head.west); Curses_write_window(INFO_WINDOW, 6, 4, msg); Curses_write_window(INFO_WINDOW, 9, 2, "ZOOM WINDOW"); sprintf(msg, "N = %10.2f E = %10.2f", VIEW_MAP2_ZOOM->cell.head.north, VIEW_MAP2_ZOOM->cell.head.east); Curses_write_window(INFO_WINDOW, 11, 4, msg); sprintf(msg, "S = %10.2f W = %10.2f", VIEW_MAP2_ZOOM->cell.head.south, VIEW_MAP2_ZOOM->cell.head.west); Curses_write_window(INFO_WINDOW, 12, 4, msg); } if (zoomit) { /* ie ! DO_NEW */ dsp_setup(blank, &cellhd); for (i = 0; i < numfiles; i++) { sprintf(msg, "Displaying %s", vect_file[i]); Menu_msg(msg); R_standard_color(vectclr[i]); if (zoomit != DO_WARP) stat = plot(vect_file[i], vect_mapset[i], Points); else stat = plot_warp(vect_file[i], vect_mapset[i], Points, E, N, trans_order); } } else { /* ie DO_NEW */ if (numfiles == 1) { /* let first file set window */ G_copy(&VIEW_MAP2->cell.head, &cellhd, sizeof(cellhd)); cellhd.rows = VIEW_MAP2->nrows; cellhd.cols = VIEW_MAP2->ncols; cellhd.ns_res = (cellhd.north - cellhd.south) / cellhd.rows; cellhd.ew_res = (cellhd.east - cellhd.west) / cellhd.cols; if (cellhd.ns_res > cellhd.ew_res) cellhd.ew_res = cellhd.ns_res; else cellhd.ns_res = cellhd.ew_res; VIEW_MAP2->cell.ns_res = cellhd.ns_res; VIEW_MAP2->cell.ew_res = cellhd.ew_res; G_copy(&VIEW_MAP2->cell.head, &cellhd, sizeof(cellhd)); G_adjust_window_to_box(&cellhd, &VIEW_MAP2->cell.head, VIEW_MAP2->nrows, VIEW_MAP2->ncols); if (!cellmap_present) { Configure_view(VIEW_MAP2, vect_file[numfiles - 1], vect_mapset[numfiles - 1], cellhd.ns_res, cellhd.ew_res); } Curses_write_window(INFO_WINDOW, 15, 2, "WHERE CURSOR-> Mid Button"); } dsp_setup(blank, &cellhd); R_standard_color(YELLOW); Outline_box(top, top + nrows - 1, left, left + ncols - 1); sprintf(msg, "Displaying %s", vect_file[numfiles - 1]); Menu_msg(msg); R_standard_color(line_color); vectclr[numfiles - 1] = line_color; get_clr_name(vect_color[numfiles - 1], line_color); stat = plot(vect_file[numfiles - 1], vect_mapset[numfiles - 1], Points); } display_points(1); R_standard_color(WHITE); Outline_box(top, top + nrows - 1, left, left + ncols - 1); Menu_msg(""); Vect_destroy_line_struct(Points); /* VIEW_MAP2->cell.configured = 1; XXX */ select_current_env(); if (from_screen < 0) { from_flag = 1; from_screen = 0; if (from_keyboard < 0) { from_keyboard = 0; from_screen = 1; } } if (numfiles) { Curses_clear_window(MENU_WINDOW); Curses_write_window(MENU_WINDOW, 1, 5, "COLOR MAP FILE"); for (i = 0; i < numfiles; i++) { sprintf(msg, "%7s %s", vect_color[i], vect_file[i]); Curses_write_window(MENU_WINDOW, i + 3, 3, msg); } } return 0; }
int main() { //Basic Matrix Math struct matrix *a; struct matrix *b; a=new_matrix(4,4); b=new_matrix(4,2); printf("Identity matrix:\n"); ident(a); print_matrix(a); b->m[0][0]=1; b->m[0][1]=2; b->m[1][0]=3; b->m[1][1]=4; b->m[2][0]=5; b->m[2][1]=6; b->m[3][0]=7; b->m[3][1]=8; printf("Matrix #2:\n"); print_matrix(b); printf("Scalar Multiplication by 2:\n"); scalar_mult(2, b); print_matrix(b); printf("New Matrix #1:\n"); a->m[2][1]=3; a->m[0][3]=2; print_matrix(a); printf("Matrix Multiplication:\n"); matrix_mult(a, b); print_matrix(b); printf("Adding points/edges:\n"); struct matrix *d; d = new_matrix(3, 3); add_point(d, 200,400,70); add_point(d, 200,0,7); print_matrix(d); printf("\n"); add_edge(d, 300,500,100,300,100,134); add_edge(d, 100,500,100,100,100,134); add_edge(d, 400,00,100,400,400,134); print_matrix(d); printf("\n"); screen s; color c; c.red = 200; c.green = 100; c.blue = 250; int i, j; for( i=0; i<XRES; i++) for ( j=0; j<YRES; j++) { plot( s, c, i, j); } c.red=0; c.green=200; c.blue=200; draw_lines(d, s, c); display( s ); save_ppm(s, "image" ); save_extension(s, "image.jpg"); }
void QwtPlotCanvas::drawCanvas( QPainter *painter, bool withBackground ) { bool hackStyledBackground = false; if ( withBackground && testAttribute( Qt::WA_StyledBackground ) && testPaintAttribute( HackStyledBackground ) ) { // Antialiasing rounded borders is done by // inserting pixels with colors between the // border color and the color on the canvas, // When the border is painted before the plot items // these colors are interpolated for the canvas // and the plot items need to be clipped excluding // the anialiased pixels. In situations, where // the plot items fill the area at the rounded // borders this is noticeable. // The only way to avoid these annoying "artefacts" // is to paint the border on top of the plot items. if ( d_data->styleSheet.hasBorder && !d_data->styleSheet.borderPath.isEmpty() ) { // We have a border with at least one rounded corner hackStyledBackground = true; } } if ( withBackground ) { painter->save(); if ( testAttribute( Qt::WA_StyledBackground ) ) { if ( hackStyledBackground ) { // paint background without border painter->setPen( Qt::NoPen ); painter->setBrush( d_data->styleSheet.background.brush ); painter->setBrushOrigin( d_data->styleSheet.background.origin ); painter->setClipPath( d_data->styleSheet.borderPath ); painter->drawRect( contentsRect() ); } else { qwtDrawStyledBackground( this, painter ); } } else if ( autoFillBackground() ) { painter->setPen( Qt::NoPen ); painter->setBrush( palette().brush( backgroundRole() ) ); if ( d_data->borderRadius > 0.0 && ( rect() == frameRect() ) ) { if ( frameWidth() > 0 ) { painter->setClipPath( borderPath( rect() ) ); painter->drawRect( rect() ); } else { painter->setRenderHint( QPainter::Antialiasing, true ); painter->drawPath( borderPath( rect() ) ); } } else { painter->drawRect( rect() ); } } painter->restore(); } painter->save(); if ( !d_data->styleSheet.borderPath.isEmpty() ) { painter->setClipPath( d_data->styleSheet.borderPath, Qt::IntersectClip ); } else { if ( d_data->borderRadius > 0.0 ) painter->setClipPath( borderPath( frameRect() ), Qt::IntersectClip ); else painter->setClipRect( contentsRect(), Qt::IntersectClip ); } plot()->drawCanvas( painter ); painter->restore(); if ( withBackground && hackStyledBackground ) { // Now paint the border on top QStyleOptionFrame opt; opt.initFrom(this); style()->drawPrimitive( QStyle::PE_Frame, &opt, painter, this); } }
int main() { screen s; color c; c.red = 0; c.green = 0; c.blue = 0; clear_screen(s); int i, j; for (i=0; i < YRES; i++) for (j=0; j < XRES; j++ ) plot(s, c, i, j); c.green = MAX_COLOR; draw_line(250, 0, 250, 500, s, c); draw_line(125, 0, 375, 500, s, c); draw_line(0, 0, 500, 500, s, c); draw_line(0, 125, 500, 375, s, c); draw_line(0, 250, 500, 250, s, c); draw_line(0, 375, 500, 125, s, c); draw_line(0, 500, 500, 0, s, c); draw_line(125, 500, 375, 0, s, c); /* c.green = 0; c.red = MAX_COLOR; draw_line(125, 0, 125, 250, s, c); draw_line(62, 0, 187, 250, s, c); draw_line(0, 0, 250, 250, s, c); draw_line(0, 62, 250, 187, s, c); draw_line(0, 125, 250, 125, s, c); draw_line(0, 187, 250, 62, s, c); draw_line(0, 250, 250, 0, s, c); draw_line(62, 250, 187, 0, s, c); c.red = 0; c.blue = MAX_COLOR; draw_line(375, 0, 375, 250, s, c); draw_line(312, 0, 427, 250, s, c); draw_line(250, 0, 500, 250, s, c); draw_line(250, 62, 500, 187, s, c); draw_line(250, 125, 500, 125, s, c); draw_line(250, 187, 500, 62, s, c); draw_line(250, 250, 500, 0, s, c); draw_line(312, 250, 427, 0, s, c); c.red = MAX_COLOR; draw_line(125, 250, 125, 500, s, c); draw_line(62, 250, 187, 500, s, c); draw_line(0, 250, 250, 500, s, c); draw_line(0, 312, 250, 427, s, c); draw_line(0, 375, 500, 375, s, c); draw_line(0, 427, 250, 312, s, c); draw_line(0, 500, 250, 250, s, c); draw_line(62, 500, 187, 250, s, c); c.blue = 0; c.green = MAX_COLOR; draw_line(375, 250, 375, 500, s, c); draw_line(312, 250, 427, 500, s, c); draw_line(250, 500, 500, 250, s, c); draw_line(250, 312, 500, 427, s, c); draw_line(250, 375, 500, 375, s, c); draw_line(250, 427, 500, 312, s, c); draw_line(250, 250, 500, 500, s, c); draw_line(312, 500, 427, 250, s, c); */ //Note: Display may not work on your system //save_ppm and save_extension should be fine //display(s); save_ppm(s, "pic.ppm"); save_extension(s, "whatevs.png"); }
int main () { #if defined(VISP_HAVE_DISPLAY) try { //Create a window with one graphic vpPlot plot(1); // Change the default font //plot.setFont("-misc-fixed-bold-r-semicondensed--0-0-75-75-c-0-iso8859-10"); //The graphic contains 2 curves plot.initGraph(0,2); //Set the graphic parameters plot.setTitle(0, "First graphic"); plot.setUnitX(0, "time (s)"); plot.setUnitY(0, "y"); plot.setUnitZ(0, "z"); plot.setLegend(0,0, "y^2+z^2=1 and y(0) = 1"); plot.setLegend(0,1, "y^2+z^2=1 and y(0) = -1"); plot.setColor(0,0,vpColor::red); plot.setColor(0,1,vpColor::green); double x = 0; double y = 1; double z = 0 ; double dx = 0.08; double dy = 0.04; double zsign = 1.0; unsigned long iter = 0; std::cout << "Hit CTRL-C to or right mouse button to exit..." << std::endl; bool end = false; while( !end ) { if (iter < 300) { //y*y+z*z = 1 if (fabs(y) < 1.0) z = sqrt(1.0-y*y); else z = 0; //Add points to the graphic if (plot.plot(0,0, x, y, z*zsign) == vpMouseButton::button3) end = true; if (plot.plot(0,1, x, -y, -z*zsign) == vpMouseButton::button3) end = true; x += dx; if (fabs(y) >= 1.0 ) dy = -dy; y += dy; if (fabs(y) >= 1.0 ) zsign = -zsign; } else { // Tip: to allows modifying the point of view with the mouse we // plot always the last point if (plot.plot(0,0, x, y,z*zsign) == vpMouseButton::button3) end = true; if (plot.plot(0,1, x, -y,-z*zsign) == vpMouseButton::button3) end = true; } iter ++; } return 0; } catch(vpException e) { std::cout << "Catch an exception: " << e << std::endl; return 1; } #else std::cout << "Plot functionalities are not avalaible since no display is available." << std::endl; #endif }
int main() { screen s; color c; // TEST: add_point struct matrix *a; a = (struct matrix *)new_matrix(3,3); add_point(a,1,0,2); // TEST: print_matrix printf("\nAdding one point to matrix A:\n"); print_matrix(a); // TEST: add_edge add_edge(a,4,5,3,2,2,2); printf("Adding an edge:\n"); print_matrix(a); // TEST: scalar multiplication scalar_mult(5,a); printf("Scalar multiplication by 5:\n"); print_matrix(a); scalar_mult(0.2,a); printf("Scalar multiplication by 0.2, returning to original matrix:\n"); print_matrix(a); // TEST: matrix matrix multiplication struct matrix *b; b = (struct matrix *)new_matrix(3,1); add_point(b,1,2,3); printf("Matrix B:\n"); print_matrix(b); matrix_mult(a,b); printf("Matrix multiplication of A with B:\n"); print_matrix(a); // TEST: turning a matrix into the identity matrix struct matrix *d; d = (struct matrix *)new_matrix(3,3); add_edge(d,3,4,5,8.2,9.1,2); add_point(d,5,2,1); printf("Matrix C:\n"); print_matrix(d); ident(d); printf("Matrix C after being made into the 3 x 3 identity matrix:\n"); print_matrix(d); /* struct matrix *m; m = (struct matrix *)new_matrix(3,3); m->m[0][0] = 1; m->m[0][1] = 2; m->m[0][2] = 5; m->m[1][0] = 3; m->m[1][1] = 4; m->m[1][2] = 6; m->m[2][0] = 7; m->m[2][1] = 8; m->m[2][2] = 9; */ /* struct matrix *n; n = (struct matrix *)new_matrix(3,4); n->m[0][0] = 1; n->m[1][0] = 2; n->m[2][0] = 1; n->m[0][1] = 1; n->m[1][1] = 0; n->m[2][1] = 1; n->m[0][2] = 1; n->m[1][2] = 2; n->m[2][2] = 1; n->m[0][3] = 1; n->m[1][3] = 1; n->m[2][3] = 0; */ /* struct matrix *p; p = (struct matrix *)new_matrix(3,5); p->m[0][0] = 1; //print_matrix(p); //print_matrix(matrix_mult(m,n)); */ /* struct matrix *q; q = (struct matrix *)new_matrix(3,2); add_point(q,0,0,0); add_point(q,100,0,0); struct matrix *t; t = (struct matrix *)new_matrix(3,3); t->m[0][0] = cos(M_PI / 6); t->m[1][0] = sin(M_PI / 6); t->m[0][1] = -1 * sin(M_PI / 6); t->m[1][1] = cos(M_PI / 6); t->lastcol = 2; */ /*add_edge(t,cos( M_PI / 6),sin( M_PI / 6), 0, -1 * sin(M_PI / 6), cos(M_PI / 6), 0); */ /* struct matrix *u; u = (struct matrix *)new_matrix(3,2); add_edge(u,0,0,0,100,0,0); int i; for(i = 0; i < 11; i++){ matrix_mult(t,q); add_edge(u,q->m[0][0],q->m[1][0],q->m[2][0], q->m[0][1],q->m[1][1],q->m[2][1]);} int j,k; float f; for(j = 0; j < u->rows; j++){ for(k = 0; k < u->cols; k++){ f = u->m[j][k]; u->m[j][k] = (int)f + 250;} } print_matrix(t); printf("%f\n", cos(M_PI / 6)); */ /* struct matrix *r; r = (struct matrix *)new_matrix(3,2); r->m[0][0] = 0; r->m[0][1] = 0; r->m[1][0] = 50; r->m[1][1] = 50; print_matrix(m); matrix_mult(m,q); print_matrix(m); */ /* int i,j; c.red = 0; c.green = 0; c.blue = 255; for(i = 0; i < XRES; i++){ for(j = 0; j < YRES; j++){ plot(s,c,i,j); } } c.red = 0; c.green = 0; c.blue = 0; draw_lines(q,s,c); */ /* int i, j; for( i=0; i<XRES; i++) for ( j=0; j<YRES; j++) { c.red = random() % (MAX_COLOR + 1); c.green = random() % (MAX_COLOR + 1); c.blue = random() % (MAX_COLOR + 1); plot( s, c, i, j); } */ c.red = 170; c.green = 240; c.blue = 30; int i,j; for(i = 0; i < XRES; i++){ for(j = 0; j < YRES; j++){ plot(s,c,i,j); } } // TEST: draw lines in edge matrix c.red = 0; c.green = 0; c.blue = 0; struct matrix *e; e = (struct matrix *)new_matrix(3,2); //add_point(e,0,0,0); //add_point(e,250,250,0); //draw_lines(e,s,c); for(i = 0; i < 25; i++){ add_edge(e,250+5*i,250+5*i,0,500-5*i,250+5*i,0); add_edge(e,500-5*i,250+5*i,0,500-5*i,500-5*i,0); //add_edge(e,500-5*i,500-5*i,0,250+5*i,250+5*i,0); } for(i = 0; i < 25; i++){ add_edge(e,5*i,5*i,0,250-5*i,5*i,0); add_edge(e,250-5*i,5*i,0,250-5*i,250-5*i,0); //add_edge(e,250-5*i,250-5*i,0,5*i,5*i,0); } for(i = 0; i < 25; i++){ add_edge(e,125+5*i,125+5*i,0,125+5*i,375-5*i,0); add_edge(e,125+5*i,375-5*i,0,375-5*i,375-5*i,0); //add_edge(e,375-5*i,375-5*i,0,125+5*i,125+5*i,0); } add_edge(e,0,0,0,125,125,0); add_edge(e,375,375,0,500,500,0); draw_lines(e,s,c); display( s ); save_ppm(s, "image" ); save_extension(s, "image.jpg"); }
void LegendItem::paint(QPainter *painter) { if (!isVisible()) { return; } RelationList legendItems; if (_auto) { legendItems = plot()->renderItem(PlotRenderItem::Cartesian)->relationList(); } else { legendItems = _relations; } int count = legendItems.count(); if (count <= 0) { // no legend or box if there are no legend items return; } QList<DrawnLegendItem> legendPixmaps; QSize legendSize(0, 0); QFont font(_font); font.setPointSizeF(view()->viewScaledFontSize(_fontScale)); // generate string list of relation names QStringList names; bool allAuto = true; bool sameX = true; bool sameYUnits = true; LabelInfo label_info = legendItems.at(0)->xLabelInfo(); QString yUnits = legendItems.at(0)->yLabelInfo().units; for (int i = 0; i<count; i++) { RelationPtr relation = legendItems.at(i); if (relation->descriptiveNameIsManual()) { allAuto = false; } if (relation->xLabelInfo() != label_info) { sameX = false; } // sameYUnits is false if any non empty units are defined differently. if (yUnits.isEmpty()) { yUnits = relation->yLabelInfo().units; } else if (relation->yLabelInfo().units != yUnits) { if (!relation->yLabelInfo().units.isEmpty()) { sameYUnits = false; } } } if (!allAuto) { for (int i = 0; i<count; i++) { names.append(legendItems.at(i)->descriptiveName()); } } else { for (int i = 0; i<count; i++) { RelationPtr relation = legendItems.at(i); QString label = relation->titleInfo().singleRenderItemLabel(); if (label.isEmpty()) { label_info = relation->yLabelInfo(); QString y_label = label_info.name; if (!sameYUnits) { if (!label_info.units.isEmpty()) { y_label = i18n("%1 \\[%2\\]").arg(y_label).arg(label_info.units); } } if (!y_label.isEmpty()) { LabelInfo xlabel_info = relation->xLabelInfo(); if (!sameX) { label = i18n("%1 vs %2").arg(y_label).arg(xlabel_info.name); } else if (xlabel_info.quantity.isEmpty()) { label = y_label; } else if (xlabel_info.quantity != xlabel_info.name) { label = i18n("%1 vs %2").arg(y_label).arg(xlabel_info.name); } else { label = y_label; } } else { label = relation->descriptiveName(); } } int i_dup = names.indexOf(label); if (i_dup<0) { names.append(label); } else { RelationPtr dup_relation = legendItems.at(i_dup); if (!dup_relation->yLabelInfo().file.isEmpty()) { names.replace(i_dup, label + " (" + dup_relation->yLabelInfo().file + ')'); } if (!relation->yLabelInfo().file.isEmpty()) { names.append(label + " (" + relation->yLabelInfo().file + ')'); } } } } for (int i = 0; i<count; i++) { RelationPtr relation = legendItems.at(i); DrawnLegendItem item; item.pixmap = QPixmap(LEGENDITEMMAXWIDTH, LEGENDITEMMAXHEIGHT); item.size = paintRelation(names.at(i), relation, &item.pixmap, font); if (_verticalDisplay) { legendSize.setWidth(qMax(legendSize.width(), item.size.width())); legendSize.setHeight(legendSize.height() + item.size.height()); } else { legendSize.setHeight(qMax(legendSize.height(), item.size.height())); legendSize.setWidth(legendSize.width() + item.size.width()); } legendPixmaps.append(item); } int x = rect().left(); int y = rect().top(); painter->save(); if (!_title.isEmpty()) { // Paint the title Label::Parsed *parsed = Label::parse(_title); if (parsed) { painter->save(); QPixmap pixmap(400, 100); pixmap.fill(Qt::transparent); QPainter pixmapPainter(&pixmap); Label::RenderContext rc(font, &pixmapPainter); QFontMetrics fm(font); rc.y = fm.ascent(); Label::renderLabel(rc, parsed->chunk, false); int startPoint = qMax(0, (legendSize.width() / 2) - (rc.x / 2)); int paddingValue = fm.height() / 4; setViewRect(viewRect().x(), viewRect().y(), qMax(rc.x, legendSize.width()), rc.y + legendSize.height() + paddingValue * 3); painter->drawRect(rect()); painter->drawPixmap(QPoint(x + startPoint, y + paddingValue), pixmap, QRect(0, 0, rc.x, fm.height())); painter->restore(); y += fm.height() + (paddingValue *2); delete parsed; parsed = 0; } } else { // No Title setViewRect(viewRect().x(), viewRect().y(), legendSize.width(), legendSize.height()); painter->drawRect(rect()); } foreach(const DrawnLegendItem &item, legendPixmaps) { painter->drawPixmap(QPoint(x, y), item.pixmap, QRect(0, 0, item.size.width(), item.size.height())); if (_verticalDisplay) { y += item.size.height(); } else { x += item.size.width(); } }
/** * Do setup for line rasterization, then render the line. * Single-pixel width, no stipple, etc. We rely on the 'draw' module * to handle stippling and wide lines. */ void sp_setup_line(struct setup_context *setup, const float (*v0)[4], const float (*v1)[4]) { int x0 = (int) v0[0][0]; int x1 = (int) v1[0][0]; int y0 = (int) v0[0][1]; int y1 = (int) v1[0][1]; int dx = x1 - x0; int dy = y1 - y0; int xstep, ystep; uint layer = 0; unsigned viewport_index = 0; #if DEBUG_VERTS debug_printf("Setup line:\n"); print_vertex(setup, v0); print_vertex(setup, v1); #endif if (setup->softpipe->no_rast || setup->softpipe->rasterizer->rasterizer_discard) return; if (dx == 0 && dy == 0) return; if (!setup_line_coefficients(setup, v0, v1)) return; assert(v0[0][0] < 1.0e9); assert(v0[0][1] < 1.0e9); assert(v1[0][0] < 1.0e9); assert(v1[0][1] < 1.0e9); if (dx < 0) { dx = -dx; /* make positive */ xstep = -1; } else { xstep = 1; } if (dy < 0) { dy = -dy; /* make positive */ ystep = -1; } else { ystep = 1; } assert(dx >= 0); assert(dy >= 0); assert(setup->softpipe->reduced_prim == PIPE_PRIM_LINES); setup->quad[0].input.x0 = setup->quad[0].input.y0 = -1; setup->quad[0].inout.mask = 0x0; if (setup->softpipe->layer_slot > 0) { layer = *(unsigned *)setup->vprovoke[setup->softpipe->layer_slot]; layer = MIN2(layer, setup->max_layer); } setup->quad[0].input.layer = layer; if (setup->softpipe->viewport_index_slot > 0) { unsigned *udata = (unsigned*)setup->vprovoke[setup->softpipe->viewport_index_slot]; viewport_index = sp_clamp_viewport_idx(*udata); } setup->quad[0].input.viewport_index = viewport_index; /* XXX temporary: set coverage to 1.0 so the line appears * if AA mode happens to be enabled. */ setup->quad[0].input.coverage[0] = setup->quad[0].input.coverage[1] = setup->quad[0].input.coverage[2] = setup->quad[0].input.coverage[3] = 1.0; if (dx > dy) { /*** X-major line ***/ int i; const int errorInc = dy + dy; int error = errorInc - dx; const int errorDec = error - dx; for (i = 0; i < dx; i++) { plot(setup, x0, y0); x0 += xstep; if (error < 0) { error += errorInc; } else { error += errorDec; y0 += ystep; } } } else { /*** Y-major line ***/ int i; const int errorInc = dx + dx; int error = errorInc - dy; const int errorDec = error - dy; for (i = 0; i < dy; i++) { plot(setup, x0, y0); y0 += ystep; if (error < 0) { error += errorInc; } else { error += errorDec; x0 += xstep; } } } /* draw final quad */ if (setup->quad[0].inout.mask) { clip_emit_quad(setup, &setup->quad[0]); } }
void DeJong::reseed(){ clear(); seed(); plot(1); }
int main() { screen s; color c; int i, j; c.red = 0; c.green = MAX_COLOR; c.blue = 0; clear_screen(s); /* //octant 1 draw_line( 0, 0, XRES-1, YRES - 75, s, c); // draw_line( XRES-1, YRES - 75, 0, 0, s, c); //octant 2 draw_line( 0, 0, XRES - 75, YRES-1, s, c); //octant 8 draw_line( 0, YRES-1, XRES-1, 75, s, c); //octant 7 draw_line( 0, YRES-1, XRES - 75, 0, s, c); c.green = 0; c.blue = MAX_COLOR; //octant 5 draw_line( XRES - 1, YRES - 1, 0, 75, s, c); //octant 6 draw_line( XRES - 1, YRES -1, 75, 0, s, c); //octant 4 draw_line( XRES - 1, 0, 0, YRES - 75, s, c); //octant 3 draw_line( XRES - 1, 0, 75, YRES - 1, s, c); c.blue = 0; c.red = MAX_COLOR; //y = x, y = -x draw_line( 0, 0, XRES - 1, YRES - 1, s, c); draw_line( 0, YRES - 1, XRES - 1, 0, s, c); //horizontal, vertical line draw_line( 0, YRES / 2, XRES - 1, YRES / 2, s, c); draw_line( XRES / 2, 0, XRES / 2, YRES - 1, s, c); draw_coord(s, c); draw_border(s, c); */ c.red = MAX_COLOR; c.green = 0; c.blue = 0; for ( i = 0; i < XRES; i+=6 ) { draw_line( XRES / 2, YRES / 2, i, 0, s, c ); c.red = c.red - 3; c.green = c.green + 3; } c.red = 0; c.green = MAX_COLOR; for ( i = 0; i < YRES; i+=6 ) { draw_line( XRES / 2, YRES / 2, YRES, i, s, c ); c.green = c.green - 3; c.blue = c.blue + 3; } c.green = 0; c.blue = MAX_COLOR; for (i = 0; i < XRES; i+=6 ) { draw_line( XRES / 2, YRES /2, XRES - i, YRES, s, c ); c.blue = c.blue - 3; c.green += 3; c.red += 3; } c.blue = 0; for (i = 0; i < XRES; i+=6 ) { draw_line( XRES / 2, YRES /2, 0, YRES - i, s, c ); c.green -= 3; } for ( i = 0; i < XRES; i++ ) { for ( j = 0; j < YRES; j++ ) { if ( i % 100 <= 3 || j % 100 <= 3 ) { c.red = MAX_COLOR; c.green = MAX_COLOR / 2 + 50; c.blue = MAX_COLOR; plot (s, c, i, j); } } } for ( i = 0; i < XRES; i+=10 ) { c.red = 0; c.green = 0; c.blue = 0; draw_line( i, 0, 0, i, s, c ); draw_line( i, 0, YRES - i, XRES, s, c ); draw_line( 0, i, XRES, YRES - i, s, c ); } draw_border(s, c); save_extension(s, "lines.png"); display(s); }
void draw_line(int x0, int y0, int x1, int y1, screen s, color c) { int x, y, dx, dy, d, A, B; x = x0; y = y0; //swap values if octants 3-6 if ( x0 > x1 ) { x = x1; y = y1; x1 = x0; y1 = y0; } dx = x1 - x; dy = y1 - y; A = dy * 2; B = -2 * dx; //positive slope: Octants 1,2 if ( dy > 0 ) { //Octant 1 if ( dx > dy ) { d = A + B/2; while ( x <= x1 ) { plot( s, c, x, y ); if ( d > 0 ) { y++; d+= B; } x++; d+= A; } }// end octant 1 //Octant 2 else { d = A/2 + B; while ( y <= y1 ) { plot( s, c, x, y ); if ( d < 0 ) { x++; d+=A; } y++; d+= B; } }//Octant 2 }//octants: 1, 2 //negative slope: Octants: 7, 8 else { //Octant 8 if ( dx > (-1 * dy) ) { d = A - B/2; while ( x <= x1 ) { plot(s, c, x, y); if ( d < 0 ) { y--; d-=B; } x++; d+= A; } }//end octant 8 //octant 7 else { d = A/2 - B; while( y >= y1 ) { plot(s, c, x, y); if ( d > 0 ) { x++; d+= A; } y--; d-= B; } } //end octant 7 }//end Octants 7,8 }
graph (struct s_record r[]) { int i, j; long max, max_d; char buf[200]; if (!strncmp (buf, "CARBONE", 7)) break_debug(); /* printf ("%s", r[0].nom); */ sprintf (buf, "%s", r[0].nom); #ifdef TEST #else #ifdef LOWLEVEL #else /* if (strncmp (buf, "SOPRA", 5)) */ outtextxy (1, 1, buf); #endif #endif if (!strcmp (r[0].nom, "CARBONE LORRAINE")) restorecrtmode(); max = 0; for (i=0; r[i].status; i++) { if (r[i].clot > max) max = r[i].clot; } max_d = 0; for (i=1; r[i].status; i++) { if (r[i].dl > max_d) max_d = r[i].dl; if (-r[i].dl > max_d) max_d = -r[i].dl; } if (max == 0) max = 1; if (max_d == 0) max_d = 1; for (i=0; r[i].status; i++) { plot (i*10, HAUT + BAS - r[i].clot * BAS / max, 15); plot (i*10, AXE_X - r[i].dl * AXE_X / max_d / DIV_D, 15); } for (i=0; r[i+1].status; i++) { /* plot (i*4, 100-r[i].clot / 100, 1); */ /* plot (i*10, 800 - r[i].clot, 15); */ for (j=0; j<=N; j++) { plot (i*10+j, HAUT + BAS - (r[i].l * (N-j) + r[i+1].l * j) / N * BAS / max, 7); plot (XD0 + (r[i].dl * (N-j) + r[i+1].dl * j) * AXE_X / N / max_d / DIV_D, HAUT + BAS - (r[i].l * (N-j) + r[i+1].l * j) / N * BAS / max, 7); /* plot (i*10+j, BAS - (r[i].dl * (N-j) + r[i+1].dl * j) / N * BAS / max, 6); plot (i*10+j, BAS - (r[i].ldl * (N-j) + r[i+1].ldl * j) / N * BAS / max, 5); */ plot (i*10+j, AXE_X, 6); /* plot (i*10+j, AXE_X - (r[i].dl * (N-j) + r[i+1].dl * j) / N * AXE_X / max_d , 15); */ plot (i*10+j, AXE_X - (r[i].ldl * (N-j) + r[i+1].ldl * j) * AXE_X / N / max_d / DIV_D, 7); } /* printf ("%d\n", r[i].clot); */ /* printf ("%d %d %d %d\n", r[i].clot, r[i].l, r[i].dl, r[i].ldl); */ } /* if (!strcmp (r[0].nom, "CARBONE LORRAINE")) restorecrtmode(); */ }
void SARRERA_pantailenAukerak(int x, int y, int zabalera, int altuera, int pantailaKopurua){ //aldagaiak int i = 0, t = 0; //programa borraCopiaPantalla(); for (i = y; i < y + altuera; i++){ for (t = x; t < x + zabalera; t++){ plot(t, i, URDINA_FONDO); } } if (pantailaKopurua == 1){ escribirTexto(225, 50, TITULOA); escribirTexto(150, 150, AUKERA0); escribirTexto(150, 200, EXIT); } if (pantailaKopurua == 2){ escribirTexto(225, 50, TITULOA); escribirTexto(150, 150, AUKERA0); escribirTexto(150, 200, AUKERA1); escribirTexto(150, 250, EXIT); } if (pantailaKopurua == 3){ escribirTexto(225, 50, TITULOA); escribirTexto(150, 150, AUKERA0); escribirTexto(150, 200, AUKERA1); escribirTexto(150, 250, AUKERA2); escribirTexto(150, 300, EXIT); } if (pantailaKopurua == 4){ escribirTexto(225, 50, TITULOA); escribirTexto(150, 150, AUKERA0); escribirTexto(150, 200, AUKERA1); escribirTexto(150, 250, AUKERA2); escribirTexto(150, 300, AUKERA3); escribirTexto(150, 350, EXIT); } if (pantailaKopurua == 5){ escribirTexto(225, 50, TITULOA); escribirTexto(150, 150, AUKERA0); escribirTexto(150, 200, AUKERA1); escribirTexto(150, 250, AUKERA2); escribirTexto(150, 300, AUKERA3); escribirTexto(150, 350, AUKERA4); escribirTexto(150, 400, EXIT); } if (pantailaKopurua == 6){ escribirTexto(225, 50, TITULOA); escribirTexto(150, 150, AUKERA0); escribirTexto(150, 200, AUKERA1); escribirTexto(150, 250, AUKERA2); escribirTexto(150, 300, AUKERA3); escribirTexto(150, 350, AUKERA4); escribirTexto(150, 400, AUKERA5); escribirTexto(150, 450, EXIT); } if (pantailaKopurua == 7){ } actualizaPantalla(); }
int main() { Plotdata x(-3.0, 3.0), y = sin(x) - 0.5*x; plot(x, y); return 0; }
void drawLine(sf::RenderTarget& target, float x1, float y1, float x2, float y2, const sf::Color& color) { float dx = x2 - x1; float dy = y2 - y1; // Store all points in an arrry sf::VertexArray va(sf::Points); if (std::fabs(dx) > std::fabs(dy)) { if(x2 < x1) { std::swap(x1, x2); std::swap(y1, y2); } float gradient = dy / dx; float xend = static_cast<float>(round(x1)); float yend = y1 + gradient * (xend - x1); float xgap = rfpart(x1 + 0.5f); int xpxl1 = static_cast<int>(xend); int ypxl1 = ipart(yend); // Add the first endpoint plot(va, xpxl1, ypxl1, rfpart(yend) * xgap, color); plot(va, xpxl1, ypxl1 + 1, fpart(yend) * xgap, color); float intery = yend + gradient; xend = static_cast<float>(round(x2)); yend = y2 + gradient * (xend - x2); xgap = fpart(x2 + 0.5f); int xpxl2 = static_cast<int>(xend); int ypxl2 = ipart(yend); // Add the second endpoint plot(va, xpxl2, ypxl2, rfpart(yend) * xgap, color); plot(va, xpxl2, ypxl2 + 1, fpart(yend) * xgap, color); // Add all the points between the endpoints for(int x = xpxl1 + 1; x <= xpxl2 - 1; ++x) { plot(va, x, ipart(intery), rfpart(intery), color); plot(va, x, ipart(intery) + 1, fpart(intery), color); intery += gradient; } } else { if(y2 < y1) { std::swap(x1, x2); std::swap(y1, y2); } float gradient = dx / dy; float yend = static_cast<float>(round(y1)); float xend = x1 + gradient * (yend - y1); float ygap = rfpart(y1 + 0.5f); int ypxl1 = static_cast<int>(yend); int xpxl1 = ipart(xend); // Add the first endpoint plot(va, xpxl1, ypxl1, rfpart(xend) * ygap, color); plot(va, xpxl1, ypxl1 + 1, fpart(xend) * ygap, color); float interx = xend + gradient; yend = static_cast<float>(round(y2)); xend = x2 + gradient * (yend - y2); ygap = fpart(y2 + 0.5f); int ypxl2 = static_cast<int>(yend); int xpxl2 = ipart(xend); // Add the second endpoint plot(va, xpxl2, ypxl2, rfpart(xend) * ygap, color); plot(va, xpxl2, ypxl2 + 1, fpart(xend) * ygap, color); // Add all the points between the endpoints for(int y = ypxl1 + 1; y <= ypxl2 - 1; ++y) { plot(va, ipart(interx), y, rfpart(interx), color); plot(va, ipart(interx) + 1, y, fpart(interx), color); interx += gradient; } } target.draw(va); }
int main(int argc, char **argv) { int xx,yy,ch,i; double theta,delta=0.0; grsim_init(); gr(); // clear_screens(); ram[DRAW_PAGE]=PAGE0; clear_bottom(); ram[DRAW_PAGE]=PAGE1; clear_bottom(); ram[DRAW_PAGE]=PAGE2; clear_bottom(); // clear_bottom(PAGE0); // clear_bottom(PAGE1); // clear_bottom(PAGE2); // grsim_unrle(demo_rle,0x400); // grsim_unrle(demo_rle,0xc00); // gr_copy_to_current(0xc00); // page_flip(); // gr_copy_to_current(0xc00); // page_flip(); ram[DRAW_PAGE]=PAGE0; while(1) { ch=repeat_until_keypressed(); if (ch=='q') break; clear_top(); for(theta=0;theta<360.0;theta+=STEP) { xx=cos(d2r(theta+delta))*SCALE+20; yy=sin(d2r(theta+delta))*SCALE*1.33+24; #if 1 color_equals(15); plot(xx,yy); if (xx<20) { color_equals(1); for(i=xx;i<(20-xx)+20;i++) { plot(i,yy); } } else { color_equals(2); for(i=xx;i<40;i++) { plot(i,yy); } } #endif #if 0 color_equals(4); plot(xx,yy); if (xx>20) { for(i=xx;i<40;i++) { plot(i,yy); } } #endif #if 0 color_equals(4); // plot(xx,yy); if (xx<20) { for(i=xx;i<40;i++) { plot(i,yy); } } #endif } delta+=DELTA; grsim_update(); } return 0; }
/* plot_point * * Plot a point given in window coordinates. */ void canvashdl::plot_point(vec3f v, vector<float> varying) { plot((vec3i)v, varying); }
void QtDensity::getKernel(int kernel) { if (kernel != m_kernel) { m_kernel = kernel; plot(); } }
/* plot_half_triangle * * Plot half of a triangle defined by three points in window coordinates (v1, v2, v3). * The remaining inputs are as follows (s1, s2, s3) are the pixel coordinates of (v1, v2, v3), * and (ave) is the average value of the normal and texture coordinates for flat shading. * Use Bresenham's algorithm for this. You may plot the horizontal half or the vertical half. */ void canvashdl::plot_half_triangle(vec3i s1, vector<float> v1_varying, vec3i s2, vector<float> v2_varying, vec3i s3, vector<float> v3_varying, vector<float> ave_varying) { int b12 = (abs(s2[1] - s1[1]) > abs(s2[0] - s1[0])); int b13 = (abs(s1[1] - s3[1]) > abs(s1[0] - s3[0])); vec2i dv12 = s2 - s1; vec2i dv13 = s3 - s1; vec2i step12, step13; for (int i = 0; i < 2; i++) { step12[i] = (int)(dv12[i] > 0) - (int)(dv12[i] < 0); dv12[i] *= step12[i]; step13[i] = (int)(dv13[i] > 0) - (int)(dv13[i] < 0); dv13[i] *= step13[i]; } int D12 = 2*dv12[1-b12] - dv12[b12]; int D13 = 2*dv13[1-b13] - dv13[b13]; vector<float> varying12(v1_varying.size()); vector<float> varying13(v1_varying.size()); vector<float> varying12_diff(v1_varying.size()); vector<float> varying13_diff(v1_varying.size()); vector<float> varying_diff(v1_varying.size()); if (shade_model != flat) { for (int i = 0; i < (int)v1_varying.size(); i++) { varying12_diff[i] = v2_varying[i] - v1_varying[i]; varying13_diff[i] = v3_varying[i] - v1_varying[i]; } } else { varying12 = v1_varying; varying13 = v1_varying; } plot(s1, v1_varying); vec3i p12 = s1, p13 = s1; float increment12 = (float)step12[b12]/(float)(s2[b12] - s1[b12]); float increment13 = (float)step13[b13]/(float)(s3[b13] - s1[b13]); float interpolate12 = 0.0f; float interpolate13 = 0.0f; while (step12[b12] != 0 && step13[b13] != 0 && step12[b12]*p12[b12] < step12[b12]*s2[b12] && step13[b13]*p13[b13] < step13[b13]*s3[b13]) { vec2i old = p12; do { if (D12 > 0) { p12[1-b12] += step12[1-b12]; D12 += 2*(dv12[1-b12] - dv12[b12]); } else D12 += 2*dv12[1-b12]; p12[b12] += step12[b12]; interpolate12 += increment12; } while ((step12[b12] != 0 || step12[1-b12] != 0) && (vec2i)p12 == old && step12[b12]*p12[b12] < step12[b12]*s2[b12]); while ((step13[b13] != 0 || step13[1-b13] != 0) && p13[0] != p12[0] && step13[b13]*p13[b13] < step13[b13]*s3[b13]) { p13[b13] += step13[b13]; interpolate13 += increment13; if (D13 > 0) { p13[1-b13] += step13[1-b13]; D13 += 2*(dv13[1-b13] - dv13[b13]); } else D13 += 2*dv13[1-b13]; } p12[2] = (int)((float)(s2[2] - s1[2])*interpolate12 + (float)s1[2]); p13[2] = (int)((float)(s3[2] - s1[2])*interpolate13 + (float)s1[2]); if (shade_model != flat) { for (int i = 0; i < (int)v1_varying.size(); i++) { varying12[i] = varying12_diff[i]*interpolate12 + v1_varying[i]; varying13[i] = varying13_diff[i]*interpolate13 + v1_varying[i]; } } vec3i Ai = p12; vec3i Bi = p13; if (Ai[1] > Bi[1]) { swap(varying12, varying13); swap(Ai, Bi); } vec3i p = Ai; float increment = 1.0f/(float)(Bi[1] - Ai[1]); float interpolateab = 0.0f; if (shade_model != flat) for (int i = 0; i < (int)varying12.size(); i++) varying_diff[i] = varying13[i] - varying12[i]; float zdiff = (float)(Bi[2] - Ai[2]); for (; p[1] < Bi[1]; p[1]++) { p[2] = (int)(zdiff*interpolateab) + Ai[2]; if (shade_model != flat) for (int i = 0; i < (int)varying12.size(); i++) ave_varying[i] = varying_diff[i]*interpolateab + varying12[i]; plot(p, ave_varying); interpolateab += increment; } plot(Bi, varying13); } }
void draw_line(int x0, int y0, int x1, int y1, screen s, color c) { int x, y, d, dx, dy; x = x0; y = y0; //swap points so we're always draing left to right if ( x0 > x1 ) { x = x1; y = y1; x1 = x0; y1 = y0; } //need to know dx and dy for this version dx = (x1 - x) * 2; dy = (y1 - y) * 2; //positive slope: Octants 1, 2 (5 and 6) if ( dy > 0 ) { //slope < 1: Octant 1 (5) if ( dx > dy ) { d = dy - ( dx / 2 ); while ( x <= x1 ) { plot(s, c, x, y); if ( d < 0 ) { x = x + 1; d = d + dy; } else { x = x + 1; y = y + 1; d = d + dy - dx; } } } //slope > 1: Octant 2 (6) else { d = ( dy / 2 ) - dx; while ( y <= y1 ) { plot(s, c, x, y ); if ( d > 0 ) { y = y + 1; d = d - dx; } else { y = y + 1; x = x + 1; d = d + dy - dx; } } } } //negative slope: Octants 7, 8 (3 and 4) else { //slope > -1: Octant 8 (4) if ( dx > abs(dy) ) { d = dy + ( dx / 2 ); while ( x <= x1 ) { plot(s, c, x, y); if ( d > 0 ) { x = x + 1; d = d + dy; } else { x = x + 1; y = y - 1; d = d + dy + dx; } } } //slope < -1: Octant 7 (3) else { d = (dy / 2) + dx; while ( y >= y1 ) { plot(s, c, x, y ); if ( d < 0 ) { y = y - 1; d = d + dx; } else { y = y - 1; x = x + 1; d = d + dy + dx; } } } } }
int main(int argc, char const **argv) { // Initialise ncurses WINDOW* win = nullptr; if ((win = initscr()) == nullptr) { std::cerr << "failed to initialize ncurses\n"; return 1; } // Check for colors. if (!has_colors()) { delwin(win); endwin(); refresh(); std::cerr << "your terminal doesn't support colors\n"; return 1; } noecho(); keypad(win, true); start_color(); use_default_colors(); // Color pairs init_pair(1, COLOR_WHITE, COLOR_BLACK); init_pair(2, COLOR_RED, COLOR_BLACK); init_pair(3, COLOR_YELLOW, COLOR_BLACK); init_pair(4, COLOR_GREEN, COLOR_BLACK); init_pair(5, COLOR_CYAN, COLOR_BLACK); init_pair(6, COLOR_BLUE, COLOR_BLACK); init_pair(7, COLOR_MAGENTA, COLOR_BLACK); // Width must be a multiple of 8 for AVX. u32 const w = COLS - (COLS % 8); // Leave one line for printing timing info. u32 const h = LINES - 1; // Initial center point float cx = 0.0f; float cy = 0.0f; // Compute size of area viewable float sx = 2.7f; float sy = -4.0f / 3.0f * 2.7f * (float) h / (float) w; // Compute corner points float x1 = cx - sx / 2.0f; float y1 = cy - sy / 2.0f; float x2 = cx + sx / 2.0f; float y2 = cy + sy / 2.0f; // Compute deltas float dx = (x2 - x1) / (float) w; float dy = (y2 - y1) / (float) h; // Main loop bool running = true; bool dirty = true; while (running) { if (dirty) { // Recompute corner points x1 = cx - sx / 2.0f; y1 = cy - sy / 2.0f; x2 = cx + sx / 2.0f; y2 = cy + sy / 2.0f; // Recompute deltas dx = (x2 - x1) / (float) w; dy = (y2 - y1) / (float) h; clear(); plot(w, h, x1, y1, x2, y2, dx, dy); refresh(); dirty = false; } // Check for keyboard input u32 input = getch(); switch (input) { // Quit case 'q': running = false; break; // Move case KEY_LEFT: cx -= 5.0f * dx; dirty = true; break; case KEY_RIGHT: cx += 5.0f * dx; dirty = true; break; case KEY_UP: cy -= 5.0f * dy; dirty = true; break; case KEY_DOWN: cy += 5.0f * dy; dirty = true; break; // Zoom case '-': sx *= 1.1f; sy *= 1.1f; dirty = true; break; case '=': sx /= 1.1f; sy /= 1.1f; dirty = true; break; } } // Kill ncurses delwin(win); endwin(); refresh(); return 0; }