tidbyt/pixlet

API weirdness

DevArctic opened this issue · 0 comments

Personally guys, I think your choice of Starlark as the way to draw stuff was a bad one. I have a lot of fun drawing images in python but without the extensive libraries and such, I'm ending up writing a lot of weird stuff just to get it working.

I realized I don't have to use your render, I can just render stuff with a different program and push to it with Pixlet, but I keep running into an issue where the stuff I push gets rejected for being too large ( with nothing about size requirements, frame requirements, anything, just "this image is too large" ) OR the stuff I push doesn't show up at all, despite Pixlet not throwing an error. I'm guessing that that might be due to some sort of funniness with colors or something, but the tidbyt can run webps from my iphone without a hiccup, it's only when I push the image to the device that it can't do it.

And anyways, I like the device and all, but it's not super "hackable." There seems to be a lot going on that I don't fully understand and isn't documented.

But here's a sample of the stuff I wrote in Skylark. Like I said, weird.

load("math.star", "math")

def pix(col):
	return render.Box(width=1,height=1,color=col)	

def splitHex(col):
	bones = col % 16
	mones = col // 16
	btens = mones % 16
	mtens = mones // 16
	gones = mtens % 16
	mhuns = mtens // 16
	gtens = mhuns % 16
	mthos = mhuns // 16
	rones = mthos % 16
	mtths = mthos // 16
	rtens = mtths % 16
	red = (rtens*16) + rones
	green = (gtens*16) + gones
	blue = (btens*16) + bones
	return (red,green,blue)

def three_dimensional_line(start, end, frames):
	""" ...between two points within a three-dimensional space. """
	startx, starty, startz = start
	endx, endy, endz = end
	dx = endx - startx
	dy = endy - starty
	dz = endz - startz
	print (dx,dy,dz)
	ix = dx/frames
	iy = dy/frames
	iz = dz/frames
	track = []
	for frame in range(frames):
		stepx = startx + (ix * frame)
		stepy = starty + (iy * frame)
		stepz = startz + (iz * frame)
		track.append(
			(int(math.round(stepx)),
			int(math.round(stepy)),
			int(math.round(stepz))))
	return track
	
	
def oneDimLine(start, end, frames):
	start = start
	end = end
	i = (end - start)//frames
	track = []
	for x in range(frames):
		step = start + (i * x)
		track.append(step)
	return track
	
def hex(int):
	digits = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']
	ones = int % 16
	hexs = int // 16
	return str(digits[hexs]) + str(digits[ones])
	
def hex3(tuple):
	r, g, b = tuple
	return "#" + hex(r) + hex(g) + hex(b)
	
def gradientH(col1,col2):
	line = three_dimensional_line(splitHex(col1),splitHex(col2),64)
	return render.Column(
		children = [render.Row(
			children = [pix(hex3(line[x])) for x in range(64)])
				for j in range(32)]
			)
			
def gradientV(col1,col2):
	line = three_dimensional_line(splitHex(col1),splitHex(col2),32)
	return render.Row(
		children = [render.Column(
			children = [pix(hex3(line[x])) for x in range(32)])
				for j in range(64)]
			)

def rowFromTrack(track, offset):
	return render.Row(
		children = [pix(hex3(track[x+offset])) for x in range(64)])



def rollingGradientH(col1,col2):
	line = three_dimensional_line(splitHex(col1),splitHex(col2),64)
	liner = line[::-1]
	final = line + liner + line
	return render.Animation(
		children = [render.Column(
			children = [rowFromTrack(final,o) for x in range(32)])
				for o in range(128)]
			)


load("render.star", "render")
def main():
    return render.Root(
		rollingGradientH(0x991850,0x00367c)
        )