Viral Post

Can someone help me with this coding assignment

Context/Assignment: This is the base code which I have to change. There has to be 5 random colors only and the code has to affect each individual leaf/oval. I've been working on it for a few days, but I still don't know what I have to change up and how the randomizer works. Can someone please help me?

Description:

It’s fall, which means it’s time for the leaves to change! Use the getRandomFallColor() function to change the color of the leaves on the tree. Use 5 colors.

Starter code!

// use this function to get a random fall color!

function getRandomFallColor(){

var colors = [];

return colors[Randomizer.nextInt(0, colors.length - 1)];

}

function makeTree(){

var tree = new Rectangle(50, getHeight());

tree.setPosition(getWidth()/2 - 25, 0);

tree.setColor("brown");

add(tree);

for(var z=0; z < 6; z++){

for(var i = 0; i<25; i ++){

makeLeaf(25*i, 60*z);

}

}

}

function makeLeaf(x,y){

var rotation = Randomizer.nextInt(50, 125);

var oval = new Oval (100, 45);

oval.setPosition(x, y);

oval.setRotation(rotation);

// hint: this is where we set the leaf's color!

oval.setColor('green');

var oval2 = new Oval (101, 46);

oval2.setPosition(x, y);

oval2.setRotation(rotation);

oval2.setColor(Color.BLACK) ;

add(oval2);

add(oval);

}

makeTree();



Submitted April 01, 2019 at 03:48AM by Aqibs123 https://ift.tt/2UhWpSf
Share:

Blog Archive

Labels