globals = {

	-- camera will be overwritten, so no worry there
	
 	camera = { x = 12, y=0, z=0 },
     fov = 50,
     
     -- target: look at center
     
	target = { x = 0, y=0.0, z=0 },
	
	-- light will be changed for each frame
	light0 = {   	direction = {x=1, y=0.8, z=-0.2 }, 
				color = {x=1, y=1, z=1}, 
			},
	-- add some ambient background colors
	ambient = { x = 0.6, y = 0.4, z = 0.4 },
     raymarch_steps = 30,
     
     -- define the "up" vector
     
 	up = { x = 0, y=1, z=0 },
	raymarch_shadow_steps = 4,
	sky = 0,
	shadow_scale = 0.5,
	isPaused = 0
	
}

output = {
	-- resolution equals 1 multicolor sprite (12x21 pixles)
	
	resolution = { width = 12*4, height=21*3},
-- to view the scene properly, render with higher resolution
--	resolution = { width = 128, height=128},
	
	-- Allow for dithering (2)	
	dither = 2,
	-- set dither strength 30
	ditherStrength= {x=20, y=1, z=1},
	
	-- Enable c64 output
	output_type = 1, -- c64 image type
     aspect = 1,
     -- Set character set
	c64_imageType = 0, -- 0 = character set (4 colors, compressable), 1 = multicolor image 
	c64_multicolor = 1,
	-- Define the 4 colors (black, purple, white, blue)
--	index_colors = { 0,4,1,6 }
	index_colors = { 0,1,6,4 }

}

-- Two materials in this scene: a regular one and a black one
Material0 = {
   color = { x=1, y=1.0, z=1 },
	reflection = 0.5,
	shininess = 50,
	shininess_intensity = 0.7, 
	checkerboard = 0,
	checkerboard_color = { x=1, y=1, z=0.2}

}

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


frame = 0
-- 128 frames * 64 bytes per sprite = $2000 bytes of raw data
noFrames = 16
hasSaved = 0

function Init()
	-- Create a box with a smaller box surround it
	s = 1.2
--	AddObject("box","object1","","Material0",0,0,0,3.3*s,30.3*s,3.3*s);
	AddObject("torus","object1","","Material0",0,0,0,3.3*s,1.3*s,0);
	--AddObject("box","object2","","Material0",0,0,0,3.3,30.3,3.3);
	--AddObject("torus","object1","","Material0",0,0,0,3.3,1.9,3.3);
--	AddObject("box","object2","","MaterialBlack",0,0,0,3.5,0.6,3.5);
--	AddObject("box","object2","","Material0",0,0,0,3.5,3.5,1.4);

--	AddObject("torus","object1","","Material0",0,0,0,4,1.5,3);
	
	UpdateScene()
	Message("Rendering.. please wait")
end



function UpdateScene()
	
  	t = ((frame)/noFrames)
	-- Convert from (0,1) -> angles (0,360)
	j=t*360/2
	-- Rotate both objects
	SetRotation("object1",j,j,90+j) --box
--	SetRotation("object2",0,j+45,0) --box
	--SetRotation("object2",20,j+90,j) --box
--	SetUVShift("object1",t*0.5,t*0.5);


end


function Update()
	-- For each frame, add a new 64 byte sprite to the internal buffer	
	if (hasSaved == 0) then 
		for y =0,2 do
		for x = 0, 3 do
		-- Add raw data starting at (0,0) to bytes (3,21) = 3*21=63 bytes of data (size of a sprite)
		AddC64LineToData(x*3,y*21,3,21)
		AddC64LineToData(0,0,1,1) -- add a random single byte to fill up to 64 bytes
		end
		end
	end
	-- increase frame count
	frame=frame+1
	-- if final frame has been reached
	if (frame==noFrames) then 
		hasSaved = 1
		
		-- save the noFrames*48 bytes of data as raw data
		SaveRawData("drunk_santa/xmassprite.bin");
		
		Message("You can now close this window.")
		
	end	

		-- Update scene again
	UpdateScene()

end
