Discussion forum about PANORAMIC language

Mac, Windows & Android application development with PANORAMIC language
 
HomeFAQSearchRegisterMemberlistUsergroupsLog in
Latest topics
» Hello world.
by Mon Jun 19, 2017 1:37 am

» Biomorphes de PICKOVER
by Sun Jun 18, 2017 2:33 am

» In less than 10 lines of code
by Fri Jun 16, 2017 5:03 am

» Effect Dopler
by Fri Jun 16, 2017 3:29 am

» SuperEllipse
by Wed Jun 14, 2017 4:01 am

» Plants
by Wed Jun 14, 2017 3:38 am

» Mira's attractor
by Wed Jun 14, 2017 3:30 am

» Triangle of Sierpinski
by Wed Jun 14, 2017 3:22 am

» Esthétique polaire
by Wed Jun 14, 2017 3:16 am

» Butterfly effect : Lorenz equations
by Wed Jun 14, 2017 3:08 am

» Collision detection
by Tue Jun 13, 2017 5:09 am

» The Bees Laline Paull Epub Books
by Mon Oct 10, 2016 8:58 pm

» PANORAMIC for Mac OSX 10 is available
by Tue Aug 09, 2016 6:08 pm

» ide
by Sat Jul 16, 2016 12:27 am

» Can I change the program icon/logo in my application ?
by Thu Jul 07, 2016 3:32 am

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Share | 
 

 PLANT GROWTH

View previous topic View next topic Go down 
AuthorMessage
papydall

avatar

Number of posts : 39
Age : 67
Localisation : TUNISIA
Registration date : 2013-03-16

PostSubject: PLANT GROWTH   Sat Mar 16, 2013 1:43 am

Hi everyone.

I come from the French Forum, which is much more active than the English Forum.
I want to help lead a little more conversation on this forum.
Here is my modest contribution: a small program to simulate plant growth.

As I speak very little English, please excuse my mistakes.

Code:
' ******************************************************************************
'
'        PLANT GROWTH  BY  PAPYDALL
'
' ******************************************************************************
Run()
end
' ******************************************************************************
SUB Run()
    Initialization() : Init_Principle(): Evolution() : Draw()
END_SUB
' ******************************************************************************
SUB Initialization()
    dim pi : pi = 4*atn(1)
    dim xm,ym,NumCh%,NbEvol%,AngRamDeg, princ$,Lp%,ram%,r,i%,L$,L0princ%,Lgprinc%,L1princ%
    dim ch$(20),L0%(20),L1%(20),xn(200),yn(200),a(200)
    dim Long%,plus$ ,Lch% ,n%, c , L ,x, y ,f
    dim angle, pasmax, dpas,ramax%,nb%,pas,noeud%,rf,h%
    height 0 ,800 : width 0,800 : xm = 700 : ym = 700
    caption 0 , " PLANT GROWTH  BY  PAPYDALL .... Please Wait .... <CLICK> to terminate"
END_SUB
' ******************************************************************************
SUB Init_Principle()
    ' SIMULATION OF GROWTH VEGETATE
    ' By the method of L-systems (Aristid Lindenmeyer 1968)
    ' Coding principle of evolution:
    ' ==========================================================================
    ' 0: flower
    ' 1: stem
    ' 3: End of branch
    ' 4: Opening branching left
    ' 5: Opening the branching random
    ' 6: Opening branching right
    ' ==========================================================================
    ' Try one of the following principles (online REM)
    ' You can enter your own principles, being careful to respect
    ' The method of coding.
    ' An opening branch must always be followed by a closing
    ' NbEvol% : number of changes > 2
    ' AngRamDeg : branching angle in degrees 0 < AngRamDeg < 90
    ' F: step factor for plot (adjust)
    ' ==========================================================================

    princ$ = "1440316030366031403031140360310" : NbEvol% = 5 : AngRamDeg = 25 : f = 55
    ' princ$ = "1403603140360310"                : NbEvol% = 6 : AngRamDeg = 25 : f = 27
    ' princ$ = "1415030361503031140360310"      : NbEvol% = 5 : AngRamDeg = 16 : f = 28
    ' princ$ = "140360310"                      : NbEvol% = 7 : AngRamDeg = 20 : f = 6
    ' princ$ = "14031603140310"                  : NbEvol% = 6 : AngRamDeg = 20 : f = 10
    ' princ$ = "14036031403160310"              : NbEvol% = 6 : AngRamDeg = 25 : f = 24
    ' princ$ = "1603140316031503140310"          : NbEvol% = 5 : AngRamDeg = 36 : f = 18
    ' princ$ = "150316031403160340310"          : NbEvol% = 5 : AngRamDeg = 29 : f = 16

    verification()
    ch$(1) = "0" : L0%(1) = 1 : L1%(1) = 0
    AngRamDeg = AngRamDeg * pi / 180
END_SUB
' ******************************************************************************
SUB verification()
    repeat
      Lp% = len(princ$) : ram% = 0 : r = 0
      for i% = 1 to Lp%
        L$ = mid$(princ$,i%,1)
        if L$ = "0"
          L0princ% = L0princ% + 1
          if ram% = 0 then Lgprinc% = Lgprinc% + 1
        else
          if L$ = "1"
            L1princ% = L1princ% + 1
            if ram% = 0 then Lgprinc% = Lgprinc% + 1
          else
            if L$ = "3"
                ram% = ram% - 1
            else
                if (L$ = "4") or (L$ = "6") or (L$ = "5")
                  ram% = ram% + 1
                else
                  R = 1
                end_if
            end_if
          end_if
        end_if
      next i%
  until (R < 1) and (ram% = 0)
END_SUB
' ******************************************************************************
SUB evolution()
    for NumCh% = 1 to (NbEvol% - 1)
        Long% = 0
        for i% = 1 to len(ch$(NumCh%))
            L$ = mid$(ch$(NumCh%),i%,1)
          if L$ = "0"
              plus$ = princ$ : L0%(NumCh% + 1) = L0%(NumCh% + 1) + L0princ%
              L1%(NumCh% + 1) = L1%(NumCh% + 1) + L1princ%
              if ram% <>  0 then long% = long% + lgprinc%
          end_if
          if L$ = "1"
              plus$ = "11" : L1%(NumCh% + 1) = L1%(NumCh% + 1) + 2
              if ram% = 0  then Long% = Long% + 2
          end_if
          if L$ = "5" then plus$ = str$(int(rnd(2)+2)*2) : ram% = ram% + 1
          if L$ = "3"
            if ram% > ramax% then ramax% = ram%
            ram% = ram% - 1 : plus$ = "3"
          end_if
        if (L$ = "4") or (L$ = "6") then plus$ = L$ : ram% = ram% + 1
        ch$(NumCh% + 1) = ch$(NumCh% + 1) + plus$
      next i%
    if NumCh% < (NbEvol% - 1) then error()
    next NumCh%
END_SUB

' ******************************************************************************
SUB error()
    Lch% = len(ch$(NumCh% + 1))+ L1%(NumCh% + 1)+ L0%(NumCh% + 1)*(Lp% - 1)
    if Lch% > 32767
      message "The string is too long to process."
      message "You will be limited to the generation No " + str$(NumCh% + 1)
      n% = NumCh% + 1 : NumCh% = NbEvol% : NbEvol% = n%
    end_if
END_SUB
' ******************************************************************************
SUB draw()
    cls
    print "  Principle : " ; princ$ ; "  Generation n° : " ; NumCh% ; "  " ;
    2d_fill_color 50,100,255 : 2d_rectangle 10,20,790,690
    angle = pi/2 : pasmax = ym*f/long% : dpas = (pasmax/3)/ramax% : sun()
    for NumCh% = 1 to NbEvol%
        y = ym -20 : x = xm/2
        for i% = 1 to len(ch$(NumCh%))
            nb% = val(mid$(ch$(NumCh%),i%,1))
          pas = pasmax - noeud% * dpas : rf = pas/8
          select nb%+1
            case 1 : flower()
            case 2 : stem()
            case 3 : ' nothing
            case 4 : close()
            case 5 : open()
            case 6 : random()
            case 7 : open()
          end_select
          if scancode <> 0 then terminate
      next i%
    next NumCh%
    caption 0 , " PLANT GROWTH  BY  PAPYDALL .... "
    print " completed"
END_SUB
' ******************************************************************************

SUB stem()
    c = x : L = y : x = x + pas * cos(angle) : y = y - pas * sin(angle)
    2d_pen_color 0,255,0 : 2d_line c,l,x,y
END_SUB
' ******************************************************************************
SUB flower()
    pas = pas - (2*rf) : stem() : c = x + rf * cos(angle) : L = y - rf * sin(angle)
    2d_pen_color 255,0,0 : 2d_circle c, L, rf+1
END_SUB
' ******************************************************************************
SUB open()
    noeud% = noeud% + 1 : a(noeud%) = angle : xn(noeud%) = x : yn(noeud%) = y
    angle = angle + (5 - nb%) * AngRamDeg
END_SUB
' ******************************************************************************
SUB random()
    open() : h% = rnd(2) + 1
    if h% = 2 then angle = angle + AngRamDeg : else : angle = angle - AngRamDeg
END_SUB
'*******************************************************************************
SUB close()
    x = xn(noeud%) : y = yn(noeud%) : angle = a(noeud%) : noeud% = noeud% - 1
END_SUB
' ******************************************************************************
SUB sun()
    x = 20 +rnd(700) : y = 40  + rnd(100)
    2d_fill_color 255,255,0 : 2d_circle x,y,20
END_SUB
' ******************  THE END  *************************************************
Back to top Go down
View user profile
aurel



Number of posts : 6
Registration date : 2010-03-24

PostSubject: Re: PLANT GROWTH   Thu Oct 24, 2013 8:50 pm

why this example not work on my computer.
i have latest release of panoramic and interpreter complain
about that is not aloved this number of subroutines...
(24)
what is this ???????
Back to top Go down
View user profile
jean_debord



Number of posts : 19
Registration date : 2010-08-08

PostSubject: Re: PLANT GROWTH   Fri Oct 25, 2013 10:12 am

I have tested with Panoramic version 0.9.25i4 and it works well.

This version is available here:

http://panoramic-language.pagesperso-orange.fr/PANORAMIC_EDITOR.zip
Back to top Go down
View user profile
papydall

avatar

Number of posts : 39
Age : 67
Localisation : TUNISIA
Registration date : 2013-03-16

PostSubject: Re: PLANT GROWTH   Fri Oct 25, 2013 4:35 pm

Hello Aurel

You have maybe a version limited of Panoramic.
Otherwise, it works and that gives this, for example:



Thank you Jean_debord for the test Very Happy 
Back to top Go down
View user profile
Sponsored content




PostSubject: Re: PLANT GROWTH   

Back to top Go down
 
PLANT GROWTH
View previous topic View next topic Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Discussion forum about PANORAMIC language :: Panoramic for Windows :: Source code (snippets)-
Jump to: