Question Description
I’m working on a javascript exercise and need support to help me study.
Lab Lesson #8 – Loopy For-ests
See Gitbook for supplemental content – using math formula to draw patterns:
https://kdoore.gitbook.io/cs1334/loops-using-math-…
my forest project: https://www.khanacademy.org/computer-programming/l…
1.Spin-off a copy of your forest project from Lab 4, where you wrote 2 functions:
Leaf ( x, y, leafAngle ) //x,y position, leafAngle of each leaf
Tree ( x, y ) //x,y position of each tree
2.Using the copied project, modify your code to generate:
at least 20 trees with at least 100 leaves on each ?tree
– Dont include more than one call to your tree function or leaf ?function in your code. (instead, use the for-loops to create multiple trees, multiple leaves on each tree)
– Use 2 for-loops to generate multiple copies of each object (1 loop for trees, 1 loop for leaves)
– Use one for-loop to call the Tree function ( 20+ times)
– Within the Tree function, use one ?for-loop to call the Leaf function ?(100+ times)
– See details of math function for Leaf x, y, input parameters below
– Use a constant or random value for the leafAngle parameter
– Do not use draw( ) function ?
3.Use random numbers: (a, b) and mathematical formulas to place the leaves on the trees
- Generate two random numbers, with min, max as specified below:
- 0 <= a <= w [w is the size of tree or however big you want] ?
- 0 <= b <= 360 [ angle ]
Pick a math equation to generate a pattern,?below
Or, create your own pattern
Circle |
x = a*sin(b) |
y = a*cos(b) |
Oval |
x = a*sin(b) |
y = 2*a*cos(b) |
Half-circle |
x = a*sin(b/2+90) |
y = a*cos(b/2+90) |
Triangle |
x = a*sin(b) |
y = -a |
Conifer |
x = a*cos(b/2) |
y = a*sin(b+90) |
Crown |
x = a*cos(b/2) |
y = -abs(a*sin(b+90)) |
Butterfly |
x = (2*a/w)*((b+45)%90- 45)*sin(b) |
y = (2*a/w)*((b+45)%90- 45)*cos(b) |
4. Save your code and submit following the lab submission instructions on e-learning