<commit_before>from PIL import Image
from math import sqrt
import os.path

def clamp(a, x, b):
	if (x < a):
		return a
	if (x > b):
		return b
	return x

def get_tuple(line):
	temp = "".join(line.split(" ")).split(",")
	assert(len(temp) == 3)
	temp[0] = float(temp[0])
	temp[1] = float(temp[1])
	temp[2] = float(temp[2])
	return tuple(temp)

def gen_data(frame):
	fname = str(frame)
	while (len(fname) < 4):
		fname = "0" + fname
	fname = "data/" + fname + ".txt"
	return fname

def gen_image(frame):
	fname = str(frame)
	while (len(fname) < 4):
		fname = "0" + fname
	fname = "img/" + fname + ".png"
	return fname
	
def render(frame, size):
	try:
		data = open(gen_data(frame), 'r')
	except:
		return False
	im = Image.new("RGB", (size, size))
	pix = im.load()
	for line in data:
		temp = get_tuple(line)
		x = clamp(0, int(temp[0] + size/2), size - 1)
		y = clamp(0, int(temp[1] + size/2), size - 1)
		pix[x, y] = (255, 255, 255)
	print("Saving " + gen_image(frame))
	im.save(gen_image(frame))
	return True
	
def render_iso(frame, size):
	if (os.path.isfile(gen_image(frame))):
		return True
	try:
		data = open(gen_data(frame), 'r')
	except:
		return False
	im = Image.new("RGB", (size * 2, size * 2))
	pix = im.load()
	for line in data:
		temp = get_tuple(line)
		x = clamp(0, int((sqrt(3) / 2.0) * (temp[0] - temp[1]) + size), (size * 2) - 1)
		y = clamp(0, int((-0.5) * (temp[0] + temp[1] + 2 * temp[2]) + size), (size * 2) - 1)
		pix[x, y] = (255, 255, 255)
	print("Saving " + gen_image(frame))
	im.save(gen_image(frame))
	return True
	
frame = 0
size = 1024
while (render_iso(frame, size)):
	frame += 1<commit_msg>Added psudo-transparancy support to draw<commit_after>from PIL import Image
from math import sqrt
import os.path

def clamp(a, x, b):
	if (x < a):
		return a
	if (x > b):
		return b
	return x

def get_tuple(line):
	temp = "".join(line.split(" ")).split(",")
	assert(len(temp) == 3)
	temp[0] = float(temp[0])
	temp[1] = float(temp[1])
	temp[2] = float(temp[2])
	return tuple(temp)

def inc_tuple(tup, inc):
	return (clamp(0, tup[0] + inc, 255), clamp(0, tup[1] + inc, 255), clamp(0, tup[2] + inc, 255))

def gen_data(frame):
	fname = str(frame)
	while (len(fname) < 4):
		fname = "0" + fname
	fname = "data/" + fname + ".txt"
	return fname

def gen_image(frame):
	fname = str(frame)
	while (len(fname) < 4):
		fname = "0" + fname
	fname = "img/" + fname + ".png"
	return fname
	
def render(frame, size, inc):
	try:
		data = open(gen_data(frame), 'r')
	except:
		return False
	im = Image.new("RGB", (size, size))
	pix = im.load()
	i = 0
	for line in data:
		temp = get_tuple(line)
		x = clamp(0, int(temp[0] + size/2), size - 1)
		y = clamp(0, int(temp[1] + size/2), size - 1)
		pix[x, y] = inc_tuple(pix[x, y], inc)
	print("Saving " + gen_image(frame))
	im.save(gen_image(frame))
	return True
	
def render_iso(frame, size, inc):
	if (os.path.isfile(gen_image(frame))):
		return True
	try:
		data = open(gen_data(frame), 'r')
	except:
		return False
	im = Image.new("RGB", (size * 2, size * 2))
	pix = im.load()
	i = 0
	for line in data:
		temp = get_tuple(line)
		x = clamp(0, int((sqrt(3) / 2.0) * (temp[0] - temp[1]) + size), (size * 2) - 1)
		y = clamp(0, int((-0.5) * (temp[0] + temp[1] + 2 * temp[2]) + size), (size * 2) - 1)
		pix[x, y] = inc_tuple(pix[x, y], inc)
	print("Saving " + gen_image(frame))
	im.save(gen_image(frame))
	return True
	
frame = 0
size = 1024
inc = 2
while (render_iso(frame, size, inc)):
	frame += 1
{'fraction_non_alphanumeric': 0.19652173913043477, 'fraction_numerical': 0.035942028985507246, 'mean_word_length': 3.6446837146702555, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1242123', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1490, 'n_words': 398}