0

I'm working on a game with a lawn mower that orients itself to the mouse and colours white over a grass Bitmap to give the illusion of a mower cutting (erasing) grass.

I want to create a function that checks the percentage of grass cut, which basically means checking how much white is currently drawn into the grass image.

How would I go about doing this? Is there an easy way?

Here is my current code:

import flash.display.BitmapData;
import flash.events.Event;

var bitmapData = new grass();

var bitmap = new Bitmap(bitmapData);

var mower = new Mower();

var radiance:Number = 180/Math.PI;

var erase:Sprite=new Sprite();
erase.cacheAsBitmap = true;

bitmap.y=0;
bitmap.x=0;
addChild(bitmap);

addChild(erase);

addChild(mower);

this.addEventListener(Event.ENTER_FRAME, function(e:Event):void
                  {  
                        erase.graphics.beginFill(0xFFFFFF);
                               erase.graphics.drawCircle(mower.x,mower.y,25);
                        erase.graphics.endFill();

                        var mowerdirection = -    (Math.atan2(mouseX-mower.x, mouseY-mower.y))*radiance;
                        mower.rotation = mowerdirection;

                        followMower();

                        var myTestingBitmapData:BitmapData =     new BitmapData(bitmapData.width, bitmapData.height, true, 0x00000000);

                        trace( myTestingBitmapData.compare( bitmap.bitmapData) )

                  });

erase.addEventListener(MouseEvent.CLICK, function(e:Event):void
                    {
                        trace('click');

                    });

function followMower():void 
 {
var dx:int = mower.x - mouseX;
var dy:int = mower.y - mouseY;
mower.x -= dx / 10;
mower.y -= dy /10;
}
Cmaxster
  • 1,035
  • 2
  • 11
  • 18

1 Answers1

0

You can try to use image analysing frameworks or some methods to count colour in an image. There is build in function called histogram that may help you, you can also use solution of this post or under this link

Community
  • 1
  • 1
Lukasz 'Severiaan' Grela
  • 6,078
  • 7
  • 43
  • 79