TFPColor lazarus / 39-Graphics ---------------------------------------------------------------------- Andrew0Red · 2020-11-14 18:00 How do I write a TFPColor? $aa00aa ? &Haa00aa ? ---------------------------------------------------------------------- wp · 2020-11-14 18:59 No, FPColor is a record: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TFPColor = record    Red,Green,Blue,Alpha : word;  end; i.e. you set the record elements directly: FPColor.Red := $FFFFFF. There are named constants for the important colors, e.g colRed or colYellow in unit FPImage. And there are conversion functions FPColorToTColor and TColorToFPColor() in unit Graphics to convert the 16-bit-per-color- colors of FPImage to the 8-bit-per-channel colors of Graphics, and vice versa. ---------------------------------------------------------------------- Andrew0Red · 2020-11-14 19:10 So essentially, they make us jump through hoops when we just want to draw a simple dot on a paintbox??? The easiest least cumbersome way is TColorToTFPColor($aa00aa) or do you know something simpler? ---------------------------------------------------------------------- circular · 2020-11-14 20:00 You can use the Pixels property instead of Colors. ---------------------------------------------------------------------- winni · 2020-11-14 20:41 Hi! Use TBGRAPixel from the BGRAbitmap pack. It is meanwhile the swiss knife for colors: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TBGRAPixel = packed record ....    red, green, blue, alpha: byte; ....end;  You can use it very different ways. The three most often used are this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var col : TBGRAPixel;    ....    col := $FF00FF;    col := BGRA(50,100,150,200);         col.FromString('#AA99FF'); And you can use the predifined colors from TColor but also the predefines CSS Colors from BGRA: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i col := clBlue;col := cssNavajoWhite;  Winni ---------------------------------------------------------------------- Andrew0Red · 2020-11-14 20:54 You seem to have forgotten how to change col into a color. I figure'd it out, but col.ToFPColor would have saved me some sweat. And I'm not sure Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  col : TBGRAPixel;...  col :=$aa00aa;... ... col.ToFPColor ... is easier than Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ... TColorToFPColor($aa00aa) ... , MHO. ---------------------------------------------------------------------- circular · 2020-11-14 21:33 @Andrew0Red Did you see my answer? ---------------------------------------------------------------------- Andrew0Red · 2020-11-14 21:46 About as useless. *beat* Now, it's probably usefull to some, maybe even most, but not to me - it doesn't say anything about how to generate a TFPColor. Ostensibly, if I knew exactly how to proceed from your post (what to google/where to look it up/???), I would find something usefull, but the post itself... ---------------------------------------------------------------------- circular · 2020-11-14 21:53 Quote from: Andrew0Red on November 14, 2020, 10:46:59 pm*beat* What is this? ---------------------------------------------------------------------- Bart · 2020-11-14 21:55 Quote from: Andrew0Red on November 14, 2020, 10:46:59 pmAbout as useless. *beat* Now, it's probably usefull to some, maybe even most, but not to me - it doesn't say anything about how to generate a TFPColor. Ostensibly, if I knew exactly how to proceed from your post (what to google/where to look it up/???), I would find something usefull, but the post itself... There is no need for such a tone. Please be a little more polite to those that try to help you (wether or not the answer is indeed what you need). Bart ---------------------------------------------------------------------- Andrew0Red · 2020-11-14 22:06 @Circular: *beat* is a pause, included in the post to generate some rythm, making it more dramatic ... if the poster get's it right, that is. (Memo to self: work on internet skills.) @Bart: It doesn't actually answer the question, does it? And if it doesn't it's useless, quiaff? Now, it *is* possible that circular doesn't want or know how to help, but I consider that rather unlikely. Then, why is his post unhelpfull? Because there is stuff missing from it. Maybe advanced users can guess that on their own, but I certainly couldn't, and I informed him... in a rather verbose fashion... ---------------------------------------------------------------------- winni · 2020-11-14 22:15 Okay. Seems you don't need our help. Buy some colors on monday morning and paint your screen. Winni ---------------------------------------------------------------------- Roland57 · 2020-11-14 22:26 Are there moderators in this forum? Please kick that asshole out there. ---------------------------------------------------------------------- Andrew0Red · 2020-11-14 22:33 I *do* need your help. Getting it ... ahgr ... I lack words ... variables: how good a student the student is, how good a teacher the teacher is, how difficult the subject is (more). (Does this make sense?) And I've gotten some help already: 1: it is not possible to write a TFPColor simply, 2: TBGRAPixel was not usefull here, but it is another tool in the toolbox (we can both cook up many situations where it is better), 3: pixels property? Nothing here ... yet. But on my next problem, I'll have another search phrase. (I still say that half a line of code would have helped a lot), 4: TPColor can be autocompleted to TPColorToTFPColor (different thread, but same crowd.)  - thank you for that help. Next time I need help, I'll ask for it. Whether I get it is partly up to me ---------------------------------------------------------------------- Bart · 2020-11-14 23:03 You can use operator overloading to simply assing something (a Cardinal?) to a TFPColor if you wish to do so. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}uses fpimage, ucomplex; operator := (Value: QWord): TFPColor;begin  Result.Alpha := 0;  //do the correct math here  Result.Blue := 0;  Result.Green := 0;  Result.Red := 0;end; var C: tfpcolor;begin  C := $AAAABBBBCCCCEEE;end. Bart ---------------------------------------------------------------------- Bart · 2020-11-14 23:07 Quote from: Andrew0Red on November 14, 2020, 11:06:49 pm@Bart: It doesn't actually answer the question, does it? And if it doesn't it's useless, quiaff? Now, it *is* possible that circular doesn't want or know how to help, but I consider that rather unlikely. Then, why is his post unhelpfull? Because there is stuff missing from it. Maybe advanced users can guess that on their own, but I certainly couldn't, and I informed him... in a rather verbose fashion... You could have phrased that (not being of help for you) quite a bit nicer. A simple "I don't get how that helps with my current problem", would have sufficed. This leaves open the possibility that the answer indeed was helpfull, but you did not quite see how. The way you behave in this thread is not going to make you popular here. Mind you, most of us really like to help anybody who asks questions here. You make it rather difficult for us. Bart ---------------------------------------------------------------------- wp · 2020-11-14 23:10 Quote from: Andrew0Red on November 14, 2020, 08:10:43 pmSo essentially, they make us jump through hoops when we just want to draw a simple dot on a paintbox??? You don't need TFPColor at all to draw a dot on a paintbox, TColor is enough. Please specify what you want to do. ---------------------------------------------------------------------- winni · 2020-11-14 23:16 Quote from: Andrew0Red on November 14, 2020, 11:33:56 pm(Does this make sense?) No. If you were not so bullheaded and just have a look at the offered solutions, maybe you step a little bit forward. Again: TBGRApixel It has: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure FromFPColor(AColor: TFPColor); function ToFPColor: TFPColor;  You could have found out . With our help. But it seems that you don't even have looked into the code. Winni ---------------------------------------------------------------------- Andrew0Red · 2020-11-14 23:38 I was trying to do something like PaintBox.Canvas.DrawPixel(x,y,TColorToFPColor($aa00aa)); to draw a pixel on a paintbox. (Not set on a paintbox, could be anything.) 'Operator overload' - sort of creating my own constructor for TFPColor? That would work too (prob. not with my skills, though). And I think I should have posted in beginner... ---------------------------------------------------------------------- wp · 2020-11-15 00:24 The canvas of a Paintbox (I hope we are talking of the same thing...) is class TCanvas which uses 8-bit-per-channel colors. Using TFPColor does not give you an advantage here, in particular since you start with a TColor value. So, I'd set a TColor to the Pixels[] property instead which uses a TColor directly. (not the fastest, though): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   Paintbox.Canvas.Pixels[x, y] := $aa00aa; ---------------------------------------------------------------------- anyone · 2020-11-15 07:58 This is how I extract RGB from TFPColor, though I have not tested with it how to form a TFPColor with RGB values. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var img : TFPMemoryImage;    pixel : TFPColor;   r, g, b:byte;              pixel := img.Colors[x,y];             r := (pixel.Red shr 8) and $00ff;             g := (pixel.Green shr 8) and $00ff;             b := (pixel.Blue shr 8) and $00ff; I have not tested the following, but it can compiles: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i                         pixel.Red:=r * $101;             pixel.Green:=g * $101;             pixel.Blue:=b * $101; So if r=$cc (Byte), if would expand to $cccc (Word) for pixel.Red, and so forth. ---------------------------------------------------------------------- Andrew0Red · 2020-11-15 11:34 Quote from: anyone on November 15, 2020, 08:58:13 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i                         pixel.Red:=r * $101; Don't think I'm going to use this, but *sweet* scaling! Quote from: wp on November 15, 2020, 01:24:02 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   Paintbox.Canvas.Pixels[x, y] := $aa00aa; Ah, much simpler! You mention inefficiency, but if I only use this for creating the hexagonal bitmaps in the first place, and then use the completed bitmaps later, it'd probably run fast enough for turn-based. Thank you! Sorry. ---------------------------------------------------------------------- wp · 2020-11-15 16:14 Quote from: Andrew0Red on November 15, 2020, 12:34:55 pmQuote from: wp on November 15, 2020, 01:24:02 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   Paintbox.Canvas.Pixels[x, y] := $aa00aa;You mention inefficiency, but if I only use this for creating the hexagonal bitmaps in the first place, and then use the completed bitmaps later, it'd probably run fast enough for turn-based. No problem in this kind of application. You'll be unhappy with Canvas.Pixels[], though, when you manipulate a 20 mega-pixel image. ---------------------------------------------------------------------- circular · 2020-11-15 21:57 Quote from: Andrew0Red on November 15, 2020, 12:34:55 pmQuote from: wp on November 15, 2020, 01:24:02 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   Paintbox.Canvas.Pixels[x, y] := $aa00aa; Ah, much simpler! That's the Pixels property I was mentioning. ---------------------------------------------------------------------- winni · 2020-11-15 22:29 Quote from: wp on November 15, 2020, 05:14:00 pm No problem in this kind of application. You'll be unhappy with Canvas.Pixels[], though, when you manipulate a 20 mega-pixel image. Not such a big problem. Meanwhile you can boil fresh coffee. Winni ---------------------------------------------------------------------- wp · 2020-11-15 23:39 Quote from: circular on November 15, 2020, 10:57:38 pmQuote from: Andrew0Red on November 15, 2020, 12:34:55 pmQuote from: wp on November 15, 2020, 01:24:02 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   Paintbox.Canvas.Pixels[x, y] := $aa00aa; Ah, much simpler! That's the Pixels property I was mentioning. Sorry, circular. I misunderstood your post then. The OP was asking about FPColor and since I had never used FPColor in the context of a TCanvas I thought he is working with FP-Image where there is a Pixels property, too, but with a different meaning (Palette index). Only later it became clear that the questions was about a standard TCanvas, and I still did not see your post in this new context. ---------------------------------------------------------------------- circular · 2020-11-16 08:26 No problem. We agree with a solution.