#
# R
# Triângulo de Sierpinski
#
# Segunda~Feira 30 Março 2026 18:04
# by
# j
# 

x <- c()
y <- c()

x0 <- 1
y0 <- 1

max <- 5000
i <- 1

while (i<=max) {
    
    P <- runif(1, min=1, max=4)

    Q = switch(P,
               "1",
               "2",
               "3"
               )
    
    switch(Q,
        
        "1" = {

               xm <- (1/2)*( x0 + (-3) )
               ym <- (1/2)*( y0 + (0) )
            
              },
        "2" = {

               xm <- (1/2)*( x0 + (+3) )
               ym <- (1/2)*( y0 + (0) )
            
              },
        "3" = {

               xm <- (1/2)*( x0 + (0) )
               ym <- (1/2)*( y0 + 6*sqrt(3)/2)          
            
              }
           
           )
           
    x <- c(x,xm)
    y <- c(y,ym)

    x0 <- xm
    y0 <- ym
    
    i <- i + 1
    
}

plot(x, y, pch=19, col="red", cex = 1)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: