我的目标是使用围绕圆的边缘和恒定起点(圆圈的中间)的随机端点在pygame中使用线条形成圆形.所以我决定将pygame.draw.line函数:screen,aRandomColor,startingPosition和endingPosition作为参数.结束位置是包含随机生成的x值的元组,辅助函数将根据圆的半径计算y值.我的第一个函数计算y值,如下所示:
import math
import random
def findY(pos1, pos2, distance, bothValues=False):
p1 =pos1
p2 = pos2
x1 = float(p1[0])
y1 = float(p1[1])
x2 = float(p2[0])
d = float(distance)
y2 = y1 - math.sqrt(d**2 - (x1-x2)**2)
_y2 = y1 + math.sqrt(d**2 - (x1-x2)**2)
if bothValues==True:
return y2, _y2
else:
return y2
Run Code Online (Sandbox Code Playgroud)
和线条抽屉:
width = 500
height = 500
def randLine(surface, color=rand, start=rand, end=rand,length=rand):
if start==rand:
start = randPos()
if end==rand:
end = randPos()
if color==rand:
color = randColor()
if length != rand: …Run Code Online (Sandbox Code Playgroud) 是否有内置功能的 Racket 列表?我正在为 python寻找类似这样的列表。我似乎无法在文档中找到一个。
Racket 是我正在学习的第一种方案方言,而且我还没有那么远,但是由于方案的语法最少,我相信可以安全地假设解释器对变量名中的问号的处理与任何不同其他可行的字符。
有了这个句子,为什么方案使用符号“?” 表示返回真或假的函数(称为谓词)?例如,在球拍中,有一个名为number?. number?应用于任何数字(1、5、-5、2.7 等)时返回 true,否则返回 false。我相信这number?是类似于is_the_following_argument_a_number?. 假设这是真的,表达式(number? 5)将转换为(is_the_following_argument_a_number? 5)。
在英语(此变量的编写语言)中,谓词“以下参数是数字吗?” 可以通过先移动动词:“the following argument is a number”,然后提取谓词:“is a number”,将问题翻译成陈述句形式找到。现在,我不像我在编程语言那样擅长语言,但我相信这是正确的。另外,对不起,如果这变成了一个英语问题而不是一个计划问题。
我难以理解的是,如果 lisp 社区调用number?谓词,为什么变量名不是英语谓词(我说变量名不是英语谓词,不是它的函数类型) in scheme 不是谓词)我发现我认为我认为number?翻译成的谓词是“是一个数字”,而不是整个问题“下面的参数是一个数字吗?”,只是谓词。那么,为什么 lisp 社区选择将方案中的谓词命名为英语中的问题?我认为这是因为社区错误地将陈述的价值(真或假)作为是/否问题的答案(是或否(显然))。我这样想有错吗?