#I having trouble with my codes set.color and animation
1 messages · Page 1 of 1 (latest)
@tidal wing do you want me to post it in the chat?
Yes it is what it's for
ok
var cakeWidth = 300;
var cakeHeight = 200;
var plateWidth = cakeWidth + 50;
var plateHeight = plateWidth/10;
// calculate the frosting circle radius
var frostingDropRadius = cakeWidth/24;
var candleHeight = cakeHeight/3;
var candleWidth = candleHeight/8;
var flameHeight = candleHeight/2.5;
var flameWidth = candleWidth * 1.5;
var cake;
var plate;
var WAIT = 1 ;
var seconds_left = WAIT ;
var numCandles = [];
var flame;
function start(){
drawCake();
var text = new Text("Happy Birthday!","30pt Arial");
text.setPosition(getWidth()/2 - text.getWidth()/2, getHeight()/2+text.getHeight()/2);
text.setColor(Color.RED);
add(text);
//add text under Happy Birthday that says"Click to blow out candles"
var text1 = new Text("Click to blow out candles", "20pt Arial");
text1.setPosition(getWidth()/2- text.getWidth()/2,getHeight()/2 + text.getHeight() +
text1.getHeight());
text1.setColor(Color.PURPLE);
add(text1);
drawCandles(numCandles);
setTimer(timeClock,1000);// will call timeClock every second
//until seconds_left == 0
mouseClickMethod(blowOutCandles);
}
function drawCandles(numCandles){
for(var i = 1; i < numCandles +1; i++){
var candle = new Rectangle(candleWidth,candleHeight);
candle.setColor(Color.RED);
if(i % 2 == 0){
var candle_x_pos = getWidth()/2 - candleWidth*i;
candle.setPosition(candle_x_pos,cake.getY()-candleHeight);
}else{
var candle_x_pos = getWidth()/2 + candleWidth*i
candle.setPosition(candle_x_pos,cake.getY()-candleHeight);
}
add(candle);
}
for(var i = 0; i < numCandles.length; i++){
flame = new Oval(flameWidth,flameHeight);
flame.setColor(Color.ORANGE);
flame.setPositionz(candle_x_pos);
add(flame);
}
}
function blowOutCandles(e){
flame.setColor(Color.WHITE);
//setTimer(timeClock,1000);// will call timeClock every second
//until seconds_left == 0
}
function timeClock(){
seconds_left--;
if(seconds_left == 0){
stopTimer(timeClock);
flame.setColor(Color.ORANGE);
//reset seconds_left
seconds_left = WAIT;
}
}
function drawCake(){
cake = new Rectangle(cakeWidth,cakeHeight);
var color ="#FFD0CF" ; // to make cake pink use "#FFD0CF", blue use "#C6E4EE"
cake.setColor(color);
cake.setPosition(getWidth()/2 - cakeWidth/2, getHeight()/2 - cakeHeight/2);
add(cake);
plate = new Rectangle(plateWidth, plateHeight);
plate.setColor(Color.BLUE);
plate.setPosition(getWidth()/2 - plateWidth/2, getHeight()/2 + cakeHeight/2);
add(plate);
var age = readInt("How old are you?");
drawCandles(age);
drawFrosting();
}
function drawFrosting(){
for(var i = 0; i < 26; i+=2){
var frosting = new Circle(frostingDropRadius);
frosting.setColor(Color.PURPLE);
frosting.setPosition(cake.getX()+frostingDropRadius*i,cake.getY() + cakeHeight);
add(frosting);
}
for(var i = 0; i < 26; i+=2){
var frosting = new Circle(frostingDropRadius);
frosting.setColor(Color.PURPLE);
frosting.setPosition(cake.getX() + frostingDropRadius*i,cake.getY());
add(frosting);
}
}
@tidal wing in my function drawCandles is candleWidth*i appearing on your screen?
i noticed that it does not show up in what i had pasted
im still stuck and its due tomorrow😭
#📄・posting-guidelines for formating and asking an actual question
You need help explain why? We can't guess what you need help for
Again, read the #📄・posting-guidelines
And not, we need much more details to understand what is going on and what you need help with
I reiterate, read the #📄・posting-guidelines
@tidal wing I added my photo of my code because my teacher specifically wants the code in a certain format that was given to us (by document)but guidelines are staying no images and I can’t really describe beyond my knowledge that my code is having a problem setting the color of my plate while the color of my cake is being set in the function makeCake
I’m not sure why it’s not working and my teacher gave us global variables for plate and cake