#include <iostream>
#include "img.h"
#include "imgfunctions.hpp"

using namespace std;
diainput di;

void angled_tiling(int w, int h)
{
      /*
        Mapping for a resize is easy:
        x' = x * (width' / width)
        y' = y * (height' / height)

        Mapping for rotation is only a little bit harder.

        x' = x * cos(a) + y * sin(a)
        y' = y * cos(a) - x * sin(a)

        img.screenH = img.screenH * 5;
        img.screenW = img.screenW * 5;
        imgdata.buffer = imlib_create_image(img.screenW, img.screenH);

        set_buffer();

        imlib_context_set_color(0, 0, 0, 255);
        imlib_image_fill_rectangle(0, 0, img.screenW, img.screenH);
        imlib_context_set_dither(1);
        imlib_context_set_blend(1);
        imgdata.modifier = imlib_create_color_modifier();
        imlib_context_set_color_modifier(imgdata.modifier);
        */
        //set image 1/3 of its orginal size
        int newW = (w/3);
        int newH = (h/3);

        if (newW > img.screenW)
            newW = (img.screenW / 2);

        if (newH > img.screenH)
            newH = (img.screenH / 2);

        //adjust screen width and height so
        //images will cover entire screen


        int left = ( img.screenW - w) / 2;
        int top = (img.screenH - h) /2;
        int y = top;
        int x = left;

        x = x * cos(45) + y * sin(180);
        y = y * cos(45) - x * sin(180);
           std::cout<<"x " <<x<<" y "<<y<<" top "<<top<<" left "<<left<<std::endl;
        for (; left > 0; left -= newW) {}
            for (; top > 0; top -= newH) {}

        for (x = left; x < img.screenW; x += newW)
        {
            for (y = top; y < img.screenH; y += newH)
                imlib_blend_image_onto_image_at_angle (imgdata.image, 0, 0, 0, w, h, x,
                y, newW / space_tile_gap((rand() % 3)), newH / space_tile_gap((rand() % 5)));
        }
        //imlib_blend_image_onto_image
        //imlib_blend_image_onto_image_at_angle

}
void moveItInCircles(int w, int h)
{
        Imlib_Image temp;
        temp = imlib_create_image(img.screenW, img.screenH);
     /*
         x' = x * cos(a) + y * sin(a)
        y' = y * cos(a) - x * sin(a)
        */
        int top = (img.screenH - (int) (h * get_aspect(h))) / 2;
        int left = (img.screenW - (int) (w * get_aspect(h))) / 2;

        di.x = 3;
        top = 50;
        left = 40;
        int y = top;
        int x = left;
        int ww = w / (img.screenW - img.screenH);
        int hh = h / (4);

        int xx = x * cos(100) + y * sin(100);
        int yy = y * cos(150) - x * sin(150);
         std::cout<<"xx " <<xx<<" yy "<<yy<<" top "<<top<<" left "<<left<<std::endl;
        std::cout<<"x " <<x<<" y "<<y<<" top "<<top<<" left "<<left<<std::endl;
        cout<<"dix.x "<<di.x<<endl;
       set_image();
        imgdata.image = imlib_create_rotated_image(36);
       // set_image();
       set_buffer();
      //  set_image();
      //  set_buffer();
        imlib_blend_image_onto_image(imgdata.image,0,0,0,w,h,img.screenW/2,img.screenH/2,350,350); //,-50,180);

      //        imlib_blend_image_onto_image_at_angle(temp,0, 0, 0,w,h,img.screenW/2,img.screenH/2,100,100);
        /*
        imlib_blend_image_onto_image_at_angle(imgdata.image,0,xx,yy,w,h,left,top,ww,hh);
        */
        /* //holding because it works as far as setting the image to screen
        imlib_blend_image_onto_image_at_angle (imgdata.image, 0, 0, 0, w, h, left, top,
                                                get_adjusted_by_aspect(get_aspect(h),w),
                                                get_adjusted_by_aspect(get_aspect(h),h));
        */

}
