|
-
July 20th, 2005, 09:42 AM
#1
how to use rgb color?
I want to create a program that when I click, it will display a square with rgb color(fill).
and everytimes I click, a new square with different color will appear.
please provide rgb code.
>>
or any other idea, the concept is to display different color everytimes I click the mouse. (it doesnt have to be rgb.)
>>
thanx!
-
July 27th, 2005, 05:08 AM
#2
Re: how to use rgb color?
Hi,
U can set a color to graphics object as below:
g2obj.setColor(Color.blue);
You can also create your own color objects:
1. Color ( int red, int green, int blue)
parameter values between 0 and 255
2. Color ( int red, int green, int blue , int alpha )
4th parameter transparency measure
0 - transparent
255 - opaque
also exist with float parameters…….
3. Color ( float red, float green, float blue)
4. Color ( float red, float green, float blue , float alpha )
parameter values between 0.0 and 1.0
After deciding upon the sequence of colors, Use MouseMotionListener and change color
-
July 27th, 2005, 05:55 AM
#3
Re: how to use rgb color?
You can get the the device context of the dialog and OnLButtonDown do as shown in the code snippet ..
void CKeyboardcaptureDlg::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
char lschar;
lschar = char(nChar); //Get the Key Up character
CClientDC dc(this); //Get the device context for this dialog
CRect rc;
GetWindowRect(&rc);
ScreenToClient(&rc);
if(lschar == 'R')
{
dc.FillSolidRect(rc,RGB(200,4,56));
}
if(lschar == 'T')
{
//CString strText = "Hello world";
//dc.DrawText(strText ,rc,DT_MODIFYSTRING);
dc.FillSolidRect(rc,RGB(0,4,244));
}
CDialog::OnKeyUp(nChar, nRepCnt, nFlags);
}
-
July 27th, 2005, 07:04 AM
#4
Re: how to use rgb color?
To generate random colors everytime. Use Math.random()*255
Give the below code in mousePressed()
int r=(int)(Math.random()*255);
int g=(int)(Math.random()*255);
int b=(int)(Math.random()*255);
Color c=new Color(r,g,b);
gr.setColor(c);
gr.fillRect(50,50,100,100);
Let me know, if you still have problem.
-pkalp
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|