높은 곳에서 조건을 조정하여 서클을 만들 필요가 있습니다.이 프로그램은 무작위 서클을 많이 사용하지만 여기에서 어디로 가야할지 확실하지 않습니다. 다음 방정식 d = (sqrt) ((x1-x2)^2 + (y1 - y2)^2)을 사용하려고합니다. 지금 프로그램은 많은 무작위 원형을 그리기 때문에 수식을 조정하면 특정 원이 중앙에 빨간색으로 표시되도록 조작 할 수 있어야합니다 (예 : japan flag).무작위 서클 SimpleGraphics를 사용하여
# using the SimpleGraphics library
from SimpleGraphics import *
# use the random library to generate random numbers
import random
diameter = 15
##
# returns a valid colour based on the input coordinates
#
# @param x is an x-coordinate
# @param y is a y-coordinate
# @return a colour based on the input x,y values for the given flag
##
def define_colour(x,y):
##
if y < (((2.5 - 0)**2) + ((-0.5 - 0)**2)**(1/2)):
c = 'red'
else:
c = 'white'
return c
return None
# repeat until window is closed
while not closed():
# generate random x and y values
x = random.randint(0, getWidth())
y = random.randint(0, getHeight())
# set colour for current circle
setFill(define_colour(x,y))
# draw the current circle
ellipse(x, y, diameter, diameter)
'define_colour (x, y)'함수는별로 의미가 없습니다. 당신이해야 할 일을 설명해 주시겠습니까? 말로 설명 할 수없는 경우 몇 가지 일반적인 입력과 각 입력에 대한 예상 출력을 제공하십시오. –
@ PM2Ring 중간과 흰색 바탕에 빨간색 동그라미가 있도록 만들어야합니다. 이 프로그램은 현재 많은 임의의 원을 그립니다 –
당신이하려는 일은 아직 명확하지 않습니다. 화면의 중앙에 빨간 원을 하나만 그려야한다고 말하는 것입니까? 그렇다면 왜 무작위로 무작위로 서클을 그리는 루프가 있습니까? –