fora1
![](images/star2.gif) ![](images/star2.gif)
发贴: 217
|
2008-12-08 14:53
![收藏这篇帖子](http://abbs.cn/images/icons/icon_favorite.gif)
Case Study 2.2
Self-Growth System
Example 2.1.1(L-System by Michael Hansmayer)
L system,应该也算是很长历史了,和voronoi一样都属于高数学逻辑的system,基本上是一种模拟自然植物生长的system,设定好一个参数的开始点,和参数之间的替换逻辑,system本身就可以自己生成参数序列
![](http://abbs.cn/pic/2008/12/08/1228715498.jpg)
得到参数序列之后,就可以进行下一步,将特定的意义赋予参数,再进行下一步运算
下面的例子是将参数排成矩阵,然后赋予矩阵中字母于意义
![](http://abbs.cn/pic/2008/12/08/1228714632.jpg)
![](http://abbs.cn/pic/2008/12/08/1228714732.jpg)
![](http://abbs.cn/pic/2008/12/08/1228714663.jpg)
![](http://abbs.cn/pic/2008/12/08/1228714673.jpg)
![](http://abbs.cn/pic/2008/12/08/1228714848.jpg)
![](http://abbs.cn/pic/2008/12/08/1228714888.jpg)
![](http://abbs.cn/pic/2008/12/08/1228715024.jpg)
![](http://abbs.cn/pic/2008/12/08/1228715078.jpg)
![](http://abbs.cn/pic/2008/12/08/1228716133.jpg)
![](http://abbs.cn/pic/2008/12/08/1228716170.jpg)
![](http://abbs.cn/pic/2008/12/08/1228716193.jpg)
![](http://abbs.cn/pic/2008/12/08/1228716438.jpg)
![](http://abbs.cn/pic/2008/12/08/1228716330.jpg)
![](http://abbs.cn/pic/2008/12/08/1228716356.jpg)
或者也可以给予每个字母一种运动意义(这种方式被称为Turtle),比如说A是直走,B是右转,C是左转(当然可以根据需求自己定义);
![](http://abbs.cn/pic/2008/12/08/1228716534.jpg)
![](http://abbs.cn/pic/2008/12/08/1228716905.jpg)
![](http://abbs.cn/pic/2008/12/08/1228716937.jpg)
![](http://abbs.cn/pic/2008/12/08/1228717001.jpg)
![](http://abbs.cn/pic/2008/12/08/1228717102.jpg)
也可以让特定的单元按照turtle的方式运动,并且回应外界的因素
![](http://abbs.cn/pic/2008/12/08/1228717426.jpg)
![](http://abbs.cn/pic/2008/12/08/1228717441.jpg)
![](http://abbs.cn/pic/2008/12/08/1228717467.jpg)
![](http://abbs.cn/pic/2008/12/08/1228717683.jpg)
![](http://abbs.cn/pic/2008/12/08/1228717709.jpg)
![](http://abbs.cn/pic/2008/12/08/1228717727.jpg)
![](http://abbs.cn/pic/2008/12/08/1228717746.jpg)
![](http://abbs.cn/pic/2008/12/08/1228717783.jpg)
![](http://abbs.cn/pic/2008/12/08/1228717794.jpg)
![](http://abbs.cn/pic/2008/12/08/1228717808.jpg)
![](http://abbs.cn/pic/2008/12/08/1228717826.jpg)
![](http://abbs.cn/pic/2008/12/08/1228717837.jpg)
或者通过全局的参数来控制turtle的运动
![](http://abbs.cn/pic/2008/12/08/1228718254.jpg)
![](http://abbs.cn/pic/2008/12/08/1228718285.jpg)
![](http://abbs.cn/pic/2008/12/08/1228718368.jpg)
![](http://abbs.cn/pic/2008/12/08/1228718395.jpg)
![](http://abbs.cn/pic/2008/12/08/1228718414.jpg)
![](http://abbs.cn/pic/2008/12/08/1228718434.jpg)
Example 2.1.2(Nested loops by TheVeryMany)
Nested loops,在c++中很常用,通俗点说是一种用来数数的方式
for(num1 = 0; num1 <= 9; num1++) { cout << num1 << endl; }
![](http://abbs.cn/pic/2008/12/08/1228718994.jpg)
![](http://abbs.cn/pic/2008/12/08/1228719017.jpg)
![](http://abbs.cn/pic/2008/12/08/1228719126.jpg)
![](http://abbs.cn/pic/2008/12/08/1228719168.jpg)
rhino script(导入rhino应该就可以了)
Sub Tower() ' declare variables Dim i, j Dim arrCrvBank() 'dynamic array ' ------------------------------------------------------ ' set variables: "Fl" = Floor Dim intFloorNumber: intFloorNumber = 30 Dim intFloorHeight: intFloorHeight = 4'random(1,5)'random(1,3)'4 Dim intFloorRadius: intFloorRadius = Sin(i*10)+10'2'random(1,3)'(i/2+1,i)'8 ' ------------------------------------------------------ Dim intSubDivide: intSubDivide = (2*intFloorNumber) + 4 Dim intLevel: intLevel = 0 ' ------------------------------------------------------
' ////////////////////////////////////////////////////// '' FOR EVERY FLOOR ' ////////////////////////////////////////////////////// For i = 0 To intFloorNumber Randomize ' ------------------------------------------------------ '' DRAW A CIRCLE ' ------------------------------------------------------ ' setCenter Dim x: x = 0'random(-1,1)'(-i/2,i/2)'0 Dim y: y = 0'random(-1,1)'(-i/2,i/2)'0 Dim z: z = intLevel Dim arrCenter: arrCenter = Array(x,y,z) ' addCircle Dim strCircle: strCircle = Rhino.AddCircle (arrCenter, intFloorRadius) ' ------------------------------------------------------ '' ROTATE THE CIRCLE ' ------------------------------------------------------ ' getCircleDomain Dim arrDomain: arrDomain = Rhino.CurveDomain(strCircle) ' Rotation for Twist Dim intTwisting: intTwisting = i'random(1,(intSubDivide/2)) Dim dblParameter: dblParameter = arrDomain(0) + (arrDomain(1)/intSubDivide)*intTwisting ' reSet cercleOrigine Rhino.CurveSeam strCircle, dblParameter ' ------------------------------------------------------ '' DIVIDE THE CIRCLE ' ------------------------------------------------------ ' addPts onCircle Dim arrPts: arrPts = Rhino.DivideCurve (strCircle, intSubDivide) ' deleteCircle Rhino.DeleteObject strCircle
' ////////////////////////////////////////////////////// '' FOR EVERY (TWO) PTS ' ////////////////////////////////////////////////////// For j = 2 To UBound(arrPts) Step 2 ' ------------------------------------------------------ '' DRAW A RADIAL ' ------------------------------------------------------ ' addRadial Dim strRadial : strRadial = Rhino.AddLine (arrPts(0), arrPts(j)) ' ------------------------------------------------------ '' SET RADIAL LENGHT RADIAL ' ------------------------------------------------------ ' setLength Dim dblLength : dblLength = Random(2,10) ' getDomain : arrDomainRad(1) = original radius endPt Dim arrDomainRad : arrDomainRad = Rhino.CurveDomain(strRadial) ' startPt 'Dim dblParam : dblParam = arrDomainRad(1) + (arrDomainRad(1) / dblLength) Dim dblParam : dblParam = arrDomainRad(1) - (arrDomainRad(1) / dblLength) Dim arrPointStart : arrPointStart = Rhino.EvaluateCurve(strRadial, dblParam) ' endPt 'dblParam = arrDomainRad(1) + dblParam dblParam = arrDomainRad(1) + (arrDomainRad(1) / dblLength) Dim arrPointEnd : arrPointEnd = Rhino.EvaluateCurve(strRadial, dblParam) ' ------------------------------------------------------ ' deleteRadial Rhino.DeleteObject strRadial ' ------------------------------------------------------ ' SET PROFIL TO LOFT ' ------------------------------------------------------ ' set arrPtsProfil Dim arrPtsProfils: arrPtsProfils = array( arrPointStart,arrPts(j-1),arrPointEnd,arrPts(j+1),arrPointStart ) ' addCurve ReDim Preserve arrCrv((UBound(arrPts)/2)-1) arrCrv((j/2)-1) = Rhino.AddCurve ( arrPtsProfils ) ' addPolyline ReDim Preserve arrPolyLines((UBound(arrPts)/2)-1) arrPolyLines((j/2)-1) = Rhino.addPolyline ( arrPtsProfils ) Next ' //////////////////////////////////////////////////////
' ------------------------------------------------------ ' createFloors Dim arrFloor : arrFloor = Rhino.AddPlanarSrf ( arrPolyLines ) Rhino.SurfaceIsocurveDensity arrFloor, -1 ' ------------------------------------------------------ ' collecteCurvesToLoft (byFloors) ReDim Preserve arrCrvBank(i): arrCrvBank(i) = arrCrv ' ------------------------------------------------------ ' FOR NEXT LOOP: intSubDivide = intSubDivide-2 intLevel = intLevel + intFloorHeight ' ------------------------------------------------------ Next ' ////////////////////////////////////////////////////// ' ////////////////////////////////////////////////////// ' INCREMENTAL LOFT PROCESS ' ////////////////////////////////////////////////////// Dim arrPolyLoft(), arrPtsCurves() Dim intMax: intMax = intFloorNumber j = 0 Do Until intMax = 0 ' ------------------------------------------------------ For i=0 To intMax ReDim Preserve arrPolyLoft(i) arrPolyLoft(i) = arrCrvBank(i)(j) Next ' ------------------------------------------------------ Dim strLoft : strLoft = Rhino.AddLoftSrf (arrPolyLoft,,,2,1,40) Rhino.SurfaceIsocurveDensity strLoft, -1 j=j+1 intMax = intMax-1 Loop ' ////////////////////////////////////////////////////// End Sub
Example 2.1.3(Nested loops by Dimitris Gourdoukis)
![](http://abbs.cn/pic/2008/12/08/1228719483.jpg)
fora1 edited on 2008-12-08 14:57
|