Ejemplo n.º 1
0
// Returns value of parameter at the given position (fraction is a
// fractional bar position, 0-255)
int CVariableParameter::GetValueAt(int iBar,int iFraction) const 
{
	int 
		iBefore=GetPreviousPoint(iBar,iFraction),
		iAfter=GetNextPoint(iBar,iFraction);

	// If before any points, return default/first value
	if(iBefore==-1)
	{
		if(iAfter==-1)
			return m_iDefaultValue;
		else
			return GetPointValue(iAfter);
	}

	// If after all points, return last value
	if(iAfter==-1)
		return GetPointValue(iBefore);

	// Calculate relative position
	int iSize = 
		(GetPointBar(iAfter) * 256 + GetPointFraction(iAfter)) -
		(GetPointBar(iBefore) * 256 + GetPointFraction(iBefore));
	int iOffset =
		(iBar * 256 + iFraction) -
		(GetPointBar(iBefore) * 256 + GetPointFraction(iBefore));

	// Get proportional distance (0-256)
	int iDistance=(iOffset*256)/iSize;

	// Return scaled value
	return
		(GetPointValue(iBefore) * (256-iDistance) +
		GetPointValue(iAfter) * iDistance) / 256;
}
Ejemplo n.º 2
0
void Snake::Move()
{
    painter.clear(vpoint.first());
    vpoint.removeFirst();
    Point Head=GetNextPoint();
    vpoint.append(Head);
    head=Head;
    painter.draw(head);
}
Ejemplo n.º 3
0
gboolean 
FindSinglePoint ( gsl_matrix *pic, gsl_matrix* raw, gint width, gint height, gsl_vector **v, gsl_vector **v1, GuiData *gd ) {
	gint dx = gsl_vector_get ( *v1, 0 ) - gsl_vector_get ( *v, 0 );
	gint dy = gsl_vector_get ( *v1, 1 ) - gsl_vector_get ( *v, 1 );

	gint x = 0, y = 0;
	// 沿y正方向 111111111111
	if ( dx == 0 && dy == 1 ) {
		GetNextPoint ( pic, raw, *v1, 0, 1, 1, 1, -1, 1, &x, &y );
	// 沿y负方向 222222222222222
	} else if ( dx == 0 && dy == -1 ) {
		GetNextPoint ( pic, raw, *v1, 0, -1, 1, -1, -1, -1, &x, &y );
	// 沿x正方向 333333333333333
	} else if ( dx == 1 && dy == 0 ) {
		GetNextPoint ( pic, raw, *v1, 1, 0, 1, -1, 1, 1, &x, &y );
	// 沿x负方向 4444444444444444
	} else if ( dx == -1 && dy == 0 ) {
		GetNextPoint ( pic, raw, *v1, -1, 0, -1, -1, -1, 1, &x, &y );
	// 沿xy正方向 55555555555555555
	} else if ( dx == 1 && dy == 1 ) {
		GetNextPoint ( pic, raw, *v1, 1, 1, 1, 0, 0, 1, &x, &y );
	// 沿xy负方向 6666666666666666
	} else if ( dx == -1 && dy == -1 ) {
		GetNextPoint ( pic, raw, *v1, -1, -1, -1, 0, 0, -1, &x, &y );
	// 沿x正y负方向 77777777777777777
	} else if ( dx == 1 && dy == -1 ) {
		GetNextPoint ( pic, raw, *v1, 1, -1, 1, 0, 0, -1, &x, &y );
	// 沿y正x负方向 88888888888888888888
	} else if ( dx == -1 && dy == 1 ) {
		GetNextPoint ( pic, raw, *v1, -1, 1, -1, 0, 0, 1, &x, &y );
	}

	if ( x < ignore || x > height - ignore
			|| y < ignore || y > width - ignore
			|| gsl_matrix_get ( raw, x, y ) < 1000 ) 
		return FALSE;

	*v = *v1;

	*v1 = gsl_vector_alloc (3);
	gsl_vector_set ( *v1, 0, x );
	gsl_vector_set ( *v1, 1, y );
	gsl_vector_set ( *v1, 2, gsl_matrix_get ( raw, x, y ) );
	gd->rawlist = g_slist_append ( gd->rawlist, *v1 );

//	printf ( "w:%d x:%d y:%d\n", width-ignore, x, y ); fflush ( stdout );

	gd->x = y;
	gd->y = x;
//	gd->redraw = TRUE;
//	while ( gd->redraw ) usleep ( 2 );

	return TRUE;
}