We are about to switch to a new forum software. Until then we have removed the registration on this forum.
float x,y,w,h;
float witchX = 70, witchY = 70;
float sunX=100, sunY=90;
float horizon;
int speed = 2 , speedY=2;
color colorbackground = 22;
void setup() {
size(600, 600);
smooth();
background( 255 );
textAlign(CENTER);
witch();
x= width/2;
y= height/2;
w= 60;
h= 20;
horizon = height/5;
}
void draw() {
background( colorbackground );
text ("Night", 120, 110);
text ("Day", 500, 110);
text ("Quit", 500,400);
text ("Witch", 110,400);
sun();
bird();
witch();
witchX = witchX + speed;
witchY = witchY + speedY;
if ((witchX > width-22) || (witchX < 0+22)) {
speed = speed * -1;
}
if ((witchY > height) || (witchY < 0)) {
speedY = speedY * -1;
}
}
void sun() {
// Draw sun
fill(255,255,0); // Yellow
ellipse(sunX, sunY,40,40);
// Sun's movement
if (sunX > width) {
sunX=0;
sunY= random( 10, horizon-20);
}
sunX= sunX+2;
}
void bird(){
//draw bird and make bird move
float birdY= horizon-50;
fill(145,40,130);
triangle(x,birdY, x-w,birdY-h, x-w,birdY+h);
triangle(x-25,birdY, x-w,birdY-h-25, x-w,birdY+35);
//move bird
x= (x+3);
if(x>width*1){
x=0;
}
}
void witch(){
//draw witch
fill(28,2,43);
rect(witchX,witchY, 25,50);
fill(255,0,0);
ellipse(witchX+10,witchY-10, 25,25);
ellipse(witchX+10,witchY-10, 10,10);
fill(150,50,50);
strokeWeight(5);
stroke(150,50,50);
line(witchX-25, witchY+50, witchX+35,witchY+50);
}
void mousePressed () {
if (dist(120, 110, mouseX, mouseY) < 60)
colorbackground=22;
else if (dist(500, 110, mouseX, mouseY) < 60)
colorbackground=222;
else if (dist(500, 400, mouseX, mouseY) < 60)
exit();
else if (dist(110, 400, mouseX, mouseY) < 60)
witch();
}
--
--
I need to put two different colors in each theme. In day, I want to put two day colors and the same thing with the night? How would I make the witch disappear so it only appears when the button is pressed? How would I put the moon so when I press sun or moon, it appears and my sun has brown outline, how would I get rid of it?
Answers
http://forum.processing.org/two/discussion/7892/halloween-witch
Thanks
ok, you probably want one rect sky and one rect earth for day and for night
so you had colorbackground=22; and colorbackground=222;
but now you need
change both vars in lines 89 and 91 make a { around }
(there is a color selector in the menu to choose good colors)
in draw use
you need a flag that indicates if witch is to be drawn or not.
now in draw() you say witch();
thus witch is always drawn
instead say
in line 95 say
declare witchDrawFlag before setup as
similar to the witch thing
sunDrawFlag = true;
when the sun is clicked sunDrawFlag = !sunDrawFlag;
so have another line in mousePressed () where you use dist to check the pos of the sun please
noStroke();
before drawing the sun
Best, Chrisir ;-)
thanks for sharing
handmade natural soap
I've tried what you've mentioned me here, but I think I did something wrong and I can't figure it out
what happens?
define both vars before setup()
It's working now, but "witch" and "exit" aren't showing up. I tried to make the moon so I basically copy the sun's code, but its not working. I put up the border, but I don't know how to put on every direction.--
you should show moon only at night and sun only at day
the words witch and Quit didn't show, because they had the same color as the earth background
I got it, but my moon is coming out with the sun. I need the moon when I hit the night button otherwise I don't want to see the moon. Same thing with the witch. So should I do what you did with the witch?
Yes
I did that, but both sun and moon are showing up when I run the code, I don't want that I want only moon in the night when I run it.
in these lines
where the colors are turned to day colors
say moonFlag = false; sunFlag = true;
within the { }
same for night colors
Good luck!
don't ever say moon(); in mousePressed(), say moonFlag = false; or moonFlag = true;
in draw() say
like you did with witch, you know?
What am I doing wrong now, most of the time my moon get outlined or it goes faster.
I added one more object, but my sun isn't showing up
after line 206 switch sun on
But its not working the way I want it
sunDrawFlag = false;
sunDrawFlag = true;
etc.
I want the sun or the moon appears when I hit the button, but instead both are appearing
read draw() : one moon is enough
just read mousepressed careful and draw as well
I figured out the Draw and I looked the mousepressed and did some changes, but still no result.
read your mousepressed() code please,
what if you hit "day"-button?
What happens, what want you to happen?
Is it because I have moonflag = true in day?
hoorray!
there are more errors
Same problem with sunflag
yes....
read careful your own code...
think it through...
as if you had to excute your program yourself...
it's all in your code
read mousePressed()
I turned both off now does it has to do something with sundrawflag=?
yes
So I should get rid of sunDrawFlag =!sunDrawFlag
yes. This line is meaningless when you set the flag right afterwards. Get rid of it.
oh boy.....
those are switches....
just turn them on and off how you need it
I tried in any possible with on and off, but didn't work
why?
post code
you still have 3moons in draw()!!! Bad.
and witch in setup()
Thank you so much, sorry for giving you a hard time.
you haven't given me a hard time, it's alright
here is what I made of it - only one moon in draw() now.
At the beginning, it is day, so sun is on, moon is off, witch is off (before setup()).
I also defined 4 fix colors that we use for the 4 backgrounds.
You still need to do some cleaning up the code.
;-)