mandelbrot displaybuffer scrolling, zoom out

This commit is contained in:
Sebastian 'iggy' Steuer 2011-07-21 17:04:22 +02:00
parent 4bef39e4f3
commit 62bc287d0f
1 changed files with 103 additions and 46 deletions

View File

@ -24,7 +24,7 @@ void blink(){
struct mb { struct mb {
long rmin, rmax, imin, imax; long rmin, rmax, imin, imax;
bool dirty; bool dirty, dup, ddown, dleft, dright;
} mandel; } mandel;
void mandelInit() { void mandelInit() {
@ -38,51 +38,64 @@ void mandelInit() {
mandel.imax = fixpt(2); mandel.imax = fixpt(2);
mandel.dirty = true; mandel.dirty = true;
mandel.dup = false;
mandel.ddown = false;
mandel.dleft = false;
mandel.dright = false;
} }
void mandelMove() { void mandelMove() {
long delta_r = (mandel.rmax - mandel.rmin)/10; //long delta_r = (mandel.rmax - mandel.rmin)/10;
long delta_i = (mandel.imax - mandel.imin)/10; //long delta_i = (mandel.imax - mandel.imin)/10;
long rs =(mandel.rmax-mandel.rmin)/RESY;
long is =(mandel.imax-mandel.imin)/RESX;
char key = getInputRaw(); char key = getInputRaw();
if (key == BTN_LEFT) { if (key == BTN_LEFT) {
mandel.imax -= delta_i; mandel.imax -=is;
mandel.imin -= delta_i; mandel.imin -=is;
mandel.dirty = true; mandel.dleft = true;
} else if (key == BTN_RIGHT) { } else if (key == BTN_RIGHT) {
mandel.imax += delta_i; mandel.imax += is;
mandel.imin += delta_i; mandel.imin += is;
mandel.dirty = true; mandel.dright = true;
} else if (key == BTN_DOWN) { } else if (key == BTN_DOWN) {
mandel.rmax += delta_r; mandel.rmax += rs;
mandel.rmin += delta_r; mandel.rmin += rs;
mandel.dirty = true; mandel.ddown = true;
} else if (key == BTN_UP) { } else if (key == BTN_UP) {
mandel.rmax -= delta_r; mandel.rmax -= rs;
mandel.rmin -= delta_r; mandel.rmin -= rs;
mandel.dirty = true; mandel.dup = true;
} else if (key == BTN_ENTER) { } else if (key == (BTN_ENTER + BTN_UP)) {
mandel.imin = mandel.imin + (mandel.imax-mandel.imin)/10; mandel.imin = mandel.imin + (mandel.imax-mandel.imin)/10;
mandel.imax = mandel.imax - (mandel.imax-mandel.imin)/10; mandel.imax = mandel.imax - (mandel.imax-mandel.imin)/10;
mandel.rmin = mandel.rmin +(mandel.rmax-mandel.rmin)/10; mandel.rmin = mandel.rmin +(mandel.rmax-mandel.rmin)/10;
mandel.rmax = mandel.rmax -(mandel.rmax-mandel.rmin)/10; mandel.rmax = mandel.rmax -(mandel.rmax-mandel.rmin)/10;
mandel.dirty = true; mandel.dirty = true;
} else if (key == (BTN_ENTER + BTN_DOWN)) {
mandel.imin = mandel.imin - (mandel.imax-mandel.imin)/10;
mandel.imax = mandel.imax + (mandel.imax-mandel.imin)/10;
mandel.rmin = mandel.rmin -(mandel.rmax-mandel.rmin)/10;
mandel.rmax = mandel.rmax +(mandel.rmax-mandel.rmin)/10;
mandel.dirty = true;
}
} }
} void mandelPixel(int x, int y) {
void mandelCalc() {
long r0,i0,rn, p,q; long r0,i0,rn, p,q;
long rs,is; long rs,is;
int iteration; int iteration;
char x, y;
rs=(mandel.rmax-mandel.rmin)/RESY; rs=(mandel.rmax-mandel.rmin)/RESY;
is=(mandel.imax-mandel.imin)/RESX; is=(mandel.imax-mandel.imin)/RESX;
//p=fixpt(mandel.rmin+y*rs);
for (x=0; x<RESX; x++){ //q=fixpt(mandel.imin+x*is);
for (y=0; y<RESY; y++) {
p=mandel.rmin+y*rs; p=mandel.rmin+y*rs;
q=mandel.imin+x*is; q=mandel.imin+x*is;
rn=0; rn=0;
r0=0; r0=0;
i0=0; i0=0;
@ -96,10 +109,55 @@ void mandelCalc() {
bool pixel = ( iteration>1); bool pixel = ( iteration>1);
lcdSetPixel(x, y, pixel); lcdSetPixel(x, y, pixel);
} }
}
void mandelUpdate() {
int xmin,xmax,ymin,ymax;
if (mandel.dirty) {
xmin = 0;
xmax = RESX;
ymin = 0;
ymax = RESY;
mandel.dirty = false; mandel.dirty = false;
} else if (mandel.dleft) {
lcdShift(1,0,false);
xmin = 0;
xmax = 1;
ymin = 0;
ymax = RESY;
mandel.dleft = false;
} else if (mandel.dright) {
lcdShift(-1,0,false);
xmin = RESX-1;
xmax = RESX;
ymin = 0;
ymax = RESY;
mandel.dright = false;
} else if (mandel.dup) {
lcdShift(0,-1,true);
xmin=0;
xmax=RESX;
ymin=0;
ymax=1;
mandel.dup = false;
} else if (mandel.ddown) {
lcdShift(0,1,true);
xmin=0;
xmax=RESX;
ymin=RESY-1;
ymax=RESY;
mandel.ddown = false;
} else {
return;
} }
for (int x = xmin; x<xmax; x++) {
for (int y = ymin; y<ymax; y++) {
mandelPixel(x,y);
}
}
}
void main_mandelbrot2(void) { void main_mandelbrot2(void) {
backlightInit(); backlightInit();
IOCON_PIO3_3 = 0x10; IOCON_PIO3_3 = 0x10;
@ -108,9 +166,8 @@ void main_mandelbrot2(void) {
while (1) { while (1) {
lcdDisplay(); lcdDisplay();
mandelMove(); mandelMove();
if (mandel.dirty) { mandelUpdate();
mandelCalc();
}
if(gpioGetValue(RB_BTN0)==0 && gpioGetValue(RB_BTN4)==0){ if(gpioGetValue(RB_BTN0)==0 && gpioGetValue(RB_BTN4)==0){
DoString(0,0,"Enter ISP!"); DoString(0,0,"Enter ISP!");