Publisher Lab 4 4 4

Lab Assignment Number 4 –cs258

  • LAB 4 Inverse Kinematics 4.1 Important Read the entire lab before starting and especially the Grading' section so you are aware of all due dates and requirements associated with the lab.
  • Lab 4: Food Calories Report: You have been hired by a textbook publisher to evaluate the accuracy and feasibility of laboratory experiments for first-year chemistry students. The first lab they send you to evaluate is a lab involving the concepts of heat and energy. Use your results to submit your opinions to the textbook publisher.
  • Publisher Lab - Templates 4.4.4 Jumsoft’s Publisher Lab for Pages is a powerful companion to supercharge your personal and business Pages documents! Make use of thousands of professionally-designed templates with limitless customization opportunities.

Keyboarding/Computer Basics Lab Beginners Welcome (4 week session) The Location: Arlington Peers Helping Peers In Recovery When: Mondays Thru Fridays Welcome to MS Word and Excel: Word - Learn how to create, design and construct documents, use spellcheck, format text and paragraphs, use tabs and insert graphics/objects and more. View Homework Help - Pre-Lab 4 from BIS 2B at University of California, Davis. The two Barssica morphs used in this lab differ at the body color locus. List three other aspects of.


1)Tobecome comfortable with recursion.

2)Tobecome comfortable with the GUIs using the Graphics class.

3)Tounderstand how to position to pixels on the display.

4)Tounderstand how complex graphics can be created using fractals.

5)Implementa graphics program using recursion.

Synthesis Questions

1)Whyis a basis case needed for recursive programming?

2)Arerecursive methods faster or slower than equivalent iterative methods? Why?

3)Whatis an activation record?

4)Supposewe pass the value 16 to a recursive method with formal parameter n where thebasis case is n1. If the basis case is false, a recursive call is passed thevalue n/2. What is the maximum number of activation records on the stack duringthe evaluation of this method?

5)Write recursive programs tosolve the following problems:

a.PrintOdds -- Printthe odd numbers between 1 and n.Assumen is non-negative.

b.CountSubStrs -- Countthe number of times a substring occurs within a string. For example'ab' occurs 4 times in 'abbaababccab'.(Both the string and the substring must besupplied to the recursive method.)


1)Thelisting of is supplied below as a starting point for this lab.A picture of output is also shown. Either cut/paste the codeor type it in. Run the program to verify that it works. Study the listing untilyou understand completely what it does. In the Java Class Library (appendix M)look up Graphics, Point, and Applet if you need to refreshyourself on how to use these classes.

2)Thisis a good lab to make changes one at a time. In this way, you won't ever be toofar from having a working program. Always make a backup copy after each step.Name your new program A picture of the output of Dan’sversion of this program is shown below.

3)Firstlet’s tackle some easy changes.

a.An easychange is to set the background color in the init()method. The Applet class method setBackground() can be called to color the sky section.There are examples of setBackground() in the text.

b.Anothereasy change is to color the grass section green. First use setColor() toalter the foreground color that will be used. The graphics method fillRect()can than be called. In Dan’s completed program,whose output is shown below, the grass occupies the bottom quarter of thedisplay. Redownload office with product key. Remember that Java considers the point (0,0)to be the upper left corner of the display; the coordinate (APPLET_WIDTH,APPLET_LENGTH) is the bottom right corner (See the listing below); and 0degrees points vertically down towards the bottom.

c.Next use setColor() in the drawTree()method to turn the bark of the tree brown.

4)Inthis lab you will declare many constants. As you proceed with theimplementation, if you are tempted to write a hard-coded number, declare aconstant to hold it, e.g., note how APPLET_WIDTH, and APPLET_LENGTH aredeclared in the listing below. This strategy allows you to see how differentvalues affect the output by changing the value of a constant without having toalter your programmed logic.

5)Now letsconcentrate enhancing the trees that are drawn. We'll need to widen the trunk,add leaves, and randomly vary the number/length/angles of the tree branches.

a.Firstcreate a method that randomly picks a number between two integers. It's a goodidea to make this a method because we'll be using it many times in this lab.The signature line is: intpickRandom(int min, int max); You canuse the method Math.Random() to pick arandom number between 0 and 1. That value needs to be scaledbetween min and max; and the scaled result is returned. Anexample of the use of this method is x = pickRandom(3, 10). Afterthe call, x will have some value between 3 through 10. pickRandom() needs to contain only one executablestatement.

b.UsepickRandom() to effect how drawTree() works.The number of branches, the angles of the branches, and the lengths of thebranches will be varied randomly at each level of recursion. Dan’s programvaried the number of branches between 2 and 6; the angles between-40 and +40 degrees from that of the parent branch; and the length of a branchbetween 1/10 and 9/10 of that of the parent branch.

6)Nextwiden the branches so they are not stick figures. One way to accomplish this isto use the GraphicsfillPolygon()method. You'll need four horizontaland vertical coordinates. If (x,y),and (x',y') representsthe coordinates for the ends of a branch and width represents the widthof the branch; the four points to be supplied to fillPolygon()are (x,y), (x+width,y),(x'+width,y'), and (x',y'). It is a good idea to tiethe length of the branch to the width. Dan used an 8 to 1 ratioin his implementation.

7)We need a method to draw the leaves. This method is tobe called by drawTree() each time it finishes drawing a branch. Seeif you can figure out the proper place(s) to insert this call in the Tree.javalisting shown below.

a.Thefollowing signature should be used to implement the method to draw a leaf:
public void drawLeaf
(Graphics g,intx,inty,intw,inth,double
angle,int order);
where: x,y = the coordinates fortop left corner of a rectangle surrounding the leaf; w,h = the width and height of thisrectangle; angle = the angle of the direction that the leafpoints, order = the level of the recursion. You may assumethe size of yourleaf is fine, so long as it fits inside the bounding box at angle 0 or angle180. I.e., you don’t need to worry about the angle the leaf points whencomputing whether the leaf fits inside the bounding box.

b.As aninitial step draw something simple without recursion. Drawing a circle or ovalwill suffice for this step. A simple drawLeaf() implementation allows you to establish thatthe leaves are being inserted properly on your tree. In this version of drawLeaf(),set the color to some shade of green. The statement Color color = new Color(102, 153, 51);instantiates a dark green. The 102, 153, and 51 in the abovestatement are respectively the red, green, and blue components of theinstantiated color.

c.If everythingworks so far, we're ready to program the real drawLeaf()method. I would suggest that you debug it separately and then plug it intothe program after you know it works.

.The first requirement for this method isthat it should have at least three levels of recursion. The initial call willspecify the order parameter to be total levels of recursion (ex: 3).The basis case to terminate the recursion is when order< 1; Recursive calls to the leaf method specifies the last parameter as order- 1 so the basis case will eventually be reached.

Your part in this design is to come up with a fractal pattern that resembles a leaf. Any reasonablepattern that you come up will suffice. See the snowflake example in the text tobecome familiar with how to draw images using fractals.This subrequirementis not well integrated with bullet i. – at least 3levels.The intent was to color the“new” portion of the fractal at level n with a different color than was used onthe “old” portion at level n-1.Eachlevel needs to add something to the leaf, and the addition must use a newcolor.

A final requirement for the drawLeaf()method, is to vary the colors at each level of recursion. A simple array colors[] = new Color[3] can be created forthis purpose (Assuming 3 levels of recursion). An example of a statementthat could be used is page.setColor(colors[order]); where order is therecursion level and page is the instantiated Graphics object.Remember to instantiate the array object itself and also to instantiate eachindex of the color array with a color. Lots of rgbcolor patterns can be found on the Internet.

Publisher lab 4 4 4 6

iv.The final step relating to the tree phase of theproject is to draw multiple trees. Randomly select the size and position ofeach tree. The base of the tree should be in the grass area. Dan varied theinitial tree size between 20 and 100 pixels. Make sure to draw atleast 3 trees. You can draw more if you like. Dan drew 8 in hisimplementation.

8)Nowwe move to the task of drawing the clouds. The first step is to succeed drawingone cloud. A good java method that can be used is fillOval(),which is called using the variables x, y, width, and height. Note that the x,y arguments given to fillOval() point to the pixel at the top left cornerof the oval; not the middle. The signature for the method to use for drawingclouds is:
void drawCloud
(Graphics page, int x, inty, int w, int h, int order)

where: x, y is the coordinate of the top left pixel of the cloud’s boundingbox; w,h indicates the width and height of thecloud’s bounding box; order is the level of recursion.
You can design your drawCloud method as you wish, butDan used the following pseudo code to draw his clouds.
RETURN if level <= 1
Randomly pick a color and fill the oval using x,y, w, and h

Hint: To make ‘whispier’ looking clouds,create new color objects using low ‘alpha’ values.

Find the middle of the oval (x+w/2,y+h/2)

FOR a random number of recursive calls
Randomly pick an angle
Randomly pick a distance from the middle
Compute a new point (newX, newY) based on angle/distance from x/y
Randomly pick a new width (newW)and height (newH)
Recursively call drawCloud using newX, newY, newW, newH

9)The final step is to draw multiple clouds. Randomlypick the coordinates and the size of each cloud. Dan’s program drew 30 clouds,each having a random width and height with a 75 pixel maximum.All of his clouds were drawn starting on the top half of the screen so theywould not likely expand to the grass section.

10)Answer the synthesis questions in an rtf or doc file(answers.rtf or answers.doc). Type your name and the lab number on this fileand include the questions with the answers.

11)Zip your Eclipse project along with the synthesisanswers and submit it on moodle.

Listing of

// Program to create a recursive tree.

// This is the basis program to be usedto start the cs258 project on recursion.



publicclassTreeextendsApplet {

privatefinalintAPPLET_WIDTH= 320;

privatefinalintAPPLET_HEIGHT = 320;

privatefinaldoubleSTART_SIZE= 110.0;





// Initialize the applet.




Publisher Lab 4 4 4 6

// Create the drawing that displays onthe applet.

publicvoid paint(Graphics page) {



publicvoiddrawTree( Graphics page, intx, inty, doublesize, doubleangle ) {

Point endPoint = calculatePoint(x, y, size, angle );

page.drawLine(x, y, endPoint.x, endPoint.y);

if (size > MIN_SIZE) {

drawTree(page, endPoint.x, endPoint.y,


drawTree(page, endPoint.x, endPoint.y,




public Point calculatePoint(intx, inty, doublesize, doubledegree ) {

Point point = new Point(x, y);

doubleradians = Math.PI/180* degree;

point.x+= (int)(size * Math.sin(radians));

point.y+= (int)(size * Math.cos(radians));




Output of

Sample output


3219 Columbia Pike, Suite 101, Arlington, VA 22204, (703) 567-1346

Free Computer Classes

Publisher lab 4 4 4 4 math game

Beginning the week of

April 2020

Computer Basics



Publisher Lab 4 4 4

Microsoft Word

Publisher Lab 4 4 4 8

Keyboarding/Computer Basics Lab

Beginners Welcome

(4 week session)

The Location:

Arlington Peers Helping Peers In Recovery

When: Mondays Thru Fridays

Welcome to MS Word and Excel: Word - Learn how to create, design andconstruct documents, use spellcheck, format text and paragraphs, use tabs andinsert graphics/objects and more.

Excel, learn how to create, organize and structure a spreadsheets; use formulas, charts and other graphics to develop basic and advanced Excel sheets.

There are no registration/reservations orpre-requisites – just Drop-In anytime! Thanks, and tell a friend!

10 AM to 2 PM (Free!)

Where: 3219 Columbia Pike, Suite #101

Arlington, VA 22204

4.4.4 Android


Contact: Gregory at 703.567.1346 or E-mail him at [email protected]

Publisher Lab 4 4 4 10 Kg

visit Arlington Peers Helping Peers website: