Color

This topic contains 18 replies, has 11 voices, and was last updated by  Sledge 1 year, 9 months ago.

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #9173

    MarkB
    Participant

    Hi

    why is Color syntaxed like this.

    Color . Black

    Color . Yellow

    Seems very 80s like Amos or Stos. (Child like)

    #9175

    impixi
    Participant

    There are named constants for some colors. You can also create create your own colors. eg

    [/crayon]

    The docs have more information…

    #9185

    GfK
    Participant

    They’re just predefined constants for basic color definition – common in many languages.

    #9186

    AdamStrange
    Participant

    how about:

    col = Color.Yellow * 0.5

    #9192

    Pakz
    Participant

    @adamstrange – Does that work?? Color has three floats inside it right?

    #9194

    MarkB
    Participant

    So a simple Color command turns into Jeckle and Hide.

    #9197

    cocon
    Participant

    I don’t understand why this would be a problem. Is there any better way?

    #9201

    Hezkore
    Participant

    I was a bit sceptical about the color system myself at first, but it’s proven to be very effective!

    MarkB I have no idea what you wrote…
    But it’s real simple to use!
    Local myColor:=New Color(1,0,0)
    Or you could do Local myColor:=Color.Red
    Then you just pass it to whatever you want to use it with.
    Before (in BlitzMax for example) you had to do:
    Local r:Byte=255
    Local g:Byte=0
    Local b:Byte=0
    And then pass each RGB value to whatever was going to use it.

    And yes Pakz, that does work!
    So does /, – and +
    In fact, that works with every Vec class.
    You can also use the .Blend function to get a nice blend between two colors 🙂

    #9203

    MarkB
    Participant

    Hi sorry for the mess post.

    I copied and pasted it,and must of thrown up that mess.I will delete it.

    Thank you All. So you can create your own Color(R,G,B).

    I must remember to read the Docs.

    Ps: In BlitzMax i just used SetColor(r,g,b).

    So now i have to make Color a variaible.

    #9236

    abakobo
    Participant

    So now i have to make Color a variaible.

    Not really, you may:

    [/crayon]

    This should the equivalent of SetColor(r,g,b)

    #9242

    Sledge
    Participant

    I’m not sold on having to make an allocation to alter the properties of an existing object. Is there no way to arbitrarily set the colour of the canvas without New rearing its head?

    #9243

    Jesse
    Participant

    I believe you can do it like this also:
    canvas.Color.R = .5
    canvas.Color.G = .5
    canvas.Color.B = .1
    canvas.Color.A = 1.0
    not much faster then using New with a Struct though. Probably slower.

    #9244

    Mark Sibly
    Keymaster

    canvas.Color.R = .5

    This will *not* work. Since Color is a struct, the canvas.Color property returns a copy of the current color so you will only be modifying a copy.

    Just use New Color(…). It’s plenty fast since (also because Color is a struct) no heap allocation occurs.

    #9245

    Jesse
    Participant

    it works in my MacBook. I will update to the latest version of M2 to make sure it still works or not.
    [Edit]
    My fault, I misunderstood the concept. correction it doesn’t work.

    #9246

    Sledge
    Participant

    This will *not* work

    no heap allocation occurs.

    Ah, gotcha. Structs on the stack, passed by value, and class instances on the heap, by reference, is quite a nice convention if that’s the situation. So it will be memory-safe to New a struct in a function then pass it back as the result due to it always being copied, I assume…?

Viewing 15 posts - 1 through 15 (of 19 total)

You must be logged in to reply to this topic.