JAVA   28
LightenUp
Guest on 9th February 2023 03:05:01 AM


  1. import objectdraw.*;
  2. import java.awt.*;
  3.  
  4.     // A program to simulate the brightening of the sky at sunrise
  5. public class LightenUp extends WindowController {
  6.  
  7.     private FilledRect sky;     // background rectangle
  8.     private int brightness;     // brightness of sky's color
  9.     private FilledOval sun;     // Circle that represents the sun
  10.  
  11.     public void begin() {
  12.             // Create the sky and make it a dark gray
  13.         brightness = 50;
  14.         sky = new FilledRect( 0, 0, canvas.getWidth(), canvas.getHeight(), canvas );
  15.         sky.setColor( new Color( brightness, brightness, brightness));
  16.  
  17.             // Place the sun and some brief instructions on the screen
  18.         sun = new FilledOval( 50, 150, 100, 100, canvas);
  19.         new Text( "Please click the mouse repeatedly", 20, 20, canvas);
  20.     }
  21.  
  22.        // Brighten the sky and move the sun with each click
  23.     public void onMouseClick(Location point) {
  24.         brightness = brightness + 1;
  25.         sky.setColor( new Color(brightness, brightness, brightness));
  26.         sun.move(0, -5);
  27.     }
  28. }

Raw Paste

Login or Register to edit or fork this paste. It's free.