Beispiel #1
0
int main()
{
	bitmap mBitmap(STRIP_LENGTH, 1);	// one dimension led_strip
	led_strip mLedStrip(SPI_DEVICE, mBitmap.width * mBitmap.height);	// LED Strip initialized on spi.0

	mBitmap.fill(ColorRed);				// full red color	
	mLedStrip.paint(&mBitmap, true);
	sleep(1);

	mBitmap.fill(ColorGreen);			// full green color
	mLedStrip.paint(&mBitmap, true);
	sleep(1);

	mBitmap.fill(ColorBlue);			// full blue color
	mLedStrip.paint(&mBitmap, true);
	sleep(1);

	mBitmap.fill(ColorWhite);			// full white color
	mLedStrip.paint(&mBitmap, true);
	sleep(1);

	hsv_color color;					// HSV pixel
	color.S = 255;						// maximum saturation
	color.V = 255;						// maximum value
	for(int i = 0; i < STRIP_LENGTH; i++)
	{									// rainbow colors
		color.H = i * 360 / STRIP_LENGTH;
		mBitmap.set_hsv_pixel(i, 0, color);
	}
	mLedStrip.paint(&mBitmap, true);

	return 0;
}
Beispiel #2
0
//трассировка
bool TraceClass::Trace(/*int Width, int Height, */HBITMAP hBitmap)
{
	if (PotraceFunc.isOK() != 0) return false;
	if (!hBitmap) return false;
	if (!CurrentTraceParam) return false;


	MYBitmap mBitmap(hBitmap);
	if (!mBitmap.pixels) return false;
	if (!mBitmap.isOK) return false;

	//предварительный расчёт
	int kratn = (mBitmap.Width & -32);
	int DY = (mBitmap.Width-kratn != 0) ? kratn/32+1 : kratn/32;	//кол-во Potrace_Word в одной строке
	int CountWord32 = mBitmap.Height * DY;     			//общее кол-во слов Potrace_Word в буффере

	//potrace переменные
	potrace_bitmap_t bitmap;

	//инициализация массива данных
	bitmap.w = mBitmap.Width;
	bitmap.h = mBitmap.Height;
	bitmap.dy = DY;
	bitmap.map = new potrace_word[CountWord32]; //mBitmap.pixels;

	for (int n = 0; n < CountWord32; n++)
	{
		bitmap.map[n] = GetScanLineINT32(mBitmap.pixels, DY, mBitmap.Width, n);
		//DebugMessage("GetScanLineINT32", bitmap.map[n]);
	}

	//трассировка
	if (State) PotraceFunc.func_potrace_state_free(State);
	State = PotraceFunc.func_potrace_trace(CurrentTraceParam, &bitmap);

	delete [] bitmap.map;
	if (State)
		if (State->status != POTRACE_STATUS_OK) return false;
	return true;
}
	void CGDIPracticeView::OnDraw(CDC* pDC)
	{
		CClientDC dc(this);			//Client DC를 얻는다.

		// Client Rect를 얻는다.
		CRect rClientRect;
		GetClientRect(&rClientRect);

		// Bitmap 생성
		Bitmap mBitmap(rClientRect.Width(), rClientRect.Height());

		// Graphics를 얻는다.
		Graphics graphics(dc);

		// 비트맵을 메모리 내에서 그릴 그래픽 생성
		Graphics memGraphics(&mBitmap);

		// 화면을 흰색 바탕으로 그리기 위한 브러쉬
		SolidBrush drawBrush(Color(255,255,255));

		// 검은색 컬러 지정
		Color drawColor(255,0,0,0);

		// 팬 생성
		Pen drawPen(drawColor, 1);
		drawPen.SetStartCap(LineCapRound);
		drawPen.SetEndCap(LineCapRound);

		// bitmap을 흰색으로 칠한다(line같은 경우 이미지가 남기 때문에)
		memGraphics.FillRectangle(&drawBrush, 0,0,rClientRect.Width(), rClientRect.Height());

		int componentSize = m_components.GetSize();
		CString str;
		str.Format(_T("size : %d\n"), componentSize);
		TRACE(str);
		for (int i = 0; i < componentSize; i++)
		{
			// 컴포넌트의 팬 설정
			drawColor.SetFromCOLORREF(m_components.GetAt(i)->m_colorPen);
			drawPen.SetColor(drawColor);
			drawPen.SetWidth((float)m_components.GetAt(i)->m_nPenSize);

			// 얕은 복사
			CDrawComponent *component = m_components.GetAt(i);

			switch (component->m_nDrawMode)
			{
				// 지우개인 경우
			case DRAW_NONE:
				{
					// 팬의 브러쉬 색을 흰색으로 변경
					drawBrush.SetColor(drawColor);

					// 지우개를 사용한 좌표를 순차적으로 다시 그린다.
					int pointSize = component->m_points.GetSize();
					for (int j = 0; j < pointSize; j++)
					{
						// 흰색의 지우개 사각형을 그린다. 
						memGraphics.FillRectangle(&drawBrush, component->m_points.GetAt(j).X, component->m_points.GetAt(j).Y,
							component->m_nEraserSize * 2, component->m_nEraserSize * 2);
					}
					break;
				}
			case LINE_MODE:
				memGraphics.DrawLine(&drawPen, component->m_ptStart.x, component->m_ptStart.y,
					component->m_ptEnd.x, component->m_ptEnd.y);
				break;
			case RECT_MODE:
			{
				// 우측 아래
				if(component->m_ptStart.x < component->m_ptEnd.x && component->m_ptStart.y < component->m_ptEnd.y)
					memGraphics.DrawRectangle(&drawPen, component->m_ptStart.x, component->m_ptStart.y,
					component->m_ptEnd.x - component->m_ptStart.x, component->m_ptEnd.y - component->m_ptStart.y);
				// 우측 위
				else if(component->m_ptStart.x < component->m_ptEnd.x && component->m_ptStart.y > component->m_ptEnd.y)
					memGraphics.DrawRectangle(&drawPen, component->m_ptStart.x, component->m_ptEnd.y,
					component->m_ptEnd.x - component->m_ptStart.x, component->m_ptStart.y - component->m_ptEnd.y);
				// 좌측 아래
				else if(component->m_ptStart.x > component->m_ptEnd.x && component->m_ptStart.y < component->m_ptEnd.y)
					memGraphics.DrawRectangle(&drawPen, component->m_ptEnd.x, component->m_ptStart.y,
					component->m_ptStart.x - component->m_ptEnd.x, component->m_ptEnd.y - component->m_ptStart.y);
				// 좌측 위
				else
					memGraphics.DrawRectangle(&drawPen, component->m_ptEnd.x, component->m_ptEnd.y,
					component->m_ptStart.x - component->m_ptEnd.x, component->m_ptStart.y - component->m_ptEnd.y);

				break;
			}
			case CIRCLE_MODE:
				memGraphics.DrawEllipse(&drawPen, component->m_ptStart.x, component->m_ptStart.y,
					component->m_ptEnd.x - component->m_ptStart.x, component->m_ptEnd.y - component->m_ptStart.y);
				break;
			case FREE_MODE:
				if (component->m_points.GetSize() > 1)
				{
					// 자유선의 작은 선들을을 순차적으로 하나씩 그린다.
					int pointSize = component->m_points.GetSize();
					for (int j = 1; j < pointSize; j++)
						memGraphics.DrawLine(&drawPen, component->m_points.GetAt(j - 1).X, component->m_points.GetAt(j - 1).Y,
						component->m_points.GetAt(j).X, component->m_points.GetAt(j).Y);
				}
				break;
			case POLY_MODE:
			{
				int pointSize = component->m_points.GetSize();
				for (int j = 1; j < pointSize; j++)
					memGraphics.DrawLine(&drawPen, component->m_points.GetAt(j-1).X, component->m_points.GetAt(j-1).Y,
					component->m_points.GetAt(j).X, component->m_points.GetAt(j).Y);

				// 처음 점과 마지막점을 이어준다.
				memGraphics.DrawLine(&drawPen, component->m_points.GetAt(component->m_points.GetSize() - 1).X,
					component->m_points.GetAt(component->m_points.GetSize() - 1).Y,
					component->m_points.GetAt(0).X, component->m_points.GetAt(0).Y);

				break;
			}
			default:
				break;
			}
		}

		//현재 그리고 있는 것

		drawColor.SetFromCOLORREF(m_colorPen);
		drawPen.SetColor(drawColor);
		drawPen.SetWidth(m_nPenSize);

		// 왼쪽 버튼 클릭시 || 지우개인경우 | 다각형인 경우(삭제)
		if (m_nDrawMode == DRAW_NONE || m_nDrawMode == POLY_MODE || m_bLButtonDown)
		{
			switch (m_nDrawMode)
			{
			case DRAW_NONE:
				{
					// 브러쉬 흰색 설정
					drawColor.SetFromCOLORREF(RGB(255, 255, 255));
					drawBrush.SetColor(drawColor);
					// 팬 컬러 검정색 설정
					drawColor.SetFromCOLORREF(RGB(0, 0, 0));
					drawPen.SetColor(drawColor);
					drawPen.SetWidth(1);

					int pointSize = m_points.GetSize()-1;
					for (int i = 0; i < pointSize; i++)
					{
						memGraphics.FillRectangle(&drawBrush, m_points.GetAt(i).X, m_points.GetAt(i).Y,
							m_nEraserSize * 2, m_nEraserSize * 2);
					}
					memGraphics.FillRectangle(&drawBrush, m_points.GetAt(m_points.GetSize() - 1).X, m_points.GetAt(m_points.GetSize() - 1).Y,
						m_nEraserSize * 2, m_nEraserSize * 2);
					memGraphics.DrawRectangle(&drawPen, m_points.GetAt(m_points.GetSize() - 1).X, m_points.GetAt(m_points.GetSize() - 1).Y,
						m_nEraserSize * 2, m_nEraserSize * 2);

					break;
				}
			case LINE_MODE:
				memGraphics.DrawLine(&drawPen, m_ptPrev.x, m_ptPrev.y,
					m_ptDrawing.x, m_ptDrawing.y);
				break;
			case RECT_MODE:
			{
				memGraphics.DrawRectangle(&drawPen, m_ptPrev.x, m_ptPrev.y,
					m_ptDrawing.x - m_ptPrev.x, m_ptDrawing.y - m_ptPrev.y);

				// 우측 아래
				if(m_ptPrev.x < m_ptDrawing.x && m_ptPrev.y < m_ptDrawing.y)
					memGraphics.DrawRectangle(&drawPen, m_ptPrev.x, m_ptPrev.y,
					m_ptDrawing.x - m_ptPrev.x, m_ptDrawing.y - m_ptPrev.y);
				// 우측 위
				else if(m_ptPrev.x < m_ptDrawing.x && m_ptPrev.y > m_ptDrawing.y)
					memGraphics.DrawRectangle(&drawPen, m_ptPrev.x, m_ptDrawing.y,
					m_ptDrawing.x - m_ptPrev.x, m_ptPrev.y - m_ptDrawing.y);
				// 좌측 아래
				else if(m_ptPrev.x > m_ptDrawing.x && m_ptPrev.y < m_ptDrawing.y)
					memGraphics.DrawRectangle(&drawPen, m_ptDrawing.x, m_ptPrev.y,
					m_ptPrev.x - m_ptDrawing.x, m_ptDrawing.y - m_ptPrev.y);
				// 좌측 위
				else
					memGraphics.DrawRectangle(&drawPen, m_ptDrawing.x, m_ptDrawing.y,
					m_ptPrev.x - m_ptDrawing.x, m_ptPrev.y - m_ptDrawing.y);

				break;
			}
			case CIRCLE_MODE:
				memGraphics.DrawEllipse(&drawPen, m_ptPrev.x, m_ptPrev.y,
					m_ptDrawing.x - m_ptPrev.x, m_ptDrawing.y - m_ptPrev.y);
				break;
			case FREE_MODE:
				if (m_points.GetSize() > 1)
				{
					for (int i = 1; i < m_points.GetSize(); i++)
						memGraphics.DrawLine(&drawPen, m_points.GetAt(i - 1).X, m_points.GetAt(i - 1).Y,
						m_points.GetAt(i).X, m_points.GetAt(i).Y);
				}
				break;
			case POLY_MODE:
				if (m_points.GetSize() > 1)
				{
					for (int i = 1; i < m_points.GetSize(); i++)
						memGraphics.DrawLine(&drawPen, m_points.GetAt(i-1).X, m_points.GetAt(i-1).Y,
						m_points.GetAt(i).X, m_points.GetAt(i).Y);

					// 처음 점과 마지막점을 이어준다.
					memGraphics.DrawLine(&drawPen, m_points.GetAt(m_points.GetSize() - 1).X, m_points.GetAt(m_points.GetSize() - 1).Y,
						m_ptDrawing.x, m_ptDrawing.y);
				}
				else if (m_points.GetSize() == 1)
					memGraphics.DrawLine(&drawPen, m_points.GetAt(0).X, m_points.GetAt(0).Y, m_ptDrawing.x, m_ptDrawing.y);
				break;
			default:
				break;
			}
		}
		graphics.DrawImage(&mBitmap, 0, 0);
	}