How to draw a sky with grass background -- Greenfoot programming lesson
Find other posts in the same category: | | |

Long description

* This script shows you how to draw your own background
* Top 2/3 is filled with blue
* Bottom 2/3 is filled with green
* This was based on Michael Kolling's video tutorial for drawing space and stars
*
* author is user computers.fun on Greenfoot Gallery
* @version date is Dec. 19, 2008

import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;

/**
* This script shows you how to draw your own background
* This was based on Michael Kolling's video tutorial for drawing space and stars
*
* author is user computers.fun on Greenfoot Gallery
* @version date is Dec. 19, 2008
*/
public class SkyGrass extends World // Change this name to rename your World background
{
public SkyGrass() // Change this name to rename your World background. Make it match 2 lines above
{
super(600, 400, 1);

GreenfootImage bg = getBackground();
bg.setColor(Color.WHITE);
bg.fill();
createSky();
createGrass();
}

/****************** this block is commented out. was used for making stars
private void createStars(int numberOfStars)
{
GreenfootImage bg = getBackground();
bg.setColor(Color.GRAY);
for (int i = 0; i < numberOfStars; i++) {
int x = Greenfoot.getRandomNumber( getWidth() );
int y = Greenfoot.getRandomNumber( getHeight() );
bg.fillOval(x, y, 2, 2);
}
}
commented out *****************************/

private void createSky()
{
GreenfootImage bg = getBackground();
bg.setColor(Color.BLUE);
int skyHeight = 2 * (getHeight() / 3);
int width = getWidth();
int height = getHeight();
bg.fillRect(0, 0, width, skyHeight);
}

private void createGrass()
{
GreenfootImage bg = getBackground();
bg.setColor(Color.GREEN);
for (int i = 0; i < 1; i++) {
int grassHeight = getHeight() / 3;
int width = getWidth();
int height = getHeight();
bg.fillRect(0, height - grassHeight, width, grassHeight);
}


}


}


To see articles on the same topic, click the links below the name of the author at the top of this page.