function start_drawing()
	pge.gfx.startdrawing()
	pge.gfx.clearscreen()
	IMG_BACK:activate()
	IMG_BACK:draweasy(0,0)
end

function wordwrap(text,font,width)
	lines = 1                                     
	out = ""                                       
	int = ""                                      
  	for word in string.gmatch(text,"%S+") do       
    		if font:measure(int.." "..word) > width then
      			out = out..'\n'                            
     			int = ""                                   
     			lines = lines + 1                         
    		end
  		out = out.." "..word                           
  		int = int.." "..word                           
  	end
  	return out                            
end

function drawcursor(x1,y1,x2,y2,t)
	if cur_lop==2 then
		cur_val=cur_val+10
		if cur_val>254 then
			cur_lop=3
		end
	end	
	if cur_lop==1 then
		cur_val=cur_val-10
		if cur_val<11 then
			cur_lop=2
		end
	end
	if cur_lop==3 then
		cur_lop=1
	end
	if t==1 then
		pge.gfx.drawrect(x1, y1, x2, y2, pge.gfx.createcolor(0,0,255,cur_val))
	elseif t==2 then
		pge.gfx.drawrectoutline(x1, y1,x2, y2, pge.gfx.createcolor(0,0,255,cur_val))
		pge.gfx.drawrectoutline(x1+1, y1+1,x2-2, y2-2, pge.gfx.createcolor(0,0,255,cur_val))
		pge.gfx.drawrectoutline(x1+2, y1+2,x2-4, y2-4, pge.gfx.createcolor(0,0,255,cur_val))		
	end
end

function clsold()
	fl=nil
	sr=nil
	gl=nil
	al=nil
	tl=nil
	ol=nil
	show_group=nil
	collectgarbage("collect")
	cur_selected=1
	fl={}
	sr={}
	gl={}
	al={}	
	tl={}
	ol={}
end

function finis_drawing()
	pge.gfx.enddrawing()
	pge.gfx.swapbuffers()
end

function init_stars()
	pge.math.srand(os.time())
	MYSTA={}
	for K=1,100 do
		MYSTA[K] = {X=pge.math.randint(480,960), Y=pge.math.randint(0,272),S=(pge.math.randint(0,2)+pge.math.randfloat(0,1)),B=pge.math.randint(0,255)}
	end
end

function update_stars()
	for K=1,100 do
		MYSTA[K].X=MYSTA[K].X-MYSTA[K].S
		MYSTA[K].B=MYSTA[K].B-1
		if MYSTA[K].X<=0 then
			MYSTA[K].X=480
			MYSTA[K].Y=pge.math.randint(0,272)

		end
		if MYSTA[K].B<=0 then
			MYSTA[K].B=255
		end
		IMG_STAR:activate()
		IMG_STAR:draweasy(MYSTA[K].X, MYSTA[K].Y, 0, MYSTA[K].B)
	end
end
