About Monkey 2 › Forums › General Discussion › Color
This topic contains 18 replies, has 11 voices, and was last updated by
Sledge 1 year, 9 months ago.
-
AuthorPosts
-
July 7, 2017 at 11:33 pm #9173
Hi
why is Color syntaxed like this.
Color . Black
Color . Yellow
Seems very 80s like Amos or Stos. (Child like)
July 8, 2017 at 1:05 am #9175There are named constants for some colors. You can also create create your own colors. eg
[/crayon]Monkey12[crayon-5cb9cfe75bb6d493209870 inline="true" ]Local myColor1 := New Color(0.2, 0.1, 0.6, 1.0)Local myColor2 := Color.FromARGB($FFA06620)The docs have more information…
July 8, 2017 at 10:01 am #9185They’re just predefined constants for basic color definition – common in many languages.
July 8, 2017 at 10:19 am #9186how about:
col = Color.Yellow * 0.5
July 8, 2017 at 9:25 pm #9192@adamstrange – Does that work?? Color has three floats inside it right?
July 9, 2017 at 12:22 am #9194So a simple Color command turns into Jeckle and Hide.
July 9, 2017 at 3:49 am #9197I don’t understand why this would be a problem. Is there any better way?
July 9, 2017 at 6:29 pm #9201I 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 colorsJuly 9, 2017 at 8:48 pm #9203Hi 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.
July 10, 2017 at 10:26 am #9236So now i have to make Color a variaible.
Not really, you may:
[/crayon]Monkey123[crayon-5cb9cfe76bf51884536742 inline="true" ]canvas.Color=New Color (0.6,0.7,0.01)This should the equivalent of SetColor(r,g,b)
July 10, 2017 at 10:18 pm #9242I’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?
July 10, 2017 at 11:14 pm #9243I 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.July 10, 2017 at 11:40 pm #9244canvas.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.
July 10, 2017 at 11:46 pm #9245it 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.July 10, 2017 at 11:55 pm #9246This 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…?
-
AuthorPosts
You must be logged in to reply to this topic.