import numpy as np
import random as rand
import matplotlib.pyplot as plt

def generateMany(vector):
	#receive a list of encoded data in form of [[center],distance,size] and return the datapoints in a single array result
	for line in vector:
		if 'result' not in locals():
			result = generateOne(line[0], line[1], line[2])
		else:
			result = np.concatenate((result, generateOne(line[0], line[1], line[2])),axis = 0)
	return result

def generateOne(center, distance, size):
	#generate single square cluster at position center, distance is width, size is number of points
	x = np.random.uniform(center[0], center[0]+distance, size)
	y = np.random.uniform(center[1], center[1]+distance, size)
	total = [[x,y] for x, y in zip(x,y)]
	return total

def generateLine(points, intercept, gradient):
	#generate a list of points with gradient and intercept of a straight line as above
	x = 2*np.random.rand(points)
	y = [intercept+gradient*i+4*np.random.rand()-2 for i in x]
	data = [list(a) for a in zip(x, y)]
	return data

def plotLine(intercept, gradient):
	#plot a line with given intercept and gradient
	x = np.linspace(0,2,10)
	y = [gradient*j + intercept for j in x]
	plt.plot(x,y,'-r')