Link to home
Start Free TrialLog in
Avatar of Mutley2003
Mutley2003

asked on

Drop Shadow and Torn Paper Graphics Effects

I have been looking around for Delphi code or algorithms for these effects and I have not been able to find a source.

Can anyone help me .. rough out some code perhaps?

Thanks
Avatar of Ivanov_G
Ivanov_G
Flag of Bulgaria image

Avatar of Mutley2003
Mutley2003

ASKER

I guess I was not clear enough in my request. Ivanov G's solution applies to windows.

I want these graphicFX to apply to an image (Timage, TBitmap etc)

aaa, if you mean the "Drop Shadow" effect (PhotoShop like), I don't think I can help ...
Dropshadow could be done by drawing a (usually) black rectangle and then applying a "blurfilter".
The filter replaces the "color" of a pixel witht the average of it's neighbours (and itself).
This kinda looks like torn paper. You could use this as a mask.

procedure TForm1.Button2Click(Sender: TObject);

  procedure fractal (B: TBitmap; t1,f1,t2,f2, resolution,roughness: double);
  var
    r,tmid,fmid: double;
  begin
    if (sqr(t2 - t1) + sqr(f2 - f1)) < sqr(resolution) then
    begin
      B.Canvas.MoveTo(round(t1), round(f1));
      B.Canvas.LineTo(round(t2), round(f2));
    end
    else begin
      r := 2 * random - 1;
      tmid := (t1 + t2) / 2 - roughness * (f2 - f1)*r;
      fmid := (f1 + f2) / 2 + roughness * (t2 - t1)*r;

      fractal (B, t1,f1, tmid,fmid, resolution,roughness);
      fractal (B, tmid,fmid, t2,f2, resolution,roughness);
    end;
  end;

var
  B: TBitmap;
  y1,y2: Integer;
begin
  B := TBitmap.Create;
  try
    B.Width := 400;
    B.Height := 400;
    B.PixelFormat := pf8Bit;
    B.canvas.Brush.Color := clWhite;
    B.Canvas.FillRect(RECT(0,0,B.Width,B.Height));

    y1 := Trunc (200 * (1 + Random));
    y2 := Trunc (200 * (1 + Random));

    fractal (B, 0,y1, B.Width,y2, 4, 0.2);

    B.canvas.Brush.Color := clBlack;
    B.canvas.FloodFill(2,2, clBlack, fsBorder);

    BitBlt (Canvas.Handle, 0,0,B.Width,B.Height, B.Canvas.Handle, 0,0, SRCCOPY);
  finally
    B.Free;
  end;
Ow.. it's from 3D Computer Graphics by Alan Watt (2nd edition)
hello Mutley2003 , can you give some more info about your "Drop Shadow", do you just want a rectangular drop shadow (darken blend to an existing bitmap)  ? ? Or maybe some "How does it look" about the Torn Paper Graphics Effects?
Bart, is "3D Computer Graphics by Alan Watt" in Pascal ? still in print?

Slick812 .. no, not just rectangular.

This example combines the two effects

http://www.psptips.com/4/readers/tornedge.html

This is not so clear
http://www.iboost.com/build/software/psp/939.htm

also called "ripped edges"
http://www.cbtcafe.com/fireworks/rippededges/rippededges.html

also some nice "torn paper" effects here
http://www.ec-software.com/tnt3.htm

Apparently you can do a "ragged edge" with the GIMP by using distress in script-fu.
http://lists.xcf.berkeley.edu/lists/gimp-user/1999-September/000003.html
Source for that would possibly be available deep in the GIMP (in C, though)

ASKER CERTIFIED SOLUTION
Avatar of Bart_Thomas
Bart_Thomas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial