Ejemplo n.º 1
0
void drawVector(int theArray[5][5], neopixel::Pixel * vectorPixel, int r, int g, int b){
    for(int i = 0;i<5;i++){
        for(int j = 0; j<5;j++){
            if(theArray[i][j] == 1)
                fill_pixel(vectorPixel,i,j,r,g,b);
            else
                fill_pixel(vectorPixel,i,j,0,0,0); 
        }
    }
}
Ejemplo n.º 2
0
int main()
{
    // Turn off miniblip buzzer
    PwmOut speaker(P0_8);
    speaker=0.0;
    // Create a temporary DigitalIn so we can configure the pull-down resistor.
    DigitalIn(DATA_PIN, PullDown);

    // The pixel array control class.
    neopixel::PixelArray array(DATA_PIN);

    // Generamos el array y lo vaciamos
    neopixel::Pixel vector[25];
    void_matrix(vector);
    //Introducimos varios colores de prueba
    fill_pixel(vector,0,0,255,0,0);
    fill_pixel(vector,1,1,255,0,0);
    fill_pixel(vector,2,2,0,255,0);
    fill_pixel(vector,3,3,255,0,0);
    fill_pixel(vector,4,4,255,0,0);
    fill_pixel(vector,0,4,0,0,255);
    fill_pixel(vector,1,3,0,0,255);
    fill_pixel(vector,3,1,0,0,255);
    fill_pixel(vector,4,0,0,0,255);
    
    
    while (1) {
        array.update(vector, 64);
        
    }
}
Ejemplo n.º 3
0
Archivo: border.c Proyecto: yydaor/LCUI
static int
Graph_Draw_RoundBorder_LeftTop( 
	LCUI_Graph *des,	LCUI_Pos center,
	int radius,		int line_width,
	LCUI_RGB line_color,	LCUI_BOOL hide_outarea )
/* 绘制左上角的圆角,从左边框的上端到上边框的左端绘制一条圆角线 */
{
	LCUI_Rect real_rect;
	int pos, center_pos, y, x, i, n;
	int max_x, max_y, min_x, min_y;
	
	if( line_width <= 0 && !hide_outarea ) {
		return 1;
	}
	
	real_rect = Graph_GetValidRect( des );
	des = Graph_GetQuote( des );
	if( !Graph_IsValid( des ) ) {
		return -1;
	}
	/* 预先计算xy轴坐标的有效范围 */
	max_x = radius*2;
	if( center.x+radius > real_rect.x + real_rect.width ) {
		max_x -= (center.x+radius-real_rect.x-real_rect.width);
	}
	if( max_x < 0 ) {
		max_x = 0;
	}
	min_x = center.x>radius? 0:radius-center.x;
	if( min_x < 0 ) {
		min_x = 0;
	}
	max_y = radius*2;
	if( center.y+radius > real_rect.y + real_rect.height ) {
		max_y -= (center.y+radius-real_rect.y-real_rect.height);
	}
	min_y = center.y>radius? 0:radius-center.y;
	if( min_y < 0 ) {
		min_y = 0;
	}
	
	/* 预先计算圆心的线性坐标 */
	center_pos = (real_rect.y + center.y) * des->width;
	center_pos = center_pos + center.x + real_rect.x;

	/* 根据y轴计算各点的x轴坐标并填充点 */
	for( y=0; y<=radius; ++y, center_pos -= des->width ) {
		if( radius-y >= max_y || radius-y < min_y ) {
			continue;
		}
		/* 计算出x轴整数坐标 */
		x = (int)sqrt( pow(radius, 2) - y*y );
		
		if( line_width > 0 && radius-x >= min_x 
		 && radius-x <= max_x ) {
			pos = center_pos - x;
			fill_pixel( des->rgba, pos, line_color );
			if( des->have_alpha ) {
				des->rgba[3][pos] = 255;
			}
		}
		
		if( hide_outarea && des->have_alpha ) {
			/* 计算起点坐标 */
			pos = center_pos - center.x;
			if( radius-x > max_x ) {
				n = max_x - min_x;
			} else {
				n = radius-x-min_x;
			}
			/* 加上圆与背景图的左边距 */
			n += (center.x-radius);
			for(i=0; i<n; ++i) {
				des->rgba[3][pos++]=0;
			}
		}
		/* 计算需要向右填充的像素点的个数n */
		n = radius-x+line_width;
		n = n>radius ? x:line_width;
		/* 如果该点x轴坐标小于最小x轴坐标 */
		if( radius-x < min_x ) {
			/* 重新确定起点坐标pos和填充的像素点的个数n */
			pos = center_pos - radius+min_x-1;
			n -= (min_x-radius+x);
		} else {
			pos = center_pos - x;
		}
		/* 从下一个像素点开始 */
		++pos;
		/* 如果填充的像素点超出了最大x轴范围 */
		if( radius-x + n > max_x ) {
			/* 重新确定需要填充的像素点的个数n */
			n = max_x - radius + x;
		}
		/* 开始填充当前点右边的n-1个像素点 */
		for(i=0; i<n-1; ++i,++pos) {
			fill_pixel( des->rgba, pos, line_color );
			if( des->have_alpha ) {
				des->rgba[3][pos] = 255;
			}
		}
	}
	return 0;
}
Ejemplo n.º 4
0
Archivo: border.c Proyecto: yydaor/LCUI
static int
Graph_Draw_RoundBorder_BottomRight(
	LCUI_Graph *des,	LCUI_Pos center,
	int radius,		int line_width,
	LCUI_RGB line_color,	LCUI_BOOL hide_outarea )
/* 绘制右下角的圆角,从下边框的右端到右边框的下端绘制一条圆角线 */
{
	LCUI_Rect real_rect;
	int pos, center_pos, y, x, i, n;
	int max_x, max_y, min_x, min_y;
	
	if( line_width <= 0 && !hide_outarea ) {
		return 1;
	}
	
	real_rect = Graph_GetValidRect( des );
	des = Graph_GetQuote( des );
	if( !Graph_IsValid( des ) ) {
		return -1;
	}
	
	max_x = radius*2;
	if( center.x+radius > real_rect.x + real_rect.width ) {
		max_x -= (center.x+radius-real_rect.x-real_rect.width);
	}
	if( max_x < 0 ) {
		max_x = 0;
	}
	min_x = center.x>radius? 0:radius-center.x;
	if( min_x < 0 ) {
		min_x = 0;
	}
	max_y = radius*2;
	if( center.y+radius > real_rect.y + real_rect.height ) {
		max_y -= (center.y+radius-real_rect.y-real_rect.height);
	}
	min_y = center.y>radius? 0:radius-center.y;
	if( min_y < 0 ) {
		min_y = 0;
	}
	
	center_pos = (real_rect.y + center.y) * des->width;
	center_pos = center_pos + center.x + real_rect.x;

	for( x=0; x<=radius; ++x ) {
		if( radius+x >= max_x || radius+x < min_x ) {
			continue;
		}
		
		y = (int)sqrt( pow(radius, 2) - x*x );
		
		if( line_width > 0 && radius+y >= min_y 
		 && radius+y < max_y ) {
			pos = center_pos + y * des->width + x;
			fill_pixel( des->rgba, pos, line_color );
			if( des->have_alpha ) {
				des->rgba[3][pos] = 255;
			}
		}
		if( hide_outarea && des->have_alpha ) {
			if( radius+y > max_y ) {
				pos = center_pos;
				pos += (max_y-radius)*des->width;
			} else {
				pos = center_pos + y * des->width + x;
			}
			if( radius+y < min_y ) {
				n = max_y - min_y;
			} else {
				n = max_y-radius-y;
			}
			n += (real_rect.height-center.y-radius);
			pos+=des->width;
			for(i=0; i<n; ++i,pos+=des->width) {
				des->rgba[3][pos]=0;
			}
		}
		
		n = radius+y-line_width;
		n = n<radius ? y:line_width;
		if( radius+y > max_y ) {
			pos = center_pos + (max_y-radius)*des->width;
			n -= (radius+y-max_y);
		} else {
			pos = center_pos + y * des->width + x;
		}
		if( radius+y - n < min_y ) {
			n = min_y - radius - y;
		}
		pos -= des->width;
		for(i=0; i<n-1; ++i,pos-=des->width) {
			fill_pixel( des->rgba, pos, line_color );
			if( des->have_alpha ) {
				des->rgba[3][pos] = 255;
			}
		}
	}
	return 0;
}
Ejemplo n.º 5
0
Archivo: border.c Proyecto: yydaor/LCUI
static int
Graph_Draw_RoundBorder_BottomLeft(
	LCUI_Graph *des,	LCUI_Pos center,
	int radius,		int line_width,
	LCUI_RGB line_color,	LCUI_BOOL hide_outarea )
/* 绘制左下角的圆角,从下边框的左端到左边框的下端绘制一条圆角线 */
{
	LCUI_Rect real_rect;
	int tmp_pos, pos, center_pos, y, x, i, n;
	int max_x, max_y, min_x, min_y;
	
	if( line_width <= 0 && !hide_outarea ) {
		return 1;
	}
	
	real_rect = Graph_GetValidRect( des );
	des = Graph_GetQuote( des );
	if( !Graph_IsValid( des ) ) {
		return -1;
	}
	
	max_x = radius*2;
	if( center.x+radius > real_rect.x + real_rect.width ) {
		max_x -= (center.x+radius-real_rect.x-real_rect.width);
	}
	if( max_x < 0 ) {
		max_x = 0;
	}
	min_x = center.x>radius? 0:radius-center.x;
	if( min_x < 0 ) {
		min_x = 0;
	}
	max_y = radius*2;
	if( center.y+radius > real_rect.y + real_rect.height ) {
		max_y -= (center.y+radius-real_rect.y-real_rect.height);
	}
	min_y = center.y>radius? 0:radius-center.y;
	if( min_y < 0 ) {
		min_y = 0;
	}
	
	center_pos = (real_rect.y + center.y) * des->width;
	center_pos = center_pos + center.x + real_rect.x;

	for( x=0; x<=radius; ++x ) {
		if( radius-x >= max_x || radius-x < min_x ) {
			continue;
		}
		
		y = (int)sqrt( pow(radius, 2) - x*x );
		
		if( radius+y > max_y ) {
			pos = center_pos;
			pos += (max_y-radius)*des->width;
		} else {
			pos = center_pos + y * des->width - x;
		}
		
		if( line_width > 0 && radius+y >= min_y 
		 && radius+y <= max_y ) {
			fill_pixel( des->rgba, pos, line_color );
			if( des->have_alpha ) {
				des->rgba[3][pos] = 255;
			}
		}
		
		if( hide_outarea && des->have_alpha ) {
			tmp_pos = pos;
			if( radius+y < min_y ) {
				n = max_y - min_y;
			} else {
				n = max_y-radius-y;
			}
			/* 加上圆与背景图的下边距 */
			n += (real_rect.height-center.y-radius);
			tmp_pos+=des->width;
			for(i=0; i<n; ++i,tmp_pos+=des->width) {
				des->rgba[3][tmp_pos]=0;
			}
		}
		/* 计算需要向上填充的像素点的个数n */
		n = radius+y-line_width;
		/* 判断是否超过圆的x轴对称线 */
		n = n<radius ? y:line_width;
		if( radius+y > max_y ) {
			n -= (radius+y-max_y);
		}
		/* 从上一行像素点开始 */
		pos -= des->width;
		if( radius+y - n < min_y ) {
			n = min_y - radius - y;
		}
		/* 开始填充当前点下边的n-1个像素点 */
		for(i=0; i<n-1; ++i,pos-=des->width) {
			fill_pixel( des->rgba, pos, line_color );
			if( des->have_alpha ) {
				des->rgba[3][pos] = 255;
			}
		}
	}
	return 0;
}
Ejemplo n.º 6
0
Archivo: border.c Proyecto: yydaor/LCUI
static int
Graph_Draw_RoundBorder_LeftBottom(
	LCUI_Graph *des,	LCUI_Pos center,
	int radius,		int line_width,
	LCUI_RGB line_color,	LCUI_BOOL hide_outarea )
/* 绘制左下角的圆角,从左边框的下端到下边框的左端绘制一条圆角线 */
{
	LCUI_Rect real_rect;
	int pos, center_pos, y, x, i, n;
	int max_x, max_y, min_x, min_y;
	
	if( line_width <= 0 && !hide_outarea ) {
		return 1;
	}
	
	real_rect = Graph_GetValidRect( des );
	des = Graph_GetQuote( des );
	if( !Graph_IsValid( des ) ) {
		return -1;
	}
	
	max_x = radius*2;
	if( center.x+radius > real_rect.x + real_rect.width ) {
		max_x -= (center.x+radius-real_rect.x-real_rect.width);
	}
	if( max_x < 0 ) {
		max_x = 0;
	}
	min_x = center.x>radius? 0:radius-center.x;
	if( min_x < 0 ) {
		min_x = 0;
	}
	max_y = radius*2;
	if( center.y+radius > real_rect.y + real_rect.height ) {
		max_y -= (center.y+radius-real_rect.y-real_rect.height);
	}
	min_y = center.y>radius? 0:radius-center.y;
	if( min_y < 0 ) {
		min_y = 0;
	}
	
	center_pos = (real_rect.y + center.y) * des->width;
	center_pos = center_pos + center.x + real_rect.x;

	if( hide_outarea && des->have_alpha ) {
		
	}
	for( y=0; y<=radius; ++y, center_pos += des->width ) {
		if( radius+y >= max_y || radius+y < min_y ) {
			continue;
		}
		x = (int)sqrt( pow(radius, 2) - y*y );
		
		if( line_width > 0 && radius-x >= min_x 
		 && radius-x <= max_x ) {
			pos = center_pos - x;
			fill_pixel( des->rgba, pos, line_color );
			if( des->have_alpha ) {
				des->rgba[3][pos] = 255;
			}
		}
		if( hide_outarea && des->have_alpha ) {
			pos = center_pos - center.x;
			if( radius-x > max_x ) {
				n = max_x - min_x;
			} else {
				n = radius-x-min_x;
			}
			n += (center.x-radius);
			for(i=0; i<n; ++i) {
				des->rgba[3][pos++]=0;
			}
		}
		n = radius-x+line_width;
		n = n>radius ? x:line_width;
		if( radius-x < min_x ) {
			pos = center_pos - radius+min_x-1;
			n -= (min_x-radius+x);
		} else {
			pos = center_pos - x;
		}
		++pos;
		if( radius-x + n > max_x ) {
			n = max_x - radius + x;
		}
		for(i=0; i<n-1; ++i,++pos) {
			fill_pixel( des->rgba, pos, line_color );
			if( des->have_alpha ) {
				des->rgba[3][pos] = 255;
			}
		}
	}
	return 0;
}
Ejemplo n.º 7
0
Archivo: border.c Proyecto: yydaor/LCUI
static int
Graph_Draw_RoundBorder_RightTop( 
	LCUI_Graph *des,	LCUI_Pos center,
	int radius,		int line_width,
	LCUI_RGB line_color,	LCUI_BOOL hide_outarea )
/* 绘制右上角的圆角,从右边框的上端到上边框的右端绘制一条圆角线 */
{
	LCUI_Rect real_rect;
	int pos, center_pos, y, x, i, n;
	int max_x, max_y, min_x, min_y;
	
	if( line_width <= 0 && !hide_outarea ) {
		return 1;
	}
	
	real_rect = Graph_GetValidRect( des );
	des = Graph_GetQuote( des );
	if( !Graph_IsValid( des ) ) {
		return -1;
	}
	
	max_x = radius*2;
	if( center.x+radius > real_rect.x + real_rect.width ) {
		max_x -= (center.x+radius-real_rect.x-real_rect.width);
	}
	if( max_x < 0 ) {
		max_x = 0;
	}
	min_x = center.x>radius? 0:radius-center.x;
	if( min_x < 0 ) {
		min_x = 0;
	}
	max_y = radius*2;
	if( center.y+radius > real_rect.y + real_rect.height ) {
		max_y -= (center.y+radius-real_rect.y-real_rect.height);
	}
	min_y = center.y>radius? 0:radius-center.y;
	if( min_y < 0 ) {
		min_y = 0;
	}
	
	center_pos = (real_rect.y + center.y) * des->width;
	center_pos = center_pos + center.x + real_rect.x;
	
	for( y=0; y<=radius; ++y, center_pos -= des->width ) {
		if( radius-y >= max_y || radius-y < min_y ) {
			continue;
		}
		x = (int)sqrt( pow(radius, 2) - y*y );
		
		if( line_width > 0 && radius+x >= min_x 
		 && radius+x <= max_x ) {
			pos = center_pos + x;
			fill_pixel( des->rgba, pos, line_color );
			if( des->have_alpha ) {
				des->rgba[3][pos] = 255;
			}
		}
		
		if( hide_outarea && des->have_alpha ) {
			n = center_pos + max_x - radius;
			if( radius+x < min_x ) {
				pos = center_pos + min_x - radius;
			} else {
				pos = center_pos + x;
			}
			for( ++pos; pos<=n; ++pos ) {
				des->rgba[3][pos] = 0;
			}
		}
		
		/* 计算需要向左填充的像素点的个数n */
		n = radius+x-line_width;
		n = n<min_x ? x+radius-min_x:line_width;
		
		if( radius+x > max_x ) {
			pos = center_pos - radius+max_x-1;
			n -= (radius+x-max_x);
		} else {
			pos = center_pos + x;
		}
		for(i=0; i<n; ++i,--pos) {
			fill_pixel( des->rgba, pos, line_color );
			if( des->have_alpha ) {
				des->rgba[3][pos] = 255;
			}
		}
	}
	return 0;
}
Ejemplo n.º 8
0
Archivo: border.c Proyecto: yydaor/LCUI
static int
Graph_Draw_RoundBorder_TopLeft( 
	LCUI_Graph *des,	LCUI_Pos center,
	int radius,		int line_width,
	LCUI_RGB line_color,	LCUI_BOOL hide_outarea )
/* 绘制左上角的圆角,从上边框的左端到左边框的上端绘制一条圆角线 */
{
	LCUI_Rect real_rect;
	int pos, center_pos, y, x, i, n;
	int max_x, max_y, min_x, min_y;
	double tmp_pos;
	uchar_t alpha[2];
	
	if( line_width <= 0 && !hide_outarea ) {
		return 1;
	}
	
	real_rect = Graph_GetValidRect( des );
	des = Graph_GetQuote( des );
	if( !Graph_IsValid( des ) ) {
		return -1;
	}
	/* 预先计算xy轴坐标的有效范围 */
	max_x = radius*2;
	if( center.x+radius > real_rect.x + real_rect.width ) {
		max_x -= (center.x+radius-real_rect.x-real_rect.width);
	}
	if( max_x < 0 ) {
		max_x = 0;
	}
	min_x = center.x>radius? 0:radius-center.x;
	if( min_x < 0 ) {
		min_x = 0;
	}
	max_y = radius*2;
	if( center.y+radius > real_rect.y + real_rect.height ) {
		max_y -= (center.y+radius-real_rect.y-real_rect.height);
	}
	min_y = center.y>radius? 0:radius-center.y;
	if( min_y < 0 ) {
		min_y = 0;
	}
	
	center_pos = (real_rect.y + center.y) * des->width;
	center_pos = center_pos + center.x + real_rect.x;

	for( x=0; x<=radius; ++x ) {
		if( radius-x >= max_x || radius-x < min_x ) {
			continue;
		}
		tmp_pos = sqrt( pow(radius, 2) - x*x );
		y = (int)tmp_pos;
		alpha[1] =(uchar_t)( 255/(tmp_pos - y));
		alpha[0] = 255-alpha[1];
		
		if( line_width > 0 && radius-y >= min_y 
		 && radius-y <= max_y ) {
			pos = center_pos - y * des->width - x;
			fill_pixel( des->rgba, pos, line_color );
			if( des->have_alpha ) {
				des->rgba[3][pos] = 255;
			}
		}

		if( hide_outarea && des->have_alpha ) {
			/* 计算起点坐标 */
			if( radius-y < min_y ) {
				pos = center_pos;
				pos -= ((radius+min_y-1)*des->width);
			} else {
				pos = center_pos - y * des->width - x;
			}
			if( radius-y > max_y ) {
				n = max_y - min_y;
			} else {
				n = radius-y-min_y;
			}
			/* 加上圆与背景图的上边距 */
			n += (center.y-radius);
			pos-=des->width;
			for(i=0; i<n; ++i,pos-=des->width) {
				des->rgba[3][pos]=0;
			}
		}
		
		/* 计算需要向下填充的像素点的个数n */
		n = radius-y+line_width;
		n = n>radius ? y:line_width;
		if( radius-y < min_y ) {
			/* 重新确定起点坐标pos和填充的像素点的个数n */
			pos = center_pos - (radius+min_y-1)*des->width;
			n -= (min_y-radius+y);
		} else {
			pos = center_pos - y * des->width - x;
		}
		/* 从下一行像素点开始 */
		pos += des->width;
		/* 如果填充的像素点超出了最大y轴范围 */
		if( radius-y + n > max_y ) {
			/* 重新确定需要填充的像素点的个数n */
			n = max_y - radius + y;
		}
		/* 开始填充当前点下边的n-2个像素点 */
		for(i=0; i<n-1; ++i,pos+=des->width) {
			fill_pixel( des->rgba, pos, line_color );
			if( des->have_alpha ) {
				des->rgba[3][pos] = 255;
			}
		}
	}
	return 0;
}