-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsnowflakes.R
133 lines (105 loc) · 4.54 KB
/
snowflakes.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
png("/Users/gregorymatthews/snowTest1small.png",h=13,w=19,units="in",res=100)
par(mfrow=c(5,8))
par(mar=c(0,0,0,0))
for (greg in 1:40){print(greg)
plot(0,0,frame.plot=F,xlim=c(-10,10),ylim=c(-10,10),col="white",asp=1,xaxt='n',yaxt='n',xlab="",ylab="")
th <- runif(1,0,2*pi)
lwd<-runif(1,5,10)
x<-c(0,5)
y<-c(0,5)
for (theta in th+seq(0,2*pi,length=7)[-1]){
xTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,1]
yTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,2]
points(xTemp,yTemp,type="l",lwd=lwd,col=rgb(0,0,1,.1))
#polygon(c(xTemp),c(yTemp),col=rgb(0,0,1,0.05),bor=rgb(0,0,1,0.05))
}
yy<-runif(1,6,8)
x<-c(5,5)
y<-c(5,yy)
for (theta in th+seq(0,2*pi,length=7)[-1]){
xTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,1]
yTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,2]
# points(xTemp,yTemp,type="l",lwd=lwd,col=rgb(0,0,1,.1))
#polygon(c(xTemp),c(yTemp),col=rgb(0,0,1,0.05),bor=rgb(0,0,1,0.05))
}
x<-c(5,yy)
y<-c(5,5)
for (theta in th+seq(0,2*pi,length=7)[-1]){
xTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,1]
yTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,2]
# points(xTemp,yTemp,type="l",lwd=lwd,col=rgb(0,0,1,.1))
#polygon(c(xTemp),c(yTemp),col=rgb(0,0,1,0.05),bor=rgb(0,0,1,0.05))
}
yy<-runif(1,5,7)
x<-c(4,4)
y<-c(4,yy)
for (theta in th+seq(0,2*pi,length=7)[-1]){
xTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,1]
yTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,2]
points(xTemp,yTemp,type="l",lwd=lwd,col=rgb(0,0,1,.1))
#polygon(c(xTemp),c(yTemp),col=rgb(0,0,1,0.05),bor=rgb(0,0,1,0.05))
}
x<-c(4,yy)
y<-c(4,4)
for (theta in th+seq(0,2*pi,length=7)[-1]){
xTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,1]
yTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,2]
points(xTemp,yTemp,type="l",lwd=lwd,col=rgb(0,0,1,.1))
#polygon(c(xTemp),c(yTemp),col=rgb(0,0,1,0.05),bor=rgb(0,0,1,0.05))
}
yy<-runif(1,3,6)
x<-c(3,yy)
y<-c(3,3)
for (theta in th+seq(0,2*pi,length=7)[-1]){
xTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,1]
yTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,2]
points(xTemp,yTemp,type="l",lwd=lwd,col=rgb(0,0,1,.1))
#polygon(c(xTemp),c(yTemp),col=rgb(0,0,1,0.05),bor=rgb(0,0,1,0.05))
}
x<-c(3,3)
y<-c(3,yy)
for (theta in th+seq(0,2*pi,length=7)[-1]){
xTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,1]
yTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,2]
points(xTemp,yTemp,type="l",lwd=lwd,col=rgb(0,0,1,.1))
#polygon(c(xTemp),c(yTemp),col=rgb(0,0,1,0.05),bor=rgb(0,0,1,0.05))
}
for (q in 1:2){
w<-runif(1,1,3)
h<-runif(1,0,2)
x<-c(0,w,w,h,0)
y<-c(0,h,w,w,0)
for (theta in th+seq(0,2*pi,length=7)[-1]){
xTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,1]
yTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,2]
#points(xTemp,yTemp,type="l",lwd=3)
polygon(c(xTemp),c(yTemp),col=rgb(0,0,1,.1),bor=rgb(0,0,1,.1))
}
w<-runif(1,1,3)
h<-runif(1,0,2)
x<-c(0,w,w,h,0)
y<-c(0,h,w,w,0)
for (theta in th+pi/6+seq(0,2*pi,length=7)[-1]){
xTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,1]
yTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,2]
#points(xTemp,yTemp,type="l",lwd=3)
polygon(c(xTemp),c(yTemp),col=rgb(0,0,1,.1),bor=rgb(0,0,1,.1))
}
}
for (q in 1:2){
w<-runif(1,1,4)
h<-runif(1,1,4)
x<-c(3,w,w,h,3)
y<-c(3,h,w,w,3)
#x<-c(3,5,7,2,3)
#y<-c(3,2,7,5,3)
for (theta in th+seq(0,2*pi,length=7)[-1]){
xTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,1]
yTemp<-t(matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),ncol=2,byrow=TRUE)%*%t(cbind(x,y)))[,2]
#points(xTemp,yTemp,type="l",lwd=3)
polygon(c(xTemp),c(yTemp),col=rgb(0,0,1,.25),bor=rgb(0,0,1,.25))
}
#text(0,0,"@STATSINTHEWILD",cex=1,col=rgb(.5,.5,.5,.9))
}
}
dev.off()