Skip to content

Instantly share code, notes, and snippets.

@Rmano
Last active June 2, 2020 18:11
Show Gist options
  • Save Rmano/3cdae4dd2debe5ccc6a5b130138f3538 to your computer and use it in GitHub Desktop.
Save Rmano/3cdae4dd2debe5ccc6a5b130138f3538 to your computer and use it in GitHub Desktop.
Shading in latex for a nanometer-based visible light
#!/usr/bin/env python3
#
# this is the script that generated the visibleshading.tex file
#
lambdas = [380+20*i for i in range(21)]
for i in lambdas:
print(r"\definecolor{ww%d}{wave}{%d}" % (i, i))
print(r"\colorlet{w%d}[rgb]{ww%d}" % (i,i))
print(r"\pgfdeclarehorizontalshading{visible}{100bp}{%")
print("color(0bp)=(w%d);" % (lambdas[0]))
for i in lambdas:
bp = 25 + (i-lambdas[0])/(lambdas[-1]-lambdas[0])*50;
print("color(%dbp)=(w%d);" % (round(bp), i))
print("color(100bp)=(w%d)}" % (lambdas[-1]))
\definecolor{ww380}{wave}{380}
\colorlet{w380}[rgb]{ww380}
\definecolor{ww400}{wave}{400}
\colorlet{w400}[rgb]{ww400}
\definecolor{ww420}{wave}{420}
\colorlet{w420}[rgb]{ww420}
\definecolor{ww440}{wave}{440}
\colorlet{w440}[rgb]{ww440}
\definecolor{ww460}{wave}{460}
\colorlet{w460}[rgb]{ww460}
\definecolor{ww480}{wave}{480}
\colorlet{w480}[rgb]{ww480}
\definecolor{ww500}{wave}{500}
\colorlet{w500}[rgb]{ww500}
\definecolor{ww520}{wave}{520}
\colorlet{w520}[rgb]{ww520}
\definecolor{ww540}{wave}{540}
\colorlet{w540}[rgb]{ww540}
\definecolor{ww560}{wave}{560}
\colorlet{w560}[rgb]{ww560}
\definecolor{ww580}{wave}{580}
\colorlet{w580}[rgb]{ww580}
\definecolor{ww600}{wave}{600}
\colorlet{w600}[rgb]{ww600}
\definecolor{ww620}{wave}{620}
\colorlet{w620}[rgb]{ww620}
\definecolor{ww640}{wave}{640}
\colorlet{w640}[rgb]{ww640}
\definecolor{ww660}{wave}{660}
\colorlet{w660}[rgb]{ww660}
\definecolor{ww680}{wave}{680}
\colorlet{w680}[rgb]{ww680}
\definecolor{ww700}{wave}{700}
\colorlet{w700}[rgb]{ww700}
\definecolor{ww720}{wave}{720}
\colorlet{w720}[rgb]{ww720}
\definecolor{ww740}{wave}{740}
\colorlet{w740}[rgb]{ww740}
\definecolor{ww760}{wave}{760}
\colorlet{w760}[rgb]{ww760}
\definecolor{ww780}{wave}{780}
\colorlet{w780}[rgb]{ww780}
\pgfdeclarehorizontalshading{visible}{100bp}{%
color(0bp)=(w380);
color(25bp)=(w380);
color(28bp)=(w400);
color(30bp)=(w420);
color(32bp)=(w440);
color(35bp)=(w460);
color(38bp)=(w480);
color(40bp)=(w500);
color(42bp)=(w520);
color(45bp)=(w540);
color(48bp)=(w560);
color(50bp)=(w580);
color(52bp)=(w600);
color(55bp)=(w620);
color(58bp)=(w640);
color(60bp)=(w660);
color(62bp)=(w680);
color(65bp)=(w700);
color(68bp)=(w720);
color(70bp)=(w740);
color(72bp)=(w760);
color(75bp)=(w780);
color(100bp)=(w780)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment