# 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.

**Goals**

*GUIs *using the* Graphics* class.

**Synthesis Questions**

**Description **

*Tree.java* is supplied below as a starting point for this lab.A picture of *Tree.java* 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.

*NewTree.java*. A picture of the output of Dan’sversion of this program is shown below.

*init*()method. The *Applet *class method *setBackground**(**) *can be called to color the sky section.There are examples of *setBackground**(**) *in the text.

*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 *0*degrees points vertically down towards the bottom.

*setColor**()* in the *drawTree**()*method to turn the bark of the tree brown.

*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)

*int**( 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.*pickRandom**()* to *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.

*Graphics**fillPolygon**(**)*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*x . It is a good idea to tiethe length of the branch to the width. Dan used an

^{'}+width,y^{'}), and (^{'},y

^{'})

*8*to

*1*ratioin his implementation.

7)*drawTree**(**)* each time it finishes drawing a branch. Seeif you can figure out the proper place(s) to insert this call in the *Tree.java*listing shown below.

*public void drawLeaf (Graphics g,intx,inty,int w,inth,double*

*angle,int order);*

where:

*x,y*

*=*the coordinates fortop left corner of a rectangle surrounding the leaf;

w,h

*=*

*angle =*the angle of the direction that the leafpoints,

*order =*the level of the recursion.

*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.

*drawLeaf**()*method. I would suggest that you debug it separately and then plug it intothe program after you know it works.

*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.

*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 *rgb*color patterns can be found on the Internet.

iv.*20* and *100* pixels. Make sure to draw atleast *3* trees. You can draw more if you like. Dan drew *8 *in hisimplementation.

*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**

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)*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)**Type your name and the lab number on this fileand include the questions with the answers.**

11)

// Program to create a recursive tree.

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

**class**__Tree__**extends**Applet {

**final****int**APPLET_WIDTH

**final****int**APPLET_HEIGHT

**final****double**

**final****double**

**final****double**

**final****double**

**final****double**

// Initialize the applet.

**void**init(){

}

### Publisher Lab 4 4 4 6

// Create the drawing that displays onthe applet.

**void** paint(Graphics page) {

}

**void**drawTree( Graphics **int**x

Point

**if**

drawTree(

size

drawTree(

size

}

}

**int****int**

Point **new** Point(x

**double***PI*

**int***sin*(

**int***cos*(

**return**

}

}

**Sample output ofNewTree.java**

0

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

**Free Computer Classes**

**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

**Class-site:**https://sites.google.com/site/arllab4/

**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: