Tiny Art with R studio (ENG)
--
If you are in love with geometry here I found some cool examples of visualization in R Studio (to learn more about R — https://r4ds.had.co.nz/).
Also, you can find joy in a drawing of Lissajous figure.
#1 Cardioid in string art
Do not swear by the moon, for she changes constantly. Then your love would also change (William Shakespeare, Romeo and Juliet)
library(ggplot2)
n=200
t1=1:n
t0=seq(3,2*n+1,2)%%n
t2=t0+(t0==0)*n
df=data.frame(x=cos((t1–1)*2*pi/n),
y=sin((t1–1)*2*pi/n),
x2=cos((t2–1)*2*pi/n),
y2=sin((t2–1)*2*pi/n))
png(“pic1.png”, units=”px”, width=1600, height=1600, res=300)
ggplot(df,aes(x,y,xend=x2,yend=y2)) +
geom_segment(alpha=.1)+theme_void()
dev.off()
We can do an experiment with colors:
library(ggplot2)
n=160
t1=1:n
t0=seq(from=3, to=2*n+1, by=2) %% n
t2=t0+(t0==0)*n
df=data.frame(x1=cos((t1–1)*2*pi/n), y1=sin((t1–1)*2*pi/n), x2=cos((t2–1)*2*pi/n), y2=sin((t2–1)*2*pi/n))
opt=theme(legend.position=”none”,
panel.background = element_rect(fill=”white”),
panel.grid = element_blank(),
axis.ticks=element_blank(),
axis.title=element_blank(),
axis.text =element_blank())
png(“Cliffornd3.png”, units=”px”, width=1600, height=1600, res=300)
ggplot(df, aes(x = x1, y = y1, xend = x2, yend = y2)) +
geom_point(x=0, y=0, size=245, color=”blue”)+
geom_segment(color=”white”, alpha=.5)+opt
dev.off()
#2 Turtle graphics
library(TurtleGraphics)
png(“pic.png”, units=”px”, width=1600, height=1600, res=300)
turtle_init()
turtle_col(“gray25”)
for (i in 1:150) {
turtle_forward(dist=1+0.5*i)
turtle_right(angle=89.5)}
turtle_hide()
dev.off()
library(TurtleGraphics)
png(“pic.png”, units=”px”, width=1600, height=1600, res=300)
turtle_init()
turtle_col(“gray25”)
turtle_setpos(50,35)
turtle_right(angle=30)
d=25
turtle_setpos(50-d/2,50-d/2*tan(pi/6))
for (i in 1:100) {
turtle_forward(dist=d)
d=d+.5
turtle_right(angle=120+1)}
turtle_hide()
dev.off()
library(TurtleGraphics)
png(“pic.png”, units=”px”, width=1600, height=1600, res=300)
turtle_init()
turtle_col(“gray25”)
turtle_setpos(48,36)
d=50
for (i in 1:300) {
turtle_forward(dist=d)
if (i%%4==0) {
turtle_right(angle=75)
d=d*.95}
else turtle_right(angle=90)}
turtle_hide()
dev.off()
#3 Snail
par(mfrow=c(1,1),mar=c(0,0,0,0),oma=c(1,1,1,1))
plot(0,0,type=”n”, xlim=c(-2,32), ylim=c(3,27),
xaxs=”i”, yaxs=”i”, axes=FALSE, xlab=NA, ylab=NA,
asp=1)
for (j in 0:35) {
for (i in 0:35) {
R <- 8
alpha <- j*10
X <- 15+R*cos(alpha/180*pi)
Y <- 15+R*sin(alpha/180*pi)
r <- 3
beta <- i*10
x <- 15+r*cos(beta/180*pi)
y <- 15+r*sin(beta/180*pi)
d1 <- sqrt((X-x)²+(Y-y)²)
xc <- x
yc <- y
n <- 180-atan((Y-y)/(X-x))/pi*180
alpha2 <- -(0:n)
theta <- alpha2/180*pi
b <- d1/(n/180*pi)
r <- b*theta
x1 <- xc+r*cos(theta)
y1 <- yc+r*sin(theta)
lines(x1,y1, col=”black”)}
}