Permalink
Browse files

Merge branch 'master' of https://github.com/m34tcode/SRL-5

  • Loading branch information...
2 parents 19b625f + 1ccabdd commit 63bf2f1d1a3f4424ef314c7d2c45cb29cf251d0b @cohenadair cohenadair committed May 7, 2012
Showing with 170 additions and 0 deletions.
  1. +170 −0 srl/core/animation.simba
View
@@ -119,6 +119,176 @@ begin
result := averageTIA(shifts);
end;
+
+(*
+GetColArr
+~~~~~~~~~~~~~~
+
+.. code-block:: pascal
+
+ function GetColArr(Box : TBox): T2DIntegerArray;
+
+Returns a 2D color array from the pixels contained by Box.
+
+.. note::
+
+ Author: m34tcode
+ Last Modified: 4/7/2012
+*)
+function GetColArr (Box : TBox) : T2DIntegerArray;
+var
+ x,y : Integer;
+begin
+ SetArrayLength(Result,box.X2-box.X1);
+ for x := 0 to box.X2-box.X1-1 do
+ begin
+ SetArrayLength(Result[x],box.Y2-box.Y1);
+ for y := 0 to box.Y2-box.Y1-1 do
+ begin
+ Result[x][y] := GetColor(x+box.X1,y+box.Y1);
+ end;
+ end;
+end;
+
+(*
+ValidatePixels
+~~~~~~~~~~~~~~
+
+.. code-block:: pascal
+
+ procedure GetColArr(Box : TBox);
+
+Checks for which pixels, in OrigCols, have changed
+beyond the specified tolerance, since the last check
+
+.. note::
+
+ Author: m34tcode
+ Last Modified: 4/7/2012
+*)
+procedure ValidatePixels(Box : TBox; OrigCols : T2DIntegerArray; BoolArr : array of TBoolArray; Tolerance : Integer);
+var
+ X,Y : Integer;
+ NewCols : T2DIntegerArray;
+begin
+ NewCols := GetColArr(Box);
+ for X := 0 to Box.X2 - Box.X1-1 do
+ for Y := 0 to Box.Y2 - Box.Y1-1 do
+ begin
+ if not BoolArr[x][y] then
+ continue;
+ boolArr[x][y] := SimilarColors(origCols[x][y],NewCols[x][y],Tolerance);
+ end;
+end;
+(*
+InitBoolArr
+~~~~~~~~~~~~~~
+
+.. code-block:: pascal
+
+ function InitBoolArr(Width,Height : Integer): array of TBoolArray;
+
+Initializes a 2D boolean array, of dimensions Width x Height to True;
+
+.. note::
+
+ Author: m34tcode
+ Last Modified: 4/7/2012
+*)
+function InitBoolArr(Width,Height : Integer) : array of TBoolArray;
+var x,y : Integer;
+begin
+ SetArrayLength(Result,Width);
+ for x := 0 to Width-1 do
+ begin
+ SetArrayLength(Result[x],Height);
+ for Y := 0 to Height-1 do
+ begin
+ Result[x][y] := True;
+ end;
+ end;
+end;
+(*
+InitBoolArr
+~~~~~~~~~~~~~~
+
+.. code-block:: pascal
+
+ function CountBools(BoolArr : Array of TBoolArray; CountTrues : Boolean) : Integer;
+
+Counts all boolean values in the array, equal to CountTrue
+
+.. note::
+
+ Author: m34tcode
+ Last Modified: 4/7/2012
+*)
+function CountBools(BoolArr : Array of TBoolArray; CountTrues : Boolean) : Integer;
+var
+ X,Y,W,H,C : Integer;
+begin
+ W := GetArrayLength(BoolArr);
+ H := GetArrayLength(BoolArr[0]);
+ For X := 0 to W-1 do
+ for Y := 0 to H-2 do
+ if BoolArr[X][Y] = CountTrues then
+ Inc(C);
+ Result := C;
+end;
+(*
+PixelShiftOT - Over Time
+~~~~~~~~~~~~~~
+
+.. code-block:: pascal
+
+ function PixelShiftOT(Box : TBox; ShiftInterval, Repetitions, Tolerance : Integer) : Integer;
+
+Returns an integer equal to the number of pixels,
+ within Box, that changed more than tolerance,
+ in the time specified by ShiftInterval * Repetitions
+
+.. note::
+
+ Author: m34tcode
+ Last Modified: 4/7/2012
+
+Example:
+
+.. code-block:: pascal
+
+ PixelCount := PixelShiftOT(IntToBox(10,10,20,20), 500, 4, 10);
+*)
+function PixelShiftOT(Box : TBox; ShiftInterval, Repetitions, Tolerance : Integer) : Integer;
+var
+ I,X,Y : Integer;
+ T,TT : LongInt;
+ OrigColArr : T2DIntegerArray;
+ BoolArr : array of TBoolArray;
+begin
+ OrigColArr := GetColArr(Box);
+ BoolArr := initBoolArr(Box.X2-Box.X1,Box.Y2-Box.Y1);
+ MarkTime(T);
+ MarkTime(TT);
+ for I := 0 to Repetitions-1 do
+ begin
+ if (TimeFromMark(T) > (Repetitions*ShiftInterval)) then
+ begin
+ srl_Warn('CalcNonStaticPixelCount','Completed only ' + IntToStr(I) + ' of '
+ + IntToStr(Repetitions) + '. Try increasing the interval',1);
+ break;
+ end;
+ {$IFDEF DEBUG}
+ if (I > 0) then
+ writeln('CalcNonStaticPixelCount: Iteration ' + IntToStr(I) + ' took '
+ + FloatToStr(TimeFromMark(TT)/1000.0) + ' seconds to complete.');
+ {$ENDIF}
+ MarkTime(TT);
+ wait(Max(0,ShiftInterval-TimeFromMark(TT)));
+ ValidatePixels(Box,OrigColArr,BoolArr,Tolerance);
+ end;
+ Result := CountBools(BoolArr,False);
+end;
+
(*
AnimatingMulti
~~~~~~~~~~~~~~

0 comments on commit 63bf2f1

Please sign in to comment.