`%ProjectTitle%
`======================
`%Author%
`======================
`Main Source File
sync on
sync rate 0
autocam off
 
#constant helpObj = 1000
#constant helpMesh = 10
`#constant dfactor = 100.0
 
#constant sqrWidth = 5
#constant sqrHeight = 5
#constant sqrWidFact = -10
#constant sqrHeiFact = -15
 
#constant numSpace = 5
#constant minFade = 30.0
 
#constant numNumbers = 8
 
position camera -100,100,400
point camera 0,0,0
 
color backdrop 0
 
type Vertex
	xpos as float
	ypos as float
	xto as float
	yto as float
endtype
 
type NumberType
	curNumber as integer
	maxSpd as float
	minSpd as float
	thresh as float
	dfactor as float
	fade as float
endtype
 
global timeStart as integer
 
calibrateTimer()
 
global dim NumVertex(numNumbers,sqrWidth*sqrHeight*6) as Vertex
global dim Numbers(numNumbers) as NumberType
 
for n = 1 to numNumbers
	makeNumber(n, n, 0, (n-(numNumbers/2)) * (sqrWidFact*-1*sqrWidth+numSpace)-sqrWidFact/2, 0, 0)
	if (n-1) mod 3 = 2
		setNumber(n, 99)
	else
		setNumber(n, (n-1) mod 10)
	endif
	ghost object on n
	set object wireframe n, 1
next n
 
if numNumbers > 8
	restore numberData
else
	restore numberDataSeconds
endif
for n = 1 to numNumbers
	read Numbers(n).curNumber
	read Numbers(n).maxSpd
	read Numbers(n).minSpd
	read Numbers(n).thresh
	read Numbers(n).dfactor
	Numbers(n).fade = 100
next n
 
`--------------------------------------------------
`############# enter main loop  ###################
`--------------------------------------------------
 
do
	updateNumberTime()
 
	for n = 1 to numNumbers
		updateNumber(n, n, 0)
		setNumber(n, Numbers(n).curNumber)
	next n
 
	text 10,10,"updating numbers... (FPS: " + str$(screen fps()) + ")"
	text 10,25,"Current Time: " + getTimeStr()
	set cursor 10,40
 
	sync
 
loop
 
function updateNumberTime()
	local tmp as string
	tmp = getTimeStr()
	for n = 1 to numNumbers
		if (n-1) mod 3 = 2
			setNumber(n, 99)
		else
			lastNum = Numbers(n).curNumber
			Numbers(n).curNumber = val(mid$(tmp, numNumbers-n+1))
		endif
 
		`do a lil fadin
		if lastNum <> Numbers(n).curNumber
			Numbers(n).fade = 100.0
		else
			`if  Numbers(n).fade > minFade then dec Numbers(n).fade, ((numNumbers-n)-int((n-1)/3))/600.0
			if int((n-1)/3) = 0
				if  Numbers(n).fade > minFade then dec Numbers(n).fade, 0.02
			else
				if int((n-1)/3) = 1
					if  Numbers(n).fade > minFade then dec Numbers(n).fade, 0.002
				else
					if  Numbers(n).fade > minFade then dec Numbers(n).fade, 0.0002
				endif
			endif
		endif
 
		if  Numbers(n).fade < minFade then Numbers(n).fade = minFade
 
		fade object n, Numbers(n).fade
 
	next n
endfunction
 
function getTimeStr()
	local rtrn as string
	rtrn = get time$() + ":" + getMilliSecondsStr()
endfunction rtrn
 
function getMilliSecondsStr()
	local rtrn as string
	rtrn = str$(getMilliTime()/10 mod 100)
	if len(rtrn) < 2 then rtrn = "0" + rtrn
	if len(rtrn) < 2 then rtrn = "0" + rtrn
endfunction rtrn
 
function getMilliTime()
	local rtrn as integer
	rtrn = (timer() - timeStart)
endfunction rtrn
 
function calibrateTimer()
	local time as integer
	local lastTime as integer
	repeat
		lastTime = time
		time = val(right$(get time$(), 1))
	until lastTime <> time
 
	timeStart = timer()
endfunction
 
function updateNumber(objNum, index, zpos)
	local dist as float
 
	local x as float
	local y as float
 
	lock vertexdata for limb objNum,0,1
 
	for n = 0 to sqrWidth*sqrHeight * 6
		if abs(NumVertex(index,n).xpos - NumVertex(index,n).xto) > Numbers(index).thresh or abs(NumVertex(index,n).ypos - NumVertex(index,n).yto) > Numbers(index).thresh
 
			dist = sqrt((NumVertex(index,n).xpos - NumVertex(index,n).xto)^2 + (NumVertex(index,n).ypos - NumVertex(index,n).yto)^2)
 
	 		if dist < Numbers(index).minSpd then dist = Numbers(index).minSpd
	 		if dist > Numbers(index).maxSpd then dist = Numbers(index).maxSpd
 
	 		x = -1*(NumVertex(index,n).xpos - NumVertex(index,n).xto)/dist/Numbers(index).dfactor
	 		y = -1*(NumVertex(index,n).ypos - NumVertex(index,n).yto)/dist/Numbers(index).dfactor
 
	 		NumVertex(index,n).xpos = NumVertex(index,n).xpos + x
	 		NumVertex(index,n).ypos = NumVertex(index,n).ypos + y
		endif
 
		if abs(NumVertex(index,n).xpos - NumVertex(index,n).xto) <= Numbers(index).thresh then NumVertex(index,n).xpos = NumVertex(index,n).xto
	 	if abs(NumVertex(index,n).ypos - NumVertex(index,n).yto) <= Numbers(index).thresh then NumVertex(index,n).ypos = NumVertex(index,n).yto
 
 
		set vertexdata position n, NumVertex(index,n).xpos, NumVertex(index,n).ypos, zpos
	next n
 
	unlock vertexdata
endfunction
 
function makeNumber(objNum, index, image, posx, posy, posz)
	make object plain helpObj,abs(sqrWidFact),abs(sqrHeiFact)
	rotate limb helpObj,0,0,0,0
	make mesh from object helpMesh,helpObj
	delete object helpObj
 
	make object helpObj, helpMesh, image
 
	limbNum = 1
 
	for x = 0 to sqrWidth-1
		for y = 0 to sqrHeight-1
			if y = 0 and x = 0 : else
				add limb helpObj,limbNum,helpMesh
				offset limb helpObj,limbNum,x*sqrWidFact,y*sqrHeiFact,0
				inc limbNum
				sync
				`wait 10
			endif
		next y
	next x
 
	delete mesh helpMesh
	make mesh from object helpMesh, helpObj
	make object objNum, helpMesh, image
	delete object helpObj
 
 
	set object wireframe objNum, 1
	set object cull objNum, 0
	position object objNum, posx, posy, posz
 
	`loop through the vertexes
	lock vertexdata for limb objNum,0,1
 
	for n = 0 to sqrWidth*sqrHeight * 6
		x#=get vertexdata position x(n)
 		y#=get vertexdata position y(n)
 		NumVertex(index,n).xpos = x#+sqrWidFact/2
 		NumVertex(index,n).ypos = y#+sqrHeiFact/2
 		NumVertex(index,n).xto = x#
 		NumVertex(index,n).yto = y#
 
 		set vertexdata diffuse n, rgb(rnd(255),rnd(255),rnd(255))
 
 		set vertexdata position n, NumVertex(index,n).xpos, NumVertex(index,n).ypos, 0
	next n
 
	`unlock the vertex data now that we are done reading it
	unlock vertexdata
 
	organize(index)
endfunction
 
function setNumber(index, number)
	local tmp as integer
	local poly as integer
	select number
		case 0
			restore number0
		endcase
		case 1
			restore number1
		endcase
		case 2
			restore number2
		endcase
		case 3
			restore number3
		endcase
		case 4
			restore number4
		endcase
		case 5
			restore number5
		endcase
		case 6
			restore number6
		endcase
		case 7
			restore number7
		endcase
		case 8
			restore number8
		endcase
		case 9
			restore number9
		endcase
		case 99
			restore numberSYM
		endcase
	endselect
 
	poly = 0
	for y = 0 to sqrHeight - 1
		for x = 0 to sqrWidth - 1
			read tmp
			select tmp
				case 7
					shapeVRT(index, poly, x*sqrWidFact, y*sqrHeiFact)
				endcase
				case 6
					shapeVLF(index, poly, x*sqrWidFact, y*sqrHeiFact)
				endcase
				case 5
					shapeTRI4(index, poly, x*sqrWidFact, y*sqrHeiFact)
				endcase
				case 4
					shapeTRI3(index, poly, x*sqrWidFact, y*sqrHeiFact)
				endcase
				case 3
					shapeTRI2(index, poly, x*sqrWidFact, y*sqrHeiFact)
				endcase
				case 2
					shapeTRI1(index, poly, x*sqrWidFact, y*sqrHeiFact)
				endcase
				case 1
					shapeSQR(index, poly, x*sqrWidFact, y*sqrHeiFact)
				endcase
				case 0
					shapeNON(index, poly, x*sqrWidFact, y*sqrHeiFact)
				endcase
			endselect
			inc poly, 6
		next x
	next y
endfunction
 
`organize the plains....
function organize(index)
	local poly as integer
	poly = 0
	for y = 0 to sqrHeight-1
		for x = 0 to sqrWidth-1
			`triangle 1
			NumVertex(index,poly+0).xpos = 0         +x*sqrWidFact
			NumVertex(index,poly+0).ypos = 0         +y*sqrHeiFact
 
			NumVertex(index,poly+1).xpos = sqrWidFact+x*sqrWidFact
			NumVertex(index,poly+1).ypos = 0         +y*sqrHeiFact
 
			NumVertex(index,poly+2).xpos = 0         +x*sqrWidFact       
			NumVertex(index,poly+2).ypos = sqrHeiFact+y*sqrHeiFact
 
			`triangle 2
			NumVertex(index,poly+3).xpos = sqrWidFact+x*sqrWidFact   
			NumVertex(index,poly+3).ypos = 0         +y*sqrHeiFact
 
			NumVertex(index,poly+4).xpos = sqrWidFact+x*sqrWidFact
			NumVertex(index,poly+4).ypos = sqrHeiFact+y*sqrHeiFact
 
			NumVertex(index,poly+5).xpos = 0         +x*sqrWidFact
			NumVertex(index,poly+5).ypos = sqrHeiFact+y*sqrHeiFact
			inc poly, 6
		next x
	next y
endfunction
 
`a block of substance
function shapeSQR(index, poly, xOff, yOff)
 
	`triangle 1
	NumVertex(index,poly+0).xto = 0         +xOff
	NumVertex(index,poly+0).yto = 0         +yOff
 
	NumVertex(index,poly+1).xto = sqrWidFact+xOff   
	NumVertex(index,poly+1).yto = 0         +yOff
 
	NumVertex(index,poly+2).xto = 0         +xOff        
	NumVertex(index,poly+2).yto = sqrHeiFact+yOff
 
	`triangle 2                              
	NumVertex(index,poly+3).xto = sqrWidFact+xOff     
	NumVertex(index,poly+3).yto = 0         +yOff
 
	NumVertex(index,poly+4).xto = sqrWidFact+xOff    
	NumVertex(index,poly+4).yto = sqrHeiFact+yOff
 
	NumVertex(index,poly+5).xto = 0         +xOff   
	NumVertex(index,poly+5).yto = sqrHeiFact+yOff
 
endfunction
 
`no substance here!
function shapeNON(index, poly, xOff, yOff)
 
	`triangle 1
	NumVertex(index,poly+0).xto = 0         +xOff        
	NumVertex(index,poly+0).yto = 0         +yOff
 
	NumVertex(index,poly+1).xto = 0         +xOff      
	NumVertex(index,poly+1).yto = 0         +yOff
 
	NumVertex(index,poly+2).xto = 0         +xOff       
	NumVertex(index,poly+2).yto = 0         +yOff
 
	`triangle 2                                                      
	NumVertex(index,poly+3).xto = sqrWidFact+xOff      
	NumVertex(index,poly+3).yto = sqrHeiFact+yOff
 
	NumVertex(index,poly+4).xto = sqrWidFact+xOff
	NumVertex(index,poly+4).yto = sqrHeiFact+yOff
 
	NumVertex(index,poly+5).xto = sqrWidFact+xOff
	NumVertex(index,poly+5).yto = sqrHeiFact+yOff
 
endfunction
 
`top left in
function shapeTRI1(index, poly, xOff, yOff)
 
	`triangle 1
	NumVertex(index,poly+0).xto = sqrWidFact/2.0+xOff
	NumVertex(index,poly+0).yto = sqrHeiFact/2.0+yOff
 
	NumVertex(index,poly+1).xto = sqrWidFact    +xOff   
	NumVertex(index,poly+1).yto = 0             +yOff
 
	NumVertex(index,poly+2).xto = 0             +xOff        
	NumVertex(index,poly+2).yto = sqrHeiFact    +yOff
 
	`triangle 2                              
	NumVertex(index,poly+3).xto = sqrWidFact    +xOff     
	NumVertex(index,poly+3).yto = 0             +yOff
 
	NumVertex(index,poly+4).xto = sqrWidFact    +xOff    
	NumVertex(index,poly+4).yto = sqrHeiFact    +yOff
 
	NumVertex(index,poly+5).xto = 0             +xOff   
	NumVertex(index,poly+5).yto = sqrHeiFact    +yOff
 
endfunction
 
`top right in
function shapeTRI2(index, poly, xOff, yOff)
 
	`triangle 1
	NumVertex(index,poly+0).xto = 0             +xOff
	NumVertex(index,poly+0).yto = 0             +yOff
 
	NumVertex(index,poly+1).xto = sqrWidFact/2.0+xOff   
	NumVertex(index,poly+1).yto = sqrHeiFact/2.0+yOff
 
	NumVertex(index,poly+2).xto = 0             +xOff        
	NumVertex(index,poly+2).yto = sqrHeiFact    +yOff
 
	`triangle 2                              
	NumVertex(index,poly+3).xto = sqrWidFact/2.0+xOff     
	NumVertex(index,poly+3).yto = sqrHeiFact/2.0+yOff
 
	NumVertex(index,poly+4).xto = sqrWidFact    +xOff    
	NumVertex(index,poly+4).yto = sqrHeiFact    +yOff
 
	NumVertex(index,poly+5).xto = 0             +xOff   
	NumVertex(index,poly+5).yto = sqrHeiFact    +yOff
 
endfunction
 
`bottom right in
function shapeTRI3(index, poly, xOff, yOff)
 
	`triangle 1
	NumVertex(index,poly+0).xto = 0             +xOff
	NumVertex(index,poly+0).yto = 0             +yOff
 
	NumVertex(index,poly+1).xto = sqrWidFact    +xOff   
	NumVertex(index,poly+1).yto = 0             +yOff
 
	NumVertex(index,poly+2).xto = 0             +xOff        
	NumVertex(index,poly+2).yto = sqrHeiFact    +yOff
 
	`triangle 2                              
	NumVertex(index,poly+3).xto = sqrWidFact    +xOff     
	NumVertex(index,poly+3).yto = 0             +yOff
 
	NumVertex(index,poly+4).xto = sqrWidFact/2.0+xOff    
	NumVertex(index,poly+4).yto = sqrHeiFact/2.0+yOff
 
	NumVertex(index,poly+5).xto = 0             +xOff   
	NumVertex(index,poly+5).yto = sqrHeiFact    +yOff
 
endfunction
 
`bottom left in
function shapeTRI4(index, poly, xOff, yOff)
 
	`triangle 1
	NumVertex(index,poly+0).xto = 0             +xOff
	NumVertex(index,poly+0).yto = 0             +yOff
 
	NumVertex(index,poly+1).xto = sqrWidFact    +xOff   
	NumVertex(index,poly+1).yto = 0             +yOff
 
	NumVertex(index,poly+2).xto = sqrWidFact/2.0+xOff        
	NumVertex(index,poly+2).yto = sqrHeiFact/2.0+yOff
 
	`triangle 2                              
	NumVertex(index,poly+3).xto = sqrWidFact    +xOff     
	NumVertex(index,poly+3).yto = 0             +yOff
 
	NumVertex(index,poly+4).xto = sqrWidFact    +xOff    
	NumVertex(index,poly+4).yto = sqrHeiFact    +yOff
 
	NumVertex(index,poly+5).xto = sqrWidFact/2.0+xOff   
	NumVertex(index,poly+5).yto = sqrHeiFact/2.0+yOff
 
endfunction
 
function shapeVLF(index, poly, xOff, yOff)
 
	`triangle 1
	NumVertex(index,poly+0).xto = 0             +xOff
	NumVertex(index,poly+0).yto = 0             +yOff
 
	NumVertex(index,poly+1).xto = sqrWidFact    +xOff   
	NumVertex(index,poly+1).yto = 0             +yOff
 
	NumVertex(index,poly+2).xto = sqrWidFact    +xOff        
	NumVertex(index,poly+2).yto = sqrHeiFact/2.0+yOff
 
	`triangle 2                              
	NumVertex(index,poly+3).xto = sqrWidFact    +xOff     
	NumVertex(index,poly+3).yto = sqrHeiFact/2.0+yOff
 
	NumVertex(index,poly+4).xto = sqrWidFact    +xOff    
	NumVertex(index,poly+4).yto = sqrHeiFact    +yOff
 
	NumVertex(index,poly+5).xto = 0             +xOff   
	NumVertex(index,poly+5).yto = sqrHeiFact    +yOff
 
endfunction
 
function shapeVRT(index, poly, xOff, yOff)
 
	`triangle 1                                  
	NumVertex(index,poly+0).xto = 0             +xOff
	NumVertex(index,poly+0).yto = 0             +yOff
 
	NumVertex(index,poly+1).xto = sqrWidFact    +xOff   
	NumVertex(index,poly+1).yto = 0             +yOff
 
	NumVertex(index,poly+2).xto = 0             +xOff        
	NumVertex(index,poly+2).yto = sqrHeiFact/2.0+yOff
 
	`triangle 2                                     
	NumVertex(index,poly+3).xto = sqrWidFact    +xOff     
	NumVertex(index,poly+3).yto = sqrHeiFact    +yOff
 
	NumVertex(index,poly+4).xto = 0             +xOff    
	NumVertex(index,poly+4).yto = sqrHeiFact    +yOff
 
	NumVertex(index,poly+5).xto = 0             +xOff   
	NumVertex(index,poly+5).yto = sqrHeiFact/2.0+yOff
 
endfunction
 
 
number1:
data 0,2,1,0,0
data 0,1,1,0,0,
data 0,0,1,0,0
data 0,0,1,0,0
data 0,1,1,1,0
 
number2:
data 2,1,1,1,3
data 1,0,0,6,1
data 0,2,1,1,4
data 2,1,7,0,0
data 1,1,1,1,1
 
number3:
data 1,1,1,1,3
data 0,0,0,6,1
data 0,1,1,1,7
data 0,0,0,6,1
data 1,1,1,1,4
 
number4:
data 1,0,0,0,1
data 1,0,0,0,1
data 5,1,1,1,1
data 0,0,0,0,1
data 0,0,0,0,1
 
number5:
data 2,1,1,1,1
data 1,7,0,0,0
data 5,1,1,1,3
data 0,0,0,6,1
data 1,1,1,1,4
 
number6:
data 2,1,1,1,0
data 1,7,0,0,0
data 1,1,1,1,3
data 1,7,0,6,1
data 5,1,1,1,4
 
number7:
data 1,1,1,1,1
data 0,0,0,2,4
data 0,0,2,1,0
data 0,2,1,4,0
data 0,1,4,0,0
 
number8:
data 2,1,1,1,3
data 1,7,0,6,1
data 6,1,1,1,7
data 1,7,0,6,1
data 5,1,1,1,4
 
number9:
data 2,1,1,1,3
data 1,7,0,6,1
data 5,1,1,1,1
data 0,0,0,6,1
data 0,1,1,1,4
 
number0:
data 2,1,1,1,3
data 1,0,2,4,1
data 1,0,1,0,1
data 1,2,4,0,1
data 5,1,1,1,4
 
numberSYM:
data 0,0,0,0,0
data 0,0,1,0,0
data 0,0,0,0,0
data 0,0,1,0,0
data 0,0,0,0,0
 
`for digit 1 to 11
numberData:
`num, max, min, thresh, dfactor
data 0,10.0, 5.0, 10.0, 1.0 `data for first digit (hundreths of a second)
data 0,10.0, 5.0, 10.0 , 10.0 `data for second digit (tenths of a second)
data 99,10.0, 1.0, 1.0 , 10.0 `data for first colon
numberDataSeconds:
data 0,10.0, 1.0, 1.0 , 10.0 `data for seconds
data 0,10.0, 1.0, 1.0 , 10.0 `data for ten Seconds
data 99,10.0, 1.0, 1.0 , 10.0`data for second colon
data 0,10.0, 1.0, 1.0 , 10.0`data for minutes
data 0,10.0, 1.0, 1.0 , 10.0`data for ten minutes
data 99,10.0, 1.0, 1.0 , 10.0`data for third colon
data 0,10.0, 1.0, 1.0 , 10.0`data for one hour
data 0,10.0, 1.0, 1.0 , 10.0`data for ten hours