【本文重点】
(待完成)
1 画一条随机游动的小蛇
效果如图
1.1 涉及内容
- Random 语句:见 C# 学习笔记 Section 1.4
- toggle & timer 模块:见 Rhino (Grasshopper) 二次开发 (C#) Part 1 Section 1.1.2 & 1.1.3
1.2 具体电池组与代码
private void RunScript(bool ifRenew, ref object A, ref object B) {if (ifRenew) { // 初始化点和线p = new Point3d(0, 0, 0);ps = new List<Point3d>();ls = new List<LineCurve>();for (int i = 0; i < 10; i++) {ps.Add(p);ls.Add(new LineCurve(p, p));}}else {double x = randomGenerator.NextDouble() - 0.5;double y = randomGenerator.NextDouble() - 0.5;ls.Add(new LineCurve(p, p += new Vector3d(x, y, 0)));ps.Add(p);ls.RemoveAt(0);ps.RemoveAt(0);}A = ps;B = ls;
}Point3d p = new Point3d(0, 0, 0);
Random randomGenerator = new Random();
List<Point3d> ps = new List<Point3d>();
List<LineCurve> ls = new List<LineCurve> ();