Advertisement
flyingfisch

Untitled

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