Gambas/颜色
外观
< Gambas
返回 Gambas
十六进制值 | 颜色 |
---|---|
&H0 | 黑色 |
&HFF | 红色 |
&HFF00 | 绿色 |
&HFFFF | 黄色 |
&HFF0000 | 蓝色 |
&HFF00FF | 洋红色 |
&HFFFF00 | 青色 |
&HFFFFFF | 白色 |
此程序向您展示 RGB 颜色。您可以将每种颜色的值从 0 更改为 255,然后在单击命令按钮时,您将看到特殊的混合颜色。
使用以下代码,可以将 3 个十进制数字中的一个十六进制数字构建为字符串
sHEX = Hex$(r,2) & Hex$(g,2) & Hex$(b,2) sHEX = "&H" & sHEX & "&"
要运行该程序,您需要 1 个命令按钮、1 个绘图区域、3 个文本框和 3 个文本标签。
它看起来怎么样?请在此处查看(德语)http://www.madeasy.de/7/prgfarbergb.htm
代码
PUBLIC SUB Button1_Click() DIM sHex AS String DIM r AS Integer DIM g AS Integer DIM b AS Integer IF Textbox1.text = "" THEN Textbox1.Text = 0 IF Textbox2.text = "" THEN Textbox2.Text = 0 IF Textbox3.text = "" THEN Textbox3.Text = 0 r = Val(Textbox1.Text) g = Val(Textbox2.Text) b = Val(Textbox3.Text) sHEX = Hex$(r,2) & Hex$(g,2) & Hex$(b,2) sHEX = "&H" & sHEX & "&" DrawingArea1.BackColor = Val(sHEX) END
当您需要程序的背景时,可以使用这个简单的日落颜色程序。
要运行该程序,您需要在窗体上创建一个绘图区域。当您使用以下方案时,可以选择不同的颜色
蓝色 RGB(0, 0, i) 红色 RGB(i, 0, 0) 绿色 RGB(0, i, 0) 黄色 RGB(i, i, 0) 紫色 RGB(i, 0, i) 青色 RGB(0, i, i) 灰色 RGB(i, i, i)
它看起来怎么样?
代码
PUBLIC SUB Form_Open() DIM r AS Integer DIM g AS Integer DIM b AS Integer DIM h AS Integer DIM he AS Integer DIM sHex AS String r = 0 g = 0 FOR b = 0 TO 255 sHEX = Hex$(r,2) & Hex$(g,2) & Hex$(b,2) sHEX = "&H" & sHEX & "&" Draw.begin(DrawingArea1) Draw.Forecolor= Val(sHEX) Draw.LineWidth=5 he = DrawingArea1.Height h = he * b \ 255 Draw.Line(0, h, DrawingArea1.Width, h) Draw.End NEXT END
添加以下代码并更改窗体的边框为可调整大小,可以使该程序更完善。
PUBLIC SUB Form_Resize() DrawingArea1.Move(0, 0, ME.ClientWidth, ME.ClientHeight) END
以下程序使用滑动条显示自然颜色光谱。
您需要一个绘图区域和一个滑动条作为控件。
' Gambas class file PUBLIC SUB Form_Open() drawingarea1.BackColor = &HC2020C& scrollbar1.minvalue = 1 scrollbar1.maxvalue = 1120 END PUBLIC SUB ScrollBar1_Change() drawingarea1.BackColor = Val(spektrum(scrollbar1.value)) END PUBLIC FUNCTION spektrum(ss AS Integer) AS String x AS Integer sHEX AS String s AS Integer r AS Integer g AS Integer b AS Integer s = 0 FOR x = 1 TO 255 'red to yellow r = 255 b = 0 sHEX = Hex$(r,2) & Hex$(x,2) & Hex$(b,2) sHEX = "&H" & sHEX & "&" s = s + 1 'PRINT s IF s = ss THEN RETURN sHEX NEXT 's = 255 FOR x = 255 TO 1 STEP -1 'from yellow to green g = 255 b = 0 sHEX = Hex$(x,2) & Hex$(g,2) & Hex$(b,2) sHEX = "&H" & sHEX & "&" s = s + 1 'PRINT s IF s = ss THEN RETURN sHEX NEXT 's = 510 FOR x = 1 TO 255 'from green to cyan r = 0 g = 255 sHEX = Hex$(r,2) & Hex$(g,2) & Hex$(x,2) sHEX = "&H" & sHEX & "&" s = s + 1 'PRINT s IF s = ss THEN RETURN sHEX NEXT 's = 765 FOR x = 255 TO 1 STEP - 1 'from cyan to blue r = 0 b = 255 sHEX = Hex$(r,2) & Hex$(x,2) & Hex$(b,2) sHEX = "&H" & sHEX & "&" s = s + 1 'PRINT s IF s = ss THEN RETURN sHEX NEXT 's = 1020 b = 255 FOR x = 1 TO 100 'from blue to violett g = 0 sHEX = Hex$(x,2) & Hex$(g,2) & Hex$(b,2) sHEX = "&H" & sHEX & "&" b = b - 2 s = s + 1 'PRINT s 'PRINT shex IF s = ss THEN RETURN sHEX NEXT 's = 1120 END
也许您可以更改该程序,以便在文本框中显示颜色值。1. 从工具箱中取出一个文本框。2. 添加以下代码
textbox1.text = spektrum(scrollbar1.value)
在 PUBLIC SUB ScrollBar1_Change() 部分