alexthescott.bad marble

-- bad marble
-- alexthescott
-- 21/1/19

-- scholastic green
p1={[0]=129,131,138}
-- icky thump red
p2={[0]=1,8,7}
-- gameboy green
p3={[0]=138,135,139}
-- vein red
p4={[0]=130,2,136}
-- marble velvet
p5={[0]=141,13,6}
-- moonlit blue
p6={[0]=0,129,13}
-- mild acid green
p7={[0]=131,3,139}
-- sunkist orange
p8={[0]=135,137,10}

-- new seed every day of the year 
srand(31*stat(81)+stat(82)) 

p={p1,p2,p3,p4,p5,p6,p7,p8}
c=rnd(p)
pal(c,1)

s=rnd(-1)
fc=0
fm=4096

var1=rnd()
var2=rnd()
srand(s)

function bad_square_burn()
	for i=1,34 do
		x=(rnd(16)\1)*8
		y=(rnd(16)\1)*8
		if x!=0 and x!=120 then
			x+=(rnd(min(x,128-x,4))\1)-2
		end
		if y!=0 and y!=120 then
			y+=(rnd(min(y,128-y,4))\1)-2
		end
		
		for i=1,20 do
			rx=x+rnd(8)\1
			ry=y+rnd(8)\1
			v=get_score(rx,ry)
			pset(rx,ry,v)
		end
	end
end	

function good_square_burn()
	for i=1,34 do
		x=(rnd(16)\1)*8
		y=(rnd(16)\1)*8
		
		for i=1,20 do
			rx=x+rnd(8)\1
			ry=y+rnd(8)\1
			v=get_score(rx,ry)
			pset(rx,ry,v)
		end
	end
end

function good_byte_square()
	for i=1,14 do
		x=(rnd(16)\1)*8
		y=(rnd(16)\1)*8
		for rx=x,x+7 do
			for ry=y,y+7 do
				v=get_score(rx,ry)
				pset(rx,ry,v)
			end
		end
	end
end

function perfect_byte_square()
	for i=1,14 do
		x=(rnd(16)\1)*8
		y=(rnd(16)\1)*8
		if x!=0 and x!=120 then
			x+=(rnd(min(x,128-x,4))\1)-2
		end
		if y!=0 and y!=120 then
			y+=(rnd(min(y,128-y,4))\1)-2
		end
		
		for rx=x,x+7 do
			for ry=y,y+7 do
				v=get_score(rx,ry)
				pset(rx,ry,v)
			end
		end
	end
end

function perfect_scan()
	for i=1,7 do
		p=-1+rnd(129)
		for y=p,p+1 do
			for x=p%2,127,2 do
				v=get_score(x,y)
				pset(x,y,v)
			end
		end
	end
end

ripple_amp=32*var2
function get_score(x,y)
	v=1
	t=fc/fm
	v1=(1+cos(var1+y/128))/2
	v2=(1+sin(t+(var1+x/512)))/2
	v3=(1+cos(v1*v2+t^2))/2
	v4=(1+sin(v1+v2-t))/2
	v+=(x/ripple_amp*(v2+v2+v3+v4))
	if(v%3<1 and ((x%4==0 and y%2==0) or (x%4==1 and y%2==1)))v+=1
	return v%3
end

vard=rnd(5)\1
cls(1)
_set_fps(60)


month=stat(81)
day=stat(82)

cls(1)
::♥::
if time()<2 then
	print("bad marble",44,59,2)
	print(month.."/"..day,55,65)
else
	if vard==0 then
		perfect_scan()
	elseif vard==1 then
	 good_square_burn()
	elseif vard==2 then
	 perfect_byte_square()
	elseif vard==3 then
	 good_byte_square()
	elseif vard==4 then
	 bad_square_burn()
	end
	fc+=1
	
	if fc>=fm then
		fc=0
		srand(s)
	end
	
	for i=0,fc/fm*128,1 do
		if i%2==0 then
			pset(0,i,1)
		else
			pset(1,i,1)
		end
	end
end
flip()
goto ♥