1 / 14

Day 8: Fruit Loops: Color

Day 8: Fruit Loops: Color. Loop Review. What does the following loop print? f or ( int i= 0; i<5; i++) { for ( int j=0; j<4; j++) { System.out.println (“i: “+i+” j: “+j); } System.out.println (); }. Scope Review How many rectangles are printed?.

iniko
Download Presentation

Day 8: Fruit Loops: Color

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Day 8: Fruit Loops: Color

  2. Loop Review What does the following loop print? for (int i= 0; i<5; i++) { for (int j=0; j<4; j++) { System.out.println(“i: “+i+” j: “+j); } System.out.println(); }

  3. Scope ReviewHow many rectangles are printed? Rectangle box = new Rectangle(0,0, 20, 20); box.setColor(new Color(255, 0,0)); for (int i=0; i< 8; i++) { box.fill(); box.translate(i,i); }

  4. Scope Review—How many rectangles are printed? for (int i=0; i< 8; i++) { Rectangle box = new Rectangle(0,0, 20, 20); box.setColor(new Color(255, 0,0)); box.fill(); box.translate(i,i); }

  5. Color class Color public Color(int red, int green, int blue) Constructs a new Color object. Parameters: red - the red value of the color (between 0 and 255) green - the green value of the color (between 0 and 255) blue - the blue value of the color (between 0 and 255)

  6. Color Wheel Color(0,0,0) Color(60,0,0) Color(120,0,0) Color(180,0,0) Color(240,0,0) Note: each Color parameter ranges from 0 to 255

  7. Loop to vary the colors for(int j=0; j<5; j++) { Rectangle box = new Rectangle(i*30, j*30, 20, 20); box.setColor(new Color(i*60,0,0)); box.fill(); } Remember: Color(0,0,0) is black and Color(255,0,0) is pure red

  8. What will this print? for(int j=0; j<5; j++) { Rectangle box = new Rectangle(i*30, j*30, 20, 20); box.setColor(new Color(255-i*60,0,0)); box.fill(); }

  9. Exercise 1 Fruit Loops Loops and Color

  10. Pictures need Color Explanation and review for Exercise 2

  11. Picture Class Methods

  12. getHeight()—the height in pixels is returned as an int

  13. In Class practice getHeight() – returns an int getWidth() – returns an int getColorAt(int x, int y ) – returns a Color (Note: Color has 3 int parameters, red, green & blue. These values range from 0 to 255) Instantiate a returned Color and get its red, green and blue int values

  14. Exercise 2 Create negatives, darken and brighten pictures

More Related