12/14/2022 0 Comments Statcalc java system outputln![]() I need to represent the current position in some way. Randomly change color of the square at the current position Move current position up, down, left, or right, at random Open a Mosaic window Fill window with random colors Set the current position to the middle square in the window As long as the mosaic window is open: This should continue as long as the mosaic window is still open. The third step can be expanded a bit more, into the steps: Start in the middle of the window, then keep moving to a new square and changing the color of that square. Open a Mosaic window Fill window with random colors Move around, changing squares at random.įilling the window with random colors seems like a nice coherent task that I can work on separately, so let’s decide to write a separate subroutine to do it. With basic routines for manipulating the window as a foundation, I can turn to the specific problem at hand. Here’s a picture showing what the contents of the window might look like at one point in time: “Randomly change the colors” could mean a lot of different things, but after thinking for a while, I decide it would be interesting to have a “disturbance” that wanders randomly around the window, changing the color of each square that it encounters. I want to fill the window with randomly colored squares, and then randomly change the colors in a loop that continues as long as the window is open. My idea is to use the Mosaic class as the basis for a neat animation. For example, we’ll have to use the name Mosaic.isOpen() rather than simply isOpen(). Remember that these subroutines are members of the Mosaic class, so when they are called from outside Mosaic, the name of the class must be included as part of the name of the routine. */ public static void delay(int milliseconds) Of milliseconds, where one second is equal to 1000 * * Postcondition: The program has paused for at least the specified number * The first parameter and the number of columns by the * * Postcondition:Ī window is open on the screen that can display rows and *Ĭolumns of colored rectangles. The parameters rows, cols, w, and h are positive integers. ** * Opens a "mosaic" window on the screen. Here are some of the available routines in the API, with Javadoc-style comments: In fact, the class defines a toolbox or API that can be used for working with such windows. The window can be opened, closed, and otherwise manipulated with static member subroutines defined in the Mosaic class. This class allows a program to work with a window that displays little colored rectangles arranged in rows and columns. Suppose that I have found an already-written class called Mosaic. Use prewritten subroutines as building blocks and we will also design new subroutines that we need to complete the project. 4.6.2 A Design Example Let’s work through an example of program design using subroutines. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |