本文介绍了用乌龟画一个超级椭圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很显然,可以用其他方法绘制的任何形状都可以由乌龟绘制.圆圈和正方形都很简单

Obviously, any shape drawable by other means can be drawn by a turtle. Circles and squares are easy

rt 1 fd .0

if ticks mod 100 = 0 [rt 90]
fd 1

超级省略号没那么多. (规则的椭圆也不是无关紧要的.)有关超级椭圆的维基百科文章,如果您需要刷新该主题.

Super-ellipses not so much. (regular ellipses are not trivial either.)The Wikipedia article on super-ellipses if you need to be refreshed on the topic.

任何输入表示赞赏.

使用下垂乌龟是否有办法使从乌龟移动中出现的超椭圆形出现?

Using a pendown turtle is there way to make a super-ellipse that emerges from turtle movement?

推荐答案

我有1/4,我想您可以将其他三个部分分段. n的其他值不在此处进行测试. (使用Wiki表示法,再加上phi作为旋转整个对象的角度.)我知道,重置标记的放置位置很松散.

I have 1/4 of it, I suppose you could piece-wise put the other three together. Other values of n are not tested here. (using the Wiki notation, plus phi as an angle of rotating the whole thing.) And the placement of reset-ticks, pen-down, is sloppy, I know.

to go2
  clear-all
  reset-ticks
  let a 6
  let b 5
  let phi 0
  let n 3.5
  create-turtles 1 [
    let iNdx 1
    repeat 90 [
      show iNdx
      show cos(iNdx)
      if cos(iNdx) > 0 and sin(iNdx) > 0 [
        let tx (a * (cos(iNdx) ^ (2 / n)))
        let ty (b * (sin(iNdx) ^ (2 / n)))
        let tx2 tx * cos(phi) - ty * sin(phi)
        let ty2 tx * sin(phi) + ty * cos(phi)
        setxy tx2 ty2
        ]
      pen-down
      set iNdx iNdx + 1
      ]
    ]
  end

椭圆看起来更简单,但您是法官

The ellipse looks simpler, but you be the judge

to go
  clear-all
  reset-ticks
  let a 6
  let b 5
  let phi 45
  create-turtles 1 [

    let iNdx 1
    repeat 360 [
      let tx (a * cos(iNdx))
      let ty (b * sin(iNdx))
      let tx2 tx * cos(phi) - ty * sin(phi)
      let ty2 tx * sin(phi) + ty * cos(phi)
      setxy tx2 ty2
      pen-down
      set iNdx iNdx + 1
      ]
    ]
  end

概括和简化为一个过程.

a generalization and simplification as a procedure.

to Super-ellipse [x y a b  m n]
 create-turtles 1 [
 let iNdx 1
 repeat 360 [
 setxy  (x + (abs cos iNdx)^(2 / m) * a * (sgn cos iNdx))
        (y + (abs sin iNdx)^(2 / n) * b * (sgn sin iNdx))
 pendown
set iNdx iNdx + 1]
]
end

这篇关于用乌龟画一个超级椭圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 20:30