|
再次回顾,发现集合元素真可以是图片!- Private Sub CommandButton1_Click()
- Dim s As New Collection, i%, j%, n%, cir As New Collection, t, l%, xy#(), temp#, temp2#, p#, r#
- [b16].ClearContents
- 'vPause 10 '发现运行速度加快,原来的7不够录屏的准备
- n = [c11]
- p = Application.Pi() * 2
- ReDim xy(1 To n, 1 To 2) 'xy记录圆圈偏移中心点位置
- l = Len(n)
- r = 10.2 / Sin(p / n / 2) '推算围圈半径;估计的图形尺寸与坐标度量关系,圈径20成10.3
- For i = 1 To n '绘制n个围圈
- s.Add i
- xy(i, 1) = r * Cos(p / n * (i - 1))
- xy(i, 2) = r * Sin(p / n * (i - 1)) '▼集合真的可以容纳图形元素,与数组xy相比免去了redim的烦恼
- cir.Add ActiveSheet.Shapes.AddShape(msoShapeOval, 250 + xy(i, 1), 300 + xy(i, 2), 20, 20)
- cir(i).Select
- Selection.Characters.Text = i & ""
- Selection.HorizontalAlignment = xlCenter
- Selection.Characters(Start:=1, Length:=l).Font.Size = 10 '字号仅考虑2位数
- Next
- t = [c12] - 1
- i = 1
- Do
- If i + t > s.Count Then
- i = (i + t - 1) Mod s.Count + 1
- Else
- i = i + t
- End If
- For j = i - t To i
- If j <= 0 Then 'j出现0或负是圈邻的大数
- cir(s(j - Application.Ceiling(j - 1, -s.Count))).Select '1个s.Count不一定够负数相减
- Else
- cir(s(j)).Select
- End If
- Selection.ShapeRange.Fill.ForeColor.SchemeColor = 22 '1-t报数的灰圈
- vPause 0.6 '停顿时长的过程
- Selection.ShapeRange.Fill.ForeColor.SchemeColor = 9 '改成白底;别用Transparency=1#改透明色,会对后续圈产生影响
- Next
- cir(s(i)).Delete '出局的圈
- vPause 1
- s.Remove (i)
- r = 10.2 / Sin(p / s.Count / 2)
- If s.Count > 2 Then '余两时不必重新围圈
- For j = 1 To s.Count
- temp = r * Cos(p / s.Count * (j - 1))
- temp2 = r * Sin(p / s.Count * (j - 1))
- cir(s(j)).Select
- Selection.ShapeRange.IncrementLeft -xy(s(j), 1) '各圈先回中心点聚集初始化
- Selection.ShapeRange.IncrementTop -xy(s(j), 2)
- Selection.ShapeRange.IncrementLeft temp '再按新位一次性偏移围圈,这样避免了多次求差偏移引起的误差累积
- Selection.ShapeRange.IncrementTop temp2
- xy(s(j), 1) = temp
- xy(s(j), 2) = temp2
- Next
- End If
- Loop Until s.Count = 1
- vPause 1
- cir(s(1)).Delete
- [b16] = s(1)
- End Sub
- Sub vPause(s!)
- Dim ss!
- ss = Timer
- Do
- DoEvents
- Loop Until Abs(Timer - ss) >= s
- End Sub
复制代码
|
|