Is there a distance-based texture for Blender?

thanks. But i don’t understand. Which one is the right scripts the 1st or the 2nd (I see 2 pieces of code )?

I did the following : I copied one of the code in the script editor, gave it a name.
Then created a script node and selected my script name.
But i have an error “OSL script compilation failed, see console for error”

May be I copied the wrong code.

Can you give me the right one please.
Sorry for bothering you I am a newbie in blender.

Nice, it works without any errors now.
Thanks you very much !!!