nestedsquares - //Creates drawable frame DrawableFrame df =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 /* * Created by, Tiauna Hendrickson * CSC 2310 Assignment # 4 * the frame contains 256 squares nested within each other. The outermost * square is 512 pixels by 512 pixels. It's color has 0 as its red, green, and * blue components. Inside this recatngle is a rectangle that's 510 pixels by * 510 pixels. It's color has 1 as its red, green, and blue components. Each * subsequent rectangle is 2 pixels smaller than the previous one, and has color * components that are 1 unit larger. */ package NestedSquares import java.awt.* import jpb.* public class Main { public static void main(String[] args) {
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //Creates drawable frame DrawableFrame df = new DrawableFrame("Nested Squares") df.show() df.setSize(1023, 1023) //Obtains graphic context Graphics g = df.getGraphicsContext() int coords, width, height, color coords = 0 color = 0 // Sets the size of first square. width = 511 height = 511 // while (color >= 0 && color <= 255 && width >= 0 && height >= 0) { g.setColor(new Color(color, color, color)) g.fillRect(coords, coords, width*2, height*2) color += 1 coords += 2 width -= 2 height -= 2 } //Repaint frame df.repaint() }...
View Full Document

Ask a homework question - tutors are online