/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, {
/******/ 				configurable: false,
/******/ 				enumerable: true,
/******/ 				get: getter
/******/ 			});
/******/ 		}
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 1);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {

module.exports = {"endpoint":""}

/***/ }),
/* 1 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__manager_js__ = __webpack_require__(2);


window.onbeforeunload = function(evt) {
	this.manager.onClose()
   return true;
}

window.setup = () => {

	this.height = 600;
	this.width = 800;
	this.manager = new __WEBPACK_IMPORTED_MODULE_0__manager_js__["a" /* Manager */]();

	angleMode(DEGREES);
	createCanvas(windowWidth, windowHeight);
	frameRate(120);
}

window.draw = () => {

  clear();
  background(51);
  this.manager.draw();
}

window.mouseClicked = () => {

	this.manager.onClick();
}


window.windowResized = () => {
  resizeCanvas(windowWidth, windowHeight);
	this.manager.onRisize()
}


/***/ }),
/* 2 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__circle_js__ = __webpack_require__(3);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__api_js__ = __webpack_require__(5);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__config_json__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__config_json___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2__config_json__);




class Manager {

	constructor() {

		this.circles = {};
		this.api = new __WEBPACK_IMPORTED_MODULE_1__api_js__["a" /* Api */]();
		this.eventSource = new EventSource(__WEBPACK_IMPORTED_MODULE_2__config_json___default.a.endpoint+"/sse");
		this.r = Math.min(windowWidth, windowHeight) / 10;
		this.init();
	}

	init() {

		this.api.fetch('POST', '/api/init', {})
			.then((response) => {
				let data = response.data;
				for (let uuid of Object.keys(data)) {
					let param = data[uuid];
					let x = (param.x * windowWidth) / 100
					let y = (param.y * windowHeight) / 100
					let r = this.r;
					this.circles[uuid] = new __WEBPACK_IMPORTED_MODULE_0__circle_js__["a" /* Circle */](x, y, r, param.color,param)
				}
			})

		this.eventSource.addEventListener('add', (e) => {
			let data = JSON.parse(e.data);
			let x = (data.x * windowWidth) / 100
			let y = (data.y * windowHeight) / 100
			let r = Math.min(windowWidth, windowHeight) / 10;
			let circle = new __WEBPACK_IMPORTED_MODULE_0__circle_js__["a" /* Circle */](x, y, r, data.color);
			this.circles[data.uuid] = circle;
		})

		this.eventSource.addEventListener('delete', (e) => {
			let data = JSON.parse(e.data);
			delete this.circles[data.uuid];
		})
	}

	draw() {

		for(let uuid of Object.keys(this.circles)) {
			let circle = this.circles[uuid];
			circle.draw();
		}
	}

	onRisize() {
		let newCircles = {}
		this.r = Math.min(windowWidth, windowHeight) / 10;
		for(let uuid of Object.keys(this.circles)) {
			let circle = this.circles[uuid];
			let x = (circle.data.x * windowWidth) / 100
			let y = (circle.data.y * windowHeight) / 100
			let r = this.r;
			newCircles[uuid] = new __WEBPACK_IMPORTED_MODULE_0__circle_js__["a" /* Circle */](x, y, r, circle.data.color, circle.data)
		}
		this.circles = newCircles;
	}

	onClose() {
		this.eventSource.close();
		this.api.fetch('DELETE', '/sse', {})
	}

	onClick() {

		let create = true;

		for(let uuid of Object.keys(this.circles)) {
			let circle = this.circles[uuid];
			let d = dist(mouseX, mouseY, circle.x, circle.y);
		  if (d < this.r && circle.status) {

				circle.status = false;

				this.api.fetch('POST', '/api/delete', {
					uuid : uuid
				}).then((data) => {
					setTimeout(() => {
						circle.status = true;
					}, 200)

				})
				create = false;

		  }
		}

		if (create) {

			let circle = new __WEBPACK_IMPORTED_MODULE_0__circle_js__["a" /* Circle */](mouseX, mouseY);

			this.api.fetch('POST', '/api/add', {
				x : (100*circle.x)/windowWidth,
				y : (100*circle.y)/windowHeight,
				color : circle.color.levels
			})
		}

	}
}
/* harmony export (immutable) */ __webpack_exports__["a"] = Manager;



/***/ }),
/* 3 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__utils__ = __webpack_require__(4);


class Circle {

	constructor(x, y, r, col = [], data = {}) {

		this.x = x;
		this.y = y;
		this.r = r;
		this.status = true;
		this.data = data;

		let red = col[0] || Object(__WEBPACK_IMPORTED_MODULE_0__utils__["a" /* getRandomInt */])(0, 255);
		let green = col[1] || Object(__WEBPACK_IMPORTED_MODULE_0__utils__["a" /* getRandomInt */])(0, 255);
		let blue = col[2] || Object(__WEBPACK_IMPORTED_MODULE_0__utils__["a" /* getRandomInt */])(0, 255);

		this.color = color(red, green, blue);
	}

	draw () {

		fill(this.color);
		ellipse(this.x, this.y, this.r, this.r);
	}
}
/* harmony export (immutable) */ __webpack_exports__["a"] = Circle;



/***/ }),
/* 4 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
/* harmony export (immutable) */ __webpack_exports__["a"] = getRandomInt;
function getRandomInt(min, max) {

	return Math.round(Math.random() * (max - min) + min);
}

/***/ }),
/* 5 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__config_json__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__config_json___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__config_json__);


class Api {

	fetch(method, url, param) {

		let options = {
			method : method,
			mode : 'cors',
			body : JSON.stringify(param),
			headers: {
				'Accept': 'application/json',
				'Content-Type': 'application/json'
			}

		};

		let request = new Request(__WEBPACK_IMPORTED_MODULE_0__config_json___default.a.endpoint+url, options);

		return new Promise((resolve, reject) => {
			fetch(request)
			.then(
				(response) => {
					return response.json().then((data)=>{
						resolve(data)
					});
				}
			)
		})
	}
}
/* harmony export (immutable) */ __webpack_exports__["a"] = Api;



/***/ })
/******/ ]);