daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.Color;
  2.  
  3. /**
  4.  * Ujian Akhir Semester
  5.  * Kelas PBO B
  6.  * @author Hendra Ramadani (05111740000055)
  7.  * 10 December 2018
  8.  */
  9. public class FishEyeFilter extends Filter
  10. {
  11.     // constants:
  12.     private final static int SCALE = 20;   // this defines the strenght of the filter
  13.     private final static double TWO_PI = 2 * Math.PI;
  14.  
  15.     /**
  16.      * Constructor for objects of class LensFilter.
  17.      * @param name The name of the filter.
  18.      */
  19.     public FishEyeFilter(String name)
  20.     {
  21.         super(name);
  22.     }
  23.  
  24.     /**
  25.      * Apply this filter to an image.
  26.      *
  27.      * @param  image  The image to be changed by this filter.
  28.      */
  29.     public void apply(OFImage image)
  30.     {
  31.         int height = image.getHeight();
  32.         int width = image.getWidth();
  33.         OFImage original = new OFImage(image);
  34.  
  35.         int[] xa = computeXArray(width);
  36.         int[] ya = computeYArray(height);
  37.        
  38.         for(int y = 0; y < height; y++) {
  39.             for(int x = 0; x < width; x++) {
  40.                 image.setPixel(x, y, original.getPixel(x + xa[x], y + ya[y]));
  41.             }
  42.         }
  43.     }
  44.  
  45.     /**
  46.      * Compute and return an array of horizontal offsets for each pixel column.
  47.      * These can then be applied as the horizontal offset for each pixel.
  48.      */
  49.     private int[] computeXArray(int width)
  50.     {
  51.         int[] xArray = new int[width];
  52.        
  53.         for(int i=0; i < width; i++) {
  54.             xArray[i] = (int)(Math.sin( ((double)i / width) * TWO_PI) * SCALE);
  55.         }
  56.         return xArray;
  57.     }
  58.  
  59.     /**
  60.      * Compute and return an array of vertical offsets for each pixel row.
  61.      * These can then be applied as the vertical offset for each pixel.
  62.      */
  63.     private int[] computeYArray(int height)
  64.     {
  65.         int[] yArray = new int[height];
  66.        
  67.         for(int i=0; i < height; i++) {
  68.             yArray[i] = (int)(Math.sin( ((double)i / height) * TWO_PI) * SCALE);
  69.         }
  70.         return yArray;
  71.     }
  72. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top