Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
graphic.c@0:582c20f27326, 2012-03-05 (annotated)
- Committer:
- fblanc
- Date:
- Mon Mar 05 11:48:28 2012 +0000
- Revision:
- 0:582c20f27326
v1.0
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| fblanc | 0:582c20f27326 | 1 | // Wy�wietlacz graficzny ze sterownikiem S6B0724 |
| fblanc | 0:582c20f27326 | 2 | // sterowanie w jezyku C od podstaw |
| fblanc | 0:582c20f27326 | 3 | // Plik : graphic.c |
| fblanc | 0:582c20f27326 | 4 | // Autor : Rados�aw Kwiecie� |
| fblanc | 0:582c20f27326 | 5 | |
| fblanc | 0:582c20f27326 | 6 | #include "SPLC501C.h" |
| fblanc | 0:582c20f27326 | 7 | |
| fblanc | 0:582c20f27326 | 8 | void GLCD_Rectangle(unsigned char x, unsigned char y, unsigned char b, unsigned char a , char color) { |
| fblanc | 0:582c20f27326 | 9 | unsigned char j; // zmienna pomocnicza |
| fblanc | 0:582c20f27326 | 10 | // rysowanie linii pionowych (boki) |
| fblanc | 0:582c20f27326 | 11 | for (j = 0; j < a; j++) { |
| fblanc | 0:582c20f27326 | 12 | GLCD_SetPixel(x, y + j, color); |
| fblanc | 0:582c20f27326 | 13 | GLCD_SetPixel(x + b - 1, y + j, color); |
| fblanc | 0:582c20f27326 | 14 | } |
| fblanc | 0:582c20f27326 | 15 | // rysowanie linii poziomych (podstawy) |
| fblanc | 0:582c20f27326 | 16 | for (j = 0; j < b; j++) { |
| fblanc | 0:582c20f27326 | 17 | GLCD_SetPixel(x + j, y, color); |
| fblanc | 0:582c20f27326 | 18 | GLCD_SetPixel(x + j, y + a - 1, color); |
| fblanc | 0:582c20f27326 | 19 | } |
| fblanc | 0:582c20f27326 | 20 | } |
| fblanc | 0:582c20f27326 | 21 | |
| fblanc | 0:582c20f27326 | 22 | |
| fblanc | 0:582c20f27326 | 23 | void GLCD_Circle(unsigned char cx, unsigned char cy ,unsigned char radius , char color) { |
| fblanc | 0:582c20f27326 | 24 | int x, y, xchange, ychange, radiusError; |
| fblanc | 0:582c20f27326 | 25 | x = radius; |
| fblanc | 0:582c20f27326 | 26 | y = 0; |
| fblanc | 0:582c20f27326 | 27 | xchange = 1 - 2 * radius; |
| fblanc | 0:582c20f27326 | 28 | ychange = 1; |
| fblanc | 0:582c20f27326 | 29 | radiusError = 0; |
| fblanc | 0:582c20f27326 | 30 | while (x >= y) { |
| fblanc | 0:582c20f27326 | 31 | GLCD_SetPixel(cx+x, cy+y, color); |
| fblanc | 0:582c20f27326 | 32 | GLCD_SetPixel(cx-x, cy+y, color); |
| fblanc | 0:582c20f27326 | 33 | GLCD_SetPixel(cx-x, cy-y, color); |
| fblanc | 0:582c20f27326 | 34 | GLCD_SetPixel(cx+x, cy-y, color); |
| fblanc | 0:582c20f27326 | 35 | GLCD_SetPixel(cx+y, cy+x, color); |
| fblanc | 0:582c20f27326 | 36 | GLCD_SetPixel(cx-y, cy+x, color); |
| fblanc | 0:582c20f27326 | 37 | GLCD_SetPixel(cx-y, cy-x, color); |
| fblanc | 0:582c20f27326 | 38 | GLCD_SetPixel(cx+y, cy-x, color); |
| fblanc | 0:582c20f27326 | 39 | y++; |
| fblanc | 0:582c20f27326 | 40 | radiusError += ychange; |
| fblanc | 0:582c20f27326 | 41 | ychange += 2; |
| fblanc | 0:582c20f27326 | 42 | if ( 2*radiusError + xchange > 0 ) { |
| fblanc | 0:582c20f27326 | 43 | x--; |
| fblanc | 0:582c20f27326 | 44 | radiusError += xchange; |
| fblanc | 0:582c20f27326 | 45 | xchange += 2; |
| fblanc | 0:582c20f27326 | 46 | } |
| fblanc | 0:582c20f27326 | 47 | } |
| fblanc | 0:582c20f27326 | 48 | } |
| fblanc | 0:582c20f27326 | 49 | |
| fblanc | 0:582c20f27326 | 50 | |
| fblanc | 0:582c20f27326 | 51 | void GLCD_Line(int X1, int Y1,int X2,int Y2 , char color) { |
| fblanc | 0:582c20f27326 | 52 | int CurrentX, CurrentY, Xinc, Yinc, |
| fblanc | 0:582c20f27326 | 53 | Dx, Dy, TwoDx, TwoDy, |
| fblanc | 0:582c20f27326 | 54 | TwoDxAccumulatedError, TwoDyAccumulatedError; |
| fblanc | 0:582c20f27326 | 55 | |
| fblanc | 0:582c20f27326 | 56 | Dx = (X2-X1); // obliczenie sk�adowej poziomej |
| fblanc | 0:582c20f27326 | 57 | Dy = (Y2-Y1); // obliczenie sk�adowej pionowej |
| fblanc | 0:582c20f27326 | 58 | |
| fblanc | 0:582c20f27326 | 59 | TwoDx = Dx + Dx; // podwojona sk�adowa pozioma |
| fblanc | 0:582c20f27326 | 60 | TwoDy = Dy + Dy; // podwojona sk�adowa pionowa |
| fblanc | 0:582c20f27326 | 61 | |
| fblanc | 0:582c20f27326 | 62 | CurrentX = X1; // zaczynamy od X1 |
| fblanc | 0:582c20f27326 | 63 | CurrentY = Y1; // oraz Y1 |
| fblanc | 0:582c20f27326 | 64 | |
| fblanc | 0:582c20f27326 | 65 | Xinc = 1; // ustalamy krok zwi�kszania pozycji w poziomie |
| fblanc | 0:582c20f27326 | 66 | Yinc = 1; // ustalamy krok zwi�kszania pozycji w pionie |
| fblanc | 0:582c20f27326 | 67 | |
| fblanc | 0:582c20f27326 | 68 | if (Dx < 0) { // jesli sk�adowa pozioma jest ujemna |
| fblanc | 0:582c20f27326 | 69 | Xinc = -1; // to b�dziemy si� "cofa�" (krok ujemny) |
| fblanc | 0:582c20f27326 | 70 | Dx = -Dx; // zmieniamy znak sk�adowej na dodatni |
| fblanc | 0:582c20f27326 | 71 | TwoDx = -TwoDx; // jak r�wnie� podwojonej sk�adowej |
| fblanc | 0:582c20f27326 | 72 | } |
| fblanc | 0:582c20f27326 | 73 | |
| fblanc | 0:582c20f27326 | 74 | if (Dy < 0) { // je�li sk�adowa pionowa jest ujemna |
| fblanc | 0:582c20f27326 | 75 | Yinc = -1; // to b�dziemy si� "cofa�" (krok ujemny) |
| fblanc | 0:582c20f27326 | 76 | Dy = -Dy; // zmieniamy znak sk�adowej na dodatki |
| fblanc | 0:582c20f27326 | 77 | TwoDy = -TwoDy; // jak r�wniez podwojonej sk�adowej |
| fblanc | 0:582c20f27326 | 78 | } |
| fblanc | 0:582c20f27326 | 79 | |
| fblanc | 0:582c20f27326 | 80 | GLCD_SetPixel(X1,Y1, color); // stawiamy pierwszy krok (zapalamy pierwszy piksel) |
| fblanc | 0:582c20f27326 | 81 | |
| fblanc | 0:582c20f27326 | 82 | if ((Dx != 0) || (Dy != 0)) { // sprawdzamy czy linia sk�ada si� z wi�cej ni� jednego punktu ;) |
| fblanc | 0:582c20f27326 | 83 | // sprawdzamy czy sk�adowa pionowa jest mniejsza lub r�wna sk�adowej poziomej |
| fblanc | 0:582c20f27326 | 84 | if (Dy <= Dx) { // je�li tak, to idziemy "po iksach" |
| fblanc | 0:582c20f27326 | 85 | TwoDxAccumulatedError = 0; // zerujemy zmienn� |
| fblanc | 0:582c20f27326 | 86 | do { // ruszamy w drog� |
| fblanc | 0:582c20f27326 | 87 | CurrentX += Xinc; // do aktualnej pozycji dodajemy krok |
| fblanc | 0:582c20f27326 | 88 | TwoDxAccumulatedError += TwoDy; // a tu dodajemy podwojon� sk�adow� pionow� |
| fblanc | 0:582c20f27326 | 89 | if (TwoDxAccumulatedError > Dx) { // je�li TwoDxAccumulatedError jest wi�kszy od Dx |
| fblanc | 0:582c20f27326 | 90 | CurrentY += Yinc; // zwi�kszamy aktualn� pozycj� w pionie |
| fblanc | 0:582c20f27326 | 91 | TwoDxAccumulatedError -= TwoDx; // i odejmujemy TwoDx |
| fblanc | 0:582c20f27326 | 92 | } |
| fblanc | 0:582c20f27326 | 93 | GLCD_SetPixel(CurrentX,CurrentY, color);// stawiamy nast�pny krok (zapalamy piksel) |
| fblanc | 0:582c20f27326 | 94 | } while (CurrentX != X2); // idziemy tak d�ugo, a� osi�gniemy punkt docelowy |
| fblanc | 0:582c20f27326 | 95 | } else { // w przeciwnym razie idziemy "po igrekach" |
| fblanc | 0:582c20f27326 | 96 | TwoDyAccumulatedError = 0; |
| fblanc | 0:582c20f27326 | 97 | do { |
| fblanc | 0:582c20f27326 | 98 | CurrentY += Yinc; |
| fblanc | 0:582c20f27326 | 99 | TwoDyAccumulatedError += TwoDx; |
| fblanc | 0:582c20f27326 | 100 | if (TwoDyAccumulatedError>Dy) { |
| fblanc | 0:582c20f27326 | 101 | CurrentX += Xinc; |
| fblanc | 0:582c20f27326 | 102 | TwoDyAccumulatedError -= TwoDy; |
| fblanc | 0:582c20f27326 | 103 | } |
| fblanc | 0:582c20f27326 | 104 | GLCD_SetPixel(CurrentX,CurrentY, color); |
| fblanc | 0:582c20f27326 | 105 | } while (CurrentY != Y2); |
| fblanc | 0:582c20f27326 | 106 | } |
| fblanc | 0:582c20f27326 | 107 | } |
| fblanc | 0:582c20f27326 | 108 | } |