[Solved] Image Overlap lazarus / 39-Graphics ---------------------------------------------------------------------- zoimutante · 2019-12-31 12:26 I need help with overlapping images. I have two images, the moon, and a "black mask" with alpha channel. I need to the "black mask" overlap the moon image according to a mathematical formula.  What would be the most easy way to perform this ? And the most effective ? PS: This images are displayed inside a form, if that matter. ---------------------------------------------------------------------- lainz · 2019-12-31 12:47 Hi, I recommend you BGRABitmap that is cross platform and can be used to draw into a Canvas of a TForm. In this tutorial is explained the use of masks https://wiki.lazarus.freepascal.org/BGRABitmap_tutorial_5 But if you want to apply a mathematical formula, maybe you need direct pixel access: https://wiki.lazarus.freepascal.org/BGRABitmap_tutorial_4 Edit: There are also blending modes with BGRABitmap.BlendImageOver for example ---------------------------------------------------------------------- zoimutante · 2019-12-31 13:16 Quote from: lainz on December 31, 2019, 01:47:41 pmHi, I recommend you BGRABitmap that is cross platform and can be used to draw into a Canvas of a TForm. In this tutorial is explained the use of masks https://wiki.lazarus.freepascal.org/BGRABitmap_tutorial_5 But if you want to apply a mathematical formula, maybe you need direct pixel access: https://wiki.lazarus.freepascal.org/BGRABitmap_tutorial_4 Edit: There are also blending modes with BGRABitmap.BlendImageOver for example Thanks, I think it is exact what I need.  I just don't figure how to install. Download https://github.com/bgrabitmap/bgrabitmap from here and then ? Save it where ? install as a package ? NM. I found here: https://wiki.freepascal.org/BGRABitmap_tutorial_1 thanks ---------------------------------------------------------------------- RAW · 2019-12-31 16:38 No INSTALL necessary ... 1. Extract to any folder of your choice 2. Tell LAZARUS (Project Options) where to find the files (extra path) That's it ... ---------------------------------------------------------------------- circular · 2020-01-01 16:17 Hmm what kind of formula? Maybe there are some methods that we could suggest depending on what you would like to do. ---------------------------------------------------------------------- zoimutante · 2020-01-01 16:44 Quote from: circular on January 01, 2020, 05:17:31 pmHmm what kind of formula? Maybe there are some methods that we could suggest depending on what you would like to do. It will be something like: (current julian calendar day less last know new moon) mod duration of moon cycle in days. The reminder is an approximation of current moon age, then use it to overlap the shadow over the moon picture. I can't give the right formula now, because I could not find it, but it will be some thing similar, not hard at all. Just an ugly approximation. ---------------------------------------------------------------------- winni · 2020-01-01 17:11 Hi! If found that in my sources: 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 //========== MoonPhase =================// 0 :           Vollmond        full moon// 0..0.5 :      Abnehmender Mond  waning moon// 0.25 :      Halbmond          half moon -// 0.5 :         Neumond           new moon// 0.75 :        Halbmond          half moon  +// 0.5..0.9999:  Zunehmender Mond  waxing moon// goto Vollmondfunction MoonPhase(DT: TDateTime) : single; //  DT must be UTC!!!// synodischer Mondumlauf im Mittel= Lunation; ± 0.25 days (!!!!) Moon is wobbling!const syn = 29.530589;var Fullmoon: TDateTime;    phase : Single;begin// Vollmond Sonntag, 3. Dezember 2017, 15:46:59 Uhr UTCFullMoon := EncodeDate(2017,12,3) + EncodeTime(15,46,59,0);phase := (DT- FullMoon)/syn;result := frac(Phase);end;  But: The moon is wobbling. With this linear interpolation  you can be a lot of degrees away from the real position. To get the (amateur) position of the moon with +/- 1 degree, you need around 20 formulas! Winni ---------------------------------------------------------------------- lucamar · 2020-01-01 17:55 Quote from: winni on January 01, 2020, 06:11:42 pmBut: The moon is wobbling. With this linear interpolation  you can be a lot of degrees away from the real position. You aren't calculating the Moon position but its phase. A still approximate but more correct calculation is: 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 { Determines APPROXIMATE phase of the moon (percentage lit) 0.00 = New moon, 1.00 = Full moon Due to rounding, full values may possibly never be reached Valid from Oct. 15, 1582 to Feb. 28, 4000 Calculations and BASIC program found in   "119 Practical Programs For The TRS-80 Pocket Computer"   by John Clark Craig, TAB Books, 1982 Conversion to Turbo Pascal by Alan Graff, Wheelersburg, OH Further adapted by Luis Caballero, Madrid, Spain}function TMainForm.MoonPercentLit(const Julian: Integer): Double;var  m:real;begin  m := (Julian + 4.867) / 29.53058;  m := 2 * (m - Int(m)) - 1;  Result := Abs(m) * 100;end; with Julian calculated as: 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 ADate: TDateTime}ADate := EncodeDate(yy, mm, dd);Julian := Trunc(DateTimeToJulianDate(ADate)) + 1; ---------------------------------------------------------------------- winni · 2020-01-01 18:05 Hi! The way you do it and i do it is a rough simplification: A linear relation between time and phase. If you want the days from my formula then it is only the obvious line missing: Days := MoonPhase * syn; or Date :=  MoonPhase * syn OffsetDate; My stuff has the advantage that it works with Dephi dates - no conversion needed. The disadvantage is - due to Delphi TDateTime implementation - that it is only valid for Dates >1.1.1900. Winni ---------------------------------------------------------------------- circular · 2020-01-01 18:10 Quote from: zoimutante on January 01, 2020, 05:44:14 pmIt will be something like: (current julian calendar day less last know new moon) mod duration of moon cycle in days. The reminder is an approximation of current moon age, then use it to overlap the shadow over the moon picture. Ok so it is about the position of the mask. ---------------------------------------------------------------------- winni · 2020-01-01 18:23 Hi! Now I found it : drawing the moon phases. Parameter phase is the moonphase as shown in the last post. 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 // img must be square!procedure DrawMoon (Img: TImage; Phase : single);varradius,MidXY: Integer;p1,p2,p3,p4 : TPointF;tmp : TBGRABitMap;Xpos, YPos, Rpos, Xpos1, Xpos2, Percent: single;R : Trect;sign : String;begintmp  := TBGRABitmap.create(Img.Width,Img.Height,cssBlack);MidXY :=  Img.width div 2;radius := MidXY - 4;// Ganzer Mond in Blautmp.FillEllipseAntiali as(MidXY,MidXY,radius,radius,CssBlue);tmp.EllipseAntialias(MidXY, MidXY,radius,radius,CssYellow,0.5);tmp.LineCap := pecRound;Ypos := 0.0;// Gelben Teil des Mondes zeichnen - yellow part of moonwhile YPos <= radius do   begin   Xpos := Sqrt (sqr(radius) - sqr(Ypos));   RPos := 2*Xpos;    if Phase < 0.5 then  // abnehmed        begin          Xpos1 := -Xpos;          XPos2 := Rpos-2*Phase*Rpos-Xpos;        end else        // zunehmend        begin          XPos1 := +XPos;        XPos2 := Rpos-2*Phase*Rpos+Xpos;        end;    p1 := PointF (Xpos1+MidXY, MidXY-Ypos);    p2 := PointF (XPos2+MidXY, MidXY-Ypos);    p3 := PointF (XPos1+MidXY, MidXY+YPos);    p4 := PointF (XPos2+MidXY, MidXY+YPos);     tmp.DrawLineAntialias(p1.x,p1.y,p2.x,p2.y,cssYellow,1);    tmp.DrawLineAntialias(p3.x,p3.y,p4.x,p4.y,cssYellow,1);    yPos := yPos + 0.5;   end;// Ypos R := Rect (0,0,Img.Width,Img.Height);Img.Can vas.CopyRect(R,tmp.Canvas,R);tmp.free; if phase > 0.5 then sign := '[+]' else sign := '[-]';if phase > 0.5 then Percent := 1.0 - phase else Percent := phase;Percent := 100 -Percent * 100 *2;Img.Hint := 'Moon '+ intToStr(round(Percent))+'% '+sign;end; ---------------------------------------------------------------------- winni · 2020-01-02 00:42 Here is a screenshot of the code above. Winni