본문 바로가기

카테고리 없음

디지털영상처리


madebront

float xmin = -2.5;
float ymin = -2;
float wh = 8;

w값을 키우면 전체범위가 보인다.

pixels[i+j*width] = color(n*16 % 255)->
    pixels[i+j*width] = color(n*16 % 255,n*16 % 255,255-n*16 % 255);  rgb모드로바꿔줌

16->등고선간격


  xmin -= wh*bx/100;
  ymin -= wh*by/100;

wh를 곱해줘서 (scale) 드래그했을때 너무 많이 이동하지 않도록 해준다.






/**
 * The Mandelbrot Set
 * by Daniel Shiffman. 
 *
 * Simple rendering of the Mandelbrot set.
 */
 
// Establish a range of values on the complex plane
// A different range will allow us to "zoom" in or out on the fractal
// float xmin = -1.5; float ymin = -.1; float wh = 0.15;
double xmin = -1.5;
double ymin = -0.00001;
double wh =4;
double xc=0;
double yc=0;
  float bx;
  float by;
  boolean locked = false;
float bdifx = 0.0;
float bdify = 0.0;


void setup() {
  size(800, 800, P2D);
  //noLoop();
  background(255);
  // Make sure we can write to the pixels[] array.
  // Only need to do this once since we don't do any other drawing.
 
  loadPixels();
}

void draw() {
  // Maximum number of iterations for each point on the complex plane
  int maxiterations = 200;
  if(locked){ //들랰깅할땜움직
   
  xc -= wh*bx/500;
 yc -= wh*by/500;
 
  xmin=xc-wh/2;
  ymin=yc-wh/2; //center
  }
  // x goes from xmin to xmax
double xmax = xmin + wh;
  // y goes from ymin to ymax
 double ymax = ymin + wh;
 
  // Calculate amount we increment x,y for each pixel
double dx = (xmax - xmin) / (width);
double dy = (ymax - ymin) / (height);

  // Start y
 double y = ymin;
  for (int j = 0; j < height; j++) {
    // Start x
   double x = xmin;
    for (int i = 0;  i < width; i++) {
     
      // Now we test, as we iterate z = z^2 + cm does z tend towards infinity?
      double a = x;
      double b = y;
      int n = 0;
      while (n < maxiterations) {
       double aa = a * a;
       double bb = b * b;
       double twoab = 2.0 * a * b;
        a = aa - bb + x;
        b = twoab + y;
        // Infinty in our finite world is simple, let's just consider it 16
        if(aa + bb > 16.0) {
          break;  // Bail
        }
        n++;
      }
     
      // We color each pixel based on how long it takes to get to infinity
      // If we never got there, let's pick the color black
      if (n == maxiterations) {
        pixels[i+j*width] = 0;
      } else {
        // Gosh, we could make fancy colors here if we wanted
        pixels[i+j*width] = color(n*16 % 255,n*16 % 255,255-n*16 % 255); 
      }
      x += dx;
    }
    y += dy;
  }
  updatePixels();

 
}


void keyPressed() {
  if(key=='u') {
    wh*=0.5; //print("UP");
  }
   if(key=='d'){
     wh *=2.0; //print("DOWN");
   }
 
}

 

void mousePressed() {
    locked = true;
  bdifx = mouseX-bx;
  bdify = mouseY-by;

}

void mouseDragged() {
  if(locked) {
    bx = mouseX-bdifx;
    by = mouseY-bdify;

  }
}

void mouseReleased() {
  locked = false;
}