0
所以,我試圖將這個Scratch程序轉換爲python程序:http://scratch.mit.edu/projects/1963078/#editor。我目前使用它的圖案3.下面是我有:在python中將float轉換爲十六進制
from turtle import*
import random
import math
turtle = Turtle()
bgcolor("#000000")
ht()
speed(0)
goto(0,0)
def draw():
x1 = (random.randint(0,250))
y1 = (random.randint(0,250))
x2 = (random.randint(0,250))
y2 = (random.randint(0,250))
counts = 0
while counts < 250:
count = 0
while count<250:
c = (math.tan(math.sqrt(((xcor() - x1)**2) + ((ycor() - y1)**2))))*(math.tan(math.sqrt(((xcor() - x2)**2) + ((ycor() - y2)**2))))
color(c)
setx(xcor+1)
count += 1
counts +=1
draw()
我知道有很多人使用Python 2,但我使用3.現在的問題是,當它使用長線生成一個顏色,它返回一個十進制數,當我需要得到一個十六進制代碼。有關如何將其轉換爲像臨時項目那樣的結果的任何提示?謝謝!
你的意思是'十六進制(C)'? – 2015-03-02 18:50:00
爲什麼不單獨生產3種顏色的組件?你可以傳入一個'(r,g,b)'元組或三個獨立的參數。 – 2015-03-02 18:56:05