logo 小海龟

 

很大版本软件下载:

https://el.media.mit.edu/logo-foundation/resources/software_hardware.html

选了其中的:

MSW Logo

Based on UCBLogo, this version by George Mills is for Windows.

css的太极图: https://juejin.cn/post/6844903556378525703


简要入门

A Logo Primer

 

The most popular Logo environment has involved the Turtle, originally a robotic creature that moved around on the floor.

Student at computerIt can be directed by typing commands at the computer. The command forward 100 causes the turtle to move forward in a straight line 100 "turtle steps". Right 45 rotates the turtle 45 degrees clockwise while leaving it in the same place on the floor. Then forward 50 causes it to go forward 50 steps in the new direction.

With just the two commands forward and right, the turtle can be moved in any path across the floor. The turtle also has a pen which may be lowered to the floor so that a trace is left of where it has traveled. With the pen down, the turtle can draw geometric shapes, and pictures, and designs of all sorts.

 

Off the Floor and Onto the Screen

The turtle migrated to the computer screen where it lives as a graphics object. Viewing the screen is like looking down on the mechanical turtle from above.

The screen turtle also understands forward and right.

forward 50

right 45

forward 25

Following some exploratory messing around, a common first Turtle activity is to draw a geometric shape. How about a square?

forward 50

right 90

forward 50

right 90

forward 50

right 90

forward 50

right 90

There's also a repeat command so that

repeat 4 [forward 50 right 90]

also draws a square.

How about a triangle?

repeat 3 [forward 50 right 60]

Oops! That's fine. Debugging is part of working in Logo.

Another important aspect of Logo is defining new procedures. We drew a square using the instruction

repeat 4 [forward 50 right 90]

But if we tell Logo

square

Logo responds with the message:

I don't know how to square

So we teach Logo a new word.

to square
repeat 4 [forward 50 right 90]
end

Now if we type square, Logo draws a square just as if we had typed repeat 4 [forward 50 right 90]. Logo has learned a new word.

forward 50

square

Now that square is in Logo's vocabulary, the new word may be used as part of another instruction. For example

We can give this a name also.

to flower
repeat 36 [right 10 square]
end

repeat 36 [right 10 square]

In Logo, programming is done by adding new words to the existing vocabulary. It's like learning a spoken language. New words are defined using words you already know.

Things can get more complex. Procedures can take "inputs" so that the information they use varies. We could write a square procedure like this:

to square :size
repeat 4 [forward :size right 90]
end

Instead of always having a square of 50 units on a side we can tell it how big to be:

square 50

square 30

square 100

There's more:

to spiral :size :angle
if :size > 100 [stop]
forward :size
right :angle
spiral :size + 2 :angle
end

spiral 0 90

spiral 0 91

The traditional Euclidean geometry is built on abstractions: a point that has no size; a line that has length but no thickness. This is difficult for young learners to grasp. The turtle is a real concrete object that may be seen and manipulated. Analytic geometry rests on an outside frame of reference -- the coordinate system. In contrast, turtle geometry is "body syntonic". The turtle moves around as you do. You can identify with it and understand what it is doing.

Turtle geometry was not intended to be a replacement for traditional geometry but rather, as an alternative entry point into geometry and mathematics in general. It is appropriate for young children as well as adults.

The rationale behind turtle geometry is thoroughly explained by Seymour Papert in Mindstorms . Many versions of Logo come with tutorials and guide books about turtle geometry.

While it is easy to get started with turtle geometry, it can also get quite complex. The bookTurtle Geometry, by Hal Abelson and Adrea diSessa includes many advanced explorations with the turtle.

 

Up and Away

Another species of Logo turtle emerged in the early 1980s. Dynamic turtles, or "sprites" as they were often called, lived in computers like the Texas Instruments TI99/4 and the Atari 800. The video game hardware in these machines allowed for software with numerous high speed multi-colored objects.

The versions of Logo created for these machines includes many turtles, which could take on a variety of shapes becoming birds, trees, dogs, or spaceships. Although the early video game computers disappeared, sprite capability has been included in most modern versions of Logo.

Here's an example of how an animation may be created with a dynamic turtle:

We start by assigning a shape to the turtle with a command such as setshape "bird1 We also have a second shape of a bird in a different position which we see by typing setshape "bird2

 
Then we can write a procedure

to fly
setshape "bird1
setshape "bird2
end

The instruction fly gets the bird to flap its wings once. Repeat 9999 [fly] causes it to flap continuously but it hovers in one spot. We can make it move forward also be changing the procedure:

to fly
setshape "bird1
forward 2
setshape "bird2
forward 2
end

In MicroWorlds we can say forever [fly] to send the bird on its way, or we can program the bird-turtle itself with the instruction fly. Then clicking on the bird-turtle with the mouse sets it in motion. In PC Logo for Windows the instruction launch "fly produces an equivalent effect.

These Logo environments also allow us to have several of these processes active at the same time. This "multi-tasking" capability is particularly important when creating animations. Each character in the show can be programmed and activated independently. In this MicroWorlds project three birds and a bee are flying around at the same time.

These features have been most fully developed in Scratch, where sprites are widely used to create animations and games.

 

画分形树 执行:tree 100

 

复制代码

to btree :size
left 45
tree :size
right 90
tree :size
left 45
End

to tree :size
Forward :size
if :size<1 [stop]
btree :size/2

back :size
end

复制代码

九九乘法表: 

table99
复制代码
to myLocate :x :y 
  pu 
  setxy :myLeft + :x * :myWidth :myBottom + :y * :myHeight 
  pd 
  setheading 90 
  repeat 2 [ fd :myWidth rt 90 fd :myHeight rt 90 ] 

  pu 
  setxy :myLeft + :x * :myWidth + 5 :myBottom + :y * :myHeight - 5 
  pd 
  setheading 90 
end 

to table99 
  for [ i 1 9 1 ] [ for [ j 1 9 1 ] [ myLocate :i 10 - :j label ( se :i "* :j "= :i * :j ) ] ] 
end 

Make "mybottom 0
Make "myheight 30
Make "myleft -550
Make "mywidth 100
复制代码

 

更多:

语法学习
====================
例子1:

to polygon :len :sides
repeat :sides [ fd :len rt 360.0 / :sides ]
end

to myPic :len :rep
lt 90 pu fd 400 rt 90 pd ; fd 400 定位用,要根据自己的系统设定具体值
repeat :rep [ if 2 < repcount [ polygon :len repcount ] ]
end

myPic 100 20

效果图见 J:/skyDiary/Data/myPic.bmp
====================
例子2:

to myPrint :len
make "count 0
do.until [ print :count make "count :count + 1 ] [ :count > :len ]
end

myPrint 5

输出结果为:
0
1
2
3
4
5
====================
例子3:

用logo写的haino程序

make "steps 1

to haino :size :from :mid :to
if :size = 0 [ stop ]
haino :size - 1 :from :to :mid
print ( se :steps :from "-> :to )
make "steps :steps + 1
haino :size - 1 :mid :from :to
end

haino 3 "a "b "c

输出结果为:
1 a -> c
2 a -> b
3 c -> b
4 a -> c
5 b -> a
6 b -> c
7 a -> c
====================
例子4:

用logo做的九九乘法表

make "myLeft -550
make "myBottom 0
make "myWidth 100
make "myHeight 30

to myLocate :x :y
pu
setxy :myLeft + :x * :myWidth :myBottom + :y * :myHeight
pd
setheading 90
repeat 2 [ fd :myWidth rt 90 fd :myHeight rt 90 ]

pu
setxy :myLeft + :x * :myWidth + 5 :myBottom + :y * :myHeight - 5
pd
setheading 90
end

to table99
for [ i 1 9 1 ] [ for [ j 1 9 1 ] [ myLocate :i 10 - :j label ( se :i "* :j "= :i * :j ) ] ]
end

table99
pu setxy :myLeft + :myWidth * 4.5 :myBottom + :myHeight * 10 pd
label "九九乘法表
ht

结果见 j:/skyDiary/data/table[9by9].bmp
====================
例子5:

用logo画超立方体

to hyperCube :len
pu setxy 0 - :len - :len / 5 :len / 2 pd
setpencolor [ 0 0 255 ]
setpensize [ 2 2 ]
setheading 90
repeat 8 [ box :len rt 90 fd :len lt 135 ]
end

to box :len
repeat 4 [ fd :len rt 90 ]
end

hyperCube 100
ht
setactivearea [ -200 -200 200 200 ]
( gifsave "hyperCube.gif )

效果图见 j:/skyDiary/data/hyperCube.gif
====================
例子6:

用logo建立基本几何形的函数库


;画正三角形
;参数1 中间点的x坐标
;参数2 中间点的y坐标
;参数3 正三角形的边长
to triangel :centerX :centerY :len
local "oldPos
local "oldHeading

make "oldPos pos
make "oldHeading heading

pu setxy :centerX :centerY fd :len / sqrt 3 pd
rt 150
repeat 3 [ fd :len rt 120 ]

pu setpos :oldPos pd
setheading :oldHeading
end

;画正方形
;参数1 中间点的x坐标
;参数2 中间点的y坐标
;参数3 正方形的边长
to rect :centerX :centerY :len
polygon :centerX :centerY :len 4
end

;画正五边形
;参数1 中间点的x坐标
;参数2 中间点的y坐标
;参数3 正方五边形的边长
to pentagon :centerX :centerY :len
local "oldPos
local "oldHeading

make "oldPos pos
make "oldHeading heading

pu setxy :centerX :centerY fd :len / 2 / cos 54 pd
rt 126
repeat 5 [ fd :len rt 72 ]

pu setpos :oldPos pd
setheading :oldHeading
end

;画正六边形
;参数1 中间点的x坐标
;参数2 中间点的y坐标
;参数3 正方六边形的边长
to hexagon :centerX :centerY :len
polygon :centerX :centerY :len 6
end

;画正多边形
;参数1 中间点的x坐标
;参数2 中间点的y坐标
;参数3 正方多边形的边长
;参数4 几何形的边数,如果3表示要画正三角形,4表示要画正方形,5表示要画正五边形...
to polygon :centerX :centerY :len :sides
local "oldPos
local "oldHeading

make "oldPos pos
make "oldHeading heading

pu
setxy :centerX :centerY
if ( modulo :sides 2 ) = 1 [ make "p ( 180 - 360.0 / :sides ) / 2 fd :len / 2 / cos :p rt 180 - :p ]
if ( modulo :sides 2 ) = 0 [ make "p 360.0 / :sides / 2 fd :len / 2 / tan :p rt 90 bk :len / 2 ]
pd

repeat :sides [ fd :len rt 360.0 / :sides ]

pu setpos :oldPos pd
setheading :oldHeading
end

;画五角星
;参数1 五角星的中间点的x坐标
;参数2 五角星的中间点的x坐标
;参数3 五角星的边长
to star :centerX :centerY :len
local "oldPos
local "oldHeading
local "a
local "b

make "oldPos pos
make "oldHeading heading

make "a :len * cos 72
make "b :a / tan 36

pu
setxy :centerX :centerY
fd :b lt 90 fd :a
rt 108
pd

repeat 5 [ fd :len rt 144 fd :len lt 72 ]

pu setpos :oldpos pd
setheading :oldheading
end

; cube中参数x,y,z所指代的方向
; +--------+
; z/ /|
; +--------+ |
; |y | +
; | x |/
; +--------+

to cube :x :y :z
repeat 2 [ fd :y rt 90 fd :x rt 90 ]
fd :y
rt 45
fd :z / 2
rt 45
fd :x
rt 135
fd :z / 2
lt 45
fd :y
lt 135
fd :z / 2
lt 45
fd :y
end
====================
————————————————
版权声明:本文为CSDN博主「HJBGraphics」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/HJBGraphics/article/details/454872

posted @   Bigben  阅读(357)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2013-11-01 intest
点击右上角即可分享
微信分享提示