<< Chapter < Page Chapter >> Page >

Given that the 0,0 origin is at the upper left, you should be able to correlate the vertical position ( y-coordinate value ) of each rectangle with the color of the rectangle.

Because Image 3 is a screen shot, there is nothing in Image 3 that corresponds to the speed parameter in Listing 3 . You will see later that this parameter is used to establish the speed with which each rectangle moves across the displaywindow. Stated differently, each rectangle appears to move across the display window in incremental steps. The speed value is used by the drive method to compute the size of each incremental step.

The draw method of the Cars class

Returning now to the Cars class, the code fragment in Listing 4 shows the draw method in its entirety.

Listing 4. the draw method of the cars class.

void draw() { background(255);myCar1.drive();myCar1.display();myCar2.drive(); myCar2.display();}
Listing 4. The draw method of the Cars class.

Recall that by default, the draw method is called repeatedly 60 times per second. Nothing was done in this sketch to changethat.

Set the background color

The draw method begins by calling the inherited background method to erase everything on the display window and set its color to white.

There are seven overloaded versions of the background method where different parameter types and order are used to produce different behavior.

Here is part of what the documentation has to say about the background method.

"The background() function sets the color used for the background of the Processing window. The default background is light gray. background() is typically used within the draw() function to clear the display window at the beginning of each frame.

An image can also be used as the background for a sketch, although the image's width and height must match that of the sketch window. To resize an image to the size of the sketch window, use image.resize(width, height).

Images used with background() will ignore the current tint() setting.

It is not possible to use transparency (alpha) with background colors on the main drawing surface; you can achieve the same effect with createGraphics()."

The version of the background method that is called in Listing 4 takes a single parameter. That versions sets the background color to a gray value between white and black. A parameter valueof 255 produces white and a parameter value of 0 produces black.

Call methods on the Car objects

If you are new to OOP, you may be unfamiliar with the following syntax:

myCar1.drive();

Basically this means:

  • Go find the object whose reference is stored in the reference variable named myCar1 .
  • Knock on the object's door and ask it to execute its method named drive .

Each time the draw method is executed, it asks each Car object to first execute its drive method and then execute its display method.

At this point, we don't know what that means exactly because we haven't examined the behavior of the methods named drive and display belonging to the Car objects.

The display method of the Car class

Switching again to the Car class, the code fragment in Listing 5 shows the display method of the Car class.

Listing 5. the display method of the car class

void display() { stroke(0);fill(c); rectMode(CENTER);rect(xpos,ypos,20,10); }//end method named display
Listing 5. The display method of the Car class

Questions & Answers

what is defense mechanism
Chinaza Reply
what is defense mechanisms
Chinaza
I'm interested in biological psychology and cognitive psychology
Tanya Reply
what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

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