- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试更改屏幕上显示的颜色和圆圈数量。到目前为止,我已经弄清楚如何以递归模式使所有颜色都不同,但我需要帮助找出如何添加更多颜色。附件是我所拥有的与我需要实现的目标。
我的代码
import turtle
import colorsys
def draw_circle(x,y,r,color):
turtle.seth(0)
turtle.up()
turtle.goto(x,y-r)
turtle.down()
turtle.fillcolor(color)
turtle.begin_fill()
turtle.circle(r)
turtle.end_fill()
def draw_recursive_circles(x,y,r,color,n):
if n == 0:
return
draw_circle(x,y,r,color)
colors = ['red','orange','yellow','green','blue','purple']
i = 0
for angle in range(30,360,60):
turtle.up()
turtle.goto(x,y)
turtle.seth(angle)
turtle.fd(r*2)
draw_recursive_circles(turtle.xcor(),turtle.ycor(),r/3,colors[i],n-1)
i += 1
turtle.tracer(0)
turtle.hideturtle()
turtle.speed(0)
draw_recursive_circles(0,0,100,'red',5)
turtle.update()
最佳答案
您导入 colorsys
但从未使用它 - 这是您应该根据角度而不是固定颜色列表生成颜色的线索。导入的原因是 turtle 基于 RGB 的颜色对于我们的需求来说是错误的模型,因此我们需要一个更合适的模型,例如 HSV (我们只关心关于H/色调),并将这些值转换为RGB。
卫星数量由您的范围
调用决定:
for angle in range(30,360,60):
这张图应该更像:
for angle in range(0, 360, 30):
由于有 12 颗卫星,360/30
为 12。最后,我们需要进行适当的计算,以便每当我们更改位置或航向时,为了进行递归绘图,我们需要退出时恢复原始值。下面是我针对此问题的简化示例解决方案:
from turtle import Screen, Turtle
from colorsys import hsv_to_rgb
def draw_circle(radius):
y = turtle.ycor() # save position & heading
heading = turtle.heading()
turtle.fillcolor(hsv_to_rgb(heading / 360, 1.0, 1.0))
turtle.sety(y - radius)
turtle.setheading(0)
turtle.begin_fill()
turtle.circle(radius)
turtle.end_fill()
turtle.sety(y) # restore position & heading
turtle.setheading(heading)
def draw_recursive_circles(radius, n):
if n == 0:
return
draw_circle(radius)
if n > 1:
heading = turtle.heading() # save heading
for angle in range(0, 360, 30):
turtle.setheading(angle)
turtle.forward(radius * 2)
draw_recursive_circles(radius / 5, n - 1)
turtle.backward(radius * 2)
turtle.setheading(heading) # restore heading
screen = Screen()
screen.tracer(False)
turtle = Turtle(visible=False)
turtle.penup()
draw_recursive_circles(150, 4)
screen.update()
screen.tracer(True)
screen.exitonclick()
我故意保持 Nib 以简化我的示例,因此仅显示圆圈的填充部分。将周围的轮廓放回原处,作为练习留给您。
中心圆的颜色不正确。解决这个问题很简单,只需在首次调用 draw_recursive_circles()
关于python - 相互围绕的递归彩虹色圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55310414/
我在业余时间慢慢学习javascript,但还没有完全掌握这一点。但一位 friend 要求我制作一个简单的机器人,它可以向每个加入服务器的新用户发送私信,询问他们希望用户名的颜色是什么,并将他们添加
抱歉,标题令人困惑,我会澄清一下。我正在尝试让机器人检查用户是否在他们的 quick.db 库存中具有特定 Angular 色,如果有,它就会装备该 Angular 色。我遇到的问题是,即使在 lis
所以我想做一个小的用户配置文件,但我希望它打印出用户 Angular 色。可能吗? case "Profile": var embed = new Discord.RichEmbed()
我有一个表单,其中包含三个不同的 data-role="page" 和三个不同的 data-url="abc"。 根据某些条件,单击第一页上的按钮后,我将在第二页上渲染/显示某些字段。 现在我正在获取
我有一行不和谐机器人的代码,用于删除特定的命名 Angular 色并添加一个名为“静音”的 Angular 色一段特定的时间。基本上,服务器只能有 3 个 Angular 色,一个可以发出命令,一个具
我想在编写函数时在编辑页面上显示文本的标题。 应用程序.html {{ text }} 应用程序.ts getRoleEdit
如果 s 是一个系列,我在运行以下命令时会收到一条错误消息: s.plot(style='k--', color='b') 错误消息说 [b] 不是可识别的颜色。 我正在使用 Pandas 0.11。
这是一个 fiddle http://jsfiddle.net/aLr2yx8d/ $('#inputButton').click(function() { var value = $(
所以,基本上。我想做的是创建一个单词解密器,您可以在其中输入一个打乱的单词并对其进行解密。它工作得很好,尽管我单独检查每个字符,但由于某种原因,额外的字符漏掉了。 我输入“olehl (hello)”
在尝试console.log字符串时,我遇到了一个相当烦人的问题。我将字符串 2^{\\frac{1}{2}}x=1 存储在 Node.js 数据库中,但输出时给出 2^{rac{1}{2 }}x=1
我想创建一个命令来查找用户在服务器中拥有的最高 Angular 色。 我已经知道Python中有一个discord.user.top_role。是否有相当于该功能的 Javascript? 我尝试将此
我对 Node.js 相当陌生,目前正在开发一个 Discord 机器人。我试图让我的机器人根据用户传递的参数分配服务器 Angular 色。我知道我可以找到特定 Angular 色的名称,然后根据他
我一直在尝试创建一个简单的命令,为在聊天中说话的人提供一个 Angular 色,假设他们说了一句脏话,它会给 message.author 静音 Angular 色。 client.on("messa
如何使用expressjs和passport在nodejs中实现基于 Angular 色的授权/访问控制以及如何完美设计 Angular 色中间件? 我有两种登录类型管理员和用户 以管理员和用户的名义
我在这里有一个键盘可访问的自定义下拉组件:https://codesandbox.io/s/31440w1vo6 但是,当我打开 NVDA 或 JAWS 时,激活“选择等位基因”后焦点不会再移动到选项
我正在为我的机器人创建 Angular 色分配命令,因此用户可以输入 h.addrole @user @role 我正在尝试执行此命令,如果用户拥有该 Angular 色,它会输出说 此用户已经拥有此
我想从数据库中获取用户的 Angular 色(组织或个人)。我有一个名为“Users”的表,另一个名为“Role_users”的表,其中有 user_id 和 role_id(1 代表个人,100 代
我有一个在 Vuejs 项目中导出一些函数的文件,我还需要在外部环境中使用它们..在 Component 中我知道我要使用哪个函数应该通过名称识别并与 .JSON 文件进行比较来使用,这在开发环境中很
我想将用户添加到我的 Parse.Role 但它不起作用。我看了很多例子,它们看起来都很简单,但我无法正确理解。这是我的代码: Parse.Cloud.define("activateVendor",
我克隆了一个 https://github.com/beeman/loopback-angular-admin我已经使用环回资源管理器创建了几个新 Angular 色,但是如何为我创建的用户分配 An
我是一名优秀的程序员,十分优秀!