continuous coloring of a polygon

11 messages
Open this post in threaded view
|

continuous coloring of a polygon

 R2.7.1, WinXP Hi, I have a polygon inside a circle as follows: radius <- 3 x <- seq(-radius,radius,length=2000) y <- sqrt(radius^2-x^2) xx <- c(x,-x) yy <- c(y,-y) plot(xx,yy, xlim=c(-radius,radius),ylim=c(-radius,radius), type="l", ylab="", xlab="", axes=F) radius <- 2.7 x1 <- seq(-radius,radius,length=2000) y1 <- sqrt(radius^2-x1^2) radius <- 2.0 x2 <- seq(radius,-radius,length=2000) y2 <- sqrt(radius^2-x2^2) polygon(c(x1,x2),c(y1,y2)) (the graph much resembles a speed dial inside a car). Now I want to fill the polygon with color, such that it starts on the left with red and ends on the right with green, following the coloring of the rainbow. Preferably, the coloring should be "continuous", such that colors naturally fade into each other. I can draw the polygon as above, but I don't know how to do the coloring. It is easy to give the polygon only one color (e.g. through polygon(c(x1,x2),c(y1,y2), col="red")), but I need a way in which to color the polygon such that the color moves through the color spectrum from red (left) to green (right). Can anyone help me to achieve this? Thanks, Roger ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: continuous coloring of a polygon

 Roger Leenders rug.nl> writes: > > I have a polygon inside a circle as follows: > .. Example code removed (but it's nice you included it) > (the graph much resembles a speed dial inside a car). > Now I want to fill the polygon with color, such that it starts on the > left with red and ends on the right with green, following the coloring > of the rainbow. What comes closest is function gradient.rect in package plotrix. You could use it as an starting example, and replace the rect() in it by polygon computed in polar coordinates. Dieter ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: continuous coloring of a polygon

Open this post in threaded view
|

Re: continuous coloring of a polygon

Open this post in threaded view
|

Re: continuous coloring of a polygon

Open this post in threaded view
|

Re: continuous coloring of a polygon

 In reply to this post by Roger Leenders Am 15.08.2008 um 14:00 schrieb Roger Leenders: > I can draw the polygon as above, but I don't know how to do the > coloring. It is easy to give the polygon only one color (e.g. through > polygon(c(x1,x2),c(y1,y2), col="red")), but I need a way in which to > color the polygon such that the color moves through the color spectrum > from red (left) to green (right). > Can anyone help me to achieve this? > I don't know of another way than to segment the polygon and give the segments distinctive colours. The function rainbow(n, start=0, end=1/3) might help specifying the colours, where n is chosen sufficiently high. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: continuous coloring of a polygon

Open this post in threaded view
|

Re: continuous coloring of a polygon

Open this post in threaded view
|