本系列:
Logo Tutorial Series:
- Logo Turtle Graphics - Series 1 - Best Introductory Programming for Kids
- Logo Turtle Graphics - Series 2 - Define Procedure and Say Hello, World
今天我们要来讲一讲递归。递归就是函数自己调用自己,我们可以定义一个过程,然后这只海龟不停的画,结束的时候再调用自身再继续画。再次调用的时候参数变化了,至到参数满足一定的条件则停止。
A recursion is a function calling itself. In Logo, we can define a procedure, asking the turtle to draw something, then ask the turtle to repeat itself but with slightly different parameters, until a set of conditions are met.
比如 下面定义的这个过程可以用来画一个实现的正方 形。
For example, the following procedure can be used to draw a filled rectangle.
TO FK :B
IF :B>15 [STOP] ; 如果边长大于15就停止
REPEAT 4 [FD :B RT 90] ; Draw a square with side B 画一个长度为B的正方形
FK :B+1 ; Draw a square with side B+1 递归调用自己画一个长度为B+1的正方形
END
然后我们可以通过 调用 FK 15
来画一个空心的正方形,这样的话,通过不停的画空心实心(不断交错)则可以构成一个棋盘:
The FK 15
draws a empty square. By such, we can draw the interleaving squares.
TO QP :Y
IF :Y>4 [STOP]
REPEAT 4 [FK 15 FD 15 FK 1 FD 15]
RT 90 FD 30 RT 90
REPEAT 4 [FK 15 FD 15 FK 1 FD 15]
RT 180
QP :Y+1
END
您可以使用我写的这个PHP-LOGO解释器来验证这段LOGO代码。
You could use this PHP-LOGO Interpreter to verify the LOGO program as stated above.
Originally published at https://steemit.com Thank you for reading my post, feel free to Follow, Upvote, Reply, ReSteem (repost) @justyy which motivates me to create more quality posts.
原创 https://Steemit.com 首发。感谢阅读,如有可能,欢迎Follow, Upvote, Reply, ReSteem (repost) @justyy 激励我创作更多更好的内容。
// Later, it will be reposted to my blogs: justyy.com, helloacm.com and codingforspeed.com 稍后同步到我的中文博客和英文计算机博客。
近期热贴
- 过去7天收益排行榜
- 聂小倩 (1)| #5电影
- Ned 的代理SP是怎么被使用的 - Steemit 商业分析 Part 1, Part 2 and Part 3
- 写在2017年七夕: 爱情亲情,那些美好的回忆(就是这么任性的撒狗粮)
- LOGO 海龟作画 系列 一 之 给孩子最好的编程启蒙语言
- 通过脑残语言来保护你的STEEM钱包密码
- 不会写程序也能自动点赞 - 通过 SteemVoter 添加点赞规则
- 你好秋天,英国8月份的到Hitchin看薰衣草
- 碎碎念第365天
Recent Popular Posts
- Daily Top 30 Authors Pending Payout in the Last 7 days
- Photography of Our Love
- Logo Turtle Graphics - Series 1 - Best Introductory Programming for Kids
- Use BrainFuck to Protect Your Steem Wallet Password(s)
- Hello Autumn! Hello Lavender
- The Day 365 at SteemIt
- The profiler told me I wrote some useless code
Tags: #cn #cn-programming #logo-turtle #recursion #chessboard
矢量图!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Wow! Hi @justyy :)
You're post is very informative. Nice and clean code :) Thanks for sharing
I hope you can read some of my posts too @tiffanyrej
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
@justyy got you a $8.06 @minnowbooster upgoat, nice! (Image: pixabay.com)
Want a boost? Click here to read more!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit