示例#1
0
void PCD8544::plotRect(byte left, byte top, byte right, byte bottom)
{
  plotLine(left, top, right, top); //top
  plotLine(left, bottom, right, bottom); //bottom
  plotLine(right, top, right, bottom); //right
  plotLine(left, top, left, bottom); //left
}
示例#2
0
// ######################################################################
void ScorbotConsole::updatePlots()
{
	itsGraphicsView->setBackgroundBrush(QBrush(Qt::darkGray));

	//Clear all previous plots
	QList<QGraphicsItem*> items = itsGraphicsScene->items();
	for(int i=0; i<items.size(); i++)
	{
		itsGraphicsScene->removeItem(items[i]);
		delete items[i];
	}

	int textPos = -5000;
	int textOffset=500;
	QMap<QString, bool>::iterator dataCheckIt = plotDataCheck.begin();
	for(; dataCheckIt != plotDataCheck.end(); ++dataCheckIt)
	{
    if (dataCheckIt.value() && plotData.contains(dataCheckIt.key()))
		{
			PixRGB<byte> color = plotDataColor[dataCheckIt.key()];
			QGraphicsTextItem *text = itsGraphicsScene->addText(dataCheckIt.key());
			text->setDefaultTextColor(QColor(color.red(), color.green(), color.blue()));
			text->setPos(1, textPos);
			text->setFlags(QGraphicsItem::ItemIgnoresTransformations);
			textPos+=textOffset;
			plotLine(plotData[dataCheckIt.key()], color);
		}
	}
	itsGraphicsScene->addLine(QLineF(0, -5000, 0, 5000), QPen(QColor(128, 0, 0)));
	itsGraphicsScene->addLine(QLineF(0, 0, itsMaxPlotLength, 0), QPen(QColor(128, 0, 0)));

	itsGraphicsView->fitInView(itsGraphicsScene->itemsBoundingRect());
	itsGraphicsView->ensureVisible(itsGraphicsScene->itemsBoundingRect());
	itsGraphicsView->centerOn(itsMaxPlotLength/2, 0);
}
示例#3
0
void plotCubicBezierSeg(int x0, int y0, double x1, double y1,
                        double x2, double y2, int x3, int y3)
{                                        /* plot limited cubic Bezier segment */
    int f, fx, fy, leg = 1;
    int sx = x0 < x3 ? 1 : -1, sy = y0 < y3 ? 1 : -1;        /* step direction */
    double xc = -fabs(x0+x1-x2-x3), xa = xc-4*sx*(x1-x2), xb = sx*(x0-x1-x2+x3);
    double yc = -fabs(y0+y1-y2-y3), ya = yc-4*sy*(y1-y2), yb = sy*(y0-y1-y2+y3);
    double ab, ac, bc, cb, xx, xy, yy, dx, dy, ex, *pxy, EP = 0.01;
    /* check for curve restrains */
    /* slope P0-P1 == P2-P3    and  (P0-P3 == P1-P2      or   no slope change) */
    assert((x1-x0)*(x2-x3) < EP && ((x3-x0)*(x1-x2) < EP || xb*xb < xa*xc+EP));
    assert((y1-y0)*(y2-y3) < EP && ((y3-y0)*(y1-y2) < EP || yb*yb < ya*yc+EP));
    
    if (xa == 0 && ya == 0) {                              /* quadratic Bezier */
        sx = (int) floor((3*x1-x0+1)/2); sy = (int) floor((3*y1-y0+1)/2);   /* new midpoint */
        return plotQuadBezierSeg(x0,y0, sx,sy, x3,y3);
    }
    x1 = (x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)+1;                    /* line lengths */
    x2 = (x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)+1;
    do {                                                /* loop over both ends */
        ab = xa*yb-xb*ya; ac = xa*yc-xc*ya; bc = xb*yc-xc*yb;
        ex = ab*(ab+ac-3*bc)+ac*ac;       /* P0 part of self-intersection loop? */
        f = (int) (ex > 0 ? 1 : sqrt(1+1024/x1));               /* calculate resolution */
        ab *= f; ac *= f; bc *= f; ex *= f*f;            /* increase resolution */
        xy = 9*(ab+ac+bc)/8; cb = 8*(xa-ya);  /* init differences of 1st degree */
        dx = 27*(8*ab*(yb*yb-ya*yc)+ex*(ya+2*yb+yc))/64-ya*ya*(xy-ya);
        dy = 27*(8*ab*(xb*xb-xa*xc)-ex*(xa+2*xb+xc))/64-xa*xa*(xy+xa);
        /* init differences of 2nd degree */
        xx = 3*(3*ab*(3*yb*yb-ya*ya-2*ya*yc)-ya*(3*ac*(ya+yb)+ya*cb))/4;
        yy = 3*(3*ab*(3*xb*xb-xa*xa-2*xa*xc)-xa*(3*ac*(xa+xb)+xa*cb))/4;
        xy = xa*ya*(6*ab+6*ac-3*bc+cb); ac = ya*ya; cb = xa*xa;
        xy = 3*(xy+9*f*(cb*yb*yc-xb*xc*ac)-18*xb*yb*ab)/8;
        
        if (ex < 0) {         /* negate values if inside self-intersection loop */
            dx = -dx; dy = -dy; xx = -xx; yy = -yy; xy = -xy; ac = -ac; cb = -cb;
        }                                     /* init differences of 3rd degree */
        ab = 6*ya*ac; ac = -6*xa*ac; bc = 6*ya*cb; cb = -6*xa*cb;
        dx += xy; ex = dx+dy; dy += xy;                    /* error of 1st step */
        
        for (pxy = &xy, fx = fy = f; x0 != x3 && y0 != y3; ) {
            //setPixel(x0,y0);                                       /* plot curve */
            do {                                  /* move sub-steps of one pixel */
                if (dx > *pxy || dy < *pxy) goto exit;       /* confusing values */
                y1 = 2*ex-dy;                    /* save value for test of y step */
                if (2*ex >= dx) {                                   /* x sub-step */
                    fx--; ex += dx += xx; dy += xy += ac; yy += bc; xx += ab;
                }
                if (y1 <= 0) {                                      /* y sub-step */
                    fy--; ex += dy += yy; dx += xy += bc; xx += ac; yy += cb;
                }
            } while (fx > 0 && fy > 0);                       /* pixel complete? */
            if (2*fx <= f) { x0 += sx; fx += f; }                      /* x step */
            if (2*fy <= f) { y0 += sy; fy += f; }                      /* y step */
            if (pxy == &xy && dx < 0 && dy > 0) pxy = &EP;  /* pixel ahead valid */
        }
    exit: xx = x0; x0 = x3; x3 = (int) xx; sx = -sx; xb = -xb;             /* swap legs */
        yy = y0; y0 = y3; y3 = (int) yy; sy = -sy; yb = -yb; x1 = x2;
    } while (leg--);                                          /* try other end */
    plotLine(x0,y0, x3,y3);       /* remaining part in case of cusp or crunode */
}
示例#4
0
void plotQuadBezierSeg(int x0, int y0, int x1, int y1, int x2, int y2)
{
    int sx = x2-x1, sy = y2-y1;
    long xx = x0-x1, yy = y0-y1, xy;         /* relative values for checks */
    double dx, dy, err, cur = xx*sy-yy*sx;                    /* curvature */
    
    assert(xx*sx <= 0 && yy*sy <= 0);  /* sign of gradient must not change */
    
    if (sx*(long)sx+sy*(long)sy > xx*xx+yy*yy) { /* begin with longer part */
        x2 = x0; x0 = sx+x1; y2 = y0; y0 = sy+y1; cur = -cur;  /* swap P0 P2 */
    }
    if (cur != 0) {                                    /* no straight line */
        xx += sx; xx *= sx = x0 < x2 ? 1 : -1;           /* x step direction */
        yy += sy; yy *= sy = y0 < y2 ? 1 : -1;           /* y step direction */
        xy = 2*xx*yy; xx *= xx; yy *= yy;          /* differences 2nd degree */
        if (cur*sx*sy < 0) {                           /* negated curvature? */
            xx = -xx; yy = -yy; xy = -xy; cur = -cur;
        }
        dx = 4.0*sy*cur*(x1-x0)+xx-xy;             /* differences 1st degree */
        dy = 4.0*sx*cur*(y0-y1)+yy-xy;
        xx += xx; yy += yy; err = dx+dy+xy;                /* error 1st step */
        do {
            //setPixel(x0,y0);                                     /* plot curve */
            if (x0 == x2 && y0 == y2) return;  /* last pixel -> curve finished */
            y1 = 2*err < dx;                  /* save value for test of y step */
            if (2*err > dy) { x0 += sx; dx -= xy; err += dy += yy; } /* x step */
            if (    y1    ) { y0 += sy; dy -= xy; err += dx += xx; } /* y step */
        } while (dy < dx );           /* gradient negates -> algorithm fails */
    }
    plotLine(x0,y0, x2,y2);                  /* plot remaining part to end */
}
示例#5
0
void lineThrough(Point2D *a, Point2D *b) {
	//set a and b to be two points separating the polygons
	a->x = 30;
	a->y = 90;
	b->x = 70; 
	b->y = 50;
    plotLine(*a,*b, 2);
  	// don't forget to visualize ;)
}
示例#6
0
文件: qrplot.cpp 项目: einar90/QRPlot
void QRPlot::selectionChangedSlot(const QItemSelection & /*newSelection*/, const QItemSelection & /*oldSelection*/) {
    const QModelIndex index = ui->treeView->selectionModel()->currentIndex();
    QString selectedText = index.data(Qt::DisplayRole).toString();
    QString parent = index.parent().data(Qt::DisplayRole).toString();
    qDebug() << "Selected item: " << selectedText;
    qDebug() << "Parent: " << parent;
    plotLine(selectedText, parent);
    ui->propertyInfo->clear();
    ui->propertyInfo->insertPlainText(propertyInfo.getPropertyInfo(selectedText));
}
示例#7
0
void
ShowView(Loc x, Loc y, Direction dir)
{
	register XYpair		*tp = viewTable;
	register int		tx = x.value();
	register int		ty = y.value();
	RatIndexType			ratIndex(0);
	RatLook			ratLook;
	bool			oldVisible;

	ClearView();
	prevEdge3 = prevEdge7 = FALSE;
	while (!M->maze_[tx][ty]) {
		tp = hidden(tx, ty, dir, tp);	/* draw a cell */
		switch (dir.value()) {
		case NORTH:	tx++; break;
		case SOUTH:	tx--; break;
		case EAST:	ty++; break;
		case WEST:	ty--; break;
		}
	}
	if (prevEdge3)
		(void) plotLine(edge3Lines, TRUE);
	if (prevEdge7)
		(void) plotLine(edge7Lines, TRUE);

	/* show the tokens */

	for (ratIndex = 0; ratIndex < MAX_RATS; ratIndex = RatIndexType(ratIndex.value() + 1)) {
		if (ratIndex == MY_RAT_INDEX)
			continue;
		ratLook = &Rats2Display[ratIndex.value()];
		oldVisible = ratLook->visible;
		TokenVisible(ratIndex);
		if (ratLook->visible == TRUE)
			XORToken(ratIndex);
		if (ratLook->visible != oldVisible)
			UpdateScoreCard(ratIndex);
	}
}
void SocSystem_Analytical::displayTrajectory(const arr& q,const arr *invQ,int steps,const char *tag){
  cout <<"gnuplot trajectory display " <<tag <<endl;
  plotGnuplot();
  plotClear();
  plotPoints(obstacles);
  plotLine(q);
  arr C;
  for(uint t=0;t<q.d0;t+=1){
    inverse_SymPosDef(C,(*invQ)[t]);
    plotCovariance(q[t],C);
  }
  plot();
}
示例#9
0
// main function
int main(void) {
	
	REG_DISPCTL = MODE3 | BG2_ENABLE; // REG_DISPCTL = 1027/0x0403
	
	drawRect(0, 0, 240, 160, RGB(31, 31, 31)); //color1: white; drawRect

	while (1) {
		// draw UGLY GOOGLE

		// draw "G"
		drawRect(50, 40, 5, 5, RGB(0, 0, 31)); // color2: blue
		drawRect(45, 35, 5, 5, RGB(0, 0, 31));
		drawRect(40, 20, 15, 5, RGB(0, 0, 31));
		drawRect(45, 15, 5, 5, RGB(0, 0, 31));
		drawRect(50, 10, 5, 5, RGB(0, 0, 31));
		drawRect(55, 5, 5, 30, RGB(0, 0, 31));
		drawRect(85, 10, 5, 5, RGB(0, 0, 31));
		drawRect(90, 15, 5, 5, RGB(0, 0, 31));
		drawRect(95, 20, 15, 5, RGB(0, 0, 31));
		drawRect(90, 35, 5, 5, RGB(0, 0, 31));
		drawRect(80, 40, 5, 15, RGB(0, 0, 31));
		drawRect(75, 30, 20, 5, RGB(0, 0, 31));

		// draw "OO"
		drawHollowRect(65, 55, 30, 35, RGB(31, 0, 0)); // color3: red; drawHollowRect
		drawHollowRect(65, 90, 30, 35, RGB(31, 21, 0)); // color4: orange

		// draw 'g'
		drawHollowRect(65, 125, 20, 20, RGB(0, 0, 31));
		setPixel(64, 145, RGB(0, 0, 31)); // setPixel
		setPixel(64, 146, RGB(0, 0, 31));
		setPixel(64, 147, RGB(0, 0, 31));
		setPixel(63, 148, RGB(0, 0, 31));
		plotLine(145, 85, 150, 100, RGB(0, 0, 31)); // plotLine
		drawHollowRect(90, 125, 26, 15, RGB(0, 0, 31));

		// draw 'l'
		drawRect(40, 160, 5, 60, RGB(0, 31, 0)); // color5: green

		// draw 'e'
		drawRect(80, 180, 25, 5, RGB(31, 0, 0));
		drawRect(75, 200, 5, 5, RGB(31, 0, 0));
		drawRect(70, 195, 5, 5, RGB(31, 0, 0));
		drawRect(65, 190, 5, 5, RGB(31, 0, 0));
		drawRect(70, 185, 5, 5, RGB(31, 0, 0));
		drawRect(75, 180, 5, 5, RGB(31, 0, 0));
		drawRect(85, 180, 5, 15, RGB(31, 0, 0));
		drawRect(95, 185, 20, 5, RGB(31, 0, 0));
	}
}
示例#10
0
void plotEllipseRectAA(int x0, int y0, int x1, int y1)
{        /* draw a black anti-aliased rectangular ellipse on white background */
    long a = abs(x1-x0), b = abs(y1-y0), b1 = b&1;                 /* diameter */
    double dx = 4*(a-1.0)*b*b, dy = 4*(b1+1)*a*a;            /* error increment */
    double ed, i, err = b1*a*a-dx+dy;                        /* error of 1.step */
    bool f;
    
    if (a == 0 || b == 0) return plotLine(x0,y0, x1,y1);
    if (x0 > x1) { x0 = x1; x1 += a; }        /* if called with swapped points */
    if (y0 > y1) y0 = y1;                                  /* .. exchange them */
    y0 += (b+1)/2; y1 = y0-(int)b1;                               /* starting pixel */
    a = 8*a*a; b1 = 8*b*b;
    
    for (;;) {                             /* approximate ed=sqrt(dx*dx+dy*dy) */
        i = fmin(dx,dy); ed = fmax(dx,dy);
        if (y0 == y1+1 && err > dy && a > b1) ed = 255*4./a;           /* x-tip */
        else ed = 255/(ed+2*ed*i*i/(4*ed*ed+i*i));             /* approximation */
        i = ed*fabs(err+dx-dy);           /* get intensity value by pixel error */
        //setPixelAA(x0,y0, i); setPixelAA(x0,y1, i);
        //setPixelAA(x1,y0, i); setPixelAA(x1,y1, i);
        
        if ((f = 2*err+dy >= 0)) {                  /* x step, remember condition */
            if (x0 >= x1) break;
            i = ed*(err+dx);
            if (i < 255) {
                //setPixelAA(x0,y0+1, i); setPixelAA(x0,y1-1, i);
                //setPixelAA(x1,y0+1, i); setPixelAA(x1,y1-1, i);
            }          /* do error increment later since values are still needed */
        }
        if (2*err <= dx) {                                            /* y step */
            i = ed*(dy-err);
            if (i < 255) {
                //setPixelAA(x0+1,y0, i); setPixelAA(x1-1,y0, i);
                //setPixelAA(x0+1,y1, i); setPixelAA(x1-1,y1, i);
            }
            y0++; y1--; err += dy += a;
        }
        if (f) { x0++; x1--; err -= dx -= b1; }            /* x error increment */
    }
    if (--x0 == x1++)                       /* too early stop of flat ellipses */
        while (y0-y1 < b) {
            i = 255*4*fabs(err+dx)/b1;               /* -> finish tip of ellipse */
            //setPixelAA(x0,++y0, i); setPixelAA(x1,y0, i);
            //setPixelAA(x0,--y1, i); setPixelAA(x1,y1, i);
            err += dy += a;
        }
}
示例#11
0
void plotQuadRationalBezierSeg(int x0, int y0, int x1, int y1,
                               int x2, int y2, double w)
{                   /* plot a limited rational Bezier segment, squared weight */
    int sx = x2-x1, sy = y2-y1;                   /* relative values for checks */
    double dx = x0-x2, dy = y0-y2, xx = x0-x1, yy = y0-y1;
    double xy = xx*sy+yy*sx, cur = xx*sy-yy*sx, err;               /* curvature */
    
    assert(xx*sx <= 0.0 && yy*sy <= 0.0);   /* sign of gradient must not change */
    
    if (cur != 0.0 && w > 0.0) {                            /* no straight line */
        if (sx*(long)sx+sy*(long)sy > xx*xx+yy*yy) {    /* begin with longer part */
            x2 = x0; x0 -= dx; y2 = y0; y0 -= dy; cur = -cur;         /* swap P0 P2 */
        }
        xx = 2.0*(4.0*w*sx*xx+dx*dx);                   /* differences 2nd degree */
        yy = 2.0*(4.0*w*sy*yy+dy*dy);
        sx = x0 < x2 ? 1 : -1;                                /* x step direction */
        sy = y0 < y2 ? 1 : -1;                                /* y step direction */
        xy = -2.0*sx*sy*(2.0*w*xy+dx*dy);
        
        if (cur*sx*sy < 0.0) {                              /* negated curvature? */
            xx = -xx; yy = -yy; xy = -xy; cur = -cur;
        }
        dx = 4.0*w*(x1-x0)*sy*cur+xx/2.0+xy;            /* differences 1st degree */
        dy = 4.0*w*(y0-y1)*sx*cur+yy/2.0+xy;
        
        if (w < 0.5 && (dy > xy || dx < xy)) {   /* flat ellipse, algorithm fails */
            cur = (w+1.0)/2.0; w = sqrt(w); xy = 1.0/(w+1.0);
            sx = (int) floor((x0+2.0*w*x1+x2)*xy/2.0+0.5);    /* subdivide curve in half */
            sy = (int) floor((y0+2.0*w*y1+y2)*xy/2.0+0.5);
            dx = floor((w*x1+x0)*xy+0.5); dy = floor((y1*w+y0)*xy+0.5);
            plotQuadRationalBezierSeg(x0,y0, (int) dx, (int) dy, sx,sy, cur);/* plot separately */
            dx = floor((w*x1+x2)*xy+0.5); dy = floor((y1*w+y2)*xy+0.5);
            plotQuadRationalBezierSeg(sx,sy, (int) dx, (int) dy, x2,y2, cur);
            return;
        }
        err = dx+dy-xy;                                           /* error 1.step */
        do {
            //setPixel(x0,y0);                                          /* plot curve */
            if (x0 == x2 && y0 == y2) return;       /* last pixel -> curve finished */
            x1 = 2*err > dy; y1 = 2*(err+yy) < -dy;/* save value for test of x step */
            if (2*err < dx || y1) { y0 += sy; dy += xy; err += dx += xx; }/* y step */
            if (2*err > dx || x1) { x0 += sx; dx += xy; err += dy += yy; }/* x step */
        } while (dy <= xy && dx >= xy);    /* gradient negates -> algorithm fails */
    }
    plotLine(x0,y0, x2,y2);                     /* plot remaining needle to end */
}
示例#12
0
void PCD8544::plotRectFill(byte x0, byte y0, byte x1, byte y1)
{
    byte xDiff;

    if(x0 > x1)
      xDiff = x0 - x1; //Find the difference between the x vars
    else
      xDiff = x1 - x0;

    while(xDiff > 0)
    {
      plotLine(x0, y0, x0, y1);

      if(x0 > x1)
        x0--;
      else
        x0++;

      xDiff--;
    }
}
示例#13
0
void
plotAxes(plotPS *pps, plotParm *pparm, Nrrd *ndata) {
  double axX, axY, xx, yy, toff;
  char buff[AIR_STRLEN_SMALL];
  int ti;
  
  AIR_UNUSED(ndata);
  axX = AIR_AFFINE(pparm->dbox[0], pparm->axisOrig[0], pparm->dbox[2],
                   pps->bbox[0], pps->bbox[2]);
  axY = AIR_AFFINE(pparm->dbox[1], pparm->axisOrig[1], pparm->dbox[3],
                   pps->bbox[1], pps->bbox[3]);
  plotGray(pps, pparm, 0);
  plotWidth(pps, pparm, pparm->axisThick);
  plotLine(pps, pparm,
           axX, pps->bbox[1], axX, pps->bbox[3]);
  plotLine(pps, pparm,
           pps->bbox[0], axY, pps->bbox[2], axY);

  if (strlen(pparm->axisHorzLabel) || strlen(pparm->axisVertLabel)) {
    fprintf(pps->file, "/Helvetica findfont 20 scalefont setfont\n");
    if (strlen(pparm->axisHorzLabel)) {
      plotLabel(pps, pparm, AIR_FALSE, 
                pps->bbox[2], axY, pparm->axisHorzLabel);
    }
    if (strlen(pparm->axisVertLabel)) {
      plotLabel(pps, pparm, AIR_FALSE, 
                axX, pps->bbox[3], pparm->axisVertLabel);
    }
  }

  if (pparm->numHorzTick) {
    if (pparm->tickThick > 0) {
      toff = pparm->tickLength/2;
      plotGray(pps, pparm, 0);
      plotWidth(pps, pparm, pparm->tickThick);
      for (ti=0; ti<pparm->numHorzTick; ti++) {
        xx = AIR_AFFINE(pparm->dbox[0], pparm->horzTick[ti], pparm->dbox[2],
                        pps->bbox[0], pps->bbox[2]);
        plotLine(pps, pparm, xx, axY - toff, xx, axY + toff);
      }
    }
    if (pparm->tickLabelSize) {
      fprintf(pps->file, "/Helvetica findfont %g scalefont setfont\n",
              pparm->tickLabelSize);
      for (ti=0; ti<pparm->numHorzTick; ti++) {
        xx = AIR_AFFINE(pparm->dbox[0], pparm->horzTick[ti], pparm->dbox[2],
                        pps->bbox[0], pps->bbox[2]);
        yy = axY + pparm->horzTickLabelOffset;
        sprintf(buff, "%g", pparm->horzTick[ti]);
        plotLabel(pps, pparm, AIR_TRUE, xx, yy, buff);
      }
    }
  }
  if (pparm->numVertTick) {
    if (pparm->tickThick > 0) {
      toff = pparm->tickLength/2;
      plotGray(pps, pparm, 0);
      plotWidth(pps, pparm, pparm->tickThick);
      for (ti=0; ti<pparm->numVertTick; ti++) {
        yy = AIR_AFFINE(pparm->dbox[1], pparm->vertTick[ti], pparm->dbox[3],
                        pps->bbox[1], pps->bbox[3]);
        plotLine(pps, pparm, axX - toff, yy, axX + toff, yy);
      }
    }
    if (pparm->tickLabelSize) {
      fprintf(pps->file, "/Helvetica findfont %g scalefont setfont\n",
              pparm->tickLabelSize);
      for (ti=0; ti<pparm->numVertTick; ti++) {
        yy = AIR_AFFINE(pparm->dbox[1], pparm->vertTick[ti], pparm->dbox[3],
                        pps->bbox[1], pps->bbox[3]);
        xx = axX + pparm->vertTickLabelOffset;
        sprintf(buff, "%g", pparm->vertTick[ti]);
        plotLabel(pps, pparm, AIR_TRUE, xx, yy, buff);
      }
    }
  }
}
示例#14
0
void
DualStepper::moveTo(int ax, int ay, float speed)
{
  xStepper->targetPos = ax;
  yStepper->targetPos = ay;

  long dx = ax - xStepper->pos;
  long dy = ay - yStepper->pos;

  majorAxisSpeed = min(speed, maxSpeed) * max(abs(dx), abs(dy)) / sqrt(dx * dx + dy * dy);

  switch (octant(dx, dy)) {
  case 0:
    _xStepper = xStepper;
    _yStepper = yStepper;
    xdir = FORWARD;
    ydir = FORWARD;
    plotLine(dx, dy);
    break;
  case 1:
    _xStepper = yStepper;
    _yStepper = xStepper;
    xdir = FORWARD;
    ydir = FORWARD;
    plotLine(dy, dx);
    break;
  case 2:
    _xStepper = yStepper;
    _yStepper = xStepper;
    xdir = FORWARD;
    ydir = BACKWARD;
    plotLine(dy, -dx);
    break;
  case 3:
    _xStepper = xStepper;
    _yStepper = yStepper;
    xdir = BACKWARD;
    ydir = FORWARD;
    plotLine(-dx, dy);
    break;
  case 4:
    _xStepper = xStepper;
    _yStepper = yStepper;
    xdir = BACKWARD;
    ydir = BACKWARD;
    plotLine(-dx, -dy);
    break;
  case 5:
    _xStepper = yStepper;
    _yStepper = xStepper;
    xdir = BACKWARD;
    ydir = BACKWARD;
    plotLine(-dy, -dx);
    break;
  case 6:
    _xStepper = yStepper;
    _yStepper = xStepper;
    xdir = BACKWARD;
    ydir = FORWARD;
    plotLine(-dy, dx);
    break;
  case 7:
    _xStepper = xStepper;
    _yStepper = yStepper;
    xdir = FORWARD;
    ydir = BACKWARD;
    plotLine(dx, -dy);
    break;
  }
}
示例#15
0
/*----------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
  SDL_Surface *screen;
  int width, height;
  Uint8  video_bpp;
  Uint32 videoflags;
  int done;
  SDL_Event event;
  Uint32 then, now, frames;

  if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    fprintf(stderr, "SDL_Init problem: %s", SDL_GetError());
    exit(1);
  }
  atexit(SDL_Quit);

  videoflags = SDL_SWSURFACE | SDL_ANYFORMAT;
  width = 640;
  height = 480;
  video_bpp = 0;

  while ( argc > 1 ) {
      --argc;
           if ( strcmp(argv[argc-1], "-width") == 0 ) {
      width = atoi(argv[argc]);
      --argc;
    } else if ( strcmp(argv[argc-1], "-height") == 0 ) {
      height = atoi(argv[argc]);
      --argc;
    } else if ( strcmp(argv[argc-1], "-bpp") == 0 ) {
      video_bpp = atoi(argv[argc]);
      videoflags &= ~SDL_ANYFORMAT;
      --argc;
    } else if ( strcmp(argv[argc], "-fast") == 0 ) {
      videoflags = FastestFlags(videoflags, width, height, video_bpp);
    } else if ( strcmp(argv[argc], "-hw") == 0 ) {
      videoflags ^= SDL_HWSURFACE;
    } else if ( strcmp(argv[argc], "-flip") == 0 ) {
      videoflags ^= SDL_DOUBLEBUF;
    } else if ( strcmp(argv[argc], "-fullscreen") == 0 ) {
      videoflags ^= SDL_FULLSCREEN;
    } else {
      fprintf(stderr, "Use: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen]\n",
              argv[0]);
      exit(1);
    }
  }/*while*/

  /*Video mode activation*/
  screen = SDL_SetVideoMode(width, height, video_bpp, videoflags);
  if (!screen) {
    fprintf(stderr, "I can not activate video mode: %dx%d: %s\n",
            width, height, SDL_GetError());
    exit(2);
  }

{

  //Define Colors

  //1: White
  //2: Gray
  //3: Dark Gray
  //4: Red
  //5: Green
  //6: Blue
  Uint32 c_colors[] = {SDL_MapRGB(screen->format, 255,255,255), SDL_MapRGB(screen->format, 200,200,200),
		  SDL_MapRGB(screen->format, 64,64,64),  SDL_MapRGB(screen->format, 255,0,0),
		  SDL_MapRGB(screen->format, 0,255,0), SDL_MapRGB(screen->format, 0,0,255)};

  plotAxes(screen, c_colors, width, height, -20, 30, -20, 20);
  plotLine(screen, c_colors);

  SDL_UpdateRect(screen, 0, 0, 0, 0);

  frames = 0;
  then = SDL_GetTicks();
  done = 0;
  while( !done ) {
    ++frames;
    while ( SDL_PollEvent(&event) ) {
      switch (event.type) {
        case SDL_KEYDOWN:
        /*break;*/
        case SDL_QUIT:
          done = 1;
        break;
        default:
        break;
      }
    }/*while*/
  }/*while(!done)*/

}/*END*/

  now = SDL_GetTicks();
  if ( now > then ) {
    printf("%2.2f frames per second\n",
          ((double)frames*1000)/(now-then));
  }

  fprintf(stderr, "[END]\n");
  return 0;

}/*main*/
示例#16
0
static XYpair*
hidden(Loc x, Loc y, Direction dir, XYpair *p)
{
	int	l1x, l1y, l2x, l2y;
	int	r1x, r1y, r2x, r2y;
	int	c2x, c2y;

	/* first calculate the coordinates of the neighboring cubes */

	l1x = x.value() + l1Delta[dir.value()].xcor;	/* find left cube */
	l1y = y.value() + l1Delta[dir.value()].ycor;
	l2x = x.value() + l2Delta[dir.value()].xcor;	/* find left forward cube */
	l2y = y.value() + l2Delta[dir.value()].ycor;
	r1x = x.value() + r1Delta[dir.value()].xcor;	/* find right cube */
	r1y = y.value() + r1Delta[dir.value()].ycor;
	r2x = x.value() + r2Delta[dir.value()].xcor;	/* find right forward cube */
	r2y = y.value() + r2Delta[dir.value()].ycor;
	c2x = x.value() + c2Delta[dir.value()].xcor;	/* find forward cube */
	c2y = y.value() + c2Delta[dir.value()].ycor;

	/* next calculate which of the 7 possible cube edges are visible */

	edge2 = M->maze_[c2x][c2y];	/* c2 */
	edge3 = M->maze_[l1x][l1y];	/* l1 */
	edge4 = !edge3;			/* !l1 */

	edge7 = M->maze_[r1x][r1y];	/* r1 */
	edge6 = !edge7;			/* !r1 */

	edge1 = (edge3 && (edge2 || !M->maze_[l2x][l2y]))
		|| ((!edge2) && edge4);
	edge5 = (edge7 && (edge2 || !M->maze_[r2x][r2y]))
		|| ((!edge2) && edge6);

	/*
	 * Should be matching the following:
	 *	x1 = l1 (c2 + !l2) + !c2 !l1
	 *	x2 = c2
	 *	x3 = l1
	 *	x4 = !l1
	 *	x5 = r1 (c2 + !r2) + !c2 !r1
	 *	x6 = !r1
	 *	x7 = r1
	 */

	if (edge1)
		p = plotLine(p, FALSE);
	else
		p++;
	if (edge2)
		p = plotLine(p, TRUE);
	else
		p += 2;
	if (edge3) {
		if (prevEdge3) {
			edge3Lines[0].p2 = (p++)->p2;
			edge3Lines[1].p2 = p->p2;
		} else {
			edge3Lines[0] = *p++;
			edge3Lines[1] = *p;
			prevEdge3 = TRUE;
		}
		p++;
	} else {
		if (prevEdge3) {
			(void) plotLine(edge3Lines, TRUE);
			prevEdge3 = FALSE;
		}
		p += 2;
	}
	if (edge4)
		p = plotLine(p, TRUE);
	else
		p += 2;
	if (edge5)
		p = plotLine(p, FALSE);
	else
		p++;
	if (edge6)
		p = plotLine(p, TRUE);
	else
		p += 2;
	if (edge7) {
		if (prevEdge7) {
			edge7Lines[0].p1 = (p++)->p1;
			edge7Lines[1].p1 = p->p1;
		} else {
			edge7Lines[0] = *p++;
			edge7Lines[1] = *p;
			prevEdge7 = TRUE;
		}
		p++;
	} else {
		if (prevEdge7) {
			(void) plotLine(edge7Lines, TRUE);
			prevEdge7 = FALSE;
		}
		p += 2;
	}
	return p;
}