This landscape of randomized cube-like structures proved popular with the students in the AHO workshop:

Code: randCube.rvb

Option Explicit
'Script written by Marius Watz
'Script version 14. februar 2008 10:56:41

Call Clear
Call Main()

Sub Main()
	Call rhino.enableRedraw(False)

	Dim i,j
	For i=0 To 10
		For j=0 To 10
			Call rndCube(i*15,j*15)
		Next
	Next

	Call rhino.enableRedraw(True)
End Sub

Function rndVec(range)
	rndVec=Array(Rnd*range-range/2,Rnd*range-range/2,Rnd*range-range/2)
End Function

Function rndCube(xpos,ypos) 

	Dim pt(8)
	Dim c1,c2

	Dim rad
	rad=5
	pt(0)=Array(-rad,-rad,rad)
	pt(1)=Array(rad,-rad,rad)
	pt(2)=Array(rad,rad,rad)
	pt(3)=Array(-rad,rad,rad)

	pt(4)=Array(-rad,-rad,-rad)
	pt(5)=Array(rad,-rad,-rad)
	pt(6)=Array(rad,rad,-rad)
	pt(7)=Array(-rad,rad,-rad)	

	Dim i,rndv,rndH
	rndH=Rnd*rad*2
	For i=0 To 3
		rndv=rndVec(4)
		rndv(2)=rndv(2)+rndH
		pt(i)=Rhino.VectorAdd(pt(i),rndv)
	Next

	For i=0 To 7
		pt(i)=Rhino.VectorAdd(pt(i),Array(xpos,ypos,0))
	Next

	Dim ln(8)
	For i=0 To 3
		ln(i)=Rhino.AddLine(pt(i),pt((i+1) Mod 4))
		ln(i+4)=Rhino.AddLine(pt(i+4),pt(((i+1) Mod 4)+4))
	Next

	Dim srf(6)
	For i=0 To 3
		srf(i)=Rhino.AddEdgeSrf(Array(ln(i),ln(i+4)))
	Next

	ln(0)=Rhino.AddLine(pt(1),pt(0))
	srf(4)=Rhino.AddEdgeSrf(Array(ln(0),ln(2)))
	srf(5)=Rhino.AddEdgeSrf(Array(ln(6),ln(4)))

	For i=0 To UBound(ln)-1
		Rhino.DeleteObject ln(i)
	Next

End Function

Sub Clear
	Rhino.Command "SelAll "
	Rhino.Command "Delete "
End Sub

2 Comments »

There are 2 comments to "Rhino: randCube.rvb". You may leave your own comment.
1. Dharmesh, February 14th, 2008 at 23:25

Marius,
Great website! I am learning Rhinocscript also.
FYI I got an error when i ran the above script. Line 42 repeats on line 43 and you get an error.

Looking forward to see where you go with this.

2. RHINO | Pearltrees, April 14th, 2012 at 02:19

[...] Call rhino.enableRedraw( False ) Dim i,j Sub Main() For i=0 To 10 Code & form ยป Rhino: randCube.rvb [...]

Comment on this entry

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">