We are about to switch to a new forum software. Until then we have removed the registration on this forum.
void setup(){
size(1000,1000);
background(255)
int bearWidth=1/7*width;
int bearHeight=1/10*height;
int bearmiddleX=bearWidth*3+bearWidth/2;
int bearheadwidth=bearwidth/2;
int bearheadheight=bearheight*1/4;
int bearheadY=bearHeight*3+bearheadheight;}
//middlebear
void draw()
{
middlebear();}
void middlebear() {
fill(random(255),252,random(255));
strokeWeight(5);
ellipse(bearmiddleX,7/10*height,bearWidth,bearHeight);}
Answers
For starters: you forgot a semicolon, and case matters. A variable named bearWidth and a variable named bearwidth are two different variables.
Variables declared inside a function or another
{}
block are scoped/confined inside it!Since all your variables were declared inside setup(), they only exist there! 3:-O
That semicolon after background. Line 3.
If you are going to say, bearWidth, make sure you use the same case with it in other places.
And everything is in setup. You have not really done anything. Put a } in line 10.
Hope that helps.
thanks!! Am I aloud to do: int bearmiddleX=bearWidth*3+bearWidth/2; ?
Of course! Because bearWidth is defined. As evidenced by the int you made.
I see! I also don't quite understand why I should put a } in line 10 when it exists in line 9. There still are a few problems(I can press play but only the default gray screen comes up).
When typing in inside Processing's IDE, use CTRL+T all the time in order to auto-format your code!
It greatly aids us in spotting any misplaced
{}
and much more! *-:)Like this?
You don't need to put the bracket in line 10 anymore. How about you put what you drew in middle near in draw. Don't complicate it too much for now. Don't make a void middlebear function for now if you can help it. I would do that if I'm going to draw more than one thing.
Good luck again.
And your last bracket is not with your function, its kind of off to the outside.
Glad I could help!
I don't quite understand what you mean by what I drew in middle. Do you mean the //middle bear should be inside the draw? And I'm going to be drawing a few more bears so I need the function void middlebear.
Okay, I got you don't worry.
Do this:
That is what I would do. I mean, sometimes putting it out there could be a little confusing, so I thought this could help.
//middle won't affect the code. Processing does not read it. It's just a note for you, the user, so that you know what it is.
:)
An online example you'd be interested in: =:)
http://studio.processingtogether.com/sp/pad/export/ro.93n3OpWs89REU/latest
Wow, your very helpful! thanks for the help, unfortunately the code still seems to be not working. Nonetheless, I learnt tons of helpful tips from you! I'm really glad you were online when you posted.:)
I think the problem is due to the parameters of the ellipse(when drawing middle bear) to be incorrect. I'll post if I solved the solution. p.s has this stuff every happened to you?
Thanks. And has it happens to me? Of course! Remember this, the smallest mistakes can mess you up. I'll continue working on your code to see if I canvas fix it! Hold it, what is 7/10 the height? Maybe try putting in the actual numerical value and see what you get.
Yeah sorry forget about that next post please. I misread your code. Heh heh, see? Everyone makes mistakes! :)
In Java when both operands are whole values in a division, the fraction part is removed from the result!!! :-&
At least, 1 of the operands gotta be a fraction values for a fractional division to happen:
7.0/10*height
Yeah about that processing has some trouble with fractions, I tried it once, and it didn't work. Try the numerical value so that would be:
500*.7 which equals: 350
You included a decimal point in 7.0 would that mean the data type would then become a float? since float deals with decimal numbers?
That's right. It's a common logical bug in Java forgetting the division dual modes: integer and fractional! :-B
I don't really know. Just try the 350 for now. It could work. For float, I would say it would only be a float if you wrote
float= 7.0;
Or something like that.
still no go :(
@TechWiz777, Java coerces a whole value to become fractional when iterating w/ another fractional value! :>
Therefore, in this expression
7.0/10*height
, the(int) 10
is coerced to become(float) 10.0
due to the other(float) 7.0
operand for the/
operation! :-BSince its result is a
float
, the height's value is also coerced to become afloat
type for the*
multiplication!@GotoLoop That makes sense. Just wondering, do these types of problem occur frequently in processing :(
Got nothing to do w/ Processing, which is merely a framework library atop Java!
Any programming language got its own rules for arithmetic expressions!
Common strategy among them all is coerce any whole value to fractional when the latter is present.
Since integer operations are generally faster than fractional 1s, values should continue at their integer state until fractional is actually needed! ~O)
Yeah, I'm 10000% sure it the ellipse that's the culprit. I cropped out a large chunk of code only to leave variables and the ellipse and It did not seem to play.
I'll post again if I've got it figured.
OK! Let's make a tiny experiment. Type in these lines and see for yourself:
Why can't we try 350?
doesn't work in the code above, because it is evaluated before setup() is called, so size() hasn't be called yet, so width and height are still 0.
Do:
In the first lines, the variables are declared (and get a default value of zero), in setup they are initialized to their value. Notice we don't repeat their type, otherwise it will make different local variables.
Oh! Forgotten to notice that other bug b/c once I've spotted
7/10
, I stopped looking for other bugs! #-oAh! And of course,
.7
replaces7.0/10.0
much more fittingly! 3:-O