0 Members and 4 Guests are viewing this topic.
#include <os.h>#include "utils.c"#include "graphics3.c"#include "touchpad.c"#define texWidth 256#define texHeight 256#define screenWidth 240#define screenHeight 240int w = 240, h = 240, x, y;int texture[texWidth][texHeight];int distanceTable[screenWidth][screenHeight];int angleTable[screenWidth][screenHeight];int buffer[screenWidth][screenHeight];void masksprite(void *buffer, int *data, int x, int y, int width, int height, int mask){ int i, j; for(i = 0; i < height; i++){ for(j = 0; j < width; j++){ if(data[i*width+j] != mask && x+j < 320 && x+j > 0 && y+i < 240 && y+i > 0){ setPixelBuf(buffer, x+j, y+i, data[i*width+j]); } } }}uint16_t RGBColor(uint8_t r, uint8_t g, uint8_t b){ return ((r / 8) << 11) | ((g / 4) << 5) | (b / 8);}int main(void) { char *screen; screen = (char*)malloc(SCREEN_BYTES_SIZE * sizeof(char)); // just a buffer if(!screen) { exit(0); } initTP(); lcd_ingray(); for(x = 0; x < texWidth; x++) for(y = 0; y < texHeight; y++) { uint8_t c = x ^ y; texture[x][y] = RGBColor(c, c, c); } for(x = 0; x < w; x++) for(y = 0; y < h; y++) { int angle, distance; float ratio = 32.0; distance = (int)(ratio * texHeight / sqrt((x - w / 2.0) * (x - w / 2.0) + (y - h / 2.0) * (y - h / 2.0))) % texHeight; angle = (unsigned int)(0.5 * texWidth * atan2(y - h / 2.0, x - w / 2.0) / M_PI); distanceTable[x][y] = distance; angleTable[x][y] = angle; } float animation = 0; int shiftY = (int)(texHeight * 0.25); //begin the loop while(!isKeyPressed(KEY_NSPIRE_ESC)) { animation = animation+0.01; readTP(); int TZ = getTouchedZone4(); //calculate the shift values out of the animation value int shiftX = (int)(texWidth * 1.0 * animation); if(isKeyPressed(KEY_NSPIRE_RIGHT) || TZ==6) shiftY++; if(isKeyPressed(KEY_NSPIRE_LEFT) || TZ==4) shiftY--; for(x = 0; x < w; x++) for(y = 0; y < h; y++) { //get the texel from the texture by using the tables, shifted with the animation values int color = texture[(unsigned int)(distanceTable[x][y] + shiftX) % texWidth][(unsigned int)(angleTable[x][y] + shiftY) % texHeight]; buffer[x][y] = color; } masksprite(screen, buffer[0], 0, 0, 240, 240, 0xf800); refresh(screen); clearBuf(screen); } free(screen); endTP(); return 0;}
(unsigned int)(distanceTable[x][y] + shiftX)
(unsigned int)((unsigned int)distanceTable[x][y] + shiftX)
for(x = 0; x < w; x++)for(y = 0; y < h; y++){ color=texture[blah][blah]; buffer[x][y]=color;}
texture[((unsigned int)(distanceTable[x][y] + shiftX) % texWidth)][((unsigned int)(angleTable[x][y] + shiftY) % texHeight)];
And that doesn't work ? Weird .__.Try replacing the cast with abs(), just to be sure.