i mean i want to give codes to different colours and the line of that colour which we enter through the code should be the one which the robot is following
Are you talking about a physical robot or a software robot simulation? For the latter, yes, it should be easy ("just a simple matter of software" – famous last words).
For the physical robot, it depends upon what kind of optical sensor input you have. If you’re using a color webcam or something like that, then it should be easy.
But if you’re using something like a photodiode, then your options are more limited. Are you shining an LED to provide illumination for the photodiode, or are you using ambient illumination? You might get somewhere if you use different color LEDs, for instance. But you may also try using different color filters over the photodiode.
Your LEDs & filters would need to be carefully matched with your lines. For instance, a red light or red filter can make red lines on white paper turn "invisible", while blue or green lines would show up clearly.
There are really lots of possibilities to explore, so I don’t want to go on and on without more details on what you have.
In short, it’s certainly possible, but it may require a bit of work.