# Visible light spectrum # Michael Minn # 29 August 2020 frequencies = list( c("ultraviolet", 800, "#000000"), c("violet", 750, "#804080"), c("indigo", 675, "#400080"), c("blue", 630, "#00FFFF"), c("green", 590, "#008000"), c("yellow", 525, "#FFFF00"), c("orange", 500, "#FF8000"), c("red", 460, "#800000"), c("infrared", 380, "#000000")) frequencies = data.frame(t(data.frame(frequencies, stringsAsFactors=F)), stringsAsFactors=F) rownames(frequencies) = frequencies[,1] frequencies = cbind(frequencies, t(col2rgb(frequencies[,3]))) colnames(frequencies) = c("name", "thz", "hex", "red", "green", "blue") frequencies$thz = as.numeric(frequencies$thz) red = approxfun(frequencies$thz, as.numeric(frequencies$red) / 256) green = approxfun(frequencies$thz, as.numeric(frequencies$green) / 256) blue = approxfun(frequencies$thz, as.numeric(frequencies$blue) / 256) png("2020-visible-light-spectrum.png", width=500, height=400, pointsize=14) par(mar=c(1,1,1,1)) plot(0, 0, xlim=c(0,10), ylim=c(0,11), col="white", axes=F, xlab=NA, ylab=NA) for (thz in seq(min(frequencies$thz), max(frequencies$thz), 0.5)) { y = 10 * (thz - min(frequencies$thz)) / diff(range(frequencies$thz)) lines(x = c(1.5, 4.5), y = c(y, y), lwd=1, col=rgb(red(thz), green(thz), blue(thz))) } y = 10 * (frequencies$thz - min(frequencies$thz)) / diff(range(frequencies$thz)) text(0, y, frequencies$thz, pos=4) text(5, y, frequencies$name, pos=4) text(7, y, ifelse(frequencies$hex == "#000000", "(not visible)", frequencies$hex), pos=4) text(0, 11, "Frequency (Thz)", pos=4, font=2) text(5, 11, "Name", pos=4, font=2) text(7, 11, "RGB Hex Code", pos=4, font=2) dev.off()