## class MakeScreenImage – the code

```class MakeScreenImage{
Vector[] mappedVectors;                        // needs our improved class Vector

MakeScreenImage(){
}

//  often images result from two steps: first a transformation maps the pixel position

Vector mapVector(float i,float j){
Vector r=new Vector(i,height-j);
r.mult(r).mult(0.001);
return r;
}

//   then the color of the pixel is a function of this new position

color colorFromVector(Vector in){
return ripples(in.x,in.y);
}

// thus essentially
//        pixels[i+jWidth]=colorFromVector(mapVector(i,j));
//
// which we can accelerate using
// a two-step method for images with complicated geometry

//  first prepare pixel coordinate vectors to the input image,
//  typiccally using screenCoordinate and inputCoordinate objects
// and map the vectors

//  first step: setup the vectors

void createMappedVectors(){
int size=width*height;
mappedVectors=new Vector[size];
int i,j,jWidth;
for(j=0;j<height;j++){
jWidth=j*width;
for (i=0;i<width;i++){
mappedVectors[i+jWidth]=mapVector(i,j);
}
}
}

//  second step: use prepared vectors to make the screen image

void imageFromVectors(){
int size=width*height;
for(int i=0;i<size;i++){
pixels[i]=colorFromVector(mappedVectors[i]);
}
updatePixels();
}

//----------------------------------------------------------------------
//  for comparision: direct method, without preparation
//  and for images without mappings

void direct(){
int i,j,jWidth;
for(j=0;j<height;j++){
jWidth=j*width;
for (i=0;i<width;i++){
pixels[i+jWidth]=colorFromVector(mapVector(i,j));
}
}
updatePixels();
}
}```
This entry was posted in programming and tagged , . Bookmark the permalink.

This site uses Akismet to reduce spam. Learn how your comment data is processed.