0

オブジェクトの色を虹に合わせて変化させたいと考えました。これがうまくいかなかったので、visual.graph で問題を視覚化しようとしました visual.graph 。徐々に変わるわけではありません。バーが素敵なスペクトルを構築する必要がある場合。

from visual.graph import *

def regenbogenfarben(ausgangsfarbe=(255,0,0)):
    "liefert ausgehend vom input die nächste Farbe im Regenbogen"
    # vergleiche http://www.mikrocontroller.net/topic/238304
    step = 51
    r,g,b = ausgangsfarbe       # split the tuple...
    if r==255 and b==0 and g!=255:
        g+=5                # mehr grün
    elif b==0 and g==255 and r!=0:
        r-=5                # weniger rot
    elif r==0 and g==255 and b!=255:
        b+=5                # mehr blau
    elif b==255 and r==0 and g!=0:
        g-=5                # weniger grün
    elif g==0 and b==255 and r!=255:
        r+=5                # mehr rot
    elif g==0 and r==255 and b!=0:
        b-=5                # weniger blau
    #print((r,g,b))
    return r,g,b            # tupel zurückgeben
gdisplay(background=color.white, foreground=color.black,
         ytitle="Farbanteil", xtitle="step")
r=gcurve(color=color.red)
g=gcurve(color=color.green)
b=gcurve(color=color.blue)      # drei Farbanteile veranschaulichen

rgb=(255,0,0)

farbe=gvbars(color=color.red)   # Farbe darstellen

for i in range(6*51+20):
    r.plot(pos=(i,rgb[0]))
    g.plot(pos=(i,rgb[1]))
    b.plot(pos=(i,rgb[2]))
    farbe.plot(pos=(i,-10),color=rgb)
    rgb=regenbogenfarben(rgb)
4

1 に答える 1

1

わかりました、間違いを見つけました: vPython は色に 0 から 1 までの数字しか取りません。したがって、すべての色を 255 で割ります。

ここに画像の説明を入力

于 2015-05-07T15:57:21.663 に答える