// Space ScreenSaver
//This screensaver begins with an earth scenario of a space-ship taking off into
//space, it then proceeds to different scenes of the space ship flying across
//the skies of different plants
import java.awt.*;
import hsa.Console;
import java.util.*;
public class KhaderScreenSaver
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
//BEGIN VARIABLE SECTION
//Color Variables
Color darkGreen = new Color (0, 204, 0); //Light Green For Grass Bushes
//Variable for maxx and maxy co-ordinates
int maxx = c.getWidth ();
int maxy = c.getHeight ();
//Variable for random Y-Co-ordinates and X-Co-ordinates
//These variables are used anytime a random co-ordinate is needed for a loop
int randYCord, randXCord;
//Create an X and Y co-ordinate variable for animating
int takeOffX = (maxx / 2);
int takeOffY = (maxy / 2);
//BEGIN ROCKETS CO-ORDINATE SECTION FOR EARTH TAKE OFF SCENE
//Assign the Co-ordinates for the right space shuttle rocket top for the
//Earth Take-off scene
int[] xRRocketPoints, yRRocketPoints;
//Assign the x co-ordinates
xRRocketPoints = new int [4]; //Make the polygon 3-cordinates long
xRRocketPoints [0] = (takeOffX + 71); //Top Left
xRRocketPoints [1] = (takeOffX + 80); //Top Right
xRRocketPoints [2] = (takeOffX + 90); //Bottom Right
xRRocketPoints [3] = (takeOffX + 61); //Botom Left
//Assign the Y co-ordinates
yRRocketPoints = new int [4]; //Make the polygon 3-cordinates long
yRRocketPoints [0] = (takeOffY - 184); //Top Left
yRRocketPoints [1] = (takeOffY - 184); //Top Right
yRRocketPoints [2] = (takeOffY - 151); //Bottom Right
yRRocketPoints [3] = (takeOffY - 151); //Botom Left
//Assign the Co-ordinates for the right space shuttle rocket burner for the
//Earth Take-off scene
int[] xRBurnerPoints, yRBurnerPoints;
//Assign the x co-ordinates
xRBurnerPoints = new int [4]; //Make the polygon 3-cordinates long
xRBurnerPoints [0] = (takeOffX + 61); //Top Left
xRBurnerPoints [1] = (takeOffX + 91); //Top Right
xRBurnerPoints [2] = (takeOffX + 99); //Bottom Right
xRBurnerPoints [3] = (takeOffX + 53); //Botom Left
//Assign the Y co-ordinates
yRBurnerPoints = new int [4]; //Make the polygon 3-cordinates long
yRBurnerPoints [0] = (takeOffY + 130); //Top Left Co-ordinate
yRBurnerPoints [1] = (takeOffY + 130); //Top Right Co-ordinate
yRBurnerPoints [2] = (takeOffY + 154); //Bottom Right Co-ordinate
yRBurnerPoints [3] = (takeOffY + 154); //Botom Left Co-ordinate
//Assign the Co-ordinates for the Left space shuttle rocket top for the
//Earth Take-off scene
int[] xLRocketPoints; //Declare array for X points
//Assign the x co-ordinates
xLRocketPoints = new int [4]; //Make the polygon 4-cordinates long
xLRocketPoints [0] = (takeOffX - 41); //Top Left Co-ordinate
xLRocketPoints [1] = (takeOffX - 50); //Top Right Co-ordinate
xLRocketPoints [2] = (takeOffX - 60); //Bottom Right Co-ordinate
xLRocketPoints [3] = (takeOffX - 31); //Botom Left Co-ordinate
//Assign the Co-ordinates for the left space shuttle rocket burner for the
//Earth Take-off scene
int[] xLBurnerPoints; //Declare array for X points
//Assign the x co-ordinates
xLBurnerPoints = new int [4]; //Make the polygon 4-cordinates long
xLBurnerPoints [0] = (takeOffX - 31); //Top Left Co-ordinate
xLBurnerPoints [1] = (takeOffX - 61); //Top Right Co-ordinate
xLBurnerPoints [2] = (takeOffX - 69); //Bottom Right Co-ordinate
xLBurnerPoints [3] = (takeOffX - 23); //Botom Left Co-ordinate
//Assign the Co-Ordinates for the center space shuttle rocket burner for the
//Earth take-off scene
int[] xCBurnerPoints; //Declare array for X points
//Assign the X co-rdinates
xCBurnerPoints = new int [4]; //make array able to store 4 co-ordinates
//Assign the coordinates
xCBurnerPoints [0] = (takeOffX - 10); //Top Left Co-ordinate
xCBurnerPoints [1] = (takeOffX + 50); //Top Right Co-ordinate
xCBurnerPoints [2] = (takeOffX + 68); //Top Right Co-ordinate
xCBurnerPoints [3] = (takeOffX - 28); //Top Right Co-ordinate
int[] yCBurnerPoints; //Declare array for X points
//Assign the Y co-rdinates
yCBurnerPoints = new int [4]; //make array able to store 4 co-ordinates
//Assign the coordinates
yCBurnerPoints [0] = (takeOffY + 150); //Top Left Co-ordinate
yCBurnerPoints [1] = (takeOffY + 150); //Top Right Co-ordinate
yCBurnerPoints [2] = (takeOffY + 175); //Top Right Co-ordinate
yCBurnerPoints [3] = (takeOffY + 175); //Top Right Co-ordinate
//END ROCKETS CO-ORDINATE SECTION FOR EARTH TAKE OFF SCENE
//BEGIN SPACE SHUTTLE CO-ORDINATE SECTION FOR EARTH TAKE OFF SCENE
//Declare an Array for the top nose of the shuttle to be drawn in the shape of a triangle
//for the earth take-off scene
int[] xNC1ShuttleEarth; // X co-ordinates for nose
//Assign x Coordinates
xNC1ShuttleEarth = new int [3]; //Make array 3 ints long
xNC1ShuttleEarth [0] = (takeOffX + 20); //Top co-ordinate
xNC1ShuttleEarth [1] = (takeOffX + 30); //Bottom right co-ordinate
xNC1ShuttleEarth [2] = (takeOffX + 10); //Bottom left co-ordinate
int[] yNC1ShuttleEarth; // Y co-ordinates for nose
//Assign x Coordinates
yNC1ShuttleEarth = new int [3]; //Make array 3 ints long
yNC1ShuttleEarth [0] = (takeOffY - 125); //Top co-ordinate
yNC1ShuttleEarth [1] = (takeOffY - 110); //Bottom right co-ordinate
yNC1ShuttleEarth [2] = (takeOffY - 110); //Bottom left co-ordinate
//Declare an array for co-ordinates for the second half of the cockpit
int[] xNC2ShuttleEarth; //X co-ordinates for main cock-pit area
//Assign X co-ordinates
xNC2ShuttleEarth = new int [4]; //Make array 4 ints long
xNC2ShuttleEarth [0] = (takeOffX + 10); //Top left co-ordinate
xNC2ShuttleEarth [1] = (takeOffX + 30); //Top right co-ordinate
xNC2ShuttleEarth [2] = (takeOffX + 36); //Bottom right co-ordinate
xNC2ShuttleEarth [3] = (takeOffX + 4); //Bottom Left co-ordinate
int[] yNC2ShuttleEarth; //X co-ordinates for main cock-pit area
//Assign Y co-ordinates
yNC2ShuttleEarth = new int [4]; //Make array 4 ints long
yNC2ShuttleEarth [0] = (takeOffY - 110); //Top left co-ordinate
yNC2ShuttleEarth [1] = (takeOffY - 110); //Top right co-ordinate
yNC2ShuttleEarth [2] = (takeOffY - 87); //bottom right co-ordinate
yNC2ShuttleEarth [3] = (takeOffY - 87); //bottom left co-ordinate
//Declare an array for co-ordinates for the first part of the wings
int[] xNW1ShuttleEarth; //x cords
//Assign X Co-ordinates
xNW1ShuttleEarth = new int [4]; //Make array 4 ints long
xNW1ShuttleEarth [0] = (takeOffX + 5);
xNW1ShuttleEarth [1] = (takeOffX + 36);
xNW1ShuttleEarth [2] = (takeOffX + 56);
xNW1ShuttleEarth [3] = (takeOffX - 13);
int[] yNW1ShuttleEarth; //y cords
//Assign y Co-ordinates
yNW1ShuttleEarth = new int [4]; //Make array 4 ints long
yNW1ShuttleEarth [0] = (takeOffY - 86);
yNW1ShuttleEarth [1] = (takeOffY - 86);
yNW1ShuttleEarth [2] = (takeOffY - 10);
yNW1ShuttleEarth [3] = (takeOffY - 10);
//Declare an array for co-ordinates for the first part of the wings
int[] xNW2ShuttleEarth; //x cords
//Assign X Co-ordinates
xNW2ShuttleEarth = new int [4]; //Make array 4 ints long
xNW2ShuttleEarth [0] = (takeOffX - 13);
xNW2ShuttleEarth [1] = (takeOffX + 36);
xNW2ShuttleEarth [2] = (takeOffX + 56);
xNW2ShuttleEarth [3] = (takeOffX - 13);
int[] yNW2ShuttleEarth; //y cords
//Assign y Co-ordinates
yNW2ShuttleEarth = new int [4]; //Make array 4 ints long
yNW2ShuttleEarth [0] = (takeOffY - 10);
yNW2ShuttleEarth [1] = (takeOffY - 10);
yNW2ShuttleEarth [2] = (takeOffY - 10);
yNW2ShuttleEarth [3] = (takeOffY - 10);
//END SPACE SHUTTLE CO-ORDINATE SECTION FOR EARTH TAKE OFF SCENE
//Create a random number generator for generating random numbers for co-ordinates
Random generator = new Random ();
//END VARIABLE SECTION
//BEGIN EARTH TAKE-OFF SCENE
//Draw the background
//Draw a black background for night's sky
c.fillRect (0, 0, maxx, maxy);
//Set Color to white for white stars
c.setColor (Color.white);
//Loop to draw stars are random positions in the sky
for (int i = 0 ; i < maxx ; i += 10)
{
randYCord = generator.nextInt (maxy); //assign a random value to the star y cordinate
randXCord = generator.nextInt (maxx); //assign a random value to the star x cordinate
c.fillStar (randXCord, randYCord, 10, 10); //Draw the star in a random position
} //End loop to draw stars in random position
//Draw the grass as a green rectangle
//Set color to green for color of grass
c.setColor (Color.green);
//Draw a rectangle for the background of the grass
c.fillRect (0, 375, maxx, maxy);
//Draw grass bushes in the grass using a for loop
//Set Color to dark Green for grass bushes
c.setColor (darkGreen);
for (int i = 0 ; i < maxx ; i += 10)
{
randYCord = generator.nextInt (maxy) + 385; //assign a random value for the grass y cordinate (above the grass line)
randXCord = generator.nextInt (maxx); //assign a random value for the grass x cordinate
c.drawLine (randXCord, randYCord, randXCord, (randYCord - 10)); //Draw the main center line of the bush
c.drawLine (randXCord, randYCord, (randXCord - 7), (randYCord - 10)); //Draw the left line of bush
c.drawLine (randXCord, randYCord, (randXCord + 7), (randYCord - 10)); //Draw the right line of bush
} //End Loop to draw the grass bushes at random spots
//Begin Drawing the space-ship --
//Draw the main center rocket | Orange
//Draw the top orange curve
//Set color to orange
c.setColor (Color.orange);
c.fillOval ((takeOffX - 10), (takeOffY - 200), 60, 100);
//Draw the main hull of the center rocket, also orange
c.fillRect ((takeOffX - 10), (takeOffY - 150), 60, 300);
//Draw the burner of the center rocket, grey
c.setColor (Color.gray);
//Draw the outline of the burner in triangular shape
c.drawLine ((takeOffX - 10), (takeOffY + 150), (takeOffX + 50), (takeOffY + 150)); //Top horizontal line
c.drawLine ((takeOffX + 50), (takeOffY + 150), (takeOffX + 68), (takeOffY + 175)); //Right vertical line
c.drawLine ((takeOffX + 68), (takeOffY + 175), (takeOffX - 28), (takeOffY + 175)); //Bottom Horizontal Line
//Draw the burner as a filled polygon in grey color.
c.fillPolygon (xCBurnerPoints, yCBurnerPoints, 4);
//Draw the right white rocket
//Set the color to grey for the outline of the right rocket
c.setColor (Color.gray);
//Draw the outline of the top of the right rocket in a triangular shape
c.drawLine ((takeOffX + 70), (takeOffY - 185), (takeOffX + 80), (takeOffY - 185));
c.drawLine ((takeOffX + 80), (takeOffY - 185), (takeOffX + 90), (takeOffY - 150));
c.drawLine ((takeOffX + 90), (takeOffY - 150), (takeOffX + 60), (takeOffY - 150));
//Set Color to white to fill the triangle
c.setColor (Color.white);
c.fillPolygon (xRRocketPoints, yRRocketPoints, 4);
//Draw Orange stripe on the top of the Right Rocket (DETAIL)
//set color to orange for orange stripe
c.setColor (Color.orange);
c.fillRect ((takeOffX + 64), (takeOffY - 160), 24, 3);
//Draw black dots on right rocket (DETAIL)
//Set color to black for black dots
c.setColor (Color.black);
c.fillOval ((takeOffX + 70), (takeOffY - 174), 5, 5); //Top Left dot
c.fillOval ((takeOffX + 67), (takeOffY - 168), 5, 5); //Bottom Left dot
c.fillOval ((takeOffX + 75), (takeOffY - 174), 5, 5); //Top Right Dot
c.fillOval ((takeOffX + 72), (takeOffY - 168), 5, 5); //Bottom Right Dot
//Draw the hull of the right rocket
//Set Color to white to fill the hull
c.setColor (Color.white);
c.fillRect ((takeOffX + 61), (takeOffY - 150), 30, 280);
//Draw Connector Between right rocket and main rocketc
//Set color to grey for connector
c.setColor (Color.gray);
c.fillRect ((takeOffX + 50), takeOffY, 11, 50);
//Draw the burner of the right rocket
//Set the color to grey for the outline of the right rocket burner
c.setColor (Color.gray);
c.drawLine ((takeOffX + 61), (takeOffY + 130), (takeOffX + 91), (takeOffY + 130));
c.drawLine ((takeOffX + 91), (takeOffY + 130), (takeOffX + 99), (takeOffY + 154));
c.drawLine ((takeOffX + 99), (takeOffY + 154), (takeOffX + 53), (takeOffY + 154));
c.fillPolygon (xRBurnerPoints, yRBurnerPoints, 4);
//Draw the left white rocket
//Set the color to grey for the outline of the right rocket
c.setColor (Color.gray);
//Draw the outline of the top of the rocket in a triangular shape
c.drawLine ((takeOffX - 40), (takeOffY - 185), (takeOffX - 50), (takeOffY - 185));
c.drawLine ((takeOffX - 50), (takeOffY - 185), (takeOffX - 60), (takeOffY - 150));
c.drawLine ((takeOffX - 60), (takeOffY - 150), (takeOffX - 30), (takeOffY - 150));
//Set Color to white to fill the triangle
c.setColor (Color.white);
c.fillPolygon (xLRocketPoints, yRRocketPoints, 4);
//Draw Orange stripe on the top of the Left Rocket (DETAIL)
//set color to orange for orange stripe
c.setColor (Color.orange);
c.fillRect ((takeOffX - 57), (takeOffY - 160), 24, 3);
//Draw black dots on right rocket (DETAIL)
//Set color to black for black dots
c.setColor (Color.black);
c.fillOval ((takeOffX - 43), (takeOffY - 174), 5, 5); //Top Right dot
c.fillOval ((takeOffX - 41), (takeOffY - 168), 5, 5); //Bottom Right dot
c.fillOval ((takeOffX - 48), (takeOffY - 174), 5, 5); //Top Left Dot
c.fillOval ((takeOffX - 46), (takeOffY - 168), 5, 5); //Bottom Left Dot
//Draw the hull of the left rocket
//Set Color to white to fill the hull
c.setColor (Color.white);
c.fillRect ((takeOffX - 60), (takeOffY - 150), 30, 280);
//Draw Connector Between left rocket and main rocket
//Set color to grey for connector
c.setColor (Color.gray);
c.fillRect ((takeOffX - 30), takeOffY, 20, 50);
//Draw left rocket burner
c.fillPolygon (xLBurnerPoints, yRBurnerPoints, 4);
//Begin Drawing the main shuttle
//Draw the front of the shuttle
//Draw the nose of the cockpit in black as a polygon
//Draw the outline of the nose first
//Set Color to black for the nose
c.setColor (Color.black);
//Draw the outline of the nose
c.drawLine ((takeOffX + 20), (takeOffY - 125), (takeOffX + 30), (takeOffY - 110)); //Vertical line
c.drawLine ((takeOffX + 30), (takeOffY - 110), (takeOffX + 10), (takeOffY - 110)); //horizontal line
//draw the polygon as a triangle to fill color
c.fillPolygon (xNC1ShuttleEarth, yNC1ShuttleEarth, 3);
//Draw white polygon for the second half of the cock-pit
//Set color to white for cock-pit
c.setColor (Color.white);
c.fillPolygon (xNC2ShuttleEarth, yNC2ShuttleEarth, 4);
//Set Color to black for the wing outline
c.setColor (Color.black);
//Draw the outline of the first layer of wings for the shuttle
c.drawLine ((takeOffX + 3), (takeOffY - 87), (takeOffX + 37), (takeOffY - 87)); //Top horizontall line
c.drawLine ((takeOffX + 37), (takeOffY - 87), (takeOffX + 57), (takeOffY - 10)); //Right vertical line
c.drawLine ((takeOffX - 14), (takeOffY - 10), (takeOffX + 3), (takeOffY - 87)); //Left vertical line
//Set the wing color to white
c.setColor(Color.white);
//Draw the polygon for the first partition of the wings
c.fillPolygon(xNW1ShuttleEarth, yNW1ShuttleEarth, 4);
//Set Color to black for the wing outline
c.setColor (Color.black);
//Draw the outline of the second layer of the wings
c.drawLine ((takeOffX - 13), (takeOffY - 10), (takeOffX + 56), (takeOffY - 10));
//END EARTH TAKE-OFF SCENE
} // main method
} // Example class