Turtle Tutorial Fractal Stars 海龟画图教程 分形五角星

in #cn9 years ago (edited)

A 'Fractal Graph' can be seen as 'self similar'. For example,

This is a fractal graph that is made by LOGO turtle graphic. Each element is a tiny star and you can see the shapes of each corner are similar to the entire figure.

The idea is to draw a shape of star and in each corner of star further draw a smaller star... and this process goes on until the size of the star to draw is smaller than a threshold. The fractal graphs are often implemented in a recursive way i.e. function calls itself. The following LOGO defines a star function that draws a star and 5 smaller stars in its five corners until the sizes of the smaller stars are too small..

cs ht
to star :size :small
    if :size<:small [stop]
    repeat 5 [fd :size star :size*0.3 :small rt 144]
end
star 200 10

We can also draw more stars in a similar way by setting to a small threshold star 200 5:

Pretty amazing, huh? This is a great example to teach your kids programming and they will learn the concepts of procedure, functional call, recursive and of course the concept of fractal designs!


分形图案就是自身很相近的一些图案,比如这个:

这是用LOGO海龟画出来的,每一个角落都和整体很相像。我们可以认为每一个五角星的角都继续长满了小一点的五角形。

分形图案一般来说就是用递归来实现,直到每一个更小的图案不能再小了(再小就看不清楚了)。我们用LOGO语言来定义一个函数,功能就是画一个五角形,然后在每个小角上继续画一个五角形,直到五角形太小了。

cs ht
to star :size :small
    if :size<:small [stop]
    repeat 5 [fd :size star :size*0.3 :small rt 144]
end
star 200 10

我们把最小的阀值变小一点 star 200 5,这样就能画出更多的五角形

是不是很有意思?这是个教孩子编程的例子,可以用来教孩子递归、分形、临界条件等概念。


@justyy 是有名的晒媳妇博主,也是西半球最装X装土豪 (https://justyy.com) 的博主。@justyy 定居英国,一妻两娃,在STEEMIT上开办了历史上中文第一家银行,史称 YY央行,每日赔钱吆喝。
@justyy@tumutanzi 大哥 的介绍下加入 STEEMIT,写些帖子挣些小钱养家糊口。
@justyy 凡事喜欢折腾,现在在一家英国软件公司里当码农,好听一点叫作算法攻城狮。 @justyy 喜欢结交天下好友,一起YY。


@justyy 也是CN 区的点赞机器人,对优质内容点赞,只要代理给 @justyy 每天收利息(年化率10%)并能获得一次至少2倍(VP 200%+)的点赞,大鱼 @htliao 都加入了这个计划(530 SP)表示支持。

  1. cn区最低保障系统 上线了!
  2. cn区低保计划(鼓励新人)真的适合你么?
  3. 今天(2017-10-30) 银行股东名单

AD 一波,听说最近 STEEM没有SBD值钱,那赶紧加入 CN区低保银行,成为股东,好处多多,每天收获点赞并且能获得10%的利息(发放SBD),今日股东列表

Sort:  

Calling @originalworks :)
img credz: pixabay.com
Nice, you got a 3.0% @minnowbooster upgoat, thanks to @justyy
Want a boost? Minnowbooster's got your back!

!!!难道这个和我小学计算机课用的那个海龟画图是同一个吗!!!好怀念啊!

是的,就是 LOGO

我第一次知道这个软件的名字。这种感觉就好像打了十年游击终于找到大部队了。

这……你小学的时候肯定没认真听课。

不能全怪我,因为电脑里还有一个叫“成龙”的游戏...

小学?我可是中学才用LOGO...

中学的主要软件不应是CS吗...课程内容一般是侦查与反侦察

再说我就会暴露年龄咯~

哈哈哈...这自我介绍....牛!👍
让我们一起YY吧!😂😂😂

一起YY,这段看明白啦!

@minnowpondblue has voted on behalf of @minnowpond.
If you would like to recieve upvotes from minnowponds team on all your posts, simply FOLLOW @minnowpond.

            To receive an upvote send 0.25 SBD to @minnowpond with your posts url as the memo
            To receive an reSteem send 0.75 SBD to @minnowpond with your posts url as the memo
            To receive an upvote and a reSteem send 1.00SBD to @minnowpond with your posts url as the memo

终于有一篇能看懂(一点)的了。

我以前好像上課也聽過老師教過類似的!!! ((我明明就念商,怎麼老師會教這個!!!

晚上用python写一遍

pip3 install turtle? 我记得有个包,很容易

标准包里已含turtle

真的看懂了大部分

嗯,这个适合孩子的,所以肯定不难。

写完了python代码,果然非常简单:

from turtle  import *

def star(size, small) :
    if(size < small) :  return
    for i in range(5) :
        fd(size)
        star(size*0.3, small)
        rt(144)

star(200,10)

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.091
BTC 62729.55
ETH 1760.53
USDT 1.00
SBD 0.39