Mandalas 3D (un-punched version)

Everything related to 3D programming
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Mandalas 3D (un-punched version)

Post by kernadec »

Hello,
Here is a more complete version 7 of MANDALA3D
With a "Mandalas.csv" ascii file

I could no put all the options in my code the session punch,
It lies only With the 3D matrix And an addition of a 4th calculation To obtain graphics
beautiful beats of wings With the key delete = 2

at the request of Vera,
Now a backup To the window With popmenu And listview buttons save Or delete
And With full screen key "S" button saves the graphics settings, key no implement erase
the selected keyboard + And - choise graphics from the base.
I use a simple listView With an index number To make This easy adapte code on LInux And Mac

Best Regards

Code: Select all

;##################################################################################################
;#  English forum session punch XMas 2014 : http://www.purebasic.fr/english/viewtopic.php?f=14&t=61104
;#  Author: kernadec , Date:  XMas 2014   :http://www.purebasic.fr/english/posting.php?mode=edit&f=36&t=61302&p=458455
;#  PureBasic 5.22 : OS: Windows : (no tests Linux and Mac) 
;#  
;#  Titre: MANDALAS3D V8 ( Ellipsoid variations )
;#
;#   Display : Full Screen And windows 800/600 
;#  Use a very basic  ListViewGadget() via index to facilitate the Linux and Mac OS compatibility
;#  Mode Save/Read to file for the restoration of the parameters elements Mandalas
;###################################################################################################

Enumeration
  #Window0  
  #Window1 
  #Window2
EndEnumeration

Enumeration
  #ListView
  #Button0 
  #Button1 
  #TextGadget
  #FrameGadget
EndEnumeration

Enumeration
  #PopMenu
  #Menu1
EndEnumeration

Enumeration
  #File  
EndEnumeration

Structure Text
  L$
EndStructure

Global Dim Cl(7)
Global NewList Mandala.Text()

Procedure.s Fmt(n)
  
  n$ = Str(n)
  n$ = RSet(n$, 5, " ")        ; Spaces Previous for Tab ListView and File
  ProcedureReturn n$
  
EndProcedure

Procedure sauvefichier(Chemin$,Formtext$,type)
  
  If type = 0                 ; Mode window Save global listview function add or delete line
    
    If  FileSize(chemin$+".csv") <> -1
      CopyFile(chemin$+".csv", chemin$+".bak")    ; creation in backup old file
    EndIf
    
    CreateFile(#File , Chemin$ + ".csv")          ; creation new file
    For W = 0 To CountGadgetItems(#ListView)
      
      Tmp$ = ReplaceString(GetGadgetItemText(#ListView, W), Chr(#LF), ";", 1)
      
      Tmp$ = Right(Tmp$, Len(Tmp$)-Len(StringField(Tmp$, 1, ";")))
      
      If Tmp$ <> ""                              ;  Listview Format  1000 fields index  Numbers 
        If Len(Str(W)) = 1 : Tmp$ = "00" + Str(W) + Tmp$ : EndIf
        If Len(Str(W)) = 2 : Tmp$ =  "0" + Str(W) + Tmp$ : EndIf
        If Len(Str(W)) = 3 : Tmp$ =        Str(W) + Tmp$ : EndIf
        
        WriteStringN(#File, Tmp$)   
        
      EndIf
    Next W     
    CloseFile(#File)
    
  Else                                          ; Mode Save Key "S" full screen and add just line 
    
    W = -1
    If ReadFile(#File, Chemin$ + ".csv")
      While Eof(#File) = 0           
        Tmp$ = ReadString(#File)    
        If Tmp$ <> ""
          W + 1                                  ; Read Count Total line number 
        EndIf
      Wend
      CloseFile(#File)
    Else
      MessageRequester("Information","Unable to open file!")
    EndIf
    
    
    W + 1                                                    ; next number index for add line
    If Len(Str(W)) = 1 : Tmp$ = "00" + Str(W) + ";" + Formtext$ : EndIf
    If Len(Str(W)) = 2 : Tmp$ =  "0" + Str(W) + ";" + Formtext$ : EndIf
    If Len(Str(W)) = 3 : Tmp$ =        Str(W) + ";" + Formtext$ : EndIf
    
    OpenFile    (#File , Chemin$ + ".csv", #PB_File_Append)  ; update file
    FileSeek    (#File , Lof(#File))         
    WriteStringN(#File , Tmp$)                               ; write new line file  
    CloseFile   (#File)
    
  EndIf
  
EndProcedure 

Procedure.s chargefichier(Chemin$,type)
  
  If type = 0        ; mode window load to listview 
    If ReadFile(#File, Chemin$ + ".csv") 
      ClearGadgetItems(#ListView)
      While Eof(#File) = 0           
        
        Tmp$ = ReadString(#File)    
        If Tmp$<> ""
          AddGadgetItem(#ListView, -1, Tmp$) 
        EndIf
        
      Wend
      CloseFile(#File)              
    Else
      MessageRequester("Information","Unable to open file!")
    EndIf
    
  Else              ; mode Full Screen key "+" & "-" read file to write newlist mandala()
    
    If ReadFile(#File, Chemin$ + ".csv") 
      While Eof(#File) = 0           
        
        Tmp$ = ReadString(#File)
        If Tmp$<> ""
          AddElement(Mandala())         
          Mandala()\L$ = Tmp$
        EndIf
        
      Wend
      CloseFile(#File)              
    Else
      MessageRequester("Information","Unable to open file!")
    EndIf
    
  EndIf
  ProcedureReturn Tmp$
  
EndProcedure

Procedure Ellipse_Rotation(Axex.l, Axey.l, Xr.l, Yr.l, Zr.l, Rtx.d, Rty.d, Rtz.d, Debut.l, Fin.l, Polygone.l, Col.l, Mode.l, Styl.l) 
  
  Protected v.d, RB.d, Rx.d, Ry.d, Rz.d, X.d, Y.d, Z.d, X1.d, Y1.d, Z1.d, Psx1.l, Psy1.l, Psx2.l, Psy2.l, Side.d, Stp.d
  
  If Polygone <> 0 :   Side = 360 / Polygone : Else : Side = 360 : EndIf
  
  Rx = Radian(Rtx)
  Ry = Radian(Rty)
  Rz = Radian(Rtz)
  
  
  Stp = debut 
  
  Repeat 
    
    v = Radian(Stp)
    
    If Mode = 0                       ; ellipsoid
      X = Xr * Sin(v)
      Y = Yr * Sin(v)
      Z = Zr * Cos(v)
    EndIf
    If Mode = 1                       ; Bowl + conical sphere
      X = Xr * Sin(v)
      Y = Yr * Sin(v*0.2)
      Z = Zr * Sin(v*0.6)
    EndIf
    If Mode = 2                       ; ellipsoid drilled poles
      X = Xr *  Cos(v-0.5) 
      Y = Yr *  Sin(v)
      Z = Zr *  Cos(v)
    EndIf
    If Mode = 3                       ; 2 inverted bowls + conical sphere                          
      X = Xr * Sin(v*2)
      Y = Yr * Cos(v*0.25)
      Z = Zr * Sin(v)
    EndIf
    If Mode = 4                       ; 3 spheres discs drilled
      X = Xr * Cos(v * -3)
      Y = Yr * Cos(v / -2)
      Z = Zr * Sin(v)
    EndIf
    If Mode = 5                       ; discs + 2 disks spheres 
      X = Xr * Sin(v * 0.25)
      Y = Yr * Cos(v * 2)
      Z = Zr * Sin(v * 0.35)
    EndIf
    If Mode = 6                       ; 2 bowls + 1 conical sphere bunk
      X = Xr * Sin(v * 1.5)
      Y = Yr * Cos(v)
      Z = Zr * Sin(v * 0.65)
    EndIf
    If Mode = 7                       ; 5 discs spheres
      X = Xr * Sin(v * 0.68)
      Y = Yr * Cos(v * 2.5)
      Z = Zr * Sin(v)
    EndIf
    If Mode = 8                       ; tapered cylinders 
      X = Xr * Sin(v * 0.5)
      Y = Yr * Cos(v * -3)
      Z = Zr * Sin(v * 1.4)
    EndIf
    If Mode = 9                       ; tapered cylinders and 2 cones
      X = Xr * Cos(v)
      Y = Yr * Cos(v * 0.35)
      Z = Zr * Cos(v * 1.7)
    EndIf
    
    ;  ------- matrice 3D -----------
    X1 = X  * Cos(rz) + Y  * Sin(rz)
    y1 = Y  * Cos(rz) - X  * Sin(rz)
    Z1 = Z
    
    RB = Y1 * Cos(ry) - Z1 * Sin(ry)
    z1 = Y1 * Sin(ry) + Z1 * Cos(ry)
    Y1 = RB 
    
    RB = X1 * Cos(rx) + Z1 * Sin(rx)
    z1 = X1 * Sin(rx) - Z1 * Cos(rx)
    Y1 = RB
    
    ; -Option Wing --fourth-calculation-
    
    If styl = 2 Or styl = 3
      
      X = X1 
      Y = Y1
      Z = z1
      
      X1 = X  * Cos(rz) - Y  * Sin(rz)
      y1 = Y  * Cos(rz) + X  * Sin(rz)
      Z1 = Z
      
    EndIf
    
    ; ------------------------------
    
    
    Psx1 = Z1 + Axex
    Psy1 = Y1 + Axey
    
    
    If Psx2 = 0 And Psy2 = 0 : Psx2 = Psx1 : Psy2 = Psy1: EndIf
    
    If styl = 1 Or styl =3 : Swap Psy2,psy1 : EndIf
    
    If  Stp =>  0 And Stp <= 90 
      LineXY(Psx2, Psy2, Psx1, Psy1, Cl(0))
    EndIf
    
    If Stp =>  90 And Stp <= 180 
      LineXY(Psx2, Psy2, Psx1, Psy1, Cl(1))
    EndIf
    
    If Stp => 180 And Stp <= 270 
      LineXY(Psx2, Psy2, Psx1, Psy1, Cl(2))
    EndIf
    
    If Stp => 270 And Stp <= 360 
      LineXY(Psx2, Psy2, Psx1, Psy1, Cl(3))
    EndIf
    
    If styl = 1 Or styl =3 : Swap Psy2,psy1 : EndIf
    
    Psx2 = Psx1
    Psy2 = Psy1
    
    Stp + Side
    
  Until Stp => Fin + 1
  
EndProcedure  

ExamineDesktops()
InitSprite()
InitKeyboard()

If LoadFont(1, "Courier New", 8)  ; Font For Tab ListView
  SetGadgetFont(#PB_Default, FontID(1)) 
EndIf 

Chemin$=GetCurrentDirectory()+"mandalas"

chargefichier(Chemin$,1)

R1 = MessageRequester("SCREEN",Space(16)+"FULL SCREEN",#PB_MessageRequester_YesNo)

Xs = DesktopWidth(0)             ; Xscreen
Ys = DesktopHeight(0)            ; Yscreen

If R1 = 6 
  OpenWindow(#Window2, 0, 0, 0, 0, "", #PB_Window_Invisible) 
  OpenScreen(Xs, Ys, 32, "")
Else
  Xs = 800 : Ys = 600
  OpenWindow(#Window0, 0, 0, Xs, Ys, "MANDALAS 3D     by  kernadec     XMas  2014", #PB_Window_WindowCentered|#PB_Window_ScreenCentered )
  If CreatePopupMenu(#PopMenu) 
    MenuItem(#Menu1, "List") 
  EndIf
  OpenWindowedScreen(WindowID(#Window0) , 0, 0, Xs, Ys, 0, 0, 0,#PB_Screen_SmartSynchronization)
EndIf

Axex.l  = Xs/2  ; Axis X Screen
Axey.l  = Ys/2  ; Axis Y Screen
Debut.l = 0     ; Start Xircle 
Fin.l   = 360   ; End   Circle

Wh.l    =   0   ; Switch Wheel
Pass.l  =   0   ; Switch Vars


Nl.l    =   0   ; Numbers Display Mandala List
Mode.l  =   6   ; Mode Draw Mandala
Styl.l  =   2   ; Pixels or Stick, Wing
Plt.l   =  12   ; Polygon Side Parallel
Plg.l   =   3   ; Polygon Side Meridian
Inc     =  10   ; Speed Key Shift to X1 or X10 
Vi.l    =   1   ; Speed Rotate x1,x2,x3,x4.....

Xd      =  30   ; Corner X
Yd      =-210   ; Corner Y
Zd      = 280   ; Corner Z

Zr.l    =   1   ; Radius Z
Yr.l    =-115   ; Radius Y
Xr.l    = 290   ; Radius X

a.l     =   0   ; Color 0
b.l     =   1   ; Color 1
c.l     =   2   ; Color 2
d.l     =   3   ; Color 3

Cl(a) = RGB(255, 0, 0)           ; Red
Cl(b) = RGB( 0, 0,255)           ; Blue
Cl(c) = RGB( 0,255, 0)           ; Green
Cl(d) = RGB(255,255,0)           ; Yellow

;Cl(a) = RGB(255, 255, 255)       ; White
;Cl(b) = RGB(255, 255, 255)       ; White
;Cl(c) = RGB(255, 255, 255)       ; White
;Cl(d) = RGB(255, 255, 255)       ; White

Cl(4) = Cl(a) : Cl(5) = Cl(b) : Cl(6) = Cl(c) : Cl(7) = Cl(d)   ;  Order Color


Repeat
  
  ExamineKeyboard()
  
  StartDrawing(ScreenOutput()) 
  
  If Plt < 0 : Plt = 360 : EndIf
  
  Zd = Mod(Zd + Vi , 360)
  
  For i = 0 To 360 
    Ellipse_Rotation(Axex, Axey, Xr, Yr, Zr, Xd, Yd, Zd + i , Debut, Fin, Plt, 0, Mode, Styl)
    i + Plg
  Next i
  
  StopDrawing() 
  
  If KeyboardPushed(#PB_Key_Tab) : Delay(100) : Mode + 1    : If Mode > 9 : Mode = 0        : EndIf : EndIf
  If KeyboardReleased(#PB_Key_LeftShift)      : If Inc  = 1 : Inc  = 10   : Else : Inc  = 1 : EndIf : EndIf
  If KeyboardReleased(#PB_Key_Space)          : If Lt   = 0 : Lt   =  1   : Else : Lt   = 0 : EndIf : EndIf
  If KeyboardReleased(#PB_Key_Delete)         :    Styl + 1 : If Styl > 3 : Styl =  0       : EndIf : EndIf
  
  ; Test Speed Change x1 Or x10 For Change Polygon Or Radius Speed X1 Corners < 20
  If Abs(Plt) = 180 : Plt  + 180 : Tmp = 10 : Else : Tmp  = Inc : EndIf
  If Abs(Plt) =   0 : Plt  = 360 : Tmp = 10 : Else : Tmp  = Inc : EndIf
  If Abs(Plt) <  21 : Tmp  =   1 :            Else : Tmp  = Inc : EndIf
  If Abs(Plg) <  21 : Tmp1 =   1 :            Else : Tmp1 = Inc : EndIf
  If Abs(Zr ) <  31 : Tmp2 =   1 :            Else : Tmp2 = Inc : EndIf
  
  If KeyboardPushed(#PB_Key_Up)      :              Yd  = Mod(Yd   + Inc , 360): EndIf 
  If KeyboardPushed(#PB_Key_Down)    :              Yd  = Mod(Yd   - Inc , 360): EndIf
  
  If KeyboardPushed(#PB_Key_Left)    :              Xd  = Mod(Xd   + Inc , 360): EndIf 
  If KeyboardPushed(#PB_Key_Right)   :              Xd  = Mod(Xd   - Inc , 360): EndIf
  
  If KeyboardPushed(#PB_Key_PageUp)  :              Plt = Mod(Plt  + Tmp , 180): EndIf 
  If KeyboardPushed(#PB_Key_PageDown): Delay(100) : Plt = Mod(Plt  - Tmp , 180): Plt = Abs(Plt)     : EndIf 
  
  If KeyboardPushed(#PB_Key_Home)    : Delay(100) : Plg = Mod(Plg  + Tmp1, 360): EndIf 
  If KeyboardPushed(#PB_Key_End)     : Delay(100) : Plg = Mod(Plg  - Tmp1, 360): Plg = Abs(Plg)     : EndIf
  
  If KeyboardPushed(#PB_Key_1) Or KeyboardPushed(#PB_Key_Pad1):              Zr = Mod(Zr - Tmp2, Ys) : EndIf 
  If KeyboardPushed(#PB_Key_4) Or KeyboardPushed(#PB_Key_Pad4):              Zr = Mod(Zr + Tmp2, Ys) : EndIf 
  If KeyboardPushed(#PB_Key_2) Or KeyboardPushed(#PB_Key_Pad2):              Yr = Mod(Yr - Inc , Ys) : EndIf 
  If KeyboardPushed(#PB_Key_3) Or KeyboardPushed(#PB_Key_Pad3):              Yr = Mod(Yr + Inc , Ys) : EndIf 
  If KeyboardPushed(#PB_Key_5) Or KeyboardPushed(#PB_Key_Pad5):              Xr = Mod(Xr - Inc , Ys) : EndIf 
  If KeyboardPushed(#PB_Key_6) Or KeyboardPushed(#PB_Key_Pad6):              Xr = Mod(Xr + Inc , Ys) : EndIf 
  If KeyboardPushed(#PB_Key_7) Or KeyboardPushed(#PB_Key_Pad7): Delay(100) : Vi = Mod(Vi + 1, 180)   : EndIf 
  If KeyboardPushed(#PB_Key_8) Or KeyboardPushed(#PB_Key_Pad8): Delay(100) : Vi = Mod(Vi - 1, 180)   : EndIf 
  If KeyboardPushed(#PB_Key_9) Or KeyboardPushed(#PB_Key_Pad9):              Vi = 0                  : EndIf 
  If KeyboardPushed(#PB_Key_0) Or KeyboardPushed(#PB_Key_Pad0): a=Random(3):Repeat:b=Random(3):Until b<>a:Repeat:c=Random(3):Until c<>a And c<>b:Repeat:d=Random(3):Until d<>a And d<>b And d<>c: cl(0)=cl(4+a):cl(1)=cl(4+b):cl(2)=cl(4+c):cl(3)=cl(4+d): EndIf
  
  If KeyboardReleased(#PB_Key_S)        ; Save Element to File 
                                        ; format chaine for the file base and element newlist 
    Formtext$ = Fmt(mode) + ";" + Fmt(styl) + ";" + Fmt(Plt) + ";" + Fmt(Plg) + ";" + Fmt(Inc) + ";" + Fmt(Vi) + ";" + Fmt(Xd) + ";" + Fmt(Yd) + ";" + Fmt(Zd) + ";" + Fmt(Xr) + ";" + Fmt(Yr) + ";" + Fmt(Zr) + ";" + Fmt(a) + ";" + Fmt(b) + ";" + Fmt(c) + ";" + Fmt(d)
    sauvefichier(Chemin$,Formtext$, 1)  ; Save new element in update file and add element in Newlist mandala
    ClearList(Mandala()) 
    chargefichier(Chemin$, 1)           ; Restore NewList Mandala
    
  EndIf
  
  If KeyboardReleased(#PB_Key_Add)     : Wh = 1 : Nl = Mod(nl + 1, ListSize(Mandala())) : EndIf  ; key Read file mandala base 
  If KeyboardReleased(#PB_Key_Subtract): Wh = 1 : Nl - 1 : If Nl < 0 : Nl = ListSize(Mandala())-1 : EndIf : EndIf
  
  If Wh <> 0 : Wh = 0                   ; Wheel Key "+/-"  Display Mandala
    
    ResetList(Mandala()) 
    For i = 0 To ListSize(Mandala())
      NextElement(Mandala()) 
      If Val(StringField(Mandala()\L$, 1, ";")) = Nl
        Tmp$ = Mandala()\L$             ; Read newlist element to tmp$  
        Break
      EndIf
    Next i
    pass = 1                                 ; switch Vars
    
  EndIf
  
  If pass <> 0 : pass = 0                    ; tmp$ Restore To Vars     
    
    num  = Val(StringField(Tmp$,  1, ";"))   ; Number Index ListView
    mode = Val(StringField(Tmp$,  2, ";"))   ; Mode Draw Mandala
    styl = Val(StringField(Tmp$,  3, ";"))   ; Pixels or Stick
    Plt  = Val(StringField(Tmp$,  4, ";"))   ; Polygon Side Parallel
    Plg  = Val(StringField(Tmp$,  5, ";"))   ; Polygon Side Meridian
    Inc  = Val(StringField(Tmp$,  6, ";"))   ; Speed Key Shift to x1 or x10 
    Vi   = Val(StringField(Tmp$,  7, ";"))   ; Speed Rotate x1,x2,x3,x4.....
    Xd   = Val(StringField(Tmp$,  8, ";"))   ; Corner X
    Yd   = Val(StringField(Tmp$,  9, ";"))   ; Corner Y
    Zd   = Val(StringField(Tmp$, 10, ";"))   ; Corner Z
    Xr   = Val(StringField(Tmp$, 11, ";"))   ; Radius X
    Yr   = Val(StringField(Tmp$, 12, ";"))   ; Radius Y
    Zr   = Val(StringField(Tmp$, 13, ";"))   ; Radius Z
    a    = Val(StringField(Tmp$, 14, ";"))   ; Color Random  RGBY
    b    = Val(StringField(Tmp$, 15, ";"))   ; Color Random  RGBY
    c    = Val(StringField(Tmp$, 16, ";"))   ; Color Random  RGBY
    d    = Val(StringField(Tmp$, 17, ";"))   ; Color Random  RGBY
    
    Cl(0) = Cl(4 + a) : Cl(1) = Cl(4 + b) : Cl(2) = Cl(4 + c) : Cl(3) = Cl(4 + d)   ; Restore Order Color
    
  EndIf
  
  If Lt = 0
    StartDrawing(ScreenOutput()) 
    
    DrawText(10,   190, "1",Cl(0))
    DrawText(30,   190, "2",Cl(1))
    DrawText(50,   190, "3",Cl(2))
    DrawText(70,   190, "4",Cl(3))
    
    DrawText(10,    10, "-Key Shift left y/n >inc/dec< x1 or x10= " + Str(inc))
    DrawText(10,    30, "-Key Space y/n menu text")
    DrawText(10,    50, "-PgU/PgD  +/- Plt=  "                      + Str(Plt)  + " / 180")
    DrawText(10,    70, "-Hom/End  +/- Plg=  "                      + Str(Plg)  + " / 360")
    DrawText(10,    90, "-Key 7/8 +/- Vit/Rt= "                     + Str(Vi )  + " / 180")
    DrawText(10,   110, "-Key 9 Vit/Rt in 0")
    DrawText(10,   130, "-Key del > 0 Style= "                      + Str(Styl))
    DrawText(10,   150, "-Key 0 Move color")
    DrawText(10,   170, "-Tab  M = "                                + Str(Mode) + " / 9")
    
    DrawText(10, Ys-178, "-Key Esc = Quit")
    DrawText(10, Ys-158, "-Key S Save Draw")
    DrawText(10, Ys-138, "- +/-  Load list n°" + Str(nl))
    DrawText(10, Ys-118, "-ClickMRight = Listview ")
    DrawText(10, Ys- 98, "- <-   ->    +/- = "                       + Str(Xd)   + " / 360")
    DrawText(10, Ys- 78, "-Up/Down  +/- = "                          + Str(Yd)   + " / 360") 
    DrawText(10, Ys- 58, "-Key 1/4 +/- Zradius= "                    + Str(Zr)   + " / "     +Str(Ys))
    DrawText(10, Ys- 38, "-Key 2/3 +/- Yradius= "                    + Str(Yr)   + " / "     +Str(Ys))
    DrawText(10, Ys- 18, "-Key 5/6 +/- Xradius= "                    + Str(Xr)   + " / "     +Str(Ys))
    
    StopDrawing()
  EndIf
  
  FlipBuffers() 
  
  ClearScreen(0)
  
  Repeat
    
    Event = WindowEvent()
    
    Select event                         
      Case #WM_RBUTTONDOWN             
        DisplayPopupMenu(#PopMenu, WindowID(#Window0))  
      Case #PB_Event_Menu     
        Select EventMenu()     
          Case #Menu1            ;"Pop Menu List"
            quit = 0
            If OpenWindow   (#Window1,      0,   0, 750, 170, "File-Mandalas-List ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
              ListViewGadget(#ListView,     10,  20, 720, 120)
              FrameGadget   (#FrameGadget,  10,   5, 700, 135, "N°| Mod | Styl| Plt | Plg | Inc | Spd | Xd  | Yd  | Zd  |  Xr |  Yr |  Zr |  R  |  G  |  B  |  Y  |") 
              ButtonGadget  (#Button0,      70, 143, 100,  25, "Add Item")
              ButtonGadget  (#Button1,     580, 143, 100,  25, "Delete Item")
              TextGadget    (#TextGadget,  247, 140, 256, 200, "Selection = Double click on the line")
              StartDrawing(WindowOutput(#Window1)) : Col.l = Point(1, 1) : StopDrawing()
              SetGadgetColor(#TextGadget, #PB_Gadget_BackColor , Col)
              
              chargefichier(Chemin$,0)
              
              Formtext$=Fmt(mode) + ";" + Fmt(styl) + ";" + Fmt(Plt) + ";" + Fmt(Plg) + ";" + Fmt(Inc) + ";" + Fmt(Vi) + ";" + Fmt(Xd) + ";" + Fmt(Yd) + ";" + Fmt(Zd) + ";" + Fmt(Xr) + ";" + Fmt(Yr) + ";" + Fmt(Zr) + ";" + Fmt(a) + ";" + Fmt(b) + ";" + Fmt(c) + ";" + Fmt(d)
              
              Repeat
                
                Event2 = WaitWindowEvent()
                
                Select Event2
                  Case #PB_Event_CloseWindow : CloseWindow(#Window1) : quit = 1
                  Case #PB_Event_Gadget
                    Select EventGadget()
                        
                      Case #ListView ; Show the selected listview entry on doubleclick
                        
                        If EventType() = #PB_EventType_LeftDoubleClick 
                          
                          ; Element listView Item to Var Tmp$ 
                          Tmp$ = GetGadgetItemText(#ListView, GetGadgetState(#ListView))
                          Pass = 1                          ; switch Vars
                          Nl = GetGadgetState(#ListView)    ; Restore Count Position Newlist Screen
                          CloseWindow(#Window1) : quit = 1
                          
                        EndIf
                        
                      Case #Button0 ; Button: Add
                        
                        AddGadgetItem(#ListView ,-1 ,Str(CountGadgetItems(#ListView)-1) + ";" + Formtext$)    ; Write Element ListView,
                        sauvefichier(Chemin$,Formtext$,0)                                                     ; Update File 
                        chargefichier(Chemin$,0)                                                              ; Read Update Elements
                        ClearList(Mandala()) 
                        chargefichier(Chemin$,1)           ; Update Newlist
                        CloseWindow(#Window1) : quit = 1
                        
                      Case #Button1 ; Button: Delete
                        
                        RemoveGadgetItem(#ListView , GetGadgetState(#ListView))
                        sauvefichier(Chemin$,Formtext$,0)  ; Update File 
                        chargefichier(Chemin$,0)           ; Update Read Element
                        ClearList(Mandala()) 
                        chargefichier(Chemin$,1)           ; Update Newlist
                        
                    EndSelect
                EndSelect
              Until quit = 1
            EndIf
        EndSelect
        
      Case #PB_Event_CloseWindow
        End 
    EndSelect
    
  Until Event = 0
  
Until KeyboardPushed(#PB_Key_Escape) 
End





Save ASCII to: mandalas.csv

Code: Select all

000;    6;    2;   12;    3;   10;    1;   30; -210;  282;  290; -115;    3;    0;    1;    2;    3
001;    5;    0;   10;    5;   10;   19;   90;   50;  127;  160; -315;   -1;    2;    3;    0;    1
002;    1;    0;   10;    5;   10;   19;   90;   50;  339;  160; -315;   -1;    2;    3;    0;    1
003;    6;    1;   10;    5;   10;   19;  350; -280;  258;  -70;  325;   -8;    2;    3;    1;    1
004;    2;    0;   10;    5;   10;   19;   90;   50;  277;  160; -315;   -1;    2;    3;    0;    1
005;    4;    0;   10;    5;   10;   19;   90;   50;  166;  160; -315;   -1;    2;    3;    0;    1
006;    0;    1;   16;   18;   10;    1; -150; -170;  312;   80;  225; -235;    0;    3;    2;    1
007;    0;    1;    5;   18;   10;    1;  -90;  -20;  152;   50;   95; -141;    0;    3;    2;    1
008;    5;    1;   11;   10;   10;    1; -358; -131;  160;    0; -235;   -6;    0;    1;    3;    2
009;    8;    1;   11;   10;   10;    1;  -18; -261;  277;    0; -245;   -6;    0;    1;    3;    2
010;    0;    1;   11;   10;   10;    1;  -18; -261;  109;    0; -245;   -6;    0;    1;    3;    2
011;    2;    1;   10;    5;   10;   -1;  -50; -290; -313;  440;   15;   -1;    2;    1;    0;    3
012;    6;    2;   12;    3;   10;    1;  160  -280;  315;  110;  205;  -24;    0;    1;    2;    3
013;    9;    2;   12;    3;   10;    1;  230; -270;  193; -300; -185;-1011;    0;    1;    2;    3
014;    3;    2;   31;    3;   10;    1;  290;  -20;  265; -220; -435;    6;    3;    0;    1;    2
015;    6;    2;   12;    3;   10;    1;  120; -240;  147;  290; -165;    3;    1;    3;    2;    0
016;    7;    2;   12;    3;   10;    1; -310; -130;  218;  400;  175;    3;    2;    0;    1;    3
017;    7;    2;   12;    3;   10;    1; -310; -240;  124;  400;  175;    0;    2;    0;    1;    3
018;    7;    2;   12;    3;    1;    1;  -59;  -41;  152;  400;  175;    0;    2;    0;    1;    3
019;    4;    2;    8;    3;    1;   27; -251; -252;   35;  400;  175;    0;    3;    0;    2;    1
020;    2;    2;    5;    3;    1;   27; -339;  -90;  233;  400;  175;    0;    0;    3;    1;    2
021;    7;    2;    6;    2;    1;    1; -186; -294;  323;  351;  181;    0;    1;    0;    3;    2
022;    7;    2;    6;    2;    1;    1;  222; -104;  331;  351;  181;    0;    3;    0;    1;    2
023;    8;    2;   36;    2;    1;    1; -132;  -88;   36;  351;  181;    0;    1;    2;    0;    3
024;    0;    2;   30;    2;   10;    1;  -61;  -48;  263; -286;  207;  -71;    1;    3;    0;    2
025;    7;    2;   12;    3;    1;    4; -270;  180;  269;  240; -237;    0;    0;    2;    1;    3
026;    0;    2;    5;    2;    1;    0;  -90;  180;  128; -215;   -5;  266;    2;    3;    0;    1
027;    1;    2;   10;    2;   10;    4; -308; -326;    7; -363; -134;    0;    2;    1;    3;    0
Last edited by kernadec on Sat Dec 27, 2014 1:25 pm, edited 6 times in total.
User avatar
glomph
User
User
Posts: 48
Joined: Tue Apr 27, 2010 1:43 am
Location: St. Elsewhere / Germany
Contact:

Re: Mandalas 3D (no compress punch)

Post by glomph »

Great!
Love it.

Greetings
Glomph
User avatar
Demivec
Addict
Addict
Posts: 4281
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Mandalas 3D (no compress punch)

Post by Demivec »

Awesome!

Thanks for posting the un-punched version. :)
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: Mandalas 3D (no compress punch)

Post by kernadec »

hello,
thank glomph and demivec
I am very pleased that you like,
I add a few lines fun in mandalas.csv

Merry Christmas
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: Mandalas 3D (un-punched version)

Post by kernadec »

hello,
update code
as with the ListviewGadget melting used by default I encounter a problem of tab
and probably on Linux and Mac.
so, I put a font "courier new" and adapted the mandalas.csv file
also for this new format.

best regards
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Mandalas 3D (un-punched version)

Post by Vera »

Hello kernadec,

what a joy :-) ~ thank you

Again after adjusting several keys to my local situation ~ again everything runs fine ...
... exept for the popup-menu which resists to show.

First of: #WM_RBUTTONDOWN doesn't exist for Linux(/Mac) and there's hardly any windowevent available. But just for the sake of getting that popup menu I used #PB_Event_MoveWindow, which delivers an event, still the popup won't appear.
I also tried to call it via a further keyboardshortcut ... via procedure and even a thread, but something is suppressing the popup display and atm I've run out of ideas what else to try.

Still, I can get the popupmenu if I call it right away after OpenWindowedScreen(...), so I can access it at startup. The other commands like shuffeling the list, opening/deleting a certain setting or saving new ones work as wanted.

Also adding a font was a good idea, so the heading and list items strech accordingly across the whole width.
But one thing I couldn't figure out yet: what is ClickMRight (right mouse click?) and should it already do something?

cheerful greetings ~ Vera
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: Mandalas 3D (un-punched version)

Post by kernadec »

Hello vera
Thanks you :D
I just got back from vacation during these eight days I had no internet access.

Thanks For your comments which are encouraging For the Linux adapation :wink:
[new edit]
Given that the problem with examinekeyboard() seems difficult to resolve
I thought has another solution for the window that is really a crazy thing
It is a trick that uses a buttonimagegadget() of the size of the window that has fulfilled its role for the expected event.
now, I do not know if this can work under Linux,
Good luk

For This version the Mandalas.csv file is also required.

best regards

Code: Select all

;##################################################################################################
;#  English forum session punch XMas 2014 : http://www.purebasic.fr/english/viewtopic.php?f=14&t=61104
;#  Author: kernadec , Date:  XMas 2014
;#  PureBasic 5.22 : OS: Windows : (no tests Linux and Mac)
;# 
;#  Titre: MANDALAS3D (V8 Button Image Menu) ( Ellipsoid variations )
;#
;#   Display : Full Screen And windows 800/600
;#  Use a very basic  ListViewGadget() via index to facilitate the Linux and Mac OS compatibility
;#  Mode Save/Read to file for the restoration of the parameters elements Mandalas
;###################################################################################################

Enumeration
  #Window0 
  #Window1
  #Window2
EndEnumeration

Enumeration
  #ListView
  #Button0
  #Button1
  #Button2
  #TextGadget
  #FrameGadget
EndEnumeration

Enumeration
  #File 
EndEnumeration

Enumeration
  #image
EndEnumeration

Structure Text
  L$
EndStructure

Global Dim Cl(7)
Global NewList Mandala.Text()

Procedure.s Fmt(n)
  
  n$ = Str(n)
  n$ = RSet(n$, 5, " ")        ; Spaces Previous for Tab ListView and File
  ProcedureReturn n$
  
EndProcedure

Procedure sauvefichier(Chemin$,Formtext$,type)
  
  If type = 0                 ; Mode window Save global listview function add or delete line
    
    If  FileSize(chemin$+".csv") <> -1
      CopyFile(chemin$+".csv", chemin$+".bak")    ; creation in backup old file
    EndIf
    
    CreateFile(#File , Chemin$ + ".csv")          ; creation new file
    For W = 0 To CountGadgetItems(#ListView)
      
      Tmp$ = ReplaceString(GetGadgetItemText(#ListView, W), Chr(#LF), ";", 1)
      
      Tmp$ = Right(Tmp$, Len(Tmp$)-Len(StringField(Tmp$, 1, ";")))
      
      If Tmp$ <> ""                              ;  Listview Format  1000 fields index  Numbers
        If Len(Str(W)) = 1 : Tmp$ = "00" + Str(W) + Tmp$ : EndIf
        If Len(Str(W)) = 2 : Tmp$ =  "0" + Str(W) + Tmp$ : EndIf
        If Len(Str(W)) = 3 : Tmp$ =        Str(W) + Tmp$ : EndIf
        
        WriteStringN(#File, Tmp$)   
        
      EndIf
    Next W     
    CloseFile(#File)
    
  Else                                          ; Mode Save Key "S" full screen and add just line
    
    W = -1
    If ReadFile(#File, Chemin$ + ".csv")
      While Eof(#File) = 0           
        Tmp$ = ReadString(#File)   
        If Tmp$ <> ""
          W + 1                                  ; Read Count Total line number
        EndIf
      Wend
      CloseFile(#File)
    Else
      MessageRequester("Information","Unable to open file!")
    EndIf
    
    
    W + 1                                                    ; next number index for add line
    If Len(Str(W)) = 1 : Tmp$ = "00" + Str(W) + ";" + Formtext$ : EndIf
    If Len(Str(W)) = 2 : Tmp$ =  "0" + Str(W) + ";" + Formtext$ : EndIf
    If Len(Str(W)) = 3 : Tmp$ =        Str(W) + ";" + Formtext$ : EndIf
    
    OpenFile    (#File , Chemin$ + ".csv", #PB_File_Append)  ; update file
    FileSeek    (#File , Lof(#File))         
    WriteStringN(#File , Tmp$)                               ; write new line file 
    CloseFile   (#File)
    
  EndIf
  
EndProcedure

Procedure.s chargefichier(Chemin$,type)
  
  If type = 0        ; mode window load to listview
    If ReadFile(#File, Chemin$ + ".csv")
      ClearGadgetItems(#ListView)
      While Eof(#File) = 0           
        
        Tmp$ = ReadString(#File)   
        If Tmp$<> ""
          AddGadgetItem(#ListView, -1, Tmp$)
        EndIf
        
      Wend
      CloseFile(#File)             
    Else
      MessageRequester("Information","Unable to open file!")
    EndIf
    
  Else              ; mode Full Screen key "+" & "-" read file to write newlist mandala()
    
    If ReadFile(#File, Chemin$ + ".csv")
      While Eof(#File) = 0           
        
        Tmp$ = ReadString(#File)
        If Tmp$<> ""
          AddElement(Mandala())         
          Mandala()\L$ = Tmp$
        EndIf
        
      Wend
      CloseFile(#File)             
    Else
      MessageRequester("Information","Unable to open file!")
    EndIf
    
  EndIf
  ProcedureReturn Tmp$
  
EndProcedure

Procedure Ellipse_Rotation(Axex.l, Axey.l, Xr.l, Yr.l, Zr.l, Rtx.d, Rty.d, Rtz.d, Debut.l, Fin.l, Polygone.l, Col.l, Mode.l, Styl.l)
  
  Protected v.d, RB.d, Rx.d, Ry.d, Rz.d, X.d, Y.d, Z.d, X1.d, Y1.d, Z1.d, Psx1.l, Psy1.l, Psx2.l, Psy2.l, Side.d, Stp.d
  
  If Polygone <> 0 :   Side = 360 / Polygone : Else : Side = 360 : EndIf
  
  Rx = Radian(Rtx)
  Ry = Radian(Rty)
  Rz = Radian(Rtz)
  
  Stp = debut
  
  Repeat
    
    v = Radian(Stp)
    
    If Mode = 0                       ; ellipsoid
      X = Xr * Sin(v)
      Y = Yr * Sin(v)
      Z = Zr * Cos(v)
    EndIf
    If Mode = 1                       ; Bowl + conical sphere
      X = Xr * Sin(v)
      Y = Yr * Sin(v*0.2)
      Z = Zr * Sin(v*0.6)
    EndIf
    If Mode = 2                       ; ellipsoid drilled poles
      X = Xr *  Cos(v-0.5)
      Y = Yr *  Sin(v)
      Z = Zr *  Cos(v)
    EndIf
    If Mode = 3                       ; 2 inverted bowls + conical sphere                         
      X = Xr * Sin(v*2)
      Y = Yr * Cos(v*0.25)
      Z = Zr * Sin(v)
    EndIf
    If Mode = 4                       ; 3 spheres discs drilled
      X = Xr * Cos(v * -3)
      Y = Yr * Cos(v / -2)
      Z = Zr * Sin(v)
    EndIf
    If Mode = 5                       ; discs + 2 disks spheres
      X = Xr * Sin(v * 0.25)
      Y = Yr * Cos(v * 2)
      Z = Zr * Sin(v * 0.35)
    EndIf
    If Mode = 6                       ; 2 bowls + 1 conical sphere bunk
      X = Xr * Sin(v * 1.5)
      Y = Yr * Cos(v)
      Z = Zr * Sin(v * 0.65)
    EndIf
    If Mode = 7                       ; 5 discs spheres
      X = Xr * Sin(v * 0.68)
      Y = Yr * Cos(v * 2.5)
      Z = Zr * Sin(v)
    EndIf
    If Mode = 8                       ; tapered cylinders
      X = Xr * Sin(v * 0.5)
      Y = Yr * Cos(v * -3)
      Z = Zr * Sin(v * 1.4)
    EndIf
    If Mode = 9                       ; tapered cylinders and 2 cones
      X = Xr * Cos(v)
      Y = Yr * Cos(v * 0.35)
      Z = Zr * Cos(v * 1.7)
    EndIf
    
    ;  ------- matrice 3D -----------
    
    X1 = X  * Cos(rz) + Y  * Sin(rz)
    y1 = Y  * Cos(rz) - X  * Sin(rz)
    Z1 = Z
    
    RB = Y1 * Cos(ry) - Z1 * Sin(ry)
    z1 = Y1 * Sin(ry) + Z1 * Cos(ry)
    Y1 = RB
    
    RB = X1 * Cos(rx) + Z1 * Sin(rx)
    z1 = X1 * Sin(rx) - Z1 * Cos(rx)
    Y1 = RB
    
    ; -Option Wing --fourth-calculation-
    
    If styl = 2 Or styl = 3
      
      X = X1
      Y = Y1
      Z = z1
      
      X1 = X  * Cos(rz) - Y  * Sin(rz)
      y1 = Y  * Cos(rz) + X  * Sin(rz)
      Z1 = Z
      
    EndIf
    
    ; ------------------------------
    
    
    Psx1 = Z1 + Axex
    Psy1 = Y1 + Axey
    
    
    
    If Psx2 = 0 And Psy2 = 0 : Psx2 = Psx1 : Psy2 = Psy1: EndIf
    
    If styl = 1 Or styl =3 : Swap Psy2,psy1 : EndIf
    
    If  Stp =>  0 And Stp <= 90
      LineXY(Psx2, Psy2, Psx1, Psy1, Cl(0))
    EndIf
    
    If Stp =>  90 And Stp <= 180
      LineXY(Psx2, Psy2, Psx1, Psy1, Cl(1))
    EndIf
    
    If Stp => 180 And Stp <= 270
      LineXY(Psx2, Psy2, Psx1, Psy1, Cl(2))
    EndIf
    
    If Stp => 270 And Stp <= 360
      LineXY(Psx2, Psy2, Psx1, Psy1, Cl(3))
    EndIf
    
    If styl = 1 Or styl =3 : Swap Psy2,psy1 : EndIf
    
    Psx2 = Psx1
    Psy2 = Psy1
    
    Stp + Side
    
  Until Stp => Fin + 1
  
EndProcedure 

ExamineDesktops()
InitSprite()
InitKeyboard()

If LoadFont(1, "Courier New", 8)  ; Font For Tab ListView
  SetGadgetFont(#PB_Default, FontID(1))
EndIf

Chemin$=GetCurrentDirectory()+"mandalas"

chargefichier(Chemin$,1)

R1 = MessageRequester("SCREEN",Space(16)+"FULL SCREEN",#PB_MessageRequester_YesNo)

Xs = DesktopWidth(0)             ; Xscreen
Ys = DesktopHeight(0)            ; Yscreen

If R1 = 6
  OpenWindow(#Window2, 0, 0, 0, 0, "", #PB_Window_Invisible)
  OpenScreen(Xs, Ys, 32, "")
Else
  Xs = 800 : Ys = 600
  CreateImage(#Image,Xs+10, Ys+10, 32, RGB(0,0,0))
  OpenWindow(#Window0, 0, 0, Xs, Ys, "MANDALAS 3D     by  kernadec     XMas  2014             Click Mouse Screen --> Menu ListView", #PB_Window_SystemMenu | #PB_Window_WindowCentered | #PB_Window_ScreenCentered | #PB_Window_Invisible )
  ButtonImageGadget(#Button2, -5, -5, Xs+10, Ys+10, ImageID(#image))
  OpenWindowedScreen(WindowID(#Window0) , 0, 0, Xs, Ys, 0, 0, 0,#PB_Screen_SmartSynchronization)
  HideWindow(#Window0, 0) 
EndIf

Axex.l  = Xs/2  ; Axis X Screen
Axey.l  = Ys/2  ; Axis Y Screen
Debut.l =   0   ; Start Xircle
Fin.l   = 360   ; End   Circle

Wh.l    =   0   ; Switch Wheel
Pass.l  =   0   ; Switch Vars


Nl.l    =   0   ; Numbers Display Mandala List
Mode.l  =   6   ; Mode Draw Mandala
Styl.l  =   2   ; Pixels or Stick, Wing
Plt.l   =  12   ; Polygon Side Parallel
Plg.l   =   3   ; Polygon Side Meridian
Inc     =  10   ; Speed Key Shift to X1 or X10
Vi.l    =   1   ; Speed Rotate x1,x2,x3,x4.....

Xd      =  30   ; Corner X
Yd      =-210   ; Corner Y
Zd      = 280   ; Corner Z

Zr.l    =   1   ; Radius Z
Yr.l    =-115   ; Radius Y
Xr.l    = 290   ; Radius X

a.l     =   0   ; Color 0
b.l     =   1   ; Color 1
c.l     =   2   ; Color 2
d.l     =   3   ; Color 3

Cl(a) = RGB(255, 0, 0)           ; Red
Cl(b) = RGB( 0, 0,255)           ; Blue
Cl(c) = RGB( 0,255, 0)           ; Green
Cl(d) = RGB(255,255,0)           ; Yellow

Cl(4) = Cl(a) : Cl(5) = Cl(b) : Cl(6) = Cl(c) : Cl(7) = Cl(d)   ;  Order Color


Repeat
  ClearScreen(0)
  
  StartDrawing(ScreenOutput())
  
  If Plt < 0 : Plt = 360 : EndIf
  
  Zd = Mod(Zd + Vi, 360)
  
  For i = 0 To 360
    Ellipse_Rotation(Axex, Axey, Xr, Yr, Zr, Xd, Yd, Zd + i , Debut, Fin, Plt, 0, Mode, Styl)
    i + Plg
  Next i
  
  StopDrawing()
  
  ExamineKeyboard()
  
  If KeyboardPushed(#PB_Key_Tab) : Delay(100) :    Mode + 1 : If Mode > 9 : Mode = 0          : EndIf : EndIf
  If KeyboardReleased(#PB_Key_LeftShift)      : If Inc  = 1 : Inc  = 10   : Else : Inc  = 1  : EndIf : EndIf
  If KeyboardReleased(#PB_Key_LeftControl)    : If Lt   = 0 : Lt   =  1   : Else : Lt   = 0  : EndIf : EndIf
  If KeyboardReleased(#PB_Key_Delete)         :    Styl + 1 : If Styl > 3 : Styl =  0         : EndIf : EndIf
  
  ; Test Speed Change x1 Or x10 For Change Polygon Or Radius Speed X1 Corners < 20
  If Abs(Plt) = 180 : Plt  + 180 : Tmp = 10 : Else : Tmp  = Inc : EndIf
  If Abs(Plt) =   0 : Plt  = 360 : Tmp = 10 : Else : Tmp  = Inc : EndIf
  If Abs(Plt) <  21 : Tmp  =   1 :            Else : Tmp  = Inc : EndIf
  If Abs(Plg) <  21 : Tmp1 =   1 :            Else : Tmp1 = Inc : EndIf
  If Abs(Zr ) <  31 : Tmp2 =   1 :            Else : Tmp2 = Inc : EndIf
  
  If KeyboardPushed(#PB_Key_Up)      :              Yd  = Mod(Yd   + Inc , 360): EndIf
  If KeyboardPushed(#PB_Key_Down)    :              Yd  = Mod(Yd   - Inc , 360): EndIf
  
  If KeyboardPushed(#PB_Key_Left)    :              Xd  = Mod(Xd   + Inc , 360): EndIf
  If KeyboardPushed(#PB_Key_Right)   :              Xd  = Mod(Xd   - Inc , 360): EndIf
  
  If KeyboardPushed(#PB_Key_PageUp)  : Delay(100) : Plt = Mod(Plt  + Tmp , 180): EndIf
  If KeyboardPushed(#PB_Key_PageDown): Delay(100) : Plt = Mod(Plt  - Tmp , 180): Plt = Abs(Plt)     : EndIf
  
  If KeyboardPushed(#PB_Key_Home)    : Delay(100) : Plg = Mod(Plg  + Tmp1, 360): EndIf
  If KeyboardPushed(#PB_Key_End)     : Delay(100) : Plg = Mod(Plg  - Tmp1, 360): Plg = Abs(Plg)     : EndIf
  
  If KeyboardPushed(#PB_Key_1) Or KeyboardPushed(#PB_Key_Pad1):              Zr = Mod(Zr - Tmp2, Ys) : EndIf
  If KeyboardPushed(#PB_Key_4) Or KeyboardPushed(#PB_Key_Pad4):              Zr = Mod(Zr + Tmp2, Ys) : EndIf
  If KeyboardPushed(#PB_Key_2) Or KeyboardPushed(#PB_Key_Pad2):              Yr = Mod(Yr - Inc , Ys) : EndIf
  If KeyboardPushed(#PB_Key_3) Or KeyboardPushed(#PB_Key_Pad3):              Yr = Mod(Yr + Inc , Ys) : EndIf
  If KeyboardPushed(#PB_Key_5) Or KeyboardPushed(#PB_Key_Pad5):              Xr = Mod(Xr - Inc , Ys) : EndIf
  If KeyboardPushed(#PB_Key_6) Or KeyboardPushed(#PB_Key_Pad6):              Xr = Mod(Xr + Inc , Ys) : EndIf
  If KeyboardPushed(#PB_Key_7) Or KeyboardPushed(#PB_Key_Pad7): Delay(100) : Vi = Mod(Vi + 1, 180)   : EndIf
  If KeyboardPushed(#PB_Key_8) Or KeyboardPushed(#PB_Key_Pad8): Delay(100) : Vi = Mod(Vi - 1, 180)   : EndIf
  If KeyboardPushed(#PB_Key_9) Or KeyboardPushed(#PB_Key_Pad9):              Vi = 0                  : EndIf
  If KeyboardPushed(#PB_Key_0) Or KeyboardPushed(#PB_Key_Pad0): a=Random(3):Repeat:b=Random(3):Until b<>a:Repeat:c=Random(3):Until c<>a And c<>b:Repeat:d=Random(3):Until d<>a And d<>b And d<>c: cl(0)=cl(4+a):cl(1)=cl(4+b):cl(2)=cl(4+c):cl(3)=cl(4+d): EndIf
  
  If KeyboardReleased(#PB_Key_S)            ; Save Element to File
                                            ; format chaine for the file base and element newlist
    Formtext$ = Fmt(mode) + ";" + Fmt(styl) + ";" + Fmt(Plt) + ";" + Fmt(Plg) + ";" + Fmt(Inc) + ";" + Fmt(Vi) + ";" + Fmt(Xd) + ";" + Fmt(Yd) + ";" + Fmt(Zd) + ";" + Fmt(Xr) + ";" + Fmt(Yr) + ";" + Fmt(Zr) + ";" + Fmt(a) + ";" + Fmt(b) + ";" + Fmt(c) + ";" + Fmt(d)
    sauvefichier(Chemin$,Formtext$, 1)      ; Save new element in update file and add element in Newlist mandala
    ClearList(Mandala())
    chargefichier(Chemin$, 1)               ; Restore NewList Mandala
    
  EndIf
  
  If KeyboardReleased(#PB_Key_Add)     : Wh = 1 : Nl = Mod(nl + 1, ListSize(Mandala())) : EndIf  ; key Read file mandala base
  If KeyboardReleased(#PB_Key_Subtract): Wh = 1 : Nl - 1 : If Nl < 0 : Nl = ListSize(Mandala())-1 : EndIf : EndIf
  
  If Wh <> 0 : Wh = 0                       ; Wheel Key "+/-"  Display Mandala
    
    ResetList(Mandala())
    For i = 0 To ListSize(Mandala())
      NextElement(Mandala())
      If Val(StringField(Mandala()\L$, 1, ";")) = Nl
        Tmp$ = Mandala()\L$                  ; Read newlist element to tmp$ 
        Break
      EndIf
    Next i
    pass = 1                                 ; switch Vars
    
  EndIf
  
  If pass <> 0 : pass = 0                    ; tmp$ Restore To Vars     
    
    num  = Val(StringField(Tmp$,  1, ";"))   ; Number Index ListView
    mode = Val(StringField(Tmp$,  2, ";"))   ; Mode Draw Mandala
    styl = Val(StringField(Tmp$,  3, ";"))   ; Pixels or Stick
    Plt  = Val(StringField(Tmp$,  4, ";"))   ; Polygon Side Parallel
    Plg  = Val(StringField(Tmp$,  5, ";"))   ; Polygon Side Meridian
    Inc  = Val(StringField(Tmp$,  6, ";"))   ; Speed Key Shift to x1 or x10
    Vi   = Val(StringField(Tmp$,  7, ";"))   ; Speed Rotate x1,x2,x3,x4.....
    Xd   = Val(StringField(Tmp$,  8, ";"))   ; Corner X
    Yd   = Val(StringField(Tmp$,  9, ";"))   ; Corner Y
    Zd   = Val(StringField(Tmp$, 10, ";"))   ; Corner Z
    Xr   = Val(StringField(Tmp$, 11, ";"))   ; Radius X
    Yr   = Val(StringField(Tmp$, 12, ";"))   ; Radius Y
    Zr   = Val(StringField(Tmp$, 13, ";"))   ; Radius Z
    a    = Val(StringField(Tmp$, 14, ";"))   ; Color Random  RGBY
    b    = Val(StringField(Tmp$, 15, ";"))   ; Color Random  RGBY
    c    = Val(StringField(Tmp$, 16, ";"))   ; Color Random  RGBY
    d    = Val(StringField(Tmp$, 17, ";"))   ; Color Random  RGBY
    
    Cl(0) = Cl(4 + a) : Cl(1) = Cl(4 + b) : Cl(2) = Cl(4 + c) : Cl(3) = Cl(4 + d)   ; Restore Order Color
    
  EndIf
  
  If Lt = 0
    StartDrawing(ScreenOutput())
    
    DrawText(10,   190, "1",Cl(0))
    DrawText(30,   190, "2",Cl(1))
    DrawText(50,   190, "3",Cl(2))
    DrawText(70,   190, "4",Cl(3))
    
    DrawText(10,    10, "-Key Shift left y/n >inc/dec< x1 or x10= " + Str(inc))
    DrawText(10,    30, "-Key Left Ctrl y/n menu text")
    DrawText(10,    50, "-PgU/PgD  +/- Plt=  "                      + Str(Plt)  + " / 180")
    DrawText(10,    70, "-Hom/End  +/- Plg=  "                      + Str(Plg)  + " / 360")
    DrawText(10,    90, "-Key 7/8 +/- Vit/Rt= "                     + Str(Vi )  + " / 180")
    DrawText(10,   110, "-Key 9 Vit/Rt in 0")
    DrawText(10,   130, "-Key del > 0 Style= "                      + Str(Styl))
    DrawText(10,   150, "-Key 0 Move color")
    DrawText(10,   170, "-Tab  M = "                                + Str(Mode) + " / 9")
    
    DrawText(10, Ys-178, "-Key Esc = Quit")
    DrawText(10, Ys-158, "-Key S Save Draw")
    DrawText(10, Ys-138, "- +/-  Load list n°" + Str(nl))
    DrawText(10, Ys-118, "-ClickMRight = Listview ")
    DrawText(10, Ys- 98, "- <-   ->    +/- = "                       + Str(Xd)   + " / 360")
    DrawText(10, Ys- 78, "-Up/Down  +/- = "                          + Str(Yd)   + " / 360")
    DrawText(10, Ys- 58, "-Key 1/4 +/- Zradius= "                    + Str(Zr)   + " / "     +Str(Ys))
    DrawText(10, Ys- 38, "-Key 2/3 +/- Yradius= "                    + Str(Yr)   + " / "     +Str(Ys))
    DrawText(10, Ys- 18, "-Key 5/6 +/- Xradius= "                    + Str(Xr)   + " / "     +Str(Ys))
    
    StopDrawing()
  EndIf
  
  FlipBuffers()
  
  
  
  Repeat
    
    Event = WindowEvent()
    
    Select event                         
      Case #PB_Event_Gadget    
        Select EventGadget()   
          Case  #Button2              ;"ListView"
            quit = 0
            If OpenWindow   (#Window1,      0,   0, 750, 170, "File-Mandalas-List ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
              ListViewGadget(#ListView,     10,  20, 720, 120)
              FrameGadget   (#FrameGadget,  10,   5, 700, 135, "N°| Mod | Styl| Plt | Plg | Inc | Spd | Xd  | Yd  | Zd  |  Xr |  Yr |  Zr |  R  |  G  |  B  |  Y  |")
              ButtonGadget  (#Button0,      70, 143, 100,  25, "Add Item")
              ButtonGadget  (#Button1,     580, 143, 100,  25, "Delete Item")
              TextGadget    (#TextGadget,  247, 140, 256, 200, "Selection = Double click on the line")
              StartDrawing(WindowOutput(#Window1)) : Col.l = Point(1, 1) : StopDrawing()
              SetGadgetColor(#TextGadget, #PB_Gadget_BackColor , Col)
              
              chargefichier(Chemin$,0)
              
              Formtext$=Fmt(mode) + ";" + Fmt(styl) + ";" + Fmt(Plt) + ";" + Fmt(Plg) + ";" + Fmt(Inc) + ";" + Fmt(Vi) + ";" + Fmt(Xd) + ";" + Fmt(Yd) + ";" + Fmt(Zd) + ";" + Fmt(Xr) + ";" + Fmt(Yr) + ";" + Fmt(Zr) + ";" + Fmt(a) + ";" + Fmt(b) + ";" + Fmt(c) + ";" + Fmt(d)
              
              Repeat
                
                Event2 = WaitWindowEvent()
                
                Select Event2
                  Case #PB_Event_CloseWindow : CloseWindow(#Window1) : quit = 1
                  Case #PB_Event_Gadget
                    Select EventGadget()
                        
                      Case #ListView ; Show the selected listview entry on doubleclick
                        
                        If EventType() = #PB_EventType_LeftDoubleClick
                          
                          ; Element listView Item to Var Tmp$
                          Tmp$ = GetGadgetItemText(#ListView, GetGadgetState(#ListView))
                          Pass = 1                          ; switch Vars
                          Nl = GetGadgetState(#ListView)    ; Restore Count Position Newlist Screen
                          CloseWindow(#Window1) : quit = 1
                          
                        EndIf
                        
                      Case #Button0 ; Button: Add
                        
                        AddGadgetItem(#ListView ,-1 ,Str(CountGadgetItems(#ListView)-1) + ";" + Formtext$)    ; Write Element ListView,
                        sauvefichier(Chemin$,Formtext$,0)                                                     ; Update File
                        chargefichier(Chemin$,0)                                                              ; Read Update Elements
                        ClearList(Mandala())
                        chargefichier(Chemin$,1)           ; Update Newlist
                        CloseWindow(#Window1) : quit = 1
                        
                      Case #Button1 ; Button: Delete
                        
                        RemoveGadgetItem(#ListView , GetGadgetState(#ListView))
                        sauvefichier(Chemin$,Formtext$,0)  ; Update File
                        chargefichier(Chemin$,0)           ; Update Read Element
                        ClearList(Mandala())
                        chargefichier(Chemin$,1)           ; Update Newlist
                        
                    EndSelect
                EndSelect
              Until quit = 1
            EndIf
        EndSelect
        
      Case #PB_Event_CloseWindow
        If IsWindow(#Window0) : CloseWindow(#Window0) :  End : EndIf
    EndSelect
    
  Until Event = 0
  
Until KeyboardPushed(#PB_Key_Escape)
End
Last edited by kernadec on Wed Jan 07, 2015 12:20 pm, edited 3 times in total.
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Mandalas 3D (un-punched version)

Post by Vera »

Hello kernadec,

hope your vacation was a really relaxed and refreshing time :-)

Good idea to display and toggle the menu as well ... but it won't help as I meanwhile found out that the basic issue lies within using a menu and ExamineKeyboard at the same time (see here).

But I found other solutions (see PM) and in the end a menu is not needed if the list-creation is its own procedure. And with this it's also already at command for '#ClickMRight' ;-) (or better a neutral further key)

Greeting ~ Vera
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: Mandalas 3D (un-punched version)

Post by kernadec »

Hello vera
Thanks vera, I spent good holiday, and I hope that you also.
I am grateful for your comments back
update replaced previous code useless since it did not work on Linux

Since only the problem with examinekeyboard() seems difficult to solve
I thought has another solution for the window that is really a crazy thing
This is a trick that uses a buttonimagegadget() of the size of the window which fulfilled its role for the expected event.
now I do not know if this can work on Linux,
good luk

best regards

[new edit]
I encountered a problem with the space button event
What as forced me a change key "Space" by "LeftControl"
for fact disappear on-screen menus
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Mandalas 3D (un-punched version)

Post by Vera »

Yeah ~ it does work that way kernadec :-)

But it's a really dangerous trick and keep that in mind in case someone ever complains it wouldn't run for him/her at all.
Besides, I don't see why the image/button have to exceed the window dimensions, as it works just the same if they match and it would remove one part of the critical issue.

Nevertheless ~ it's a crazy game with new surprises every time :D

Btw: the screenmenu significantly slows down the speed of the display ... and it can make you dizzy if you turn it of :lol:
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: Mandalas 3D (un-punched version)

Post by kernadec »

hello vera
Yes it is true that the button can be the same as the size of the window
I tried this to make disappear the screen button.
but also for a question of important flip caused :?
by the entrance of the cursor in the area of the window
I do not think that this is dangerous because we have
buttons off-box window using the ScrollBar :wink:

This method seems simplest to have a gadget event
without reducing the surface of the screen to have a simple button
Since the menus do not work.
and I am happy that it works this way on Linux
only concerns the key SPACEBAR remains active in this event
I do not understand why. :shock:
Thanks again vera for your constructive comments.

best regards
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Mandalas 3D (un-punched version)

Post by Vera »

Hi kernadec,
I had a look under WIN and I understand what you mean.

On Linux the button doesn't show if I've made it smaller (0,0,30,30) but that area is active for clicking on it. The space-key toggles without pushing the button at the same time. (no difference if the button is huge or small)

On WIN the small button shows up after being activated and I can see that when using the space-key the button gets the focus first and thus being pushed while the screen-menu will hide/show after closing that opened list.

But I found a way to circumvent [prevent] this [behavior on WIN] by using:

Code: Select all

  If KeyboardReleased(#PB_Key_Space) : HideGadget(#Button2,1) : If Lt   = 0 : Lt   =  1 : HideGadget(#Button2,0)  : Else : HideGadget(#Button2,1): Lt   = 0  : HideGadget(#Button2,0): EndIf : EndIf
And it works for Linux too.

Surely having the space-key to toggle the menu is much more comfortable :-)
Last edited by Vera on Thu Jan 08, 2015 2:37 pm, edited 1 time in total.
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: Mandalas 3D (un-punched version)

Post by kernadec »

Hello vera
Thanks vera for your help
If it works for you with your development on Linux, I'm happy
I have no solution for the event of the space key
I think that the best solution is to change key keyboard
I chose used "#PB_Key_LeftControl"
Nevertheless we still together progresses
What is very rewarding

best regards
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Mandalas 3D (un-punched version)

Post by Vera »

kernadec wrote:I have no solution for the event of the space key
Yes you have, if you use the code-line I've posted above ;-)
Didn't you test it? I made it under WIN for to work on WIN and that changed line doesn't bother Linux.
I think I have not expressed that clear enough.

If you don't want to use the space-key anymore that's fine. I understood that you missed it, so I searched for a solution so that you could use it again.

cheers ~ Vera
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: Mandalas 3D (un-punched version)

Post by kernadec »

Thanks vera
excuse me, but I think it is me who was not clear
Ah yes I say:
I have no. solution for the event of the space key
but this remark was for Linux

Thank you very much, yes I tried your code is a good idea,.
but in fact Windows version 8 with popmenu works very well...
Therefore the space key works as I want.

Thank you for your patience and for your help

best regards
Post Reply