示例#1
0
void drawLine(u16 x0, u16 y0, u16 x1, u16 y1)
{
	s16 steep, t;
	s16 deltax, deltay, error;
	s16 x, y;
	s16 ystep;
	
	// simple clipping is done in the drawPixel routine
/*
	if (( x0 < 0) || (x0 > HRES)) return;
	if (( x1 < 0) || (x1 > HRES)) return;
	if (( y0 < 0) || (y0 > VRES)) return;
	if (( y1 < 0) || (y1 > VRES)) return;
*/
	
	steep = _abs_(y1 - y0) > _abs_(x1 - x0);

	if (steep)
	{ // swap x and y
		t = x0; x0 = y0; y0 = t;
		t = x1; x1 = y1; y1 = t;
	}

	if (x0 > x1)
	{ // swap ends
		t = x0; x0 = x1; x1 = t;
		t = y0; y0 = y1; y1 = t;
	}

	deltax = x1 - x0;
	deltay = _abs_(y1 - y0);

	error = 0;
	y = y0;

	if (y0 < y1) ystep = 1; else ystep = -1;

	for (x = x0; x < x1; x++)
	{
		if (steep)
			drawPixel(y,x);
		else
			drawPixel(x,y);
			
		error += deltay;

		if ( (error<<1) >= deltax)
		{
			y += ystep;
			error -= deltax;
		}
	}
}
示例#2
0
////long osc3(cpoint p0, cpoint p, long pas) {
////    long dx = (p.x - p0.x); if (dx<0) dx = -dx;
////    dx = dx/pas - (int)(dx/pas);
////    long dy = (p.y - p0.y); if (dy<0) dy = -dy;
////    dy = dy/pas - (int)(dy/pas);
////    return (0.2 + max(dx,dy)) / 1.2;
////}
void osc4(_frac_ *res, cpoint *p0, cpoint *p, long pas) {
    res->num = _max2_(_abs_(p->x - p0->x), _abs_(p->y - p0->y)) % pas;
    res->den = pas;
}