Fill the bezier drawn in R using the grid

I have a drawing as below:

grid.newpage()

grid.rect(x = 0.1, y = 0.4, width = unit(0.18, "npc"), 
          height = unit(0.6, "npc"))
grid.rect(x = 0.65, y = 0.4, width = unit(0.6, "npc"), 
          height = unit(0.6, "npc"))

for (i in c(0.1, 0.17)) {
  x <- c(0.08, 0.05, i, 0.08)
  y <- c(0.15, 0.25, 0.25, 0.5)
  grid.bezier(x, y, gp = gpar(col = "green3"))
}

for (i in c(0.38, 0.8)) {
  x <- c(0.4, i, i, 0.9)
  y <- c(0.4, i, 0.15, 0.15)
  grid.bezier(x, y, gp = gpar(col = "blue3"))
}

This gives me the following drawing, Picture 1

Here I want to fill the shapes with green and blue colors. Is there an easier way to achieve this. If I need to use grid.polygon, I have to specify a lot of points to draw this shape.

+4
source share

Source: https://habr.com/ru/post/1694723/


All Articles