function TForm1.ReadWindAngle : Integer; var wPixel : word; bRed, bGreen : byte; fHighest, fLowest, fTotalMedian : single; fMedian: array[1..6] of double; fCurAngle, nRadius, z, nX, nY, f, c : integer; begin z:=0; fhighest:=0; flowest:=0; fTotalMedian:=0; fCurAngle:=0; for nRadius:=21 to PRED(27) do begin inc(z); for fCurAngle:=0 to PRED(360) do begin nX := Trunc(241 + (cos(DegToRad(fCurAngle)) * nRadius)); //old interface nY := Trunc(573 + (sin(DegToRad(fCurAngle)) * nRadius)); //old interface //nX := Trunc(400 + (cos(DegToRad(fCurAngle)) * nRadius)); //new interface //nY := Trunc(27 + (sin(DegToRad(fCurAngle)) * nRadius)); //new interface (use SinCos) Memo1.Text := IntToHex(wPixel,2); wPixel := form1.canvas.Pixels[nX, nY]; bRed := (wPixel and $FF); bGreen := (wPixel shr 8) and $FF; Edit1.Text := IntToHex(bRed,2); Edit2.Text := IntToHex(bGreen,2); if (bRed > $17) and (bGreen < $8) then begin if fLowest <> 1 then begin fHighest := fCurAngle; fLowest := fCurAngle end else if ((fCurAngle - fLowest) < 27) then fHighest := fCurAngle; end; end; fMedian[z] := (fLowest + fHighest) / 2.00; fHighest := 0; fLowest := 0; f:=0; c:=0; end; for f:=0 to 6 do if fMedian[z] <> 0 then begin fTotalMedian := fTotalMedian + fMedian[f]; inc(c); end; fTotalMedian := fTotalMedian / c; wa := FloatToStr(fTotalMedian); end; ================= // quick macro to convert X, Y location into a 1D array location. Top `left` pixel = 0, 0 #define PIXEL(a, b) pBitmap[a + b * 800] int Aimbot_ReadWindAngle(unsigned short *pBitmap) { unsigned short wPixel; // storage for a pixel unsigned char bRed, bGreen; // red / green components of a pixel float fHighest = 0; // highest recorded possibility of wind angle float fLowest = 0; // lowest recorded possibility of wind angle float fMedians[6]; // median of each of the 6 readings float fTotalMedian = 0; // median of all 6 readings // read which pixels are in between the specified colour range, going around the // circle with 6 different radii and calculating an average angle for each radius, // finally averaging all 6. for (int nRadius = 21, int z = 0; nRadius < 27; nRadius++, z++) { for (float fCurAngle = 0; fCurAngle < 360; fCurAngle++) { int nX = 400 + (cos(fCurAngle * DegToRad) * nRadius); // can be sped up by creating a lookup table int nY = 71 + (sin(fCurAngle * DegToRad) * nRadius); // "" "" wPixel = PIXEL(nX, nY); // get a pixel from the wind meter // calculate the red and green components, lowest 5 bits = red, middle 5 bits = green bRed = wPixel & 0x1F; // 0x1F = %11111 bGreen = (wPixel >> 5) & 0x1F; // shr the wPixel by 5 bits to make the green in the position of the old red if ((bRed > 0x17) && (bGreen < 0x08)) // check if the pixel is in the desired colour range { if (!fLowest) // if we have not yet had a match then fLowest won't be set yet fLowest = fHighest = fCurAngle; // so set fLowest, and in case we don't find another, set fHighest too. else // already found a pixel at a lower angle than this if ((fCurAngle - fLowest) < 27) // if this pixel is less than 27 angles away from the lowest, record it fHighest = fCurAngle; // as the new highest (the wind meter angle is around 25 angles circum at base) } } fMedians[z] = (fLowest + fHighest) / 2.00; // calculate the median red pixel fLowest = fHighest = 0; // reset the counters } for (int f = 0, int c = 0; f < 6; f++) // cycle through and count how many readings were not 0 if (fMedians[f] != 0) // if median is not 0 { fTotalMedian += fMedians[f]; // add to total c++; // increase count of added medians } fTotalMedian /= c; // divide total sum by number of counted medians return (int)fTotalMedian; }