Microsoft Small Basic

Program Listing: TJB740
GraphicsWindow.BackgroundColor = "Black"
GraphicsWindow.PenColor = "LightGreen"
GraphicsWindow.Width = 700+10
GraphicsWindow.Height = 700+10

GraphicsWindow.DrawEllipse(100-3,100, 600+2,600)
'设圆的半径为1 1:300的比例放大作图
'最大(外切)正方形边长为2

w=600
n=math.SquareRoot((600/2)*(600/2)+300*300)
'外切1:
GraphicsWindow.DrawRectangle(100-3,100,600+2,600)
'则此时外切矩形边长为2
'(粗略PI)为 (4* 2 )/2=4

'内割1:
'GraphicsWindow.DrawRectangle
Turtle.PenUp()
turtle.speed=10 '9
Turtle.MoveTo(100+300,100)
Turtle.PenDown()
turtle.MoveTo(100,100+300)
'Turtle.Turn(-90)
turtle.speed=11 '加速
turtle.MoveTo(100+300,100+600)
turtle.MoveTo(100+600,100+300)
turtle.MoveTo(100+300,100) '回起点
'则此时内接(内割)矩形边长为 math.squareRoot(1^2+1^2) --(实际大小) 为2的算术平方根
'(粗略PI)为 (4 * squareRoot(2) )/2= 2*squareroot(2)
n1=(math.SquareRoot(2))
PI1=(4*n1)/2
TextWindow.WriteLine(n1)
TextWindow.WriteLine("PI(内接1)=")
TextWindow.WriteLine(PI1)

TextWindow.WriteLine("内接2-八边形边长=")
n2=Math.squareroot( (n1/2)*(n1/2)+(1-n1/2)*(1-n1/2) )
PI2=(8*n2)/2
TextWindow.WriteLine(n2)
TextWindow.WriteLine("PI(内接2-八边形)=")
TextWindow.WriteLine(PI2)

For i=1 To 10 Step 1
TextWindow.WriteLine(i)
TextWindow.WriteLine("内接N边形边长=")
n2=Math.squareroot( (n1/2)*(n1/2)+(1-n1/2)*(1-n1/2) )
PIn=(4*(a_2_iMi(2,i))*n2)/2
'TextWindow.WriteLine(n2)
TextWindow.WriteLine("PI(内接正N边形时)=")
TextWindow.WriteLine(PIn)

n1=n2

EndFor


Sub a_2_iMi(n2,n)
For i=1 To n
result1=2*result1
EndFor
a_2_iMi=result1

EndSub