070928_Agritect_v1.1

Option Explicit

‘##########################################################

Call Rhino.EnableRedraw(false)
Call Growth_System()
Call Rhino.EnableRedraw(true)
Sub Growth_System()

 Call Rhino.Print(“########## START SCRIPT ############”)

 ‘————— VARIABLES —————–
 Dim i,j,k,n,Plot_yieldL(), YEAR
 Dim iteration : iteration = 0
 Dim Yield_low : Yield_low = 130
 Dim Yield_high  : Yield_high  = 200
 
Dim Plot_x : Plot_x = 2

 Dim Plot_y : Plot_y = 2
 Dim Plot_m : Plot_m = 10

 
Dim nPlots
 nPlots = (Plot_x+1) *( Plot_y+1)
 Dim P(), Ptemp_x(), Ptemp_y()
 Redim Ptemp_x(Plot_x+Plot_y)
 Redim Ptemp_y(Plot_y+Plot_x)
 
 
 ‘________________________________ PLANTING ________________

 For i = 0 to Plot_x
   Redim Preserve P(i)
   P(i) = Ptemp_x
  ‘———————–
  For j = 0 to Plot_y
   P(i)(j) = Ptemp_y 
  ‘———————–
   For k = 0 to 3
     Select Case k
     Case 0
      P(i)(j)(0) = array(i*Plot_m, j*Plot_m, 0)
     Case 1
      P(i)(j)(1) = array(i*Plot_m+Plot_m, j*Plot_m, 0)
     Case 2
      P(i)(j)(2) = array(i*Plot_m, j*Plot_m+Plot_m, 0)
     Case 3
      P(i)(j)(3) = array(i*Plot_m+Plot_m, j*Plot_m+Plot_m, 0)
    End Select
   Next
  ‘———————–
   Call Rhino.AddPolyline(array( (P(i)(j)(0)),(P(i)(j)(1)),(P(i)(j)(3)),(P(i)(j)(2)), (P(i)(j)(0)) ) )
  Next
  ‘———————–
 Next

 ‘_______________________________ GROWTH CYCLE ___________________
 For YEAR = 0 To 17

  Call func_YIELD(Plot_yieldL, Yield_low, Yield_high, nPlots)
  Call func_GROW(Plot_yieldL,  Yield_low, Yield_high, iteration, P, Plot_x, Plot_y)
 
  If iteration < 2 Then
   iteration = iteration + 1
  Else
   iteration = 0   
  End If
 Next
 
 ‘__________________________________________________________________
 
End Sub
‘#########################################################
Function func_YIELD(Plot_yieldL, intlow, intup, nPlots)
 Dim i,  Plot_yieldG, n : n=0
 Plot_yieldG = Random(intlow, intup) ‘ *** Field “Average”
 ‘——————————————-
 For i = 0 To nPlots
 
  ReDim Preserve Plot_yieldL(n)
  Plot_yieldL(n) = (Random(intlow,intup) ) ‘ *** Local Yield
  n = n+1
  
 Next
 ‘——————————————-
End Function
‘########################################################
Function func_GROW(Plot_yieldL, intlow, intup, iteration, P, Plot_x, Plot_y)  
 
 Rhino.Print(“A year has passed… the harvester comes to bring new life.”)

 Dim i,j,k, Growth_MULT, Growth_HEIGHT, Growth_NEW, Check_d, Change_mod(2), Avg_modj(2), n: n=0
 
Dim DIST : DIST = 4
 Growth_HEIGHT = 3

 Dim sLofter_1, sLofter_2, arrLoft()
 Dim Temp_y, Temp_z, Temp_b, Temp_b2, Temp_arr1, Temp_x, Temp_m1, Temp_m2, Change_x, Change_y
 ‘———————————————————————————
 For i = 0 to Plot_x
  ‘———————–
  For j = 0 to Plot_y
  ‘———————–
   For k = 0 to 5
    ‘_______________________________________________________
    Select Case k
   ‘CORNER 0—————————————————————–
     Case 0 ‘P(i)(j)(0)
      Growth_MULT = Plot_yieldL(n)/((intlow + intup)/2) ‘ *** Percentage compared to average
      Growth_NEW = ( Growth_Height * Growth_MULT )
      Temp_arr1 = P(i)(j)(k)
      ‘—
      Temp_y = (P(i)(j)(2)(1) – P(i)(j)(0)(1))/2 + P(i)(j)(0)(1) ‘X
      Temp_x = (P(i)(j)(1)(0) – P(i)(j)(0)(0))/2 + P(i)(j)(0)(0) ‘X
      Temp_z = Growth_Height + P(i)(j)(0)(2)’X
      Temp_m1 = -((Temp_z – P(i)(j)(0)(2))/(Temp_y – P(i)(j)(0)(1)))’X
      Temp_m2 = -((Temp_z – P(i)(j)(0)(2))/(Temp_x – P(i)(j)(0)(0)))
      ‘—
      Temp_b = Temp_z – ( Temp_m1 * P(i)(j)(0)(1) ) ‘X
      Temp_b2 = Temp_z – ( Temp_m2 * P(i)(j)(0)(0) ) ‘X
      ‘—
      P(i)(j)(0)(1) = ( ( Growth_NEW + P(i)(j)(0)(2) ) – Temp_b ) / Temp_m1 ‘X
      P(i)(j)(0)(0) = ( ( Growth_NEW + P(i)(j)(0)(2) ) – Temp_b2 ) / Temp_m2
      P(i)(j)(0)(2) = Growth_NEW + P(i)(j)(0)(2)
      ‘—      
      ‘—————————- 
      
      
      If j > 0 Then
       Check_d = Rhino.Distance(P(i)(j)(0), P(i)(j-1)(2))
       If Check_d < DIST Then
        Change_mod(0) = P(i)(j-1)(2)(0) – P(i)(j)(0)(0)
        Change_mod(1) = P(i)(j-1)(2)(1) – P(i)(j)(0)(1)
        Change_mod(2) = P(i)(j-1)(2)(2) – P(i)(j)(0)(2)
        P(i)(j)(0) = P(i)(j-1)(2)
       End If
      Else
       If i > 0 Then
        Check_d = Rhino.Distance(P(i)(j)(0), P(i-1)(j)(1))
        If Check_d < DIST Then
        Change_mod(0) = P(i-1)(j)(2)(0) – P(i)(j)(0)(0)
        Change_mod(1) = P(i-1)(j)(2)(1) – P(i)(j)(0)(1)
        Change_mod(2) = P(i-1)(j)(2)(2) – P(i)(j)(0)(2)         
         P(i)(j)(0) = P(i-1)(j)(1)
        End If  
       End If     
      End If
      
      Change_x = Temp_arr1(0) – P(i)(j)(k)(0)
      Change_y = Temp_arr1(1) – P(i)(j)(k)(1)
      
      Call Rhino.Addline(Temp_arr1, P(i)(j)(k))
             

   ‘CORNER 1—————————————————————–
     Case 1 ‘P(i)(j)(1)
      Temp_arr1 = P(i)(j)(k)
      P(i)(j)(1)(0) = P(i)(j)(1)(0) + Change_x
      P(i)(j)(1)(1) = P(i)(j)(1)(1) – Change_y
      P(i)(j)(1)(2) = Growth_NEW + P(i)(j)(1)(2) 
      ‘—————————–
      
      If j > 0 Then
       Check_d = Rhino.Distance(P(i)(j)(1), P(i)(j-1)(3))
       If Check_d < Dist Then
        Change_mod(0) =  ( Change_mod(0) + (P(i)(j-1)(3)(0) – P(i)(1)(0)(0)) )/2
        Change_mod(1) =  ( Change_mod(1) + (P(i)(j-1)(3)(1) – P(i)(1)(0)(1)) )/2
        Change_mod(2) =  ( Change_mod(2) + (P(i)(j-1)(3)(2) – P(i)(1)(0)(2)) )/2
        P(i)(j)(1) = P(i)(j-1)(3)
       End If
      End If 
      
      Call Rhino.Addline(Temp_arr1, P(i)(j)(k))     
     

   ‘CORNER 2—————————————————————–
     Case 2 ‘P(i)(j)(2)
      Temp_arr1 = P(i)(j)(k)
      P(i)(j)(2)(0) = P(i)(j)(2)(0) – Change_x
      P(i)(j)(2)(1) = P(i)(j)(2)(1) + Change_y
      P(i)(j)(2)(2) = Growth_NEW + P(i)(j)(2)(2) 
      ‘—————————-

      If i > 0 Then
       Check_d = Rhino.Distance(P(i)(j)(2), P(i-1)(j)(3))
       If Check_d < DIST Then
        Change_mod(0) =  ( Change_mod(0) + (P(i-1)(j)(3)(0) – P(i)(j)(2)(0)) )/2
        Change_mod(1) =  ( Change_mod(1) + (P(i-1)(j)(3)(1) – P(i)(j)(2)(1)) )/2
        Change_mod(2) =  ( Change_mod(2) + (P(i-1)(j)(3)(2) – P(i)(j)(2)(2)) )/2
        P(i)(j)(2) = P(i-1)(j)(3)
       End If
      End If
      
      Call Rhino.Addline(Temp_arr1, P(i)(j)(k))      
  
          
   ‘CORNER 3—————————————————————–
     Case 3 ‘P(i)(j)(3)
      Temp_arr1 = P(i)(j)(k)
      P(i)(j)(3)(0) = P(i)(j)(3)(0) + Change_x
      P(i)(j)(3)(1) = P(i)(j)(3)(1) + Change_y
      P(i)(j)(3)(2) = Growth_NEW + P(i)(j)(3)(2)
      ‘—————————-
      If i > 0 Then
       Check_d = Rhino.Distance(P(i)(j)(2), P(i-1)(j)(3))
       If Check_d < DIST Then
        P(i)(j)(2)(0) = P(i)(j)(2)(0) – Change_mod(0)
        P(i)(j)(2)(1) = P(i)(j)(2)(1) – Change_mod(1)
        P(i)(j)(2)(2) = P(i)(j)(2)(2) – Change_mod(2) 
        P(i)(j)(2) = P(i-1)(j)(3)
       End If
      End If
      
      Call Rhino.Addline(Temp_arr1, P(i)(j)(k))
        

      
     ‘—————————————————————–
    End Select
     ‘____________________________________________________
   Next
   
   
   If iteration = 2 Then
    sLofter_1 = Rhino.Addline(P(i)(j)(0),  P(i)(j)(1))
    sLofter_2 = Rhino.Addline(P(i)(j)(2),  P(i)(j)(3))
    ‘arrLoft() = array(sLofter_1, sLofter_2)
    Call Rhino.AddLoftSrf(array(sLofter_1, sLofter_2))
    ‘Call Rhino.AddPolyline(array( (P(i)(j)(0)),(P(i)(j)(1)),(P(i)(j)(3)),(P(i)(j)(2)), (P(i)(j)(0)) ) )
   End If
   
   n = n+1
  ‘———————–
  Next
  ‘———————–
 Next
End Function
‘########################################################
Function random(low, up) 
 Randomize
 random = ((up – low)* Rnd()) + low ‘ *** take the difference of range
End Function

Advertisements

One response to “070928_Agritect_v1.1

  1. Pingback: 070930_Matt_Pauly_Agritect_v1.1 « (n)certainties

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s