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

output = {
	resolution = { width = 160, height=200 },
	output_type = 1, -- c64 image type
	aspect = 1,
	-- 0=charset, 1 = multicolor image 
	c64_imageType = 0,
	dither = 2,
	-- 160x200 multicolor
	c64_multicolor=1,
	-- dither strength plus modulo. only works for dither type 2
	ditherStrength = { x=30, y= 1, z=1}, 
	index_colors = { 0,6,4,1 }
}



Material1 = {
	color = { x=0.7, y=0.7, z=0.7 },
	reflection = 0.1,
	shininess = 100,
	shininess_intensity = 1
}

Material2 = {
	color = { x=0.7, y=0.7, z=0.7 },
	reflection = 0.0,
	shininess = 100,
	shininess_intensity = 1
}


frame = 0
-- Total number of frames
noFrames = 16


-- Text to display
text = "TRSE"
charname = "char"

-- Init is called on start  


function Init()

	AddObject("torus","torus1","","Material2",  0,0,0,  15, 0.5,0);


	radius = 10
	dx = 6
	x = -dx*(string.len(text)-1)/2
	-- Generate text
	for i=1, string.len(text) do

		-- Character set to use. Can also be a charset file (flf/bin) located in the project dir
		font ="rom"
		c = string.sub(text,i,i+1)
		char = string.byte(c)-65

		AddObject("char", charname .. tostring(i), "", "Material1",  font, char+1,   
			0,0,x,          -- position
			0.6,1,0.5,      -- width xyz 
			0.550,0.6,0.31  -- stretch xyz
		);          
       	x=x+dx

	end

	UpdateGraphics()

end

function UpdateGraphics()

  	t = ((frame+24)/noFrames)*360
	SetRotation("torus1",-40+t/2,0,10);

	-- Rotate text

	for i=1, string.len(text) do

		SetRotation(charname .. tostring(i), 0,0,t/2);


	end


end

function Update()

	compression = 8
	maxchars = 64

	CompressCharset(0,40,0,25,  compression, maxchars)
	if (frame==0) then Message("Please wait...") end
	frame=frame+1
	if (frame == noFrames) then 
			Message("Files written to data/example4_bin. You can now close this window")
			SaveScreenAndCharset("data/example4_screendata.bin", "data/example4_chardata.bin");
	end

	UpdateGraphics()

end
