Advertisement
flyingfisch

Untitled

Jun 29th, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.00 KB | None | 0 0
  1. #include <display_syscalls.h>
  2. #include <display.h>
  3. #include <keyboard_syscalls.h>
  4. #include <keyboard.hpp>
  5. #include <math.h>
  6. #include <color.h>
  7.  
  8. short unsigned int heightcolor(float z, float z_min, float z_max);
  9. void fillArea(int x, int y, int width, int height, int color);
  10. int PRGM_GetKey(void);
  11. void plot(int x0, int y0, int color);
  12.  
  13. int main(void) {
  14.     //program variables
  15.     int key;
  16.     int color;
  17.     int done = 0;
  18.    
  19.     //graphing variables
  20.     float start = 0;
  21.     float t;
  22.     int x;
  23.     int y;
  24.     int h = 2;
  25.     float g = -9.8;
  26.     int vy = 0;
  27.     int vx = 100;
  28.     float buffer;
  29.     char buffer2[10];
  30.    
  31.  
  32.    
  33.     for(t=start; t < 2; t += 0.01) {
  34.         y = h+0.5*g* t*t + vy*t;
  35.         x = vx*t;
  36.        
  37.         y = y*5;
  38.         x = x*5;
  39.        
  40.         //start debug
  41.         strcpy(buffer2,"  ");
  42.         itoa(x, buffer2+2);
  43.         PrintXY(3, 1, buffer, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
  44.        
  45.         strcpy(buffer2,"  ");
  46.         itoa(x, buffer2+2);
  47.         PrintXY(3, 2, buffer, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
  48.        
  49.         PrintXY(1, 1, "X", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
  50.         PrintXY(1, 2, "Y", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
  51.         //end debug
  52.        
  53.         plot(x, LCD_HEIGHT_PX - y, COLOR_BLACK);
  54.         Bdisp_PutDisp_DD();
  55.     }
  56.    
  57.    
  58.    
  59.     while(!done) {
  60.         key = PRGM_GetKey();
  61.    
  62.         switch(key) {
  63.             case KEY_PRGM_MENU:
  64.             done = 1;
  65.             break;
  66.         }
  67.     }
  68.  
  69.     return 1;
  70. }
  71.  
  72.  
  73. //routines
  74. short unsigned int heightcolor(float z, float z_min, float z_max) {
  75.          float frac = ((z-z_min)/(z_max-z_min));
  76.          
  77.          //color!
  78.          float r = (0.25f)-frac;
  79.          float g = (0.5f)-frac;
  80.          float b = (0.75f)-frac;
  81.  
  82.          //calculate the R/G/B values
  83.          r = (r>0.f)?r:-r; g = (g>0.f)?g:-g; b = (b>0.f)?b:-b;   //absolute value
  84.          r = (0.25f)-r; g = (1.f/3.f)-g; b = (0.25f)-b;   //invert
  85.          r = (r>0.f)?(6.f*r):0.f; g = (g>0.f)?(6.f*g):0.f; b = (b>0.f)?(6.f*b):0.f;   //scale the chromatic triangles
  86.          r = (r>1.f)?1.f:r; g = (g>1.f)?1.f:g; b = (b>1.f)?1.f:b;   //clip the top of the chromatic triangles
  87.          if (frac < 0.25f) r = (r+1.f)/2.f;   //adjust the bottom end of the scale so that z_min is red, not black
  88.          if (frac > 0.75f) b = (b+1.f)/2.f;   //adjust the top end of the scale so that z_max is blue, not black
  89.          return (short unsigned int)(0x0000ffff & (((int)(31.f*r) << 11) | ((int)(63.f*g) << 5) | ((int)(31.f*b))));   //put the bits together
  90. }
  91.  
  92. void fillArea(int x, int y, int width, int height, int color) {
  93.     //only use lower two bytes of color
  94.     char* VRAM = (char*)0xA8000000;
  95.     VRAM += 2*(LCD_WIDTH_PX*y + x);
  96.     for(int j=y; j<y+height; j++) {
  97.        for(int i=x; i<x+width;  i++) {
  98.           *(VRAM++) = (color&0x0000FF00)>>8;
  99.           *(VRAM++) = (color&0x000000FF);
  100.        }
  101.        VRAM += 2*(LCD_WIDTH_PX-width);
  102.     }
  103.  }
  104.  
  105. int PRGM_GetKey(void) {
  106.   unsigned char buffer[12];
  107.   PRGM_GetKey_OS( buffer );
  108.   return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
  109. }
  110.  
  111. void plot(int x0, int y0, int color) {
  112.     char* VRAM = (char*)0xA8000000;
  113.     VRAM += 2*(y0*LCD_WIDTH_PX + x0);
  114.     *(VRAM++) = (color&0x0000FF00)>>8;
  115.     *(VRAM++) = (color&0x000000FF);
  116.     return;
  117.  }
  118.  
  119. //my routines
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement