none
Is there an easy way to return the colour name? RRS feed

  • Question

  • Is there an easy way to return the colour name and not the colour code?

    e.g.

    TextWindow.WriteLine(GraphicsWindow.GetRandomColor())  ---> returns code
    TextWindow.WriteLine(GraphicsWindow.FontName)               ----> returns name
    TextWindow.WriteLine(GraphicsWindow.BackgroundColor)   ------> returns code

    thanks

    Wednesday, July 3, 2013 11:18 PM
    Moderator

Answers

  • I don't think so... But, for all color names usable in small basic, go to the last few pages of the introduction guide included with small basic.

    I am a 12 year old learning how to code using small basic.

    Thursday, July 4, 2013 1:12 AM
  • You can also use a hexadecimal color directly:

    GraphicsWindow.BackgroundColor = "#FFFF00"
    GraphicsWindow.DrawText(10, 10  GraphicsWindow.BackgroundColor)

    Unfortunately, only in TextWindow name colors are used:

    TextWindow.ForegroundColor = "DarkYellow"
    TextWindow.WriteLine(TextWindow.ForegroundColor)


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Thursday, July 4, 2013 1:23 AM
    Answerer
  • Check out the Color Picker by Suduadib. Maybe you can take the color array and generate the associated color codes. Then you can make yourself an array that translates color codes into color names.

    Color Picker by Suduadib

    http://blogs.msdn.com/b/smallbasic/archive/2009/06/23/color-picker.aspx

    Thursday, July 4, 2013 5:57 AM
  • Check out the Color Picker by Suduadib. Maybe you can take the color array and generate the associated color codes. Then you can make yourself an array that translates color codes into color names.

    Color Picker by Suduadib

    http://blogs.msdn.com/b/smallbasic/archive/2009/06/23/color-picker.aspx

    Similar program .... ZCX763  (  Color name number is 140)

    Info.    Old japan Color name number is 465.   try this  LML762-1

     (Color name is shown in Title.  sorry it is Japanese.) 


    Thursday, July 4, 2013 9:36 AM
    Answerer
  • Jibba Jabba,

    Here's a code snippet that I use to select colours for my programs..  This uses LitDev's extension.  Once selected I just set a variable that retains the RGB code for the colour.

    DW=Desktop.width
    DH=Desktop.Height
    GraphicsWindow.width=dw
    GraphicsWindow.height=dh
    GraphicsWindow.top=0
    GraphicsWindow.left=0
    Colors=LDUtilities.ColourList()
    For x = 1 To Array.getitemcount(Colors) Step 25
      For y=1 To 25
      GraphicsWindow.brushcolor=Colors[x+y]
      GraphicsWindow.fillRectangle(20+x*8,20*y,30,30)
      GraphicsWindow.BrushColor="Black"
      GraphicsWindow.DrawBoundText(60+x*8,20*y,200,Colors[y+x])
    EndFor
    Endfor


    JR

    Thursday, July 4, 2013 11:03 AM
    Answerer
  • I once made a program which has 140 color name table: MXV150-1.
    You can modify this program and get color randomly.

    Nonki Takahashi

    Friday, July 5, 2013 12:02 PM
    Moderator

All replies

  • I don't think so... But, for all color names usable in small basic, go to the last few pages of the introduction guide included with small basic.

    I am a 12 year old learning how to code using small basic.

    Thursday, July 4, 2013 1:12 AM
  • You can also use a hexadecimal color directly:

    GraphicsWindow.BackgroundColor = "#FFFF00"
    GraphicsWindow.DrawText(10, 10  GraphicsWindow.BackgroundColor)

    Unfortunately, only in TextWindow name colors are used:

    TextWindow.ForegroundColor = "DarkYellow"
    TextWindow.WriteLine(TextWindow.ForegroundColor)


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Thursday, July 4, 2013 1:23 AM
    Answerer
  • Thanks 8bit and goto. looks like no easy way or hard way.

    I even tried things like this. Learnt something about text string arguments though.

    GraphicsWindow.Show() GraphicsWindow.BackgroundColor = GraphicsWindow.GetRandomColor() code = GraphicsWindow.BackgroundColor char = Text.GetCharacter(34) TextWindow.ForegroundColor = char + code + char colourName = TextWindow.ForegroundColor GraphicsWindow.DrawText(10,10, colourName)


    Thursday, July 4, 2013 5:30 AM
    Moderator
  • Check out the Color Picker by Suduadib. Maybe you can take the color array and generate the associated color codes. Then you can make yourself an array that translates color codes into color names.

    Color Picker by Suduadib

    http://blogs.msdn.com/b/smallbasic/archive/2009/06/23/color-picker.aspx

    Thursday, July 4, 2013 5:57 AM
  • Thanks for the link. Another thing I could do is instead of returning the name just return a visual of the colour.

    I was a bit surprised that I couldn't pass the "colour code" of the GW to a TW object then back to the GW. But that'll never work because most of them don't even exist in TW.

    Here's a link to some msdn library data that LitDev posted on an earlier question I had on colours in TW and GW. Wow there's some good stuff in those libraries.

    ConsoleColor Enumeration

    cant-access-all-the-colours-supported-by-small-basic

    Thursday, July 4, 2013 9:30 AM
    Moderator
  • Check out the Color Picker by Suduadib. Maybe you can take the color array and generate the associated color codes. Then you can make yourself an array that translates color codes into color names.

    Color Picker by Suduadib

    http://blogs.msdn.com/b/smallbasic/archive/2009/06/23/color-picker.aspx

    Similar program .... ZCX763  (  Color name number is 140)

    Info.    Old japan Color name number is 465.   try this  LML762-1

     (Color name is shown in Title.  sorry it is Japanese.) 


    Thursday, July 4, 2013 9:36 AM
    Answerer
  • Thanks. I was trying to find a way without creating an array.

    Thursday, July 4, 2013 9:46 AM
    Moderator
  • Jibba Jabba,

    Here's a code snippet that I use to select colours for my programs..  This uses LitDev's extension.  Once selected I just set a variable that retains the RGB code for the colour.

    DW=Desktop.width
    DH=Desktop.Height
    GraphicsWindow.width=dw
    GraphicsWindow.height=dh
    GraphicsWindow.top=0
    GraphicsWindow.left=0
    Colors=LDUtilities.ColourList()
    For x = 1 To Array.getitemcount(Colors) Step 25
      For y=1 To 25
      GraphicsWindow.brushcolor=Colors[x+y]
      GraphicsWindow.fillRectangle(20+x*8,20*y,30,30)
      GraphicsWindow.BrushColor="Black"
      GraphicsWindow.DrawBoundText(60+x*8,20*y,200,Colors[y+x])
    EndFor
    Endfor


    JR

    Thursday, July 4, 2013 11:03 AM
    Answerer
  • I once made a program which has 140 color name table: MXV150-1.
    You can modify this program and get color randomly.

    Nonki Takahashi

    Friday, July 5, 2013 12:02 PM
    Moderator
  • Thanks for all your replies. This would have to conclude that the only way is array or extension. What I might try to to do is preview the next random colour by showing a square filled with the colour. It's for this program: LRM180.

    I've only used an extension once, Timo So - MoreOptions extension. That was to see how they worked and try it out for Timo. I've been avoiding them until I've used all the native objects of SB. I can see why they call them extensions I will definitely be adding some to my SB folder.

    Nonki, thanks for your sample MXV150-1. I tried to make a description that appears when the cursor moves over something months ago. I had trouble with events being triggered at the same time, it basically showed a description when the mouse pointer passed over a button. I've now learnt how to trigger events now with a small delay b/w them, Game Loop. I should be able to do this now.

    Thanks again, I learnt something from each reply.

    Friday, July 5, 2013 9:56 PM
    Moderator