a18
The Official Blog of Small Basic    http://blogs.msdn.com/b/smallbasic/   Ed Price – MSFT    NaochanON created this program that generates these triangles:
Program Listing: RBB339
  1. ‘ Fractale viewdata()              ’Input numbers&marks for controls
    init_View()
    Controls.ButtonClicked = OnButtonClicked
    Sub Show_Fractal
    ‘ Base
    Base_Triangle()
    for k=Real_No[4] To 1 Step -1
    GraphicsWindow.PenWidth=1
    GraphicsWindow.PenColor=”white”
    GraphicsWindow.BrushColor= GraphicsWindow.GetRandomColor() ’ “white”
    PowerK=Math.Power(0.5,k)
    For i=1 To  (Math.Power(2,k)-1)  Step 2          ’ Y direction
    For j=1 To (Math.Power(2,k)-1-(i-1))   Step 2        ’ X direction
    BaseY[i][j]=ACY*PowerK +(i-1)*ACY*Powerk
    BaseX[i][j]=ACX*PowerK +(j-1)*ABX*PowerK +(i-1)*ACX*powerk
    gas[i][j]=Shapes.AddTriangle(0,0,PowerK*Lc,0,PowerK*(Lc-MCX),PowerK*YH)
    Shapes.Animate(gas[i][J],SX+BaseX[i][j],SY+AY-BaseY[i][j],1000/k)
    EndFor
    EndFor
    EndFor
    EndSub
    Sub Base_Triangle
    La=Real_No[1]    ’ Length a
    Lb=Real_No[2]    ’ Length b
    Lc=Real_No[3]    ’ Length c
    MCX=(La*La+Lc*Lc-Lb*Lb)/2/Lc           ’ MCX
    YH=math.SquareRoot(La*La-MCX*MCX)      ’ Hight
    AX=0             ’ Point-A X C
    AY=YH            ’ Point-A Y . . .
    BX=Lc            ’ Point-B X . . YH .
    BY=YH            ’ Point-B Y A . . . . . B
    CX=MCX
    CY=0
    ABX=(AX+BX)
    ABY=(AY+BY)
    ACX=(AX+CX)
    ACY=(AY+CY)

    GraphicsWindow.PenColor=”#FF0000″  ’”Red”
    GraphicsWindow.BrushColor=”#FF0000″  ’”Red”
    Base=Shapes.AddTriangle(AX,AY,BX,BY,CX,CY)
    SX=50             ’ shift X
    SY=170            ’ shift Y
    Shapes.Animate(Base,SX,SY,100)
    Program.Delay(500)
    EndSub
    Sub OnButtonClicked
    GraphicsWindow.BrushColor = ”Red”
    name=controls.LastClickedButton     ’Last button
    nm=controls.GetButtonCaption(name)  ’ Button’s caption
    Xloc=50+2*BW*(count)    ’ Angle number / length showing position
    If nm=”Del” Then
    Del_word()
    elseIf nm=”AC” Then
    Reset()
    elseIf nm=”Exe” Then
    Execute()
    else
    Make_word()
    endif
    EndSub
    Sub Fractale
    If Real_No[1]+Real_No[2] <= Real_No[3] Then
    Sound.PlayBellRing()    ’ Check ( a+ b > C)
    Reset()
    endif
    For i= 1 To 4
    Shapes.Remove(T[i])   ’ initial triangle and a b c
    EndFor
    Show_Fractal()          ’ fractale showing
    EndSub
    Sub Sample_Triangle
    GraphicsWindow.PenColor=”Yellow”
    GraphicsWindow.BrushColor=”Yellow”
    AX=0
    AY=400
    BX=600
    BY=400
    CX=450
    CY=0
    MX=50
    MY=150
    T[1]=Shapes.AddTriangle(AX,AY,BX,BY,CX,CY)
    Shapes.SetOpacity(T[1],30)
    Shapes.Animate(T[1],MX,MY,600)
    T[2]=shapes.AddText(” a “)
    Shapes.Animate(T[2],MX+CX/2-50,MY+AY/2,800)
    T[3]=shapes.AddText(” b “)
    Shapes.Animate(T[3],MX+10+CX+(BX-CX)/2,MY+CY+(BY-CY)/2,1000)
    T[4]=shapes.AddText(” c “)
    Shapes.Animate(T[4],MX+BX/2,MY+BY,1200)
    EndSub
    Sub   Button_Set
    GraphicsWindow.BrushColor = ”Blue”
    nn=0
    dm=s[1]
    Loop2:
    end_P=Text.GetIndexOf(dm,” “)
    msg=text.GetSubText(dm,1,end_P-1)  ’ word
    nn=nn+1
    btn[nn][1] =Controls.AddButton(msg, 10+BW*(nn-1), BH+50)
    Controls.SetSize(btn[nn][1] ,BW-2,BH-2)  ’Set 13 Control buttons
    If nn=WN Then
    Goto end1
    EndIf
    dm=text.GetSubTextToEnd(dm,end_p+1)   ’gets number value or mark’s name
    Goto loop2
    end1:
    add_num=”"
    count=0
    EndSub
    Sub Reset
    GraphicsWindow.Clear()
    GraphicsWindow.Show()
    init_View()
    Button_Set()
    EndSub
    Sub init_View
    WN=13   ’ 13 words
    BW=70
    BH=45
    GW=BW*WN
    GH=BH*15+20
    GraphicsWindow.Hide()
    GraphicsWindow.top=0
    GraphicsWindow.Width = GW+2*10
    GraphicsWindow.Height = GH
    GraphicsWindow.Title = ”Fractale graph”
    GraphicsWindow.Show()
    GraphicsWindow.BackgroundColor = ”Teal”
    GraphicsWindow.BrushColor = ”White”
    GraphicsWindow.FillRectangle(10+BW*0, 45, BW*3/2, BH-10)
    GraphicsWindow.FillRectangle(10+BW*2, 45, BW*3/2, BH-10)
    GraphicsWindow.FillRectangle(10+BW*4, 45, BW*3/2, BH-10)
    GraphicsWindow.FillRectangle(10+BW*6, 45, BW*3/2, BH-10)
    GraphicsWindow.BrushColor =”Yellow”
    GraphicsWindow.FontSize = 20
    GraphicsWindow.FontName = ”Coorie new”
    GraphicsWindow.FontItalic=”True”
    GraphicsWindow.DrawText(15,5,”Input a b c values (300-800 may be better)”)
    GraphicsWindow.DrawText(10+BW*9,5,”Note!: Must be ( a + b > c ) “)
    GraphicsWindow.DrawText(10+BW*6,23,”Steps: Under 7 “)
    GraphicsWindow.DrawText(10+BW*9,40,”AC=All Clear”)
    GraphicsWindow.DrawText(10+BW*9,60,”Exe=Enter Value or Run”)
    Button_Set()
    GraphicsWindow.FontSize = 23
    GraphicsWindow.DrawText(20,45,”a: “)
    GraphicsWindow.DrawText(20+BW*2,45,”b: “)
    GraphicsWindow.DrawText(20+BW*4,45,”c: “)
    GraphicsWindow.DrawText(20+BW*6,45,”S: “)
    Sample_Triangle()   ’ show sample triangle
    EndSub
    Sub data  ’ 13 words
    s[1]=”1 2 3 4 5 6 7 8 9 0 Del AC Exe “
    EndSub
    Sub Del_word
    Shapes.Remove(numbers[count])
    add_num=Text.GetSubText(add_num,1,Text.GetLength(add_num)-1)
    numbers[count] = Shapes.AddText(add_num)   ’ 1 word delete
    Shapes.Move(numbers[count] , Xloc, 45)
    EndSub
    Sub Execute
    count=count+1
    Real_No[count]=add_num
    add_num=”"
    If count=4 then
    Fractale()
    endif
    EndSub
    Sub Make_word
    Shapes.Remove(numbers[count])
    add_num=text.Append(add_num,nm) ’ Add 1 word
    numbers[count] = Shapes.AddText(add_num)
    Shapes.Move(numbers[count], Xloc, 45)
    EndSub
  2. //
Copyright (c) Microsoft Corporation. All rights reserved.

Deja un comentario