On 2017-01-19 14:59, Ryan Joseph wrote:
> Is there anyway to set a pixel using TFPImageCanvas?

It is slightly confusing. If you are using an Indexed image, then use
the Pixels[] property. If you are not using an Indexed image, then use
the Colors[] property.

Attached is an example program that generates a Minecraft like grass
block (texture) and then outputs it to a PNG file. I hope the example helps.

Regards,
  Graeme

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
program project1;

{$mode objfpc}{$H+}

uses
  Classes,
  SysUtils,
  fpcanvas, fpimage,
  FPWritePNG;


const
  IMGDIM = 64;  // image dimensions

var
  mm: TFPCustomImage;
  imgwri: TFPWriterPNG;
  br, x, y: integer;
  r, g, b: word;
begin
  Randomize;

  // for later usage
  imgwri := TFPWriterPNG.create;
  imgwri.Indexed := False;

  br := 255 - Random(96);
  mm := TFPCompactImgRGB8Bit.Create(IMGDIM, IMGDIM);
  mm.UsePalette := False;
  for y := 0 to IMGDIM-1 do
  begin
    for x := 0 to IMGDIM-1 do
    begin
      (*
      // just random noise
      r := Random($FF);
      g := Random($FF);
      b := Random($FF);
      *)

      //  *****  Minecraft like grass block ;-)   *****
      // ground
      r := $96;
      g := $6C;
      b := $4A;

      if (random(3) = 0) then
        br := 255 - random(96);

      if y < (((x * x * 3 + x * 81) shr 2) and 3) + (IMGDIM * 0.125) then
      begin
        // grass
        r := $6A;
        g := $AA;
        b := $40;
      end
      else if y < (((x * x * 3 + x * 81) shr 2) and 3) + (IMGDIM * 0.1875) then
      begin
        br := br * 2 div 3;
      end;

      r := (r * br) div $FF;
      g := (g * br) div $FF;
      b := (b * br) div $FF;


      // duplicate the data to fill a WORD size channel
      r := (r shl 8) or r;
      g := (g shl 8) or g;
      b := (b shl 8) or b;
      mm.Colors[x, y] := FPColor(r, g, b, $FFFF);
    end;
  end;

  mm.SaveToFile('output-1.png', imgwri);


  imgwri.Free;
  mm.Free;
end.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to