GithubHelp home page GithubHelp logo

Hatching about skia4delphi HOT 5 CLOSED

skia4delphi avatar skia4delphi commented on June 27, 2024
Hatching

from skia4delphi.

Comments (5)

Echelon78 avatar Echelon78 commented on June 27, 2024 1

Thank you very much for both examples. Before I could report the misalignment, there was a second, better, solution. Thank you very much.

from skia4delphi.

viniciusfbb avatar viniciusfbb commented on June 27, 2024

Hi @Echelon78!
You can use the code:

uses
  System.Math.Vectors, Skia;

procedure Hatching(const ACanvas: ISkCanvas);
var
  paint: ISkPaint;
  lattice: TMatrix;
  bounds: TRectF;
begin
  paint := TSkPaint.Create;
  paint.Color := TAlphaColors.Black;
  lattice := TMatrix.CreateRotation(45) * TMatrix.CreateScaling(8, 8);
  paint.PathEffect := TSkPathEffect.Make2DLine(1, lattice);
  paint.AntiAlias := True;
  bounds := TRect.Create(0, 0, 250, 250);
  ACanvas.Clear(TAlphaColors.White);
  ACanvas.DrawRect(bounds, paint);
end;

Result:
image

from skia4delphi.

viniciusfbb avatar viniciusfbb commented on June 27, 2024

This result is a little unexpected, the traces are not aligned with the rect bounds when compared to the fiddle result. Some differences with fiddle can occur because fiddle always uses the newest skia (the current version we use, the m88, is almost 1 year older). I'll be able to investigate this in the future, but for now this difference can easily be worked around by changing the previous code to:

uses
  System.Math.Vectors, Skia;

procedure Hatching(const ACanvas: ISkCanvas);
var
  paint: ISkPaint;
  lattice: TMatrix;
  bounds: TRectF;
begin
  paint := TSkPaint.Create;
  paint.Color := TAlphaColors.Black;
  lattice := TMatrix.CreateRotation(45) * TMatrix.CreateScaling(8, 8);
  paint.PathEffect := TSkPathEffect.Make2DLine(1, lattice);
  paint.AntiAlias := True;
  bounds :=  TRect.Create(0, 0, 250, 250);
  ACanvas.Clear(TAlphaColors.White);
  ACanvas.Save;
  try
    ACanvas.ClipRect(bounds);
    bounds.Inflate(8,8);
    ACanvas.DrawRect(bounds, paint);
  finally
    ACanvas.Restore;
  end;
end;

Result:
image

from skia4delphi.

viniciusfbb avatar viniciusfbb commented on June 27, 2024

@Echelon78
Today I was doing other examples and I discovered by chance why our example was not working exactly like fiddle: although there is no documentation, TMatrix.CreateRotation works with radians and not with degree. So just add the DegToRad(, looking like this:

uses
  System.Math, System.Math.Vectors, Skia;

procedure Hatching(const ACanvas: ISkCanvas);
var
  paint: ISkPaint;
  lattice: TMatrix;
  bounds: TRectF;
begin
  paint := TSkPaint.Create;
  paint.Color := TAlphaColors.Black;
  lattice := TMatrix.CreateRotation(DegToRad(45)) * TMatrix.CreateScaling(8, 8);
  paint.PathEffect := TSkPathEffect.Make2DLine(1, lattice);
  paint.AntiAlias := True;
  bounds :=  TRect.Create(0, 0, 250, 250);
  ACanvas.Clear(TAlphaColors.White);
  ACanvas.Save;
  try
    ACanvas.ClipRect(bounds);
    bounds.Inflate(8,8);
    ACanvas.DrawRect(bounds, paint);
  finally
    ACanvas.Restore;
  end;
end;

Result:
image

from skia4delphi.

viniciusfbb avatar viniciusfbb commented on June 27, 2024

Added this example in new Demo. :)

from skia4delphi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.