Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Basic draw functions by xerpi*/
- #include <nds.h>
- #include <stdio.h>
- void drawLine(int x0, int y0, int x, int y, unsigned int color);
- void drawHline(int y, int x0, int x1, unsigned int color);
- void drawVline(int x, int y0, int y1, unsigned int color);
- void drawPlot(int x, int y, unsigned int color);
- void drawRect(int x, int y, int w, int h, unsigned int color);
- void drawFillRect(int x, int y, int w, int h, unsigned int color);
- int main(void){
- int i;
- touchPosition touch;
- consoleDemoInit();
- videoSetMode(MODE_FB0 | DISPLAY_BG3_ACTIVE);
- vramSetBankA(VRAM_A_LCD);
- printf("Basic draw functions by xerpi!\n");
- for(i = 0; i < 256 * 192; i++)
- VRAM_A[i] = RGB15(31,0,0);
- drawRect( 10, 10, 20, 80, RGB15(0, 31, 0));
- drawFillRect( 100, 100, 50, 30, RGB15(0, 0, 31));
- drawLine( 0, 0, 255, 192, RGB15(0, 0, 31));
- drawPlot(255, 191, RGB15(0, 0, 31));
- while(1){
- scanKeys();
- consoleClear();
- printf("Basic draw functions by xerpi!\n");
- if(keysHeld() & KEY_TOUCH)
- touchRead(&touch);
- printf("x: %i y: %i!\n", touch.px, touch.py);
- VRAM_A[touch.px + touch.py * 256] = rand();
- if(keysHeld() & KEY_A)
- printf("Key A is pressed");
- swiWaitForVBlank();
- }
- return 0;
- }
- void drawLine(int x0, int y0, int x, int y, unsigned int color){
- if(x == x0){
- drawVline(x0, y0, y, color);
- return;
- }
- if(y == y0){
- drawHline(y0, x0, x, color);
- return;
- }
- int i, x_dist, y_dist;
- float ratio;
- if(x0 > x)
- x_dist = x0 - x;
- else
- x_dist = x - x0;
- if(y0 > y)
- y_dist = y0 - y;
- else
- y_dist = y - y0;
- ratio = (float)x_dist/(float)y_dist;
- for(i = 0; i < y_dist; i++){
- VRAM_A[ (int)(x0 + i * ratio) + (int)(y0 + i*256)] = color;
- }
- }
- void drawPlot(int x, int y, unsigned int color){
- VRAM_A[x + y*256] = color;
- }
- void drawHline(int y, int x0, int x1, unsigned int color){
- int i;
- if(x0 < x1)
- for(i = x0; i < x1; i++)
- VRAM_A[i + y*256] = color;
- else
- for(i = x1; i < x0; i++)
- VRAM_A[i + y*256] = color;
- }
- void drawVline(int x, int y0, int y1, unsigned int color){
- int i;
- if(y0 < y1)
- for(i = y0; i < y1; i++)
- VRAM_A[x + i*256] = color;
- else
- for(i = y1; i < y0; i++)
- VRAM_A[x + i*256] = color;
- }
- void drawRect(int x, int y, int w, int h, unsigned int color){
- drawVline(x, y, y + h, color);
- drawVline(x + w, y, y + h, color);
- drawHline(y + h, x, x + w, color);
- drawHline(y, x, x + w, color);
- }
- void drawFillRect(int x, int y, int w, int h, unsigned int color){
- int i;
- for(i = y; i < y + h; i++)
- drawHline(i, x, x + w, color);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement