<< Chapter < Page Chapter >> Page >

Note that all four methods that are called in the body of the display method are inherited from the class named PApplet .

The stroke method

Six overloaded versions of the stroke method are inherited from the PApplet class into the Cars class.

(Methods inherited into the Cars class are accessible by objects of the Car class because the Car class is converted to an inner class of the Cars class when the program is compiled by the Processing environment.However, inner classes is a relatively advanced topic that is beyond the scope of this module.)

Here is some of what the documentation has to say about the stroke method.

"Sets the color used to draw lines and borders around shapes. This color is either specified in terms of the RGB or HSB color depending on the current colorMode() (the default color space is RGB, with each value in the range from 0 to 255).

When using hexadecimal notation to specify a color, use "#" or "0x" before the values (e.g. #CCFFAA, 0xFFCCFFAA). The # syntax uses six digits to specify a color (the way colors are specified in HTML and CSS).

When using the hexadecimal notation starting with "0x", the hexadecimal value must be specified with eight characters; the first two characters define the alpha component and the remainder the red, green, and blue components.

The value for the gray parameter must be less than or equal to the current maximum value as specified by colorMode(). The default maximum value is 255."

The version of the display method called in Listing 5 requires a single parameter of type int . This version apparently treats 24 bits of the 32-bit int value as the red, green, and bluecolor values and ignores the remaining 8 bits.

The parameter value of 0 passed to the stroke method in Listing 5 specifies a black stroke. This causes the rectangles shown in Image 3 to have black borders.

The fill method

The next method called inside the display method in Listing 5 is the method named fill , which is also inherited from the PApplet class. The value stored in the color instance variable named c is passed as a parameter to the fill method.

The Cars class inherits six overloaded versions of the fill method from the PApplet class. Here is part of what the documentation has to say about the fill method.

"Sets the color used to fill shapes. For example, if you run fill(204, 102, 0), all subsequent shapes will be filled with orange. This color is either specified in terms of the RGB or HSB color depending on the current colorMode(). (The default color space is RGB, with each value in the range from 0 to 255.)

When using hexadecimal notation to specify a color, use "#" or "0x" before the values (e.g., #CCFFAA or 0xFFCCFFAA). The # syntax uses six digits to specify a color (just as colors are typically specified in HTML and CSS). When using the hexadecimal notation starting with "0x", the hexadecimal value must be specified with eight characters; the first two characters define the alpha component, and the remainder define the red, green, and blue components.

The value for the "gray" parameter must be less than or equal to the current maximum value as specified by colorMode(). The default maximum value is 255.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, The processing programming environment. OpenStax CNX. Feb 26, 2013 Download for free at http://cnx.org/content/col11492/1.5
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'The processing programming environment' conversation and receive update notifications?

Ask