Advertisement
flyingfisch

Untitled

Jun 29th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.58 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;
  25.     float g = -9.8;
  26.     int vy;
  27.     int vx;
  28.     float buffer;
  29.    
  30.  
  31.    
  32.     for(t=start; t < 2; t += 0.01) {
  33.         y = h+0.5*g* t*t + vy*t;
  34.         x = vx*t;
  35.        
  36.         plot(x, LCD_HEIGHT_PX - y, COLOR_BLACK);
  37.     }
  38.    
  39.     Bdisp_PutDisp_DD();
  40.    
  41.     while(!done) {
  42.         key = PRGM_GetKey();
  43.    
  44.         switch(key) {
  45.             case KEY_PRGM_MENU:
  46.             done = 1;
  47.             break;
  48.         }
  49.     }
  50.  
  51.     return 1;
  52. }
  53.  
  54.  
  55. //routines
  56. short unsigned int heightcolor(float z, float z_min, float z_max) {
  57.          float frac = ((z-z_min)/(z_max-z_min));
  58.          
  59.          //color!
  60.          float r = (0.25f)-frac;
  61.          float g = (0.5f)-frac;
  62.          float b = (0.75f)-frac;
  63.  
  64.          //calculate the R/G/B values
  65.          r = (r>0.f)?r:-r; g = (g>0.f)?g:-g; b = (b>0.f)?b:-b;   //absolute value
  66.          r = (0.25f)-r; g = (1.f/3.f)-g; b = (0.25f)-b;   //invert
  67.          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
  68.          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
  69.          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
  70.          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
  71.          return (short unsigned int)(0x0000ffff & (((int)(31.f*r) << 11) | ((int)(63.f*g) << 5) | ((int)(31.f*b))));   //put the bits together
  72. }
  73.  
  74. void fillArea(int x, int y, int width, int height, int color) {
  75.     //only use lower two bytes of color
  76.     char* VRAM = (char*)0xA8000000;
  77.     VRAM += 2*(LCD_WIDTH_PX*y + x);
  78.     for(int j=y; j<y+height; j++) {
  79.        for(int i=x; i<x+width;  i++) {
  80.           *(VRAM++) = (color&0x0000FF00)>>8;
  81.           *(VRAM++) = (color&0x000000FF);
  82.        }
  83.        VRAM += 2*(LCD_WIDTH_PX-width);
  84.     }
  85.  }
  86.  
  87. int PRGM_GetKey(void) {
  88.   unsigned char buffer[12];
  89.   PRGM_GetKey_OS( buffer );
  90.   return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
  91. }
  92.  
  93. void plot(int x0, int y0, int color) {
  94.     char* VRAM = (char*)0xA8000000;
  95.     VRAM += 2*(y0*LCD_WIDTH_PX + x0);
  96.     *(VRAM++) = (color&0x0000FF00)>>8;
  97.     *(VRAM++) = (color&0x000000FF);
  98.     return;
  99.  }
  100.  
  101. //my routines
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement