Subscribe to our RSS Feeds

【Small Basic】练手小程序2之黑板

1 Comments »
恩……这个程序是根据帮助文件中的一个改得,增加了调整画笔粗细和颜色的按键。也是没什么说头的。status = True
clearWidth = 10
penWidth = 2
GraphicsWindow.BackgroundColor = "Black"
GraphicsWindow.PenColor = "White"
GraphicsWindow.BrushColor = "White"
GraphicsWindow.PenWidth = penWidth
GraphicsWindow.MouseDown = OnMouseDown
GraphicsWindow.MouseMove = OnMouseMove
GraphicsWindow.KeyDown = OnKeyDown
GraphicsWindow.Title = "黑板"
GraphicsWindow.DrawText(0, 0, "X:擦除 1:白色 2:黄色 3:蓝色 4:绿色 5:红色 Q/W:调整粗细")

Sub OnMouseDown
  prevX = GraphicsWindow.MouseX
  prevY = GraphicsWindow.MouseY
EndSub

Sub OnKeyDown
  If (GraphicsWindow.LastKey = "X") then
    GraphicsWindow.PenColor = GraphicsWindow.BackgroundColor
    GraphicsWindow.PenWidth = clearWidth
    status = False
  EndIf
  If (GraphicsWindow.LastKey = "D1") then
    GraphicsWindow.PenColor = "White"
    GraphicsWindow.PenWidth = penWidth
    status = True
  EndIf
  If (GraphicsWindow.LastKey = "D2") then
    GraphicsWindow.PenColor = "Yellow"
    GraphicsWindow.PenWidth = penWidth
    status = True
  EndIf
  If (GraphicsWindow.LastKey = "D3") then
    GraphicsWindow.PenColor = "Blue"
    GraphicsWindow.PenWidth = penWidth
    status = True
  EndIf
  If (GraphicsWindow.LastKey = "D4") then
    GraphicsWindow.PenColor = "Lime"
    GraphicsWindow.PenWidth = penWidth
    status = True
  EndIf
  If (GraphicsWindow.LastKey = "D5") then
    GraphicsWindow.PenColor = "Red"
    GraphicsWindow.PenWidth = penWidth
    status = True
  EndIf
  If (GraphicsWindow.LastKey = "Q") then
    If (status = True) then
      penWidth = penWidth - 1
      GraphicsWindow.PenWidth = penWidth
    Else
      clearWidth = clearWidth - 1
      GraphicsWindow.PenWidth = clearWidth
    EndIf
  EndIf
  If (GraphicsWindow.LastKey = "W") then
    If (status = True) then
      penWidth = penWidth + 1
      GraphicsWindow.PenWidth = penWidth
    Else
      clearWidth = clearWidth + 1
      GraphicsWindow.PenWidth = clearWidth
    EndIf
  EndIf
EndSub

Sub OnMouseMove
  x = GraphicsWindow.MouseX
  y = GraphicsWindow.MouseY
  If (Mouse.IsLeftButtonDown) then
    GraphicsWindow.DrawLine(prevX, prevY, x, y)
  endif
  prevX = x
  prevY = y
EndSub


提示:GraphicsWindow.LastKey属性中的D0到D9指数字键。
11/16/2008 10:25:00 上午

【Small Basic】练手小程序1之数的开方

0 Comments »
这是一个命令行程序。代码如下:TextWindow.Write("请输入一个数字:")
org = TextWindow.ReadNumber()
ClearLine()
TextWindow.Write("数字 ")
TextWindow.Write(org)
TextWindow.WriteLine(":")
number = 1
p = 0
TextWindow.Write("  ")
TextWindow.Write(org)
TextWindow.Write("^")
TextWindow.Write(p)
TextWindow.Write("=")
TextWindow.WriteLine(number)
number = number * org
p = p + 1
While (1=1)
  TextWindow.Write("  ")
  TextWindow.Write(org)
  TextWindow.Write("^")
  TextWindow.Write(p)
  TextWindow.Write("=")
  TextWindow.WriteLine(number)
  number = number * org
  p = p + 1
  PauseAndClearMessage()
EndWhile

Sub ChinesePause
  TextWindow.WriteLine("请按任意键继续. . .")
  TextWindow.PauseWithoutMessage()
EndSub

Sub PauseAndClearMessage
  ChinesePause()
  ClearLine()
EndSub

Sub ClearLine
  TextWindow.CursorTop = TextWindow.CursorTop - 1
  TextWindow.CursorLeft=0
  x = TextWindow.CursorTop
  TextWindow.WriteLine("                                                                                                        ")
  TextWindow.CursorTop=x
  TextWindow.CursorLeft=0
EndSub
特点是每次只显示一个,按下任意键才显示接下来的。

用到了一个Sub ClearLine,意思是清除光标上一行。其实这句如果用.NET写的话更简单。

程序作者:蓝蓝小雪
11/16/2008 09:22:00 上午

【Small Basic】微软推出Small Basic

0 Comments »
经过一年的封闭开发,微软上个月发布了Small Basic,一款针对儿童的免费编程语言。不像Scratch和Alice,这款工具属于“无编码”环境,本质上讲是一个简略版本的BASIC语言。
该语言脱胎于传统的BASIC语言,但是基于.Net开发框架重新建立。它有三个显著特点:

语言
只包含14个关键词,Small Basic是完全基于.Net开发框架运行的。

环境
Small Basic的开发环境非常简单,但是提供了只有专业开发人员才能使用的包含智能感知的IDE。


Small Basic有一系列的开发库,并允许用户创建新的库或者修改现有的。它还允许加在第三方开发库。



一份非常简单易懂的(我们通过一个9岁的孩子测试过)62页的PDF文档可以帮助你快速上手,每个对Small Basic感兴趣的人都可以下载。

40年前出现的BASIC语言经过了许多次改进,已经变得更加强大,特别是对于初学者来说。即使Small Basic主要针对的是儿童,许多编程的初学者都会对此感兴趣。


下载地址:http://msdn.microsoft.com/en-us/devlabs/cc950524.aspx

本博客以后也会更新关于 Small Basic 的东西!
11/16/2008 12:24:00 上午

With Blue Snow Studio, Nothing is impossible.