Page 1 of 1

begginer's lesson 9

Posted: March 21st, 2015, 4:52 pm
by sudhanva
i could not do that box reducing home work and box colour homework please help me how to do in detail and include source code :shock:

Re: begginer's lesson 9

Posted: March 22nd, 2015, 5:30 am
by albinopapa
What help do you need? What part did you not understand?

Changing the box size is done by making the width and height variables and being able to change them based on some condition, like pressing the enter key.

something like if(enterispressed) { boxWidth = boxWidth + 1; boxHeight = boxHeight + 1;}
if you are referring to the cursor changing color while inside a box, you need to think about how the box is defined. It has a left, top, right and bottom edge. The cursor also has these boundaries. So you need to test whether the boundaries of the two objects overlap. Draw a picture in Paint of how two boxes might interact with each other and see if you can come up with a logical statement that matches your observations.

Sharing code isn't a problem here, it's giving someone the answers instead of helping them learn that is the problem. If you are still stuck, upload a cleaned solution (check the sticky on the main forum page to read how to do this) of what you have and someone will help you.

Re: begginer's lesson 9

Posted: March 22nd, 2015, 9:17 am
by sudhanva
I did not understand the colouring one i tried making variables for r g b the if(kbd blablabla is pressed)
Then r= r+1 and same for other but it did not work blank screem apEared could please share colour box code :cry: :|

Re: begginer's lesson 9

Posted: March 23rd, 2015, 10:11 pm
by cameron
1)Code may never be getting called( due to condition or other reasons )
2)You never initialized your color variables.
3)You are not using your color variables in putpixel.

Btw you can just say var += amount.

Re: begginer's lesson 9

Posted: March 24th, 2015, 3:33 am
by sudhanva
Did not understand what you have typed
But i habe intialised color variables tried using loops but no use please share source xode

Re: begginer's lesson 9

Posted: March 24th, 2015, 4:28 am
by cameron
I did that 3 years ago. I no longer have that source code.
Should be something like:

Code: Select all

if(kbd.YourKeyIsPressed())
{
r = g = ++b;
}

if(kbd.OtherKeyIsressed())
{
r = g = --b;
}

for(int y = yPos, yEnd = yPos + height; y < yEnd; y++)
{
for(int x = xPos, xEnd = xPos + Width; x < xEnd; x++)
{
gfx.putpixel(x,y,r,g,b)
}
}

Just make sure all your vars are inited in ctor

Re: begginer's lesson 9

Posted: March 24th, 2015, 6:22 am
by albinopapa
cameron wrote:I did that 3 years ago. I no longer have that source code.
Should be something like:

Code: Select all

if(kbd.YourKeyIsPressed())
{
r = g = ++b;
}

if(kbd.OtherKeyIsressed())
{
r = g = --b;
}

for(int y = yPos, yEnd = yPos + height; y < yEnd; y++)
{
for(int x = xPos, xEnd = xPos + Width; x < xEnd; x++)
{
gfx.putpixel(x,y,r,g,b)
}
}

Just make sure all your vars are inited in ctor

In case the lines:
r = g = ++b;
and
r = g = --b;
are unfamiliar to you, they say add or subtract from b then assign b to g then assign g to r.

The use of ++ or -- before and after the variable has different effects.

If cameron had written it as:
r = g = b++; then it would say, assign b to g then g to r then increment b by 1, so r and g would be less than be for each frame, or in the case of r = g = b--; r and g would be one more than be each frame.

Re: begginer's lesson 9

Posted: March 29th, 2015, 3:26 am
by sudhanva
No use it did not work
It will become black to white when i use r=g=++b, or either case it of no use give me the correct code :cry: :evil: :| :( :?: :cry: :( :evil:

Re: begginer's lesson 9

Posted: March 29th, 2015, 4:27 am
by albinopapa
k, tell ya what. Upload your project as described in the sticky post from the main thread, and I will check to see what the problem is and post the correct code.

here is the link that tells how to clean and upload your project
http://www.planetchili.net/forum/viewtopic.php?f=3&t=2

Re: begginer's lesson 9

Posted: March 29th, 2015, 6:56 pm
by cameron
You have to remember most of us did this years ago and don't want to watch 9 videos to get the exact code he has( when we know how to do it ). You could try implementing single key presses with a simple bool variable to check if key was pressed last frame, and do outofbound checks on the colors, it might be why color changes so rapidly. You should first try debugging, if you cant find the problem upload your solution as albino said.