|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| The Water Effect Explained |
|
![]() nights Member since: 4/18/2003 From: Sweden |
||||
|
|
||||
| Yes, I remember my highschool physics, do you really? "If you remember your highschool physics, you know that... ...where the refraction index is that of water: 2.0." Actually water has a refraction index of 1.33, no liquids have a value of 2.0! For instance, glass have 1.5, quarts like 1.7 and diamond is worst by a value of 2.6. Anyway, its a great tutorial, i learnt alot from it! Huge thanks! [edited by - nights on April 27, 2003 9:31:07 AM] |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| This article is really helpful. But if you write the code in C language, i think it'll be more helpful. |
||||
|
||||
![]() yogeshpatel4all Member since: 3/28/2004 From: India |
||||
|
|
||||
| Hi , I read ur code ..its great.. If at any time u r going to write the Code in C or C++..let me know.. |
||||
|
||||
![]() yogeshpatel4all Member since: 3/28/2004 From: India |
||||
|
|
||||
| Hi , I read ur code ..its great.. If at any time u r going to write the Code in C or C++..let me know.. Even the Rainfall efect is great. |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
Quote: Woops... That must've slipped in during a late-night coding session. I probably used 2 as 1.33 wasn't "watery" enough for the simulation. Sorry :$ Roy Willemse. |
||||
|
||||
![]() Moe Member since: 1/24/2000 From: Calgary, Canada |
||||
|
|
||||
| For anyone who is interested (or too lazy) here is a link to the article. |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| Does anyone has an idea, how to avoid the wave reflection at the boundings ? Seems not that simple for me.. |
||||
|
||||
![]() marthien Member since: 5/20/2007 From: surabaya, Indonesia |
||||
|
|
||||
| i want to ask to every body in forum. can you help me. i was create the water effect in delphi7 but it's not work i confused because the color broken. can you help me because it's my homework. thx every body. i give the program in dephi7 was i created. unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtDlgs, ExtCtrls,math; type TForm1 = class(TForm) Image1: TImage; Image2: TImage; OpenPictureDialog1: TOpenPictureDialog; Button1: TButton; Button2: TButton; Button3: TButton; Image3: TImage; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure updatewavemap; procedure init; procedure initize; procedure gambar; procedure gambar1; procedure RenderWaveToDIB; procedure WaveMapDrop(x,y,w,MulFactor: integer); procedure FormCreate(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Image2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private { Private declarations } public { Public declarations } end; const MAXX=300; MAXY=300; DAMP = 4; rIndex = 4.0; var Form1: TForm1; CT,NW:byte; WaveMap: Array[0..1, 0..MAXX, 0..MAXY] of integer; dispLut: Array[0..511] of byte; keluar:boolean; implementation {$R *.dfm} procedure tform1.initize; var c,d:integer; begin for c:=-256 to 255 do begin d:=c div 4; dispLut[c+256] := Byte(Trunc(Tan(ArcSin((Sin(ArcTan(d))/rIndex)))*d)); end; end; procedure tform1.WaveMapDrop(x,y,w,MulFactor: integer); var u,v:integer; sqrx,sqry,sqrw: integer; begin sqrw := sqr(w); if (x>w) and (x<MAXX-w) and (y>w) and (y<MAXY-w) then begin for v:=y-w to y+w do begin sqry := sqr(v-y); for u:=x-w to x+w do begin sqrx := sqr(u-x); if (sqrx+sqry)<=sqrw then begin WaveMap[CT,u,v] := MulFactor*Trunc(w-sqrt(sqrx+sqry)); end; end; end; end; end; procedure Tform1.RenderWaveToDIB; var x,y,newcolor,xDiff,yDiff,xDisp,yDisp: Smallint; begin for y:=0 to MAXY do begin for x:=0 to MAXX do begin xDiff := WaveMap[NW,x+1,y] - WaveMap[NW,x,y]; yDiff := WaveMap[NW,x,y+1] - WaveMap[NW,x,y]; xDisp := dispLut[xDiff+256]; yDisp := dispLut[yDiff+256]; if xDiff<0 then begin // Current position is higher - Clockwise rotation if (yDiff<0) then newcolor := image1.canvas.Pixels[x-xDisp,y-yDisp] else newcolor := image1.canvas.Pixels[x-xDisp,y+yDisp] end else begin if (yDiff<0) then newcolor := image1.canvas.Pixels[x+xDisp,y-yDisp] else newcolor := image1.canvas.Pixels[x+xDisp,y+yDisp] end; image2.canvas.pixels[x,y] := newcolor; end; end; end; procedure tform1.updatewavemap; var y,x:integer; n:integer; begin for y:=2 to MAXY-2 do begin for x:=2 to MAXX-2 do begin { n:=( WaveMap[CT,x-1,y] + WaveMap[CT,x-2,y] + WaveMap[CT,x+1,y] + WaveMap[CT,x+2,y] + WaveMap[CT,x,y-1] + WaveMap[CT,x,y-2] + WaveMap[CT,x,y+1] + WaveMap[CT,x,y+2] + WaveMap[CT,x-1,y-1] + WaveMap[CT,x+1,y-1] + WaveMap[CT,x-1,y+1] + WaveMap[CT,x+1,y+1] ) div 6 - WaveMap[NW,x,y];} n := ( WaveMap[CT,x-1,y] + WaveMap[CT,x+1,y] + WaveMap[CT,x,y-1] + WaveMap[CT,x,y+1] ) div 2 - WaveMap[NW,x,y]; n:= n - (n div damp); {asm push bx mov bx, n sar bx, DAMP sub n, bx pop bx end; } WaveMap[NW,x,y] := n; // Store result end; end; end; procedure TForm1.Button1Click(Sender: TObject); begin if OpenPictureDialog1.Execute then begin image1.Picture.LoadFromFile(OpenPictureDialog1.FileName); end; end; procedure TForm1.Button2Click(Sender: TObject); var x,y,i,j:integer; totr,totg,totb:integer; tmp:integer; begin CT:=0; NW:=1; x := 40 + random(MAXX-40); y := 40 + random(MAXY-40); WaveMapDrop(x,y,10,25); UpdateWaveMap; RenderWaveToDIB; end; procedure TForm1.FormCreate(Sender: TObject); begin CT:=0; NW:=1; end; end. |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|