# 光の3原色と色の3原色 library(imager) # 黒で塗りつぶした画像 im1 <- imfill(300, 300, val = c(0, 0, 0)) # 円の半径 r <- 80 # 各カラーチャンネルにおいて1で塗りつぶした円の描画 R(im1) <- draw_circle(R(im1), 150, 110, r, t(1)) G(im1) <- draw_circle(G(im1), 110, 190, r, t(1)) B(im1) <- draw_circle(B(im1), 190, 190, r, t(1)) # 補色の計算 a <- array(im1, dim(im1)) im2 <- as.cimg(1 - a) # 文字 im1 <- implot(im1, { text(150, 90, "R", cex = 2, col = "black") text( 90, 200, "G", cex = 2, col = "black") text(210, 200, "B", cex = 2, col = "black") }) im2 <- implot(im2, { text(150, 90, "C", cex = 2, col = "black") text( 90, 200, "M", cex = 2, col = "black") text(210, 200, "Y", cex = 2, col = "black") }) layout(t(1 : 2)) plot(im1, axes = FALSE, rescale = FALSE, main = "光の3原色") plot(im2, axes = FALSE, rescale = FALSE, main = "色の3原色") layout(1)