English subtitles

← Dim The Picture - Intro to Java Programming

Get Embed Code
6 Languages

Showing Revision 5 created 05/24/2016 by Udacity Robot.

  1. We want to iterate, over every pixel in the image. The first index, in the
  2. pixels, would be 0. And the last one would the be one, less than, the number of
  3. pixels. Since I only need to affect, every fifth pixel, I'll increment, i, by 5
  4. at a time. To turn a pixel black. I'll use the setColorAt() method, and give it
  5. the number of the pixel I want, and the color to set that pixel to. So now if I
  6. run this, I get the same picture, but dimmed a little. If you look really
  7. closely, on your own screen, it's hard to seen on the video, you can actually
  8. see the little, black dots. There are probably other ways to do this, but I
  9. think this is the simplest. For example, you could count up by 1 at a time and
  10. then use mod to decide whether to actually color the pixel or not.
  11. Alternatively, instead of checking using mod, you could set the color at 5
  12. times i. But then, you would need to change the condition for stopping the
  13. loop. I think that would require a little bit more thinking.