Step 5: Extras

Launch Create setup() draw() Run Extras previous step  

Configure JRE 1. Modify workspace for all projects.
AT HOME Step 0: Getting Started.(you may skip if working on our CS lab machines)
Launch Step 1: Create a new workspace and add core.jar to Java Project.
Config Step 2: Make MovingRectangle a Processing Applet
draw() Step 3a: Override (redefine) the draw() method
setup() Step 3b: Override the setup() method
Execute Step 4: Life cycle of a PApplet.
Extras Step 5: Extras

1. Modify workspace so all projects are Processing projects. 

This step will show you how to modify your Eclipse workspace so that all new projects can use the processing classes without having to manually import core.jar and add it do the build path. Do this if you plan to write many Prossing programs so that you don't have to manually add the core.jar library each time.

Add core.jar (an external jar file) to the default JRE:

To edit the default JRE:

  1. File -> New -> Java Project to open project wizard.
  2. Select Configure JREs to enter configuration dialog.
    select JRE that is listed and click edit
  3. Select the JRE you wish to edit
  4. Click Edit
    click edit to find the core.jar file and add to current jre
  5. Click Add External JARs
    find core.jar and select
  6. navigate to s:\processing-2.2.1\amd64_rhel7\core\library\
  7. Select core.jar file.
  8. Click Open
  9. Click Finish
  10. Click OK
  11. Continue with the current project you wish to create or Cancel the current project (for now).

Now, any new projects created will be able to use classes from the processing.core package.

 

2. Add PApplet to File->New->Applet menu

3. Add text to a processing program

To display text strings on your applet, use the fill() command to set the color of the text and the text() command to set the text to display anbd where to display the text.  For example:

fill( 0 );
text( "Hello World!" , 5, 10 ); // display text near upper left corner

4. Create an instance of Color and use that in place of RGB values.

Create an instance of color borderColor = color(255,127,0); and use the named color in other commands like stroke() and fill().

5. Change the frameRate() to change the animation speed

Use the frameRate( int ) command set the number of frames per second. A frameRate(1) will only refresh (draw) the screen once per second.

6. Challenges

  1. Can you create this figure with what you know now?
    The dimensions show the width and height of each rectangtry the polygon Processing method.
    Tip #1: scale the dimensions by 10pixels per unit (or more).
    Tip #2: make the applet dimensions 1 pixel wider and longer than the dimension totals shown (for displaying the border on all four sides).
  2. To place text on a figure, call textSize(24) to set the font size of the text and call text("text", x, y) to place the text string.
    fill(153, 102, 0);
    text("13", 10, 30);
  3. Can you draw the US flag: http://www.usflag.org/flagspecs.html?  Tip: use small rectangles in the place of stars to start with. Then, try this to make stars: https://processing.org/examples/star.html
  4. Can you make the background change color when the user clicks the background.
  5. Can you make a rectangle change color when the user clicks the rectangle.

Launch Create setup() draw() Run Extras previous step  


2015 Deb Deppeler