#include "util.h"

namespace util{
	float random(float range){
		return float(rand())/RAND_MAX*range;
	}
	void ApplyMatrixEffect(PixelGameEngine*pge,Renderable&r,Renderable&originalImg,std::unique_ptr<Renderable>&matrixImg){
		pge->SetDrawTarget(r.Sprite());
		pge->Clear(BLANK);
		for(int y=0;y<r.Sprite()->height;y++){
			for(int x=0;x<r.Sprite()->width;x++){
				Pixel col=originalImg.Sprite()->GetPixel(x,y);
				if(col==WHITE){
					pge->Draw({x,y},matrixImg->Sprite()->GetPixel(x,y));
				} else {
					pge->Draw({x,y},originalImg.Sprite()->GetPixel(x,y));
				}
			}
		}
		pge->SetDrawTarget(nullptr);
		r.Decal()->Update();
	};
}