none
Random numbers RRS feed

  • Question

  • i have to get random numbers, but they have to be completely unique. None the same. How could i do this?

                 

    Count = 1
    While (Count <=32) 
      For i = 1 To row
        For j = 1 To column


          images[r][c] = ImageList.LoadImage("B:\Desktop\ImageTest\Imagess\Image"+Count+".png")

          GraphicsWindow.DrawImage(images[i][j], 10, 10)
          Count = Count + 1

        EndFor
      EndFor
    EndWhile

    The above code is what i have to integrate it into. Instead of using count in the image laod i want to use a random number. As all the images are named Image1, Image2 etc. 

    So how could i do this? Any help would be great

    Sunday, October 19, 2014 2:05 PM

Answers

  • This topic reminded me of a lottery demo I made two years ago. It draws 20 numbers in random order. The graphical interface shows what happens when an already drawn number is drawn.

    ''Lottery draw demo (20 unique numbers)
    '' WhTurner  2012-10-29     [RMV445]
    ''=============================
    speed=400
    number=20    ''max 20
    GraphicsWindow.Top=10
    GraphicsWindow.Left=10
    GraphicsWindow.Height=540
    GraphicsWindow.Width=620
    GraphicsWindow.Title="Demo lottery
    intro()
    GraphicsWindow.BackgroundColor="limegreen"
    GraphicsWindow.BrushColor="blue"
    r1= Shapes.AddEllipse(20,20)
    GraphicsWindow.FontSize=15
    For i=1 To number          ''numbers
      Set[i]=i
      If i<10 Then
        ii=text.Append(" ",i)
      Else
        ii=i
      EndIf
      GraphicsWindow.BrushColor="yellow"
      b[i]=shapes.AddEllipse(30,30)
      Shapes.Move(b[i],30*i-20,320)                            
      GraphicsWindow.BrushColor="black"
      c[i]=shapes.Addtext(ii)
      Shapes.Move(c[i],30*i-16,325)                            
    EndFor
    
    GraphicsWindow.DrawText(350,450,"Number of right draws")
    GraphicsWindow.DrawText(340,480,"Number of wrong draws")
    tt=Shapes.AddText(0)
    Shapes.Animate(tt,550,450,1)
    tw=Shapes.AddText(0)
    Shapes.Animate(tw,550,480,1)
    
    
    GraphicsWindow.PenColor="gray" 
    For i=1 To number
      GraphicsWindow.DrawLine(270+3*i,40,30*i-5,310) 
      GraphicsWindow.DrawLine(30*i-5,310,30*i-5,320)  
    endfor 
    
    GraphicsWindow.KeyDown=keys
    pau=1
    While pau<>0
      While pau<2    ''wait for spacekey
        Program.Delay(300)
      endwhile
      if pau=2 Then
        Shapes.Animate(r1,0,0,10)    
        Program.Delay(speed)  
      ElseIf pau=3 then
        shapes.Animate(r1,290,0,speed)
        Program.Delay(speed)
      EndIf
      draw= Math.GetRandomNumber(number)            ''DRAW
      shapes.Animate(r1,290,0,speed)   
      Program.Delay(speed)
      Shapes.Animate(r1,30*draw-15,300,speed)  
      Program.Delay(100)
      pau=1+pau0
      If Set[draw]<>" " then      ''DRAW OK
        Set[draw]=" "   
        Program.Delay(speed)
        Iset=Iset+1
        Shapes.Animate(b[draw],Iset*30-25,400,speed)
        Shapes.Animate(c[draw],Iset*30-20,405,speed)
        Shapes.Animate(tt,666,450,1)
        tt=Shapes.AddText(Iset)
        Shapes.Animate(tt,550,450,1)
        If Iset>=number then
          GraphicsWindow.FontSize=100
          GraphicsWindow.BrushColor="red"
          GraphicsWindow.DrawText(100,100,"R E A D Y")
          GraphicsWindow.FontSize=20
          GraphicsWindow.DrawText(180,270,"Press Q to quit")
          pau=0
        EndIf
      Else                      ''DRAW not OK                                                                 
        pau=3
        Iwrng=Iwrng+1
        Shapes.Animate(tw,666,480,1)
        tw=Shapes.AddText(Iwrng)
        Shapes.Animate(tw,550,480,1)
        Program.Delay(speed)
      EndIf
    endwhile  
    
    
    Sub keys
      key=GraphicsWindow.LastKey
      If Key="Space" then
        pau=2
      ElseIf Key="Right" then
        If speed>100 then
          speed=speed-100
        EndIf
      elseif Key="Left" then
        If speed<1000 then
          speed=speed+100
        EndIf
      elseif Key="A" then
        pau=2
        pau0=1
      elseif Key="Q" then
        Program.End()
      endif
    endsub
    
    Sub intro
      GraphicsWindow.BrushColor="yellow"
      GraphicsWindow.BackgroundColor="steelblue"
      GraphicsWindow.FontSize=16
      GraphicsWindow.DrawText(140,10,"Amimated simulation of a lottery with 20 numbers")
      GraphicsWindow.DrawText(10,40,"After the start pushing the spacebar draws a (unique) number")
      GraphicsWindow.DrawText(10,70,"  at any time key A let the program run Automatic to the end")
      GraphicsWindow.DrawText(10,160,"     the rigth arrow inceases the speed")
      GraphicsWindow.DrawText(10,180,"     the left arrow decreases the speed")
      GraphicsWindow.DrawText(10,230,"     key Q quits the animation")
      GraphicsWindow.ShowMessage("click OK to start","continue")
      GraphicsWindow.Clear()
    EndSub
    


    Jan [ WhTurner ] The Netherlands

    Monday, October 20, 2014 12:54 PM
    Answerer
  • ' To get the random order of sorted array values you can simply mix them:

    lenArray = 32

    For n = 1 To lenArray
      arr[n] = n
    EndFor
    TextWindow.WriteLine(arr)
    TextWindow.WriteLine("")

    mixArray()

    TextWindow.WriteLine(arr)


    Sub mixArray
      For n = 1 To lenArray
        n2 = Math.GetRandomNumber(lenArray)
        
        temp = arr[n]
        arr[n] = arr[n2]
        arr[n2] = temp
      EndFor
    EndSub

    Monday, October 20, 2014 8:08 PM
    Answerer
  • Mark,

    How about replacing count with:

    Math.GetRandomNumber(32)

    This will give you a random number up to and including 32. If you don't want any repetition of the same number being called you can build an array of previously called numbers. Let's say that 29 has been previously called and Math.GetRandomNumber(32) brings it up again, just keep calling the function until it gives a number that hasn't been called.


    JR

    Sunday, October 19, 2014 3:06 PM
    Answerer
  • ... I used (Shapes.Remove) to change number.

    Yep, saw it with:

    flag_btnStart="False"
    Textwindow.WriteLine(LDShapes.GetAllShapes())

    ....

    (added) in the main loop (Shapename numbering).

    Cool, espero que tengan éxito con sus números !!

    Saturday, October 25, 2014 7:59 PM
    Answerer

All replies

  • Mark,

    How about replacing count with:

    Math.GetRandomNumber(32)

    This will give you a random number up to and including 32. If you don't want any repetition of the same number being called you can build an array of previously called numbers. Let's say that 29 has been previously called and Math.GetRandomNumber(32) brings it up again, just keep calling the function until it gives a number that hasn't been called.


    JR

    Sunday, October 19, 2014 3:06 PM
    Answerer
  • This is a good solution:

    'Numeros aleatorios entre un maximo y un minimo (con posibilidad de salto entre ellos)
    'evitando numeros repetidos 
    'jalpc octubre 2014
    
    minimo=1
    maximo=32
    diferencia=maximo-minimo
    salto=1
    listaNumeros=""
    total=(maximo-minimo)+1
    
    While total <> (Array.GetItemCount(listaNumeros))
      numero= minimo+(Math.GetRandomNumber((diferencia+1)/salto)-1)
      If Array.ContainsValue(listaNumeros,numero) Then
    
      Else        
        listaNumeros[Array.GetItemCount(listaNumeros)+1]=numero
      EndIf
    EndWhile
    
    
    TextWindow.WriteLine("numeros posibles:")
    For n = minimo To maximo Step salto
      TextWindow.Write(n)
      TextWindow.Write(",")
      EndFor
     
      TextWindow.WriteLine("")
      TextWindow.WriteLine("------")
      TextWindow.WriteLine("numeros aleatorios:")
    For n = 1 To Array.GetItemCount(listaNumeros)
      TextWindow.WriteLine(listaNumeros[n])
    EndFor





    Sunday, October 19, 2014 3:14 PM
  • Example:

    randonNumbers()
    Count=0
    row=8
    column=4
    For i = 1 To row
      For j = 1 To column    
        Count = Count + 1   
        
        images[i][j] = ImageList.LoadImage("B:\Desktop\ImageTest\Imagess\Image"+listaNumeros[Count]+".png")
        
        TextWindow.WriteLine("B:\Desktop\ImageTest\Imagess\Image"+listaNumeros[Count]+".png")
        
        GraphicsWindow.DrawImage(images[i][j], 10, 10)
        
      EndFor
    EndFor
    
    Sub randonNumbers
      minimo=1
      maximo=32
      diferencia=maximo-minimo
      salto=1
      listaNumeros=""
      total=(maximo-minimo)+1
      
      While total <> (Array.GetItemCount(listaNumeros))
        numero= minimo+(Math.GetRandomNumber((diferencia+1)/salto)-1)
        If Array.ContainsValue(listaNumeros,numero) Then
          
        Else        
          listaNumeros[Array.GetItemCount(listaNumeros)+1]=numero
        EndIf
      EndWhile
      
    EndSub
      

    Sunday, October 19, 2014 6:52 PM
  • This topic reminded me of a lottery demo I made two years ago. It draws 20 numbers in random order. The graphical interface shows what happens when an already drawn number is drawn.

    ''Lottery draw demo (20 unique numbers)
    '' WhTurner  2012-10-29     [RMV445]
    ''=============================
    speed=400
    number=20    ''max 20
    GraphicsWindow.Top=10
    GraphicsWindow.Left=10
    GraphicsWindow.Height=540
    GraphicsWindow.Width=620
    GraphicsWindow.Title="Demo lottery
    intro()
    GraphicsWindow.BackgroundColor="limegreen"
    GraphicsWindow.BrushColor="blue"
    r1= Shapes.AddEllipse(20,20)
    GraphicsWindow.FontSize=15
    For i=1 To number          ''numbers
      Set[i]=i
      If i<10 Then
        ii=text.Append(" ",i)
      Else
        ii=i
      EndIf
      GraphicsWindow.BrushColor="yellow"
      b[i]=shapes.AddEllipse(30,30)
      Shapes.Move(b[i],30*i-20,320)                            
      GraphicsWindow.BrushColor="black"
      c[i]=shapes.Addtext(ii)
      Shapes.Move(c[i],30*i-16,325)                            
    EndFor
    
    GraphicsWindow.DrawText(350,450,"Number of right draws")
    GraphicsWindow.DrawText(340,480,"Number of wrong draws")
    tt=Shapes.AddText(0)
    Shapes.Animate(tt,550,450,1)
    tw=Shapes.AddText(0)
    Shapes.Animate(tw,550,480,1)
    
    
    GraphicsWindow.PenColor="gray" 
    For i=1 To number
      GraphicsWindow.DrawLine(270+3*i,40,30*i-5,310) 
      GraphicsWindow.DrawLine(30*i-5,310,30*i-5,320)  
    endfor 
    
    GraphicsWindow.KeyDown=keys
    pau=1
    While pau<>0
      While pau<2    ''wait for spacekey
        Program.Delay(300)
      endwhile
      if pau=2 Then
        Shapes.Animate(r1,0,0,10)    
        Program.Delay(speed)  
      ElseIf pau=3 then
        shapes.Animate(r1,290,0,speed)
        Program.Delay(speed)
      EndIf
      draw= Math.GetRandomNumber(number)            ''DRAW
      shapes.Animate(r1,290,0,speed)   
      Program.Delay(speed)
      Shapes.Animate(r1,30*draw-15,300,speed)  
      Program.Delay(100)
      pau=1+pau0
      If Set[draw]<>" " then      ''DRAW OK
        Set[draw]=" "   
        Program.Delay(speed)
        Iset=Iset+1
        Shapes.Animate(b[draw],Iset*30-25,400,speed)
        Shapes.Animate(c[draw],Iset*30-20,405,speed)
        Shapes.Animate(tt,666,450,1)
        tt=Shapes.AddText(Iset)
        Shapes.Animate(tt,550,450,1)
        If Iset>=number then
          GraphicsWindow.FontSize=100
          GraphicsWindow.BrushColor="red"
          GraphicsWindow.DrawText(100,100,"R E A D Y")
          GraphicsWindow.FontSize=20
          GraphicsWindow.DrawText(180,270,"Press Q to quit")
          pau=0
        EndIf
      Else                      ''DRAW not OK                                                                 
        pau=3
        Iwrng=Iwrng+1
        Shapes.Animate(tw,666,480,1)
        tw=Shapes.AddText(Iwrng)
        Shapes.Animate(tw,550,480,1)
        Program.Delay(speed)
      EndIf
    endwhile  
    
    
    Sub keys
      key=GraphicsWindow.LastKey
      If Key="Space" then
        pau=2
      ElseIf Key="Right" then
        If speed>100 then
          speed=speed-100
        EndIf
      elseif Key="Left" then
        If speed<1000 then
          speed=speed+100
        EndIf
      elseif Key="A" then
        pau=2
        pau0=1
      elseif Key="Q" then
        Program.End()
      endif
    endsub
    
    Sub intro
      GraphicsWindow.BrushColor="yellow"
      GraphicsWindow.BackgroundColor="steelblue"
      GraphicsWindow.FontSize=16
      GraphicsWindow.DrawText(140,10,"Amimated simulation of a lottery with 20 numbers")
      GraphicsWindow.DrawText(10,40,"After the start pushing the spacebar draws a (unique) number")
      GraphicsWindow.DrawText(10,70,"  at any time key A let the program run Automatic to the end")
      GraphicsWindow.DrawText(10,160,"     the rigth arrow inceases the speed")
      GraphicsWindow.DrawText(10,180,"     the left arrow decreases the speed")
      GraphicsWindow.DrawText(10,230,"     key Q quits the animation")
      GraphicsWindow.ShowMessage("click OK to start","continue")
      GraphicsWindow.Clear()
    EndSub
    


    Jan [ WhTurner ] The Netherlands

    Monday, October 20, 2014 12:54 PM
    Answerer
  • illustrative. very well
    Monday, October 20, 2014 2:53 PM
  • Oh really Great program by WhTurner specially Graphics

    Monday, October 20, 2014 3:07 PM
  • ' To get the random order of sorted array values you can simply mix them:

    lenArray = 32

    For n = 1 To lenArray
      arr[n] = n
    EndFor
    TextWindow.WriteLine(arr)
    TextWindow.WriteLine("")

    mixArray()

    TextWindow.WriteLine(arr)


    Sub mixArray
      For n = 1 To lenArray
        n2 = Math.GetRandomNumber(lenArray)
        
        temp = arr[n]
        arr[n] = arr[n2]
        arr[n2] = temp
      EndFor
    EndSub

    Monday, October 20, 2014 8:08 PM
    Answerer
  • graphic demonstration program "Pappa Lapub" :)

    TTM329: TTM329

    NOTE: You can delete them look, for a moment, Shapes Corner? (rolling on pc) Thank you.

    'Lottery draw demo 
    'jalpc October 2014
    'TTM329 : http://smallbasic.com/program/?TTM329
    '
    numMax=9
    speed=200
    delay=300
    data()
    GraphicsWindow.Hide()
    formPG()
    drawObjects()
    GraphicsWindow.Show()
    '
    Controls.ButtonClicked=OnButtonClicked
    '
    'Loop
    While "True"  
      If flag_btnStart Then    
        showDemo()
        flag_btnStart="False"
      EndIf
    EndWhile
    '
    ''Event's
    '====================
    '
    Sub OnButtonClicked  
      If Controls.LastClickedButton=btnStart Then
        flag_btnStart="True"
      Else
        Program.End()
      EndIf
    EndSub
    '
    'Sub's
    '====================
    Sub showDemo
      GraphicsWindow.Hide()
      GraphicsWindow.Clear()
      data()
      formPG()
      drawObjects()
      Shapes.SetOpacity(btnStart,0)
      GraphicsWindow.Show()
      showRandom()
      Shapes.SetOpacity(btnStart,100)
    EndSub
    '
    Sub showRandom
      For j= 1 To numMax
        'array init
        '--------------
        arr[j] = j  
        '--------------- 
      EndFor
      For item=1 To numMax    
        Sound.PlayClickAndWait()
        num=item
        ' get Random
        '-----------------------------------------------------------
        numRandom = Math.GetRandomNumber(numMax) 
        '------------------------------------------------------------
        Program.Delay(delay)   
        showCounter()
        showNumRandom()    
        shadowArray()    
        showArrows()     
        Program.Delay(delay)
        showRandom_Item()
        showTemp_Item()
        showChangeRandom_Item()  
        ' save in temp
        '-----------------------
        temp = arr[item]    
        '-----------------------    
        showChangeItem_Temp()
        'change Value
        '-------------------------------------
        arr[item] = arr[numRandom]  
        '------------------------------------   
        showChangeItem_Random()      
        Program.Delay(speed)
        showTemp_PosItemRandom()
        showTemp_ItemRandom()
        'change Value    
        '------------------------------
        arr[numRandom] = temp      
        '-------------------------------    
        showChangeTemp_ItemRandom()    
      EndFor 
      Sound.PlayChimesAndWait()
      For i=1 To 6
        Shapes.SetOpacity(rectEnd,100)
        Program.Delay(300)
        Shapes.SetOpacity(rectEnd,0)
        Program.Delay(300)
      EndFor
      Shapes.SetOpacity(rectEnd,100)
      Shapes.SetOpacity(btnStart,100)
    EndSub
    '
    Sub drawObjects
      param="1=White;2=Red;"
      color()
      Shapes.Remove(rectEnd)
      rectEnd=Shapes.AddRectangle(375,60)
      Shapes.Move(rectEnd,posNumArray_X[1]-20,posNumArray_Y[1]-20)
      Shapes.SetOpacity(rectEnd,0)
      showCounter()
      rectRandom()
      showNumRandom()
      GraphicsWindow.FontSize="15"
      For i = 1 To numMax    
        num=i
        param="1=White;2=Black;99=100;"
        color()
        drawRectArray()
        param="1=Black;2=Black;99=100;"
        color()
        drawNumArray()    
        param="1=Yellow;2=Black;99=0;"
        color()
        drawTempRectArray() 
        param="0=T;1=Red;2=Black;"
        color()
        drawTempNumArray()    
        param="0=º;1=Black;2=Black;99=0;"
        color()
        drawArrayOrder()     
      EndFor  
      btnStart=Controls.AddButton("START",PGW*0.05,PGH-50)
      btnEnd=Controls.AddButton("END",PGW*0.85,PGH-50)
    EndSub
    '
    Sub showArrows
      dif1="1=15;2=-80;3=13;4=-47;"
      dif2="1=-2;2=0;3=9;4=0;5=3;6=5;"
      x1=posRectArray_X[num]+dif1[1]
      y1=posRectArray_Y[num]+dif1[2]
      x2=posRectArray_X[num]+dif1[3]
      y2=posRectArray_Y[num]+dif1[4] 
      If num > 5 Then
        x3=195
        y3=100
      Else
        x3=x1
        y3=y1
      EndIf 
      param="1=Blue;2=Blue;"
      color()  
      Shapes.Remove(linR1)  
      linR1=Shapes.AddRectangle(3,40)
      Shapes.Move(linR1,x1,y1)
      Shapes.Remove(linR2)  
      linR2=Shapes.AddTriangle(x2+dif2[1],y2+dif2[2],x2+dif2[3],y2+dif2[4],x2+dif2[5],y2+dif2[6])
      Shapes.Remove(linR3)  
      widthLin=40*(Math.Abs(num-5))+3  
      linR3=Shapes.AddRectangle(widthLin,3)
      Shapes.Move(linR3,x3,y3)
      '
      dif1="1=15;2=72;3=15;4=72;"
      dif2="1=-5;2=6;3=7;4=6;5=1;6=0;"  
      x1=posRectArray_X[item]+dif1[1]
      y1=posRectArray_Y[item]+dif1[2]
      x2=posRectArray_X[numRandom]+dif1[3]
      y2=posRectArray_Y[numRandom]+dif1[4]
      If (num-numRandom) > 0 Then
        x=x2
        y=y2
      Else
        x=x1
        y=y1
      EndIf
      param="1=Black;2=Black;"
      color()  
      Shapes.Remove(linT1)  
      linT1=Shapes.AddRectangle(3,38)
      Shapes.Move(linT1,x1,y1)
      Shapes.Remove(linT2)  
      linT2=Shapes.AddRectangle(3,38)
      Shapes.Move(linT2,x2,y2)
      Shapes.Remove(linT3)  
      linT3=Shapes.AddTriangle(x2+dif2[1],y2+dif2[2],x2+dif2[3],y2+dif2[4],x2+dif2[5],y2+dif2[6])
      Shapes.Remove(Lin4)   
      widthLin=40*(Math.Abs(num-numRandom))+3  
      Lin4=Shapes.AddRectangle(widthLin,3)
      Shapes.Move(Lin4,x,y+38)
    EndSub
    '
    Sub formPG
      GraphicsWindow.Left=PGleft
      GraphicsWindow.Top=PGtop  
      GraphicsWindow.Width=PGW
      GraphicsWindow.Height=PGH
      GraphicsWindow.Title="Lottery draw demo "
      GraphicsWindow.CanResize="False"
    EndSub
    '
    Sub showCounter   'show counter item's  
      cont=cont+1
      param="1=White;2=Red;"
      color()
      GraphicsWindow.DrawRectangle(10,10,rectW*2,rectW*2)
      GraphicsWindow.FillRectangle(15,15,rectW*1.8,rectW*1.8)
      param="1=Red;2=Red;"
      color()  
      GraphicsWindow.FontSize="40"
      GraphicsWindow.DrawBoundText(30,20,50,cont) 
    EndSub
    '
    Sub rectRandom  
      param="1=LightBlue;2=Black;"
      color()
      GraphicsWindow.FillRectangle(100,10,200,50)
      GraphicsWindow.DrawRectangle(100,10,200,50)  
      GraphicsWindow.FillRectangle(170,50,50,40)
      GraphicsWindow.DrawRectangle(170,50,50,40)  
      param="1=Blue;2=Black;"
      color()
      GraphicsWindow.FontSize="12"  
      GraphicsWindow.DrawBoundText(105,12,150,"NUM RANDOM:") 
      param="1=Blue;2=Blue;"
      color()
      GraphicsWindow.FillRectangle(195,90,3,10)
    EndSub
    '
    Sub showNumRandom
      param="1=LightBlue;2=Black;"
      color()
      Shapes.Remove(moveRectRandom)
      moveRectRandom=Shapes.AddRectangle(rectW,rectH)
      Shapes.Move(moveRectRandom,posMoveRectRandom_X,posMoveRectRandom_Y)
      param="1=Blue;2=Black;"
      color()
      GraphicsWindow.FontSize=15
      Shapes.Remove(moveRandom)
      moveRandom=Shapes.AddText(numRandom)
      Shapes.Move(moveRandom,posMoveRandom_X,posMoveRandom_Y) 
      If numRandom <> "?" Then
        GraphicsWindow.DrawBoundText(95+(item*20),30,20,numRandom)
      EndIf
    EndSub
    '
    Sub drawRectArray
      Shapes.Remove(rectArray[num])
      rectArray[num]=Shapes.AddRectangle(35,30)
      Shapes.Move(rectArray[num],posRectArray_X[num],posRectArray_Y[num])
      Shapes.SetOpacity(rectArray[num],param[99])
    EndSub
    '
    Sub drawNumArray
      Shapes.Remove(arrayNum[num])
      arrayNum[num]=Shapes.AddText(num)
      Shapes.Move(arrayNum[num],posNumArray_X[num],posNumArray_Y[num])
      Shapes.SetOpacity(arrayNum[num],param[99])
    EndSub
    '
    Sub drawTempRectArray
      tempRectArray[num]=Shapes.AddRectangle(35,30)
      Shapes.Move(tempRectArray[num],posTempRectArray_X[num],posTempRectArray_Y[num])
      Shapes.SetOpacity(tempRectArray[num],param[99])
    EndSub
    '
    Sub drawTempNumArray
      Shapes.Remove(tempNumArray[num])
      tempNumArray[num]=Shapes.AddText(param[0])
      Shapes.Move(tempNumArray[num],posTempNumArray_X[num],posTempNumArray_Y[num])
      Shapes.SetOpacity(tempNumArray[num],param[99])
    EndSub
    '
    Sub drawArrayOrder
      GraphicsWindow.DrawBoundText(posNumArray_X[num],posNumArray_Y[num]+120,30,num+param[0])
    EndSub
    '
    Sub shadowArray 
      param="1=Magenta;2=Magenta;"
      color() 
      GraphicsWindow.DrawRectangle(posRectArray_X[num]+34,posRectArray_Y[num]+2,2,30)
      GraphicsWindow.DrawRectangle(posRectArray_X[num]+3,posRectArray_Y[num]+30,31,2)
      param="1=Black;2=Black;"
      color() 
      GraphicsWindow.DrawRectangle(posRectArray_X[num]+3,posRectArray_Y[num]+150,31,1)
    EndSub
    '
    Sub showTemp_Item
      Shapes.SetOpacity(tempRectArray[num],100)
      Shapes.SetOpacity(tempNumArray[num],100)
      Program.Delay(speed)
      Shapes.Animate(tempRectArray[num],posRectArray_X[num],posRectArray_Y[num]+40,speed)
      Shapes.Animate(tempNumArray[num],posNumArray_X[num],posNumArray_Y[num]+40,speed)
      Program.Delay(speed)
    EndSub
    '
    Sub showRandom_Item
      Shapes.Animate(moveRectRandom,posRectArray_X[num],posRectArray_Y[num]-40,speed)
      Shapes.Animate(moveRandom,posNumArray_X[num],posNumArray_Y[num]-40,speed)
      Program.Delay(speed)
    EndSub
    '
    Sub showChangeRandom_Item
      Shapes.Animate(moveRectRandom,posRectArray_X[num],posRectArray_Y[num],speed)
      Shapes.Animate(moveRandom,posNumArray_X[num],posNumArray_Y[num],speed)
      Shapes.Animate(rectArray[num],posRectArray_X[num],posRectArray_Y[num]+40,speed)
      Shapes.Animate(arrayNum[num],posNumArray_X[num],posNumArray_Y[num]+40,speed)
      Program.Delay(speed)
    EndSub
    '
    Sub showChangeItem_Temp
      Shapes.Remove(tempRectArray[num])
      Shapes.Remove(tempNumArray[num])
      param="1=Yellow;2=Black;"
      color() 
      tempRectArray[num]=Shapes.AddRectangle(35,30)
      Shapes.Move(tempRectArray[num],posRectArray_X[num],posRectArray_Y[num]+40)
      param="1=Red;2=Black;"
      color()  
      tempNumArray[num]=Shapes.AddText(temp)
      Shapes.Move(tempNumArray[num],posNumArray_X[num],posNumArray_Y[num]+40)
    EndSub
    '
    Sub showChangeItem_Random
      Shapes.Remove(rectArray[num])
      Shapes.Remove(arrayNum[num])
      Shapes.Remove(moveRandom)
      param="1=LightBlue;2=Black;"
      color()  
      rectArray[item]=Shapes.AddRectangle(35,30)
      Shapes.Move(rectArray[num],posRectArray_X[num],posRectArray_Y[num])
      GraphicsWindow.BrushColor="Blue" 
      param="1=Blue;2=Black;"
      color()  
      arrayNum[num]=Shapes.AddText(arr[numRandom])
      Shapes.Move(arrayNum[num],posNumArray_X[num],posNumArray_Y[num])
      moveRandom=Shapes.AddText("?")
      Shapes.Move(moveRandom,posMoveRandom_X,posMoveRandom_Y)
      Shapes.Move(moveRectRandom,posMoveRectRandom_X,posMoveRectRandom_Y)
    EndSub
    '
    Sub showTemp_PosItemRandom
      Shapes.Animate(tempRectArray[num],posRectArray_X[numRandom],posRectArray_Y[numRandom]+40,speed)
      Shapes.Animate(tempNumArray[num],posNumArray_X[numRandom],posNumArray_Y[numRandom]+40,speed)
      Program.Delay(speed)
    EndSub
    '
    Sub showTemp_ItemRandom
      Shapes.Animate(tempRectArray[num],posRectArray_X[numRandom],posRectArray_Y[numRandom],speed)
      Shapes.Animate(tempNumArray[num],posNumArray_X[numRandom],posNumArray_Y[numRandom],speed)
      Program.Delay(speed)
    EndSub
    '
    Sub color
      GraphicsWindow.BrushColor=param[1]
      GraphicsWindow.PenColor=param[2]
    EndSub
    '
    Sub showChangeTemp_ItemRandom
      Shapes.Remove(rectArray[numRandom])
      Shapes.Remove(arrayNum[numRandom])
      Shapes.Remove(tempNumArray)
      param="1=Yellow;2=Black;"
      color()  
      rectArray[numRandom]=Shapes.AddRectangle(35,30)
      Shapes.Move(rectArray[numRandom],posRectArray_X[numRandom],posRectArray_Y[numRandom])
      param="1=Red;2=Black;"
      color()  
      arrayNum[numRandom]=Shapes.AddText(temp)
      Shapes.Move(arrayNum[numRandom],posNumArray_X[numRandom],posNumArray_Y[numRandom])
      GraphicsWindow.PenColor="Black"
      param="1=Yellow;2=Black;"
      color()  
      tempNumArray[item]=Shapes.AddRectangle(35,30)
      Shapes.Move(tempNumArray[num],posTempNumArray_X[num],posTempNumArray_Y[num])
      Shapes.SetOpacity(tempNumArray[num],0)
    EndSub
    '
    Sub data
      cont=-1
      numRandom="?"  
      PGleft=40
      PGtop=5
      PGW=400
      PGH=430
      rectW=35
      rectH=30
      posMoveRectRandom_X=177
      posMoveRectRandom_Y=55 
      posMoveRandom_X=191
      posMoveRandom_Y=60  
      For numItem = 1 To numMax
        posRectArray_X[numItem]=40*numItem-20
        posRectArray_Y[numItem]=180
        posNumArray_X[numItem]=posRectArray_X[numItem] + 10
        posNumArray_Y[numItem]=posRectArray_Y[numItem] + 6
        posTempRectArray_X[numItem]=posRectArray_X[numItem]
        posTempRectArray_Y[numItem]=posRectArray_Y[numItem]+160
        posTempNumArray_X[numItem]=posNumArray_X[numItem]
        posTempNumArray_Y[numItem]=posNumArray_Y[numItem]+160
      EndFor
    EndSub


    jalpc



    • Edited by jalpc Saturday, October 25, 2014 12:44 PM
    Saturday, October 25, 2014 12:38 PM
  • Hi jalpc,

    1st of all: nice program, lot of work and pretty program sequences.

    If i understand you clear and your comment as a question, you're not happy with with the short flicker up left when a new shape is created in GW(0;0), which does'nt look good indeed and disturbs.

    You create 57 shapes (34 "Rectangle", 19 "Text", 2 "Triangle" (and 2 "Button")). Without going detailed through your code, i found no Shapes.HideShape or Shapes.ShowShape commands. Maybe look for their helpinfo in intellisense. The flicker only shows when a new shape is new created. So i would create such a shape while the GW is hidden too (at the program start) and park it hidden on the GW (or even outside eg. -50, -50 in 'shown' mode) until it's needed.

    Similar as demo (without flicker):

    ' Define initial variables/constants
    nShapes = 20
    dist = 10
    shpWidth = 20
    shpHeight = 20
    
    GraphicsWindow.Hide()
    ' set  initial GW settings etc.
    
    ' Add Shapes to GW and park them there hidden (HideShape).
    ' At least the ones that will be new activated during runtime
    For n = 1 To nShapes
      Shapes.AddRectangle(shpWidth,shpHeight)
      Shapes.HideShape("Rectangle"+n)
    EndFor
    
    ' Show GW in initial state and view
    GraphicsWindow.Show()
    
    ' When a new shape is needed, show <-> move it when/where it belongs to
    For n = 1 To nShapes
      Shapes.Move("Rectangle"+n, (shpWidth + dist) * (n-1), 100)
      Shapes.ShowShape("Rectangle"+n)
      Program.Delay(500)
    EndFor
    PS: ShowShapes(shapeName)  shows hidden 'shapeName' at its previous defined position and this position can also be changed while the shape is hidden.


    Saturday, October 25, 2014 6:49 PM
    Answerer
  • Hi Pappa Lapub,
    Thanks for your comment: (1st of all: nice program, lot of work and pretty program sequences.) 

    Yeah, I'll have to see Shapes.HideShape and Shapes.ShowShape (looks better option). 
    I used (Shapes.Remove) to change number. 
    Thank you. 
    (Sorry for my English)

    In Spanish:

    ------------ 

    Hola Pappa Lapub, 
    Gracias por tu comentario: (primero de todos:. Bonito programa, mucho trabajo y secuencias de programa bonitas) 

    Sí, voy a tener que ver Shapes.HideShape y Shapes.ShowShape (se ve mejor opción). 
    Usé (Shapes.Remove) para cambiar el número. 
    Gracias. 
    (Lo siento por mi Inglés) 

    ------------


    jalpc


    • Edited by jalpc Saturday, October 25, 2014 7:18 PM
    Saturday, October 25, 2014 7:13 PM
  • ... I used (Shapes.Remove) to change number.

    Yep, saw it with:

    flag_btnStart="False"
    Textwindow.WriteLine(LDShapes.GetAllShapes())

    ....

    (added) in the main loop (Shapename numbering).

    Cool, espero que tengan éxito con sus números !!

    Saturday, October 25, 2014 7:59 PM
    Answerer
  • This is another sample to get random numbers from 1 to 32.

    max = 32
    Init()
    For i = 1 To max
      Random()
      ' do something with rnd
      TextWindow.Write(rnd + " ")
    EndFor
    TextWindow.WriteLine("")
    Sub Init
      For i = 1 To max
        num[i] = i
      EndFor
    EndSub
    Sub Random
      n = Array.GetItemCount(num)
      index = Array.GetAllIndices(num)
      r = Math.GetRandomNumber(n)
      rnd = num[index[r]] ' return value
      num[index[r]] = ""  ' remove the entry from the array num
    EndSub
    


    Nonki Takahashi

    Monday, October 27, 2014 1:16 PM
    Moderator
  • ... I used (Shapes.Remove) to change number.

    Yep, saw it with:

    flag_btnStart="False"
    Textwindow.WriteLine(LDShapes.GetAllShapes())

    ....

    (added) in the main loop (Shapename numbering).

    Cool, espero que tengan éxito con sus números !!

    Hi Pappa Lapub,

    Thanks for your advice. With Shapes.ShowShape and  Shapes.HideShape ........ problem solved. 
    Thank you for your contribution ( TextWindow.WriteLine (LDShapes.GetAllShapes ()) )

    jalpc


    jalpc

    Wednesday, October 29, 2014 2:13 PM
  • PS: Forgot:
    TextWindow.WriteLine("rect: "+ (LDUtilities.GetNextMapIndex("Rectangle")-1))
    etc.
    at the same place would show the highest index number of (eg. here) created "Rectangle"
    during the program runtime. Does not mean that the object(s) still exist. May also be(en) deleted.


    And ... there are some more options for Shapes.Add..  to add to GW and prevent flickering:

    1. TextShapes: w/o extension
    ------------------
    Shapes.AddText("")
    Later then use Shapes.SetText(shapeName, "text")

    2. ImageShapes:    (w LitDev Ext)
    --------------------
    Shapes.AddImage(transparent image from filepath/ImageList)
    Later then LDShapes.SetImage to replace the blank image by the opaque one

    Blank_100.pngDefault_120.png

    like eg. 2 samples here: Blank_100.png and Default_120.png  (TWO image files !!)
    Demo ID: LHT647
    Size of the transp. template plays no role, LDShapes.SetImage adjusts shape to size of the replacement image

    3. Geometry/Drawing Shapes:
    --------------------------------------
    a. Ellipse, Rectangle:    w/o extension
    Shapes.AddEllipse(0,0)        Ell. property already defined, but zero dimension
    Shapes.AddRectangle(0,0)    Rect. -"-

    Later then Controls.SetSize to blow up to needed sizes
    Demo ID: XWR511

    b. Line, Triangle:    w/o extension
    Shapes.AddLine(pos outside of GW)
    Shapes.AddTriangle(pos outside of GW)

    Later then Shapes.Move or Controls.Move to move to desired positon inside GW
    Demo ID: XWR511  as well

    c. Ellipse, Rectangle, Line, Triangle:    (w LitDev Ext)
    GraphicsWindow.BrushColor = "Transparent"
    Shapes.Add...

    Later then LDShapes.BrushColour to set shape to desired color and make visible
    Demo ID: FSW074

    4. Controls:        w/o extension
    --------------
    Controls.AddButton("text", pos outside of GW)
    Controls.Add(MultiLine)TextBox(pos ouside of GW)

    Later then Shapes.Move or Controls.Move to move to desired positon inside GW

    or like just all the others: Add the shape during GW is hidden.


    When running a Demo ID, keep an eye at GW 0;0.


    • Edited by Pappa LapubEditor Friday, November 21, 2014 9:04 PM
    • Proposed as answer by jalpc Saturday, November 22, 2014 4:10 PM
    Friday, November 21, 2014 9:00 PM
    Answerer
  • PS: Forgot:
    TextWindow.WriteLine("rect: "+ (LDUtilities.GetNextMapIndex("Rectangle")-1))
    etc.
    at the same place would show the highest index number of (eg. here) created "Rectangle"
    during the program runtime. Does not mean that the object(s) still exist. May also be(en) deleted.


    And ... there are some more options for Shapes.Add..  to add to GW and prevent flickering:

    1. TextShapes: w/o extension
    ------------------
    Shapes.AddText("")
    Later then use Shapes.SetText(shapeName, "text")

    2. ImageShapes:    (w LitDev Ext)
    --------------------
    Shapes.AddImage(transparent image from filepath/ImageList)
    Later then LDShapes.SetImage to replace the blank image by the opaque one

    Blank_100.pngDefault_120.png

    like eg. 2 samples here: Blank_100.png and Default_120.png  (TWO image files !!)
    Demo ID: LHT647
    Size of the transp. template plays no role, LDShapes.SetImage adjusts shape to size of the replacement image

    3. Geometry/Drawing Shapes:
    --------------------------------------
    a. Ellipse, Rectangle:    w/o extension
    Shapes.AddEllipse(0,0)        Ell. property already defined, but zero dimension
    Shapes.AddRectangle(0,0)    Rect. -"-

    Later then Controls.SetSize to blow up to needed sizes
    Demo ID: XWR511

    b. Line, Triangle:    w/o extension
    Shapes.AddLine(pos outside of GW)
    Shapes.AddTriangle(pos outside of GW)

    Later then Shapes.Move or Controls.Move to move to desired positon inside GW
    Demo ID: XWR511  as well

    c. Ellipse, Rectangle, Line, Triangle:    (w LitDev Ext)
    GraphicsWindow.BrushColor = "Transparent"
    Shapes.Add...

    Later then LDShapes.BrushColour to set shape to desired color and make visible
    Demo ID: FSW074

    4. Controls:        w/o extension
    --------------
    Controls.AddButton("text", pos outside of GW)
    Controls.Add(MultiLine)TextBox(pos ouside of GW)

    Later then Shapes.Move or Controls.Move to move to desired positon inside GW

    or like just all the others: Add the shape during GW is hidden.


    When running a Demo ID, keep an eye at GW 0;0.


    Hi Pappa Lapub:
    Very interesting.
    This information will be very useful for me.
    Thank you.

    In Spanish:

    -------------

    hola Pappa Lapub:
    Muy interesante.
    Esta informacion va a ser muy util para mi.
    Gracias.

    --------------


    jalpc

    Saturday, November 22, 2014 4:10 PM