I have successfully created a number of functions which contain code which draws a single polygon at a specific location. however, my attempts to create function for code which uses a loop to draw a sequence of polygon from left to right has resulted in only one polygon being drawn - either the first or the last. (I couldn't work out how to access reprex so I have pasted the code below.) The code below draws the fist polygon. There should be 10 in total.
dev.new(width = 15, height = 10, units = "in")
plot.new()
FLAT <- 1
PYRAMID <- 0
PNT <- 10
scalefactor <- 1/2500
PDH <- 0
PDV <- 0
PW <- 100 * scalefactor
PG <- 20 * scalefactor
PH <- 1200 *scalefactor
FL_xcoordinates <- c(PDH+PW*AA+PG*AA,PDH+PW*AA+PG*AA,PDH+PW*(AA+1)+PG*AA,PDH+PW*(AA+1)+PG*AA)
FL_ycoordinates <- c(PDV, PDV+PH, PDV+PH, PDV)
FLAT_PALINGS <- function(FL_xcoordinates, FL_ycoordinates) {
if(FLAT<=0) {
polygon(c(0,0,0,0), c(0,0,0,0))
} else {
PN <- 1
AA <- 0
#FL_xcoordinates <- c(PDH+PW*AA+PG*AA,PDH+PW*AA+PG*AA,PDH+PW*(AA+1)+PG*AA,PDH+PW*(AA+1)+PG*AA)
#FL_ycoordinates <- c(PDV, PDV+PH, PDV+PH, PDV)
while (PN<=PNT) {
shape <- (polygon(c(FL_xcoordinates),c(FL_ycoordinates)))
return(shape)
PN<-PN+1
AA <- AA+1
}
}
}
FLAT_PALINGS(FL_xcoordinates,FL_ycoordinates)