Geek points if you understand this. Double points if you can do it in your head.
What can we do to improve drawBorder() ? Drawing two vertical lines uses one "recipe"! Each uses a different y value. So: Create a parameterized method to draw a vertical line. Do the same for horizontal lines. Make the size of the border a parameter. Make the size of the border grow with the size of the image. Others?
STEP BY STEP public void lighter( double amount ) { Pixel[] pixels = this.getPixels(); double factor = 1 + amount; for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } }
STEP BY STEP Pixel[] pixels = this.getPixels(); double factor = 1 + amount; pixels Pixel[0] Pixel red=127 green=163 blue=197 Pixel[1] Pixel red=127 green=163 blue=197 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } pixels Pixel[0] Pixel red=127 green=163 blue=197 Pixel[1] Pixel red=127 green=163 blue=197 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5
STEP BY STEP for ( int i = 0 ; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } pixels Pixel[0] Pixel red=127 green=163 blue=197 Pixel[1] Pixel red=127 green=163 blue=197 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5 i 0
STEP BY STEP for ( int i = 0; i < pixels.length ; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } pixels Pixel[0] Pixel red=127 green=163 blue=197 Pixel[1] Pixel red=127 green=163 blue=197 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5 i 0
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } p -> Pixel[0] Pixel red=127 green=163 blue=197 Pixel[1] Pixel red=127 green=163 blue=197 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5 i 0
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } p -> Pixel[0] Pixel red= 190 green=163 blue=197 Pixel[1] Pixel red=127 green=163 blue=197 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5 i 0
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } p -> Pixel[0] Pixel red=190 green= 244 blue=197 Pixel[1] Pixel red=127 green=163 blue=197 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5 i 0
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } p -> Pixel[0] Pixel red=190 green=244 blue= 295 Pixel[1] Pixel red=127 green=163 blue=197 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5 i 0
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } p -> Pixel[0] Pixel red=190 green=244 blue=295 Pixel[1] Pixel red=127 green=163 blue=197 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5 i 0
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } p -> Pixel[0] Pixel red=190 green=244 blue=295 Pixel[1] Pixel red=127 green=163 blue=197 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5 i 1
STEP BY STEP for ( int i = 0; i < pixels.length ; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } p -> Pixel[0] Pixel red=190 green=244 blue=295 Pixel[1] Pixel red=127 green=163 blue=197 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5 i 1
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } Pixel[0] Pixel red=190 green=244 blue=295 p -> Pixel[1] Pixel red=127 green=163 blue=197 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5 i 1
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } Pixel[0] Pixel red=190 green=244 blue=295 p -> Pixel[1] Pixel red= 190 green=163 blue=197 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5 i 1
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } Pixel[0] Pixel red=190 green=244 blue=295 p -> Pixel[1] Pixel red=190 green= 244 blue=197 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5 i 1
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } Pixel[0] Pixel red=190 green=244 blue=295 p -> Pixel[1] Pixel red=190 green=244 blue= 295 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5 i 1
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } Pixel[0] Pixel red=190 green=244 blue=295 p -> Pixel[1] Pixel red=190 green=244 blue=295 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5 i 2
STEP BY STEP for ( int i = 0; i < pixels.length ; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } Pixel[0] Pixel red=190 green=244 blue=295 p -> Pixel[1] Pixel red=190 green=244 blue=295 Pixel[2] Pixel red=128 green=164 blue=198 ... factor 1.5 i 2
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } Pixel[0] Pixel red=190 green=244 blue=295 Pixel[0] Pixel red=190 green=244 blue=295 p -> Pixel[0] Pixel red=128 green=164 blue=198 ... factor 1.5 i 2 ... AND SO ON
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } ... Pixel[179197] Pixel red=69 green=75 blue=30 p -> Pixel[179198] Pixel red=69 green=75 blue= 30 Pixel[179199] Pixel red=40 green=50 blue=18 factor 1.5 i 179198
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } ... Pixel[179197] Pixel red=69 green=75 blue=30 p -> Pixel[179198] Pixel red=69 green=75 blue=30 Pixel[179199] Pixel red=40 green=50 blue=18 factor 1.5 i 179199
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } ... Pixel[179197] Pixel red=69 green=75 blue=30 Pixel[179198] Pixel red=69 green=75 blue=30 p -> Pixel[179199] Pixel red=40 green=50 blue=18 factor 1.5 i 179199
STEP BY STEP for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } ... Pixel[179197] Pixel red=69 green=75 blue=30 Pixel[179198] Pixel red=69 green=75 blue=30 p -> Pixel[179199] Pixel red= 60 green=50 blue=18 factor 1.5 i 179199
Recommend
More recommend