globals = {
 	camera = { x = 0, y=0, z=3.6 },
     fov = 40,
	target = { x = 0, y=0.0, z=0 },
	light0 = {   	direction = {x=-0.0, y=0, z=1 }, 
				color = {x=1, y=1, z=1}, 
			},
	ambient = { x = 0.0, y = 0.0, z = 0.0 },
    raymarch_steps = 30,
	raymarch_shadow_steps = 4,
	up = {x=0, y=1, z=0 },
	sky = 0,
	shadow_scale = 1,
	isPaused = 0
	
}


scale = 8


-- 10*24
output = {
	resolution = { width = 320, height=256},
--	resolution = { width = 320, height=200},
	aspect = 1.0,
	output_type = 3,
	c64_imageType = 0,
	c64_multicolor=0,
	dither = 0,
	ditherStrength = { x = 10, y= 1, z= 1},

--	c64_colors = { 0,5,14,6 }
	index_colors = { 0,1 }
}

ll = 1.0


MaterialBlue1 = {
   color = { x=ll, y=ll, z=ll },
	reflection = 0.0,
	shininess = 50,
	shininess_intensity = 0 ,
	uv_scale= {x=0.5, y=0.5, z=0.5},
	light_type = 0,
	uv_shift = {x=1, y=1, z=1},
	texture = "images/p.png"
}

MaterialBlue2 = {
   color = { x=ll, y=ll, z=ll },
	reflection = 0.0,
	shininess = 50,
	shininess_intensity = 0 ,
	uv_scale= {x=0.5, y=0.5, z=0.5},
	light_type = 0,
	uv_shift = {x=1, y=1, z=1},
	texture = "images/R.png"
}


MaterialBlue3 = {
   color = { x=ll, y=ll, z=ll },
	reflection = 0.0,
	shininess = 50,
	shininess_intensity = 0 ,
	uv_scale= {x=0.5, y=0.5, z=0.5},
	light_type = 0,
	uv_shift = {x=1, y=1, z=1},
	texture = "images/x.png"
}




MaterialBlack = {
   color = { x=0, y=0.0, z=0 },
	reflection = 0.5,
	shininess = 50,
	shininess_intensity = 0 
}




-- Init is called on start  
 

N = 6
distance = 10
frame = 0
--noFrames = 24
noFrames = 8
char = 0
curSave = 1

hasSaved = 0

count = 3

cur = 0

charname = "char"
	n = "box"

function Init()
--	AddObject("torus",n,"","MaterialBlue",0,0,0, 1,1,1);
	ClearAllObjects()
--	AddObject("box",n,"","MaterialBlue"..tostring(cur+1),0,0,0, 1,1,1);
--	AddObject("sphere",n,"","MaterialBlue"..tostring(cur+1),0,0,0, 1.5,0.9,1);



	UpdateScene()

end



function UpdateScene()
    t = frame/(noFrames-1)*90.0;
--    if (cur==0 or cur==2) then
	
--	end
  --  if (cur==1) then
	--SetRotation(n,180,0,t)
   
	--end;
end

function PostProcess()
	t = frame/noFrames*3.14159/4.5
--	DrawCircle(output.resolution.width/2,output.resolution.height/2,t,t,255,255,255); 
	for y=0, output.resolution.height do
		for x=0, output.resolution.width do
			dx = x-output.resolution.width/2
			dy = y-output.resolution.height/2
			s = math.sqrt(dx*dx + dy*dy);
			a = math.atan2(dx,dy) + t;
--			a = (a+s/10.0)*100
			v = a*365.0+s*16.0
			v = math.floor(v)%255
			
			if (v<128) then v=0 end;
--			v = v+ (80-s)
			if (v>255) then v= 255; end
--			if (s<120) then
				DrawLine(x,y,x,y,v,v,v);	
--			end
		end
	end
end


function Update()
	

	if (frame>=1) then
--		CompressCharset(0,40,0,25,  3, 256)
-- add in binary form



--		for y = 0, output.resolution.height-1 do
--		for x = 0, output.resolution.width/scale-1 do
	--			AddC64LineToData(x,y*8+yy,1,1)
		    AddAmigaBitplaneToData(0,0, output.resolution.width/8, output.resolution.height,1);
--		end
--		end
	
	end

--	if (frame==noFrames/4 or frame==(noFrames/4)*2 or frame==(noFrames/4)*3 or frame==noFrames) then 
	if (frame==noFrames and cur<=2) then 
		if (cur==0) then SaveRawData("data/bpl_spiral.bin"); end;
	--	OptimizeScreenAndCharset(40,25,256, 1);
	--	SaveScreenAndCharset("data/screen"..tostring(cur)..".bin", "data/charset"..tostring(cur)..".bin");
		cur = cur+1
		Message("SAVED")
		frame = 0
		if (cur<3) then
			Init()
		end
	end	
	---if (frame<noFrames) then
		UpdateScene()
--	end


	frame=frame+1
	


end
