Easy Graf making Controlbox data by NaoChanON (code/ código)


a13

Microsoft Small Basic

Program Listing:  pnz684      http://smallbasic.com/smallbasic.com/program/?pnz684
a14
  1. ‘ Easy Graf making Controlbox data Input version 2011/12/21 by NaoChanON GraphicsWindow.Top=30
    GraphicsWindow.Left=50
    GraphicsWindow.Width=1000
    GraphicsWindow.Height=600
    GraphicsWindow.BackgroundColor=”Lavender”
    GraphicsWindow.Show()
    Controls.ButtonClicked=Onclick

    TextBoX_Input()

    Sub OnClick
    name=””
    name=controls.LastClickedButton     ‘ Last button
    nm=controls.GetButtonCaption(name)  ‘ Button’s caption
    If nm=”Execute” Then
    get_data()
    init()
    Plot_Data()
    Regressionline()
    EndIf
    EndSub

    Sub TextBoX_Input
    GraphicsWindow.BrushColor=”Red”
    GraphicsWindow.FontSize=30
    GraphicsWindow.DrawText(80,5,” Input boxes and push execute “)
    EXEC=Controls.AddButton(“Execute”,230,540)
    Controls.SetSize(EXEC,300,50)
    GraphicsWindow.FontSize=20

    GraphicsWindow.BrushColor=”Navy”
    GraphicsWindow.FontSize=15
    GraphicsWindow.DrawText(30,50,”Graf Width,Height”)  ‘ Width and height
    GraphicsWindow.DrawText(30,70,”EXAM: 800,500″)
    GXYBOX= Controls.AddTextBox(230,50)
    Controls.SetSize(GXYBOX,100,40)
    Controls.SetTextBoxText(GXYBOX,”800,500″)

    GraphicsWindow.DrawText(30,120,”Min-X , Max-X”)    ‘ Min-X and Max-X
    GraphicsWindow.DrawText(30,140,”EXAM: 0,800″)
    MINMAXX= Controls.AddTextBox(230,120)
    Controls.SetSize(MINMAXX,100,40)
    Controls.SetTextBoxText(MINMAXX,”0,800″)

    GraphicsWindow.DrawText(30,190,”Min-Y , Max-Y”)     ‘Min-Y and Max-Y
    GraphicsWindow.DrawText(30,210,”EXAM: 0,500″)
    MINMAXY= Controls.AddTextBox(230,190)
    Controls.SetSize(MINMAXY,100,40)
    Controls.SetTextBoxText(MINMAXY,”0,500″)

    GraphicsWindow.DrawText(30,260,”Dividing X , Y”)   ‘ dividing number
    GraphicsWindow.DrawText(30,280,”EXAM: 4,5″)
    DivBOX= Controls.AddTextBox(230,260)
    Controls.SetSize(DivBOX,100,40)
    Controls.SetTextBoxText(DivBOX,”4,5″)

    GraphicsWindow.DrawText(30,330,”Label X”)         ‘ Label-X name
    GraphicsWindow.DrawText(30,350,”EXAM: Weight”)
    LABELXBOX=Controls.AddTextBox(230,330)
    Controls.SetSize(LABELXBOX,300,40)
    Controls.SetTextBoxText(LABELXBOX,” Label X “)

    GraphicsWindow.DrawText(30,400,”Label Y”)         ‘ Label-Y name
    GraphicsWindow.DrawText(30,420,”EXAM: Height”)
    LABELYBOX=Controls.AddTextBox(230,400)
    Controls.SetSize(LABELYBOX,300,40)
    Controls.SetTextBoxText(LABELYBOX,” Label Y “)

    GraphicsWindow.DrawText(30,470,”Title name”)        ‘ Title name
    GraphicsWindow.DrawText(30,490,”EXAM: Weight vs Height”)
    TTLBOX=Controls.AddTextBox(230,470)
    Controls.SetSize(TTLBOX,300,40)
    Controls.SetTextBoxText(TTLBOX,” Test Graph “)

    GraphicsWindow.DrawText(660,5,”Input X , Y data”)   ‘ X,Y data
    GraphicsWindow.DrawText(660,25,”EXAM: 50 , 100 enter”)
    GraphicsWindow.DrawText(720,45,”80 , 150 enter”)
    MBOX= Controls.AddMultiLineTextBox(700,80)
    Controls.SetSize(MBOX,100,500)
    Controls.SetTextBoxText(MBOX,” 50,100″)
    EndSub

    Sub get_data
    GWH=Controls.GetTextBoxText(GXYBOX)
    GWidth= Text.GetSubText(GWH,1,text.GetIndexOf(GWH,”,”)-1)    ‘ Gwidth
    GHeight=Text.GetSubTextToEnd(GWH,text.GetIndexOf(GWH,”,”)+1)  ‘Ghight

    MMX=Controls.GetTextBoxText(MINMAXX)
    MinX= Text.GetSubText(MMX,1,text.GetIndexOf(MMX,”,”)-1)     ‘ Min-X
    MaxX=Text.GetSubTextToEnd(MMX,text.GetIndexOf(MMX,”,”)+1)   ‘Max-X

    MMY=Controls.GetTextBoxText(MINMAXY)
    MinY= Text.GetSubText(MMY,1,text.GetIndexOf(MMY,”,”)-1)      ‘Min-Y
    MaxY=Text.GetSubTextToEnd(MMY,text.GetIndexOf(MMY,”,”)+1)    ‘Max-Y

    DXY=Controls.GetTextBoxText(DivBOX)
    XDiv= Text.GetSubText(DXY,1,text.GetIndexOf(DXY,”,”)-1)      ‘X-Dividing number
    YDiv=Text.GetSubTextToEnd(DXY,text.GetIndexOf(DXY,”,”)+1)    ‘Y-Dividing number

    LBLX=Controls.GetTextBoxText(LABELXBOX)            ‘ Label-X
    LBLY=Controls.GetTextBoxText(LABELYBOX)            ‘ Label-Y
    TTL=Controls.GetTextBoxText(TTLBOX)                ‘ Title name

    DatXY=Controls.GetTextBoxText(MBOX)               ‘ X-Y data
    Get_XYata()                                       ‘ Pick Up X,Y data from multilinetextbox

    EndSub

    Sub Get_XYata                           ‘ Pick Up X,Y data from multilinetextbox
    DatXY=Controls.GetTextBoxText(MBOX)
    If Text.GetCharacterCode(text.GetSubText(DatXY,Text.GetLength(datXY),1))=10 Then
    DatXY= text.GetSubText(DatXY,1,Text.GetLength(datXY)-2)  ‘ if DatXY -end = Chr$(13)+chr$(10) then delete
    EndIf

    For i=1 To Text.GetLength(DatXY)
    word1=text.GetSubText(datXY,i,1)
    If word1=text.GetCharacter(13) Then     ‘ delete chr$(13)
    word1=””
    ElseIf word1=text.GetCharacter(10) Then ‘ conversion Chr$(10) to “:” =delimiter
    word1=”:”
    EndIf
    midw=text.Append(midw,word1)
    EndFor
    midw=midw+”:”                 ‘ connect all word and add “:” =delimiter

    while midw<>””
    NN=NN+1
    midp1=Text.GetIndexOf(midw,”,”)
    midp2=Text.GetIndexOf(midw,”:”)
    px[NN]=Text.GetSubText(midw,1,midp1-1)              ‘ pick up X-data
    py[NN]=Text.GetSubText(midw,midp1+1,midp2-midp1-1)  ‘ pick up Y-data
    midw=Text.GetSubTextToEnd(midw,midp2+1)
    EndWhile
    EndSub

    Sub init
    GraphicsWindow.Clear()
    GraphicsWindow.top=50
    GraphicsWindow.Left=50
    GraphicsWindow.Width=1000
    GraphicsWindow.Height=650
    GraphicsWindow.Show()
    GraphicsWindow.BackgroundColor=”Lightcyan”
    GraphicsWindow.BrushColor=”Navy”
    GraphicsWindow.PenColor=”Red”

    ‘ Draw Rectangle
    GTop=60
    GLeft=150
    GraphicsWindow.DrawRectangle(Gleft,Gtop,GWidth,GHeight)

    ‘ Title and X,Y-labels
    GraphicsWindow.FontSize=30
    GTitle=Shapes.AddText(TTL)
    Shapes.Animate(GTitle,Gleft+150,Gtop-40,1000)
    LabelY=Shapes.AddText(LBLY)
    Shapes.Animate(LabelY,15,(Gtop+GHeight)/2,1500)
    Shapes.Rotate(LabelY,-90)
    LabelX=Shapes.AddText(LBLX)
    Shapes.Animate(LabelX,(Gleft+Gwidth)/2-20,Gtop+GHeight+40,2000)

    ‘ X—–Axis
    GraphicsWindow.FontSize=20
    GraphicsWindow.BrushColor=”Red”

    For i= 0 To XDiv
    For j=GTop To GTop+Gheight-5 Step 10
    GraphicsWindow.DrawLine(Gleft+i*(Gwidth/Xdiv),J,Gleft+i*(Gwidth/Xdiv),j+5)
    EndFor
    DivX=math.round(minX+i*((MaxX-minX)/Xdiv))
    GraphicsWindow.DrawText(Gleft+i*(Gwidth/Xdiv)-20,GTop+GHeight+10,DivX)
    EndFor

    ‘ Y—Axis
    For i= YDiv To 0 Step -1
    For j=GLeft To GLeft+Gwidth-5 Step 10
    GraphicsWindow.DrawLine(j,GTop+i*(GHeight/Ydiv),j+5,GTop+i*(GHeight/Ydiv))
    EndFor
    DivY=math.Round(MaxY-i*((MaxY-minY)/Ydiv))
    GraphicsWindow.DrawText(Gleft-40,GTop+i*(GHeight/Ydiv)-10,DivY)
    EndFor

    EndSub

    Sub  Plot_Data
    GraphicsWindow.PenColor=”Green”
    GraphicsWindow.PenWidth=3
    For i=1 To NN
    plotx=Gleft + (PX[i]-minX)*Gwidth/(MaxX-MinX)
    ploty=GTop + Gheight- (PY[i]-minY)*Gheight/(MaxY-MinY)
    sc[i]=Shapes.AddEllipse(10,10)
    Shapes.Animate(sc[i],plotx-5,ploty-5,1000)
    EndFor
    EndSub

    Sub Regressionline
    For i=1 To NN
    sumx=sumx+px[i]
    sumy=sumy+py[i]
    sumX2=sumX2+px[i]*px[i]
    sumXY=sumXY+px[i]*py[i]
    sumY2=sumY2+py[i]*py[i]
    EndFor

    slope=(NN*sumXY-sumx*sumy)/(NN*sumx2-sumx*sumx)  ‘ slope a
    slope=math.Round(slope*100)/100                   ‘ round a
    intercept=sumy/NN-slope*sumx/NN                  ‘ intercept b
    intercept=math.Round(intercept*100)/100          ‘ round b

    Reg_line=”y= “+slope+”X + “+intercept          ‘ y= aX+b
    sreg=Shapes.AddText(Reg_line)
    Shapes.Animate(sreg,Gleft+10,80,1500)

    regY1=slope*minx+intercept                ‘ X=MinX Y= intercept
    regY2=maxY*0.8                           ‘ Y=maxY*0.8
    regx2=(regY2-intercept)/slope             ‘ X at Y
    Gregx1=Gleft                                           ‘conversion x1=minX
    GregX2=Gleft + (regx2-minX)*Gwidth/(MaxX-MinX)         ‘ conversion x2
    Gregy1=GTop + Gheight- (regY1-minY)*Gheight/(MaxY-MinY) ‘ conversion y1
    Gregy2=GTop + Gheight- (regY2-minY)*Gheight/(MaxY-MinY) ‘ conversion y2

    slope2=(NN*sumXY-sumx*sumy)/(NN*sumY2-sumY*sumY)  ‘ slope c
    slope2=math.Round(slope2*100)/100                 ‘ round c
    Coefficient=Math.SquareRoot(slope*slope2)         ‘Correlation coefficient
    Coefficient=math.Round(Coefficient*1000)/1000
    scoef= Shapes.AddText(“Coefficient= “+Coefficient)
    Shapes.Animate(scoef,Gleft+10,100,1500)

    GraphicsWindow.PenColor=”Green”
    GraphicsWindow.DrawLine(Gregx1,GregY1,GregX2,GregY2)   ‘ draw regression Line

    EndSub

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s