Advertisement
WarPie90

Reaction time!

Jan 18th, 2025 (edited)
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.26 KB | None | 0 0
  1. program new;
  2.  
  3. function WaitForAction(): Double;
  4. var t: Double;
  5. begin
  6.   t := PerformanceTimer();
  7.   while True do
  8.   begin
  9.     if Target.KeyPressed(EKeyCode.LBUTTON) then
  10.     begin
  11.       Result := PerformanceTimer() - t;
  12.       break;
  13.     end;
  14.   end;
  15.  
  16.   SleepUntil(not Target.KeyPressed(EKeyCode.LBUTTON), 50, 10000);
  17. end;
  18.  
  19.  
  20. var
  21.   img: TImage;
  22.   iron_url: string = "https://oldschool.runescape.wiki/images/thumb/Iron_rocks.png/1280px-Iron_rocks.png?29a7c";
  23.   iron: TImage;
  24.   depleted: TImage;
  25.   raw: string;
  26.   hsl: TColorHSL;
  27.   x,y: Int32;
  28.  
  29.   t,time: Double;
  30.   times: TSingleArray;
  31. begin
  32.   HTTPClient.GetFile(iron_url, 'tmp.png');
  33.  
  34.  
  35.   iron := TImage.Create('tmp.png');
  36.   depleted := iron.Copy();
  37.  
  38.   for y:=0 to depleted.Height-1 do
  39.     for x:=0 to depleted.Width-1 do
  40.     begin
  41.       hsl := depleted.Pixel[x,y].ToHSL();
  42.       hsl.s := 0;
  43.  
  44.       depleted.Pixel[x,y] := hsl.ToColor;
  45.     end;
  46.   iron.ReplaceColor(0, TColorHSL([32,20,70]).ToColor);
  47.   depleted.ReplaceColor(0, TColorHSL([32,20,70]).ToColor);
  48.  
  49.   depleted := depleted.Downsample(12);
  50.   iron := iron.Downsample(12);
  51.  
  52.   img := TImage.Create(700,700);
  53.   img.Fill(TColorHSL([32,20,70]).ToColor);
  54.  
  55.   img.DrawImage(depleted, [350,350]);
  56.  
  57.   img.Show();
  58.  
  59.  
  60.   WaitForAction();
  61.  
  62.   t := PerformanceTimer() + 4000;
  63.   while True do
  64.   begin
  65.     while Target.KeyPressed(EKeyCode.LBUTTON) do
  66.     begin
  67.       Sleep(500);
  68.       t += Random(1000);
  69.       WriteLn('Dont you dare!');
  70.     end;
  71.  
  72.     if PerformanceTimer() > t then
  73.     begin
  74.       img.DrawImage(iron, [350,350]);
  75.       DebugImageUpdate(img);
  76.  
  77.       time := WaitForAction();
  78.       times += time;
  79.       if Length(times) > 1 then
  80.       begin
  81.         Writeln(Format('This:   %.2fms', [times[High(times)]]));
  82.         Writeln(Format('> Avg:    %.2fms', [times.Mean]));
  83.         Writeln(Format('> Median: %.2fms', [times.Median]));
  84.         Writeln(Format('> Min:    %.2fms', [times.Min]));
  85.         Writeln(Format('> Max:    %.2fms', [times.Max]));
  86.         Writeln(Format('> Std:    %.2fms', [times.Stdev]));
  87.       end else
  88.         Writeln('This: ', times[0],'ms');
  89.       WriteLn('--------------');
  90.       img.DrawImage(depleted, [350,350]);
  91.       DebugImageUpdate(img);
  92.  
  93.       t := PerformanceTimer() + 4000;
  94.     end;
  95.   end;
  96. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement