NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

JDK1.0.2 simulations (1996-2001) => Optics => Topic started by: Fu-Kwun Hwang on January 29, 2004, 10:13:21 pm



Title: Colors (Mixing color or paint: R/G/B)
Post by: Fu-Kwun Hwang on January 29, 2004, 10:13:21 pm
Thomas Young, in the early 1800s, showed that a broad range of colors can be generated by mixing three beams of light, provided their frequencies were widely separately.
When three such beams combine to produce white light, there are called primary colors.
There is no single unique set of these primaries, nor do they have to be monochromatic.
The three components (emitted by three phoshors) that generate the whole gamut of hues seen on a color TV set are Red, Green, Blue.

Looking through a colored window or cloth is another story.
 Yellow cloth, paper, dye, paint, and ink all selectively absorb blue and reflect what remains - yellow - and that is why they appear yellow.
This java applet let you play with mixing light beams and paint pigments.





Click the right mouse button twice quickly to switch between two different modes:


Modebackground
Mixing light beamsblack
Mixing paint pigmentswhite


Click left mouse button and drag one of the colored oval to move it around.

Enter RGB values into the text field to change the color of the selected oval.
The color code (RGB value) at the mouse tip are shown in colored background.


Title: Java Code
Post by: noob on May 24, 2005, 05:09:40 pm
Hello!
I need the java code
i hope you can help me!
thx noob :D


Title: topic39
Post by: Fu-Kwun Hwang on May 25, 2005, 08:21:25 am
Java code: java source code or java class code?
If you just want the java class files , login and press the GET APPLETS FILEdS button, the system will send file to your email acount.


Title: topic39
Post by: Simone_P on August 17, 2005, 11:10:48 pm
I remember the first applet I saw about optic,was yours [with lens and mirrors]...
I liked it very much.I shall show it  to my pupils,soon.


Title: Hello fellow nerds
Post by: squika on February 28, 2006, 10:13:40 am
I really enjoy Science, espceially the hard ones. I am really smart but, so if u are trublles dont feel free to hesistatie to even think about calling me :)


Title: color
Post by: newton_83 on April 04, 2006, 06:43:54 pm
Hey hwang, can u send me the complete JAVA file, class and code to my email address?
i really appreciate it..
n a question about RGB: the subject is a supervising camera, and in order to set an alarm, a difference in the picture taken should occur different than the oroginal one, so i thought of performing a pixel comparaison with RGB values. I need to know how to compare them both n how can i get the values, is there any equation for it?
thanks..


plz reply to me on lethe_83@yahoo.com


Title: Need clarification
Post by: rhipple on April 05, 2006, 01:52:08 am
I don't understand the question. Pixel by pixel comparison means

(R1,G1,B1) - (R2,G2,B2) = (0,0,0)

in my mind so please clarify!


Title: Pls give me the Java souce code of this applet...
Post by: santhosh on September 26, 2006, 01:23:34 am

Mr Huang...can u pls send me the JAVA SOURCE CODE to my email account..??..It will be  
a great favour..Thanks in advance....

Santhosh..

Email   :  santhoshkv99@gmail.com






Title: f
Post by: mariegoodlad on October 08, 2006, 06:35:12 pm
it has been sent to my email but will not work.  can you help?


Title: topic39
Post by: berkeley74 on November 10, 2006, 02:01:05 am
thanks


Title: Java Source Code
Post by: tankw on November 12, 2006, 11:46:31 am
Hi Mr Hwang,

I would like to know how to calculate the mixing of color or paint together. Is that possible for me to get the Java source codes from you. Please email to me: kwtan21@gmail.com

Thanks

K.W.Tan



Title: topic39
Post by: macavity042 on January 05, 2007, 03:58:29 am
Mr. Huang,
I have a question I was hoping you might help with. It actually has nothing to do with physics, but I'm in the process of coding a neural network that can read 'hand'-written (or rather, mouse-written) characters. Ironically, while creating a neural network was no problem, I couldn't figure out how to do something you did in the applet up there. I was wondering how you managed to detect the colour of a given pixel.

If you could either point me in the right direction, or even better, if you'd be willing to send the source code, I'd be greatly appreciative. Thanks!

macavity042AThotmail.com




Title: how to compare RGB values of two images
Post by: garima on March 06, 2007, 01:36:34 pm
hello..
how can we compare RGB values of two images and show the percentage of matching..??



Title: Re: topic39
Post by: Fu-Kwun Hwang on March 06, 2007, 05:11:52 pm
Mr. Huang,
I have a question I was hoping you might help with. It actually has nothing to do with physics, but I'm in the process of coding a neural network that can read 'hand'-written (or rather, mouse-written) characters. Ironically, while creating a neural network was no problem, I couldn't figure out how to do something you did in the applet up there. I was wondering how you managed to detect the colour of a given pixel.

If you could either point me in the right direction, or even better, if you'd be willing to send the source code, I'd be greatly appreciative. Thanks!

macavity042AThotmail.com

The source code are included in the ZIP file you will received if you click DOWNLOAD APPLET FILES FOR OFFLINE USE button.
However, there are all written many years ago with JDK1.0.2


Title: Re: Colors (Mixing color or paint: R/G/B)
Post by: Fu-Kwun Hwang on March 21, 2007, 05:34:28 pm
The following is a message I received in my email box:
Quote
john welch :
> Hi. I just tried out your color mixing applet. I changed the three ovals to these values:
> 100,100,55
> 100,55,100
> 55,100,100
>
> I wanted to show students that you didn't have to add 3 monochromatic sources to get white.
> But it looks like the applet is averaging the values rather than adding them, so that in the center of these three ovals I get 119, 119,199, where I would expect 255,255,255.
> I know you don't want to go over 255, but could you do something like max(a+b+c, 255) ?
> Actually, I guess that would distort the color balance if one of the rgb's was cut off at 255 and the other's weren't.
> So how about a scaling factor, like:  taking the maximum value of the sum of the individual rgb's then scaling that down to 255 if it goes over, and applying that scaling factor to all the other sums.
> for example:
>
> max value= max(ar+br+cr, ag+cg+cg, ab+bb+cb)
> if max_value > 255 then scale_factor = 255/max_value
> else scale factor =1
>
> red_value = (ar+br+cr) * scale_factor
> green_value = (ag+bg+cg) * scale factor
> etc
>
> what do you think?
>


In the world of computer, everything is done in binary form.
And that is how the above applet works.
The Red,Green, Blue value will be shown in (R,G,B), i.e. (255,0,0) means red light
For example: For mixing light beams, it not adding the decimal value or binary value to give us the sum (final color value). It is a (OR) operation between two (or more) binary values.

(255,0,0)+(0,255,0)=(255,255,0) : Most of us will not have problem with this, because red + green will give us yellow light. 
In binary term: it is (1111 1111,0000 0000,0000 0000) OR (0000 0000,1111 1111,0000 0000) = (1111 1111,1111 1111,0000 0000)

(255,0,0)+ (255,0,0) = (255,0,0) : Two red lights emitted at the same place will give us red light.
So the result is not the algebra sum of decimal values.
In binary term: it is  (1111 1111,0000 0000, 0000 0000) OR (1111 1111,0000 0000, 0000 0000) = (1111 1111,0000 0000,0000 0000)

(64,64,64)+(64,64,64)=(64,64,64) : The same light mixing together, what is changing is the light intensity (not the color)
In binary term: it is (0100 0000,0000 0000, 0000 0000) OR (0100 0000,0100 0000,0100 0000)= (0100 0000,0100 0000, 0100 0000)

(64,64,64)+(32,32,32)=(92,92,92) : Because it is a sum of two different color, so the final color is different
In binary term: it is (0100 0000,0100 0000,0100 0000) OR (0010 0000,0010 0000,0010 0000)= (0110 0000,0110 0000, 0110 0000)


I hope the above examples, will help most of you understand how this applet works.
And it is also the same way, how our vision about color works.
For more information, please check out The human eye (http://users.rcn.com/jkimball.ma.ultranet/BiologyPages/V/Vision.html)
The following information are from the above page.
Quote
Four kinds of light-sensitive receptors are found in the retina:

    * rods
    * three kinds of cones, each "tuned" to absorb light from a portion of the spectrum of visible light
          o cones that absorb long-wavelength light (red)
          o cones that absorb middle-wavelength light (green)
          o cones that absorb short-wavelength light (blue)
Cone Vision

Although cones operate only in relatively bright light, they provide us with our sharpest images and enable us to see colors. Most of the 3 million cones in each retina are confined to a small region just opposite the lens called the fovea. So our sharpest and colorful images are limited to a small area of view. Because we can quickly direct our eyes to anything in view that interests us, we tend not to be aware of just how poor our peripheral vision is.

The three types of cones provide us the basis of color vision. Cones are "tuned" to different portions of the visible spectrum.

    * red absorbing cones; those that absorb best at the relatively long wavelengths peaking at 565 nm
    * green absorbing cones with a peak absorption at 535 nm
    * blue absorbing cones with a peak absorption at 440 nm.

Retinal is the prosthetic group for each pigment. Differences in the amino acid sequence of their opsins accounts for the differences in absorption.

The response of cones is not all-or-none. Light of a given wavelength (color), say 500 nm (green), stimulates all three types of cones, but the green-absorbing cones will be stimulated most strongly. Like rods, the absorption of light does not trigger action potentials but modulates the membrane potential of the cones.

Because there are three different color censors in our eye. It is the combination of those signals help us interpret the color of any object. For the color: It is similar to the logical OR operation in computer term.

For your case: (100,100,55)+(100,55,100)+(55,100,100)
100=64+32+4, 55=32+16+4+2+1
So the result is (0110 0100,0110 0100,0011 0111)+(0110 0100,0011 0111,0110 0100)+(0011 0111,0110 0100,0110 0100)=(0111 0111,0111 0111,0111 0111)
In decimal terms it give you the final result of (119,119,119)



Title: Re: Colors (Mixing color or paint: R/G/B)
Post by: shoutroy on May 28, 2007, 04:06:10 pm
please send to me this flash.i want to use it as my teaching.please.i cannot download it


Title: Re: Colors (Mixing color or paint: R/G/B)
Post by: Fu-Kwun Hwang on May 28, 2007, 11:49:39 pm
It is a java simulation (it is not a flash program).
You can select download or email to your account the file:image.zip
Unzip it and open rgbColor.html with your browser.



Title: Re: Colors (Mixing color or paint: R/G/B)
Post by: mrel on March 03, 2008, 10:42:40 am
Hi, I am an undergraduate student of electrical engineering, and I am interested in math of light and pigment color mixing.

Can you please clarify your way of thinking for OR light mixing logic?
It don't make sense to me, because you say that if you put together two of the same colours like (128,0,0) + (128,0,0) you will get (128,0,0), but if you change one of them for smallest possible amount(almost indistinguishable colors) like say for example (128,0,0) + (127,0,0) you get completely different result (255,0,0)
I am not an expert on colors but I don't think it works quite that way in our eye(we don't need perturbations, and chaos theory in this).

I'm interested in colors and i would like to learn this "color math" but I want it to be at least a little more on correct side of reasoning.


Title: Re: Colors (Mixing color or paint: R/G/B)
Post by: Fu-Kwun Hwang on March 04, 2008, 08:27:04 pm
Yes. You are right.  :o It should not happened like the way you just pointed out. :P  This is what need to be improved. I hope someone can find out a better way of doing it (I will try to think about it,too.).    :-[

The frequency response for electromagnetic wave to our eye is not a linear function. The color mixing for vision is not a simple process.
(http://www.phy.ntnu.edu.tw/oldjava/image/rgb.gif)
(http://www.phy.ntnu.edu.tw/demolab/everydayPhysics/lightNeye.gif)


Title: Re: Colors (Mixing color or paint: R/G/B)
Post by: mrel on March 05, 2008, 05:11:44 am
I gave it some thought and came up with possibility of applying fuzzy logic theory.

How about using fuzzy logic OR function for light and fuzzy logic AND function for pigment betwin each component in two of the colors normalized to 1 insted of 255 and then scaled back to 255 after evaluating, insted of using bitwise OR and AND.

Usual prototypes for fuzzy OR are: Y = X1 + X2 - X1*X2 and Y = max(X1,X2), and for fuzzy AND: Y = X1*X2 and Y = min(X1,X2), but other can be chosen.

Function prototypes for fuzzy logic can even be chosen to incorporate logarithmic behavior of human eye.
For example R = 255*log2(1 + {[2^(R1/255)-1] + [2^(R2/255)-1] - [2^(R1/255)-1]*[2^(R2/255)-1]} ) for OR, but I'm not sure what to do for AND in this case.
Also because problems that came from saturation effects on commuter interpretations, this formula can be beater adjusted for match with eye vision.

Can, you pleas give me your opinion of this thoughts? :-\


Title: Re: Colors (Mixing color or paint: R/G/B)
Post by: sonu on July 27, 2008, 06:36:51 pm
hii,could u plz send me a copy of source code of this program in my mail id.plzz


Title: Re: Colors (Mixing color or paint: R/G/B)
Post by: Fu-Kwun Hwang on July 28, 2008, 11:09:56 am
I just added source code for the applet as attachement at the first posted message.
rgbLight.java is the code for the applet and fkhStage.java contains public functions used by rgbLight.java.
However, the code was written in 1999 with JDK1.0.2.


Title: Re: Java Source Code
Post by: BlackRose18 on July 31, 2009, 07:23:06 pm
It don't accomplish faculty to me, because you say that if you put calm two of the aforementioned colours like (128,0,0) + (128,0,0) you will get (128,0,0), but if you change one of them for aboriginal accessible amount(almost duplicate colors) like say for archetype (128,0,0) + (127,0,0) you get absolutely altered aftereffect (255,0,0)

-*-




Title: Re: Colors (Mixing color or paint: R/G/B)
Post by: hunter4774 on January 18, 2011, 08:41:17 pm
mr hwang..
can u please email me the java source code for this Colors..
thanks...


Title: Re: Need java source code for Colors (Mixing color or paint: R/G/B)
Post by: Fu-Kwun Hwang on January 18, 2011, 09:55:00 pm
The source code is inlcuded in the same message as attached files.
Please download it by yourself!  ;)


Title: Re: Colors (Mixing color or paint: R/G/B)
Post by: lookang on June 21, 2012, 01:46:54 pm
Dear Prof Hwang,

would u be interested to create a EJS version?
i search OSP and NTNU and there is EJS version of the color mixing applet yet.


i wish to adapt and create a 3 circle applet that can show the TPCK diagram
http://www.tpck.org/
(http://mkoehler.educ.msu.edu/tpack/files/2011/05/tpack-1014x1024.jpg)

for your consideration
:)


Title: Re: Colors (Mixing color or paint: R/G/B)
Post by: lookang on August 29, 2013, 03:50:17 pm
hi prof,
can make an EJS version for this applet!
i wish to study the source code of color mixing.
thanks!


Title: Re: Colors (Mixing color or paint: R/G/B)
Post by: Fu-Kwun Hwang on August 29, 2013, 08:55:23 pm
EJS does not has GUI or build in library to calculate the color mixing, so I did not create an EJS version.

However, the source code is available as attached file (at the first posted message) if you want to study it.  :D


Title: Re: Colors (Mixing color or paint: R/G/B)
Post by: lookang on September 03, 2013, 10:04:55 pm
http://weelookang.blogspot.sg/2013/09/light-mixing-model.html

Light Mixing Model made in Geogebra.
http://www.geogebratube.org/student/m47961?post_id=731464494_10151686914399495#_=_
i decided to make one myself referencing some of the codes from many thanks to http://www.geogebratube.org/material/show/id/4579 Shared by ukukuku — February 12th, 2012 - 21:24

based on a conversation here http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=39, since EJS does not have the capability to create this more easier than GeoGebra.



Thinking Questions by lookang.

what do you get when red mix with green?

answer is yellow

what do you get when red mix with blue?

answer is magenta

what do you get when green mix with blue?

answer is teal

what do you get when red mix with green and blue?

answer is white