<< Chapter < Page Chapter >> Page >

Beginning of the method named displayColumnMatrices

I will explain the method named displayColumnMatrices in fragments. You can view the entire method in Listing 8 . The first fragment is shown in Listing 1 .

Listing 1 . Beginning of the method named displayColumnMatrices.
void displayColumnMatrices(Graphics2D g2D){//Get two values for each matrix from the sliders. red0 = redSlider0.getValue();red1 = redSlider1.getValue(); green0 = greenSlider0.getValue();green1 = greenSlider1.getValue();

Get two values for each matrix from the sliders

The little things with the pointed bottoms on the sliders in Figure 1 are often called the thumbs of the sliders. Each thumb points down to a numeric scale that ranges from -100 on the left to +100 on the right.

Each time you move a thumb on a slider, the method named displayColumnMatrices , including the code in Listing 1 , is executed. The code in Listing 1 gets the value corresponding to the position of each thumb and saves those four values in the variables named red0 , red1 , green0 , and green1 .

The two sliders in the top row represent red. The two sliders in the bottom row represent green.

The values of the two sliders on the left correspond to red0 and green0 . The two on the right correspond to red1 and green1 .

Use the slider values to create the two matrices

Listing 2 uses the slider values to create the two matrices named redMatrix and greenMatrix .

(More properly, the code uses the values to create two ColMatrix objects and to store references to those objects in the variables named redMatrix and greenMatrix .)

Listing 2 . Use the slider values to create the two matrices.
//Use the slider values to create the two matrices // named redMatrix and greenMatrix.GM2D03.ColMatrix redMatrix = new GM2D03.ColMatrix(red0,red1);GM2D03.ColMatrix greenMatrix = new GM2D03.ColMatrix(green0,green1);

There is nothing new in Listing 2 that you haven't seen before so further explanation should not be necessary.

Add and subtract the matrices

Listing 3 creates two additional matrices by adding and subtracting the red and green matrices. References to the new matrices are stored in the variablesnamed blueMatrix and orangeMatrix .

Listing 3 . Add and subtract the matrices.
//Create two additional matrices by adding and // subtracting the red and green matrices.GM2D03.ColMatrix blueMatrix = redMatrix.add(greenMatrix);GM2D03.ColMatrix orangeMatrix = redMatrix.subtract(greenMatrix);

Once again, there is nothing new in Listing 3 , so further explanation should not be necessary.

Display text information about the matrices

Listing 4 displays text information about the four matrices, including whether or not the red and green matrices are equal.

Listing 4 . Display text information about the matrices.
//Display text information about the matrices. System.out.println();//blank line System.out.println("redMatrix = " + redMatrix);System.out.println("greenMatrix = " + greenMatrix); System.out.println("redMatrix equals greenMatrix: " +redMatrix.equals(greenMatrix)); System.out.println("blueMatrix = redMatrix + greenMatrix = " + blueMatrix);System.out.println( "orangeMatrix = redMatrix - greenMatrix = " +orangeMatrix);

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Game 2302 - mathematical applications for game development. OpenStax CNX. Jan 09, 2016 Download for free at https://legacy.cnx.org/content/col11450/1.33
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?

Ask