pdf("test_alpha.pdf", version="1.4")

plot(1:8, 1:8, type="n", xlab="", ylab="")

lines(c(1,8), c(1,8), type="l", col="lightblue", lwd=15)

# rectangle with alphachannel=255 (no transparency)
goldenrod1 <- rgb(255,193,37,255, names=c("goldenrod1"), max=255)
rect(4,4,7,7, col=goldenrod1, border=NA)
lines(c(4,4,7,7,4), c(4,7,7,4,4), col="red", lty=2)
text(5,7, "no transparency")

# polygon with alphachannel=64 (transparency near 40%)
polygon(c(5,2,2,5,5), c(2,2,5,5,2), col=rgb(255,192,203,64, max = 255), border=NA)
lines(c(5,2,2,5,5), c(2,2,5,5,2), col="red", lty=2)
text(4,2, "transparency 40%")

#for (x in 1:8) 
#  for (y in 1:8) 
#    rect(x-0.5,y-0.5, x+0.5, y+0.5, col=rgb(255,193,37, 255/(x*y), max=255))

#rect(5,5,7,7, col=rgb(255,0,0, 255, max=255), border=NA)

dev.off()
