Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
2 views3 pages

Codeaenvoyer

voial

Uploaded by

axel.lory12345
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Codeaenvoyer

voial

Uploaded by

axel.lory12345
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

x = 0

y=0

max_tar = 7 -- Maximum target count


lastRange = 0
lastAz = 0
tarX = 0
tarY = 0
targetX=0
targetY=0
heading =0

tar = {}
tarD = {} -- Distance
tarAz = {} -- Azimuth
trackedTargets = {} -- Liste persistante des cibles

maxAge = 5000
-- 1 x /2 y / 3 age

function onTick()
zoom = input.getNumber(31)
x = input.getNumber(29)
y = input.getNumber(30)
raw_compas = input.getNumber(32)
heading = (raw_compas * 2 * math.pi) % (2 * math.pi) -- en radians 0 2p
for i=1,max_tar do
if(input.getBool(i)==true) then
tar[i]=true -- Get the bool target data
tarD[i]=input.getNumber(1 + (i - 1) * 4)
local relAz = input.getNumber(2 + (i - 1) * 4) -- Azimut
relatif (-0.5 +0.5)
local relAzRad = relAz * 2 * math.pi -- En radians
tarAz[i] = (heading + relAzRad) % (2 * math.pi) -- Azimut absolu
en radians
end

end

output.setNumber(3,tarX)
output.setNumber(4,tarY )
end

function onDraw()

w = screen.getWidth()
h = screen.getHeight()

screen.drawMap(x, y, zoom)
myX, myY = map.mapToScreen(x, y, zoom, w, h, x, y)

screen.setColor(0,255,0)
screen.drawCircle(myX, myY , 1)

lineX = x - 100 * math.sin(heading)


lineY = y + 100 * math.cos(heading)
toX, toY = map.mapToScreen(x, y, zoom, w, h, lineX, lineY)
screen.drawLine(myX, myY,toX, toY)

targetCount = 0
for i=1,max_tar do
if tar[i] then
azRad = tarAz[i] --* (2 * math.pi) -- Degree to radians
tarX = x -tarD[i] * math.sin(azRad)
tarY = y +tarD[i] * math.cos(azRad) -- We subtract since Y axis is in
down direction

trackedTargetsUpdate(tarX,tarY)

end
end

for i=1,#trackedTargets do

targetX, targetY =map.mapToScreen(x, y, zoom, w, h, trackedTargets[i]


[1], trackedTargets[i][2])

local r, g, b = getAgeColor( trackedTargets[i][3])


screen.setColor(r, g, b)
screen.drawCircle(targetX, targetY, 1)
end

end

function trackedTargetsUpdate(x1,y1)
local checked = false
if(#trackedTargets>0) then
print(#trackedTargets)
print(trackedTargets)

for i = #trackedTargets, 1, -1 do
-- 1 x /2 y / 3 age
if(distanceBetween(x1,y1,trackedTargets[i][1],trackedTargets[i]
[2])<200) then
checked = true;
trackedTargets[i][1] = x1
trackedTargets[i][2] = y1
trackedTargets[i][3] = 0;
else
trackedTargets[i][3] = trackedTargets[i][3]+1;
end

if(trackedTargets[i][3]>maxAge)then
--remove la cible ca fait longtemps que on la perdu
removeFromTableByIndex(trackedTargets,i)
end

end
end
if(checked==false)then
table.insert(trackedTargets, {x1,y1,0})

end
end

function removeFromTableByIndex(tbl, index)


table.remove(tbl, index)
end

function distanceBetween(x1, y1, xtarget, ytarget)


local dx = xtarget - x1
local dy = ytarget - y1
return math.sqrt(dx * dx + dy * dy)
end

function getAgeColor(age)
local ratio = math.min(age / maxAge, 1)
local r = 255
local g = 0

if ratio < 0.5 then


-- Rouge → Orange
g = ratio * 2 * 127
else
-- Orange → Jaune
g = 127 + (ratio - 0.5) * 2 * 128
end

return math.floor(r), math.floor(g), 0


end

You might also like