

function modeA(dt) 
    
   
C = rgbm(0.35,0.73,0.29,1) 
if car.rpm >= 6500 then
    C = rgbm(1,0,0,1)
end

    local value = math.saturate(car.rpm / 8000)
    display.rect {
        color = rgbm(C),
        pos = vec2(77, 360), 
        size = vec2(862 * value, 259), 
        uvStart = vec2(0, 0), 
        uvEnd = vec2(value, 1) 
    }
 
    display.image {
        image = "assets/1.dds",
        pos = vec2(0, -1), 
        size = vec2(1024, 1024)
    }

    local value = math.saturate(math.min(math.max(car.performanceMeter, 0), 2) / 2)
    display.rect {
        color = rgbm(1,0,0,1),
        pos = vec2(674, 271), 
        size = vec2(215 * value, 24), 
        uvStart = vec2(0, 0), 
        uvEnd = vec2(value, 1) 
    }

    local value = math.saturate(math.min(math.max(-car.performanceMeter, 0), 2) / 2)
    display.rect {
        color = rgbm(0.35,0.73,0.29,1),
        pos = vec2(671, 271), 
        size = vec2(215 * -value, 24), 
        uvStart = vec2(0, 0), 
        uvEnd = vec2(value, 1) 
    }

    display.text {
        text = string.format("%0d", car.rpm), 
        pos = vec2(130, 620),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -15,
        color = rgbm(1,1,1,1)
    }
    
    display.text {
        text = string.format("%4d", car.poweredWheelsSpeed), 
        pos = vec2(790, 510),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -15,
        color = rgbm(1,1,1,1)
    }

    local time = car.bestLapTimeMs
    local formattedTime =
        string.format(
        "%01d:%02d:%02d",
        math.floor((time / (1000 * 60))) % 60,
        math.floor((time / 1000)) % 60,
        math.floor((time % 1000) / 100)
    )
    display.text {
        text = formattedTime,
        pos = vec2(620, 620),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -10
    }

    display.text {
        text = string.format("%4.1f", car.oilPressure), 
        pos = vec2(110, 750),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -25,
        color = rgbm(0,0,0,1)
    }

    display.text {
        text = string.format("%4.0f", car.oilTemperature), 
        pos = vec2(375, 750),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -10,
        color = rgbm(0,0,0,1)
    }

    display.text {
        text = string.format("%4.0f", car.fuel), 
        pos = vec2(775, 750),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -10,
        color = rgbm(0,0,0,1)
    }

    local gearText = tostring(car.gear) -- needs to be converted so that neutral and reverse display correctly (-1 = R, 0 = N)
    if car.gear == -1 then
        gearText = "R"
    end
    if car.gear == 0 then
        gearText = "N"
    end
    display.text {
        text = gearText,
        pos = vec2(400, 415),
        letter = vec2(160, 380),
        font = "mp4_big",
        width = 46,
        alignment = 0.5,
        spacing = 0
    }

end

function modeB(dt)

C = rgbm(0.35,0.73,0.29,1) 
if car.rpm >= 7000 then
    C = rgbm(1,0,0,1)
end

    display.rect {
        color = rgbm(1,1,1,1),
        pos = vec2(0, -1), 
        size = vec2(1024, 1024)
    }
    
    display.rect {
        color = rgbm(C),
        pos = vec2(0, 290), 
        size = vec2(78, 120)
    }

    local value = math.saturate(math.min(car.rpm, 4000) / 8000) -- saturate clamps value between 0 and 1
    display.rect {
        color =rgbm(C),
        pos = vec2(75, 285), -- coordinates of top left corner of the texture, pay attention to resolution of that texture
        size = vec2(585 * value , 130), -- size of the image, "value *" makes it expand towards that maximum value
        uvStart = vec2(0, 0), -- uv coordinate of the top left corner (default is 0, 0)
        uvEnd = vec2(1, 1) -- uv coordinate of the bottom right corner (default is 1, 1), 0-8000rpms = value, 1 as range for the "uncovering fo the texture"
    }

    local value = math.saturate((math.min(car.rpm, 8000)-4000) / 8000) -- saturate clamps value between 0 and 1
    display.rect {
        color =rgbm(C),
        pos = vec2(365, 285), -- coordinates of top left corner of the texture, pay attention to resolution of that texture
        size = vec2(1150 * value , 130), -- size of the image, "value *" makes it expand towards that maximum value
        uvStart = vec2(0, 0), -- uv coordinate of the top left corner (default is 0, 0)
        uvEnd = vec2(1, 1) -- uv coordinate of the bottom right corner (default is 1, 1), 0-8000rpms = value, 1 as range for the "uncovering fo the texture"
    }

    display.image {
        image = "assets/2.dds",
        pos = vec2(0, -1), 
        size = vec2(1024, 1024)
    }  
    
    display.text {
        text = string.format("%d", car.lapCount), 
        pos = vec2(20, 450),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -15,
        color = rgbm(1,1,1,1)
    }

    display.text {
        text = string.format("%d", car.poweredWheelsSpeed), 
        pos = vec2(20, 600),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -15,
        color = rgbm(1,1,1,1)
    }

    display.text {
        text = string.format("%3d", car.waterTemperature), 
        pos = vec2(580, 440),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -10,
        color = rgbm(1,1,1,1)
    }
    
    display.text {
        text = string.format("%3.1f", car.oilPressure), 
        pos = vec2(865, 440),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -25,
        color = rgbm(1,1,1,1)
    }

    display.text {
        text = string.format("%3d", car.oilTemperature), 
        pos = vec2(570, 590),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -10,
        color = rgbm(1,1,1,1)
    }

    display.text {
        text = string.format("%3d", car.fuel), 
        pos = vec2(830, 590),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -10,
        color = rgbm(1,1,1,1)
    }

    local time = car.bestLapTimeMs
    local formattedTime =
        string.format(
        "%01d:%02d:%02d",
        math.floor((time / (1000 * 60))) % 60,
        math.floor((time / 1000)) % 60,
        math.floor((time % 1000) / 100)
    )
    display.text {
        text = formattedTime,
        pos = vec2(20, 725),
        letter = vec2(50, 100),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -10
    }

    local time = car.lapTimeMs
    local formattedTime =
        string.format(
        "%01d:%02d:%02d",
        math.floor((time / (1000 * 60))) % 60,
        math.floor((time / 1000)) % 60,
        math.floor((time % 1000) / 100)
    )
    display.text {
        text = formattedTime,
        pos = vec2(690, 725),
        letter = vec2(50, 100),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -10
    }
    
    local value = math.saturate(math.min(math.max(car.performanceMeter, 0), 2) / 2)
    display.rect {
        color = rgbm(1,0,0,1),
        pos = vec2(520, 810), 
        size = vec2(380 * value, 24), 
        uvStart = vec2(0, 0), 
        uvEnd = vec2(value, 1) 
    }

    local value = math.saturate(math.min(math.max(-car.performanceMeter, 0), 2) / 2)
    display.rect {
        color = rgbm(0.35,0.73,0.29,1),
        pos = vec2(506, 810), 
        size = vec2(380 * -value, 24), 
        uvStart = vec2(0, 0), 
        uvEnd = vec2(value, 1) 
    }
    

    
    local gearText = tostring(car.gear) -- needs to be converted so that neutral and reverse display correctly (-1 = R, 0 = N)
    if car.gear == -1 then
        gearText = "R"
    end
    if car.gear == 0 then
        gearText = "N"
    end
    display.text {
        text = gearText,
        pos = vec2(220, 370),
        letter = vec2(180, 400),
        font = "mp4_big",
        width = 46,
        alignment = 0.5,
        spacing = 0
    }

end

function modeC(dt)

    display.rect {
        color = rgbm(1,1,1,1),
        pos = vec2(0, -1), 
        size = vec2(1024, 1024)
    }

C = rgbm(0.35,0.73,0.29,1) 
if car.rpm >= 7000 then
     C = rgbm(1,0,0,1)
end

    ui.beginRotation()

    display.rect {
        color = rgbm(C),
        pos = vec2(240, 612), 
        size = vec2(200, 200)
    }

    ui.endRotation(15)

    ui.pathArcTo(vec2(511, 566), 205, 2.88, (math.saturate(math.min(car.rpm , 4000) / 8000) * math.pi * 0.78) + 2.88 , 40)
    ui.pathStroke(rgbm(C), false, 154)

    ui.pathArcTo(vec2(511, 566), 205, 4.09, (math.saturate((math.min(car.rpm , 8000) -4000) / 8000) * math.pi * 1.56) + 4.09 , 40)
    ui.pathStroke(rgbm(C), false, 154)

 display.image {
        image = "assets/3.dds",
        pos = vec2(0, -1), 
        size = vec2(1024, 1024)
    } 
    display.text {
        text = string.format("%3d", car.lapCount), 
        pos = vec2(850, 440),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -15,
        color = rgbm(1,1,1,1)
    }

    display.text {
        text = string.format("%4d", car.poweredWheelsSpeed), 
        pos = vec2(800, 310),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -15,
        color = rgbm(1,1,1,1)
    }

    display.text {
        text = string.format("%3d", car.waterTemperature), 
        pos = vec2(-30, 310),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -10,
        color = rgbm(1,1,1,1)
    }
    
    display.text {
        text = string.format("%3.1f", car.oilPressure), 
        pos = vec2(10, 440),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -25,
        color = rgbm(1,1,1,1)
    }

    display.text {
        text = string.format("%d", car.oilTemperature), 
        pos = vec2(20, 570),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -10,
        color = rgbm(1,1,1,1)
    }

    display.text {
        text = string.format("%3d", car.fuel), 
        pos = vec2(830, 570),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -10,
        color = rgbm(1,1,1,1)
    }

    local value = math.saturate(math.min(math.max(car.performanceMeter, 0), 2) / 2)
    display.rect {
        color = rgbm(1,0,0,1),
        pos = vec2(520, 815), 
        size = vec2(380 * value, 24), 
        uvStart = vec2(0, 0), 
        uvEnd = vec2(value, 1) 
    }

    local value = math.saturate(math.min(math.max(-car.performanceMeter, 0), 2) / 2)
    display.rect {
        color = rgbm(0.35,0.73,0.29,1),
        pos = vec2(506, 815), 
        size = vec2(380 * -value, 24), 
        uvStart = vec2(0, 0), 
        uvEnd = vec2(value, 1) 
    }

    local time = car.bestLapTimeMs
    local formattedTime =
        string.format(
        "%01d:%02d:%02d",
        math.floor((time / (1000 * 60))) % 60,
        math.floor((time / 1000)) % 60,
        math.floor((time % 1000) / 100)
    )
    display.text {
        text = formattedTime,
        pos = vec2(20, 700),
        letter = vec2(50, 100),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -10
    }

    local time = car.lapTimeMs
    local formattedTime =
        string.format(
        "%01d:%02d:%02d",
        math.floor((time / (1000 * 60))) % 60,
        math.floor((time / 1000)) % 60,
        math.floor((time % 1000) / 100)
    )
    display.text {
        text = formattedTime,
        pos = vec2(690, 700),
        letter = vec2(50, 100),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -10
    }

    local gearText = tostring(car.gear) -- needs to be converted so that neutral and reverse display correctly (-1 = R, 0 = N)
    if car.gear == -1 then
        gearText = "R"
    end
    if car.gear == 0 then
        gearText = "N"
    end
    display.text {
        text = gearText,
        pos = vec2(430, 370),
        letter = vec2(160, 360),
        font = "mp4_big",
        width = 46,
        alignment = 0.5,
        spacing = 0
    }
    
end

function modeD(dt) 
    
   
    C = rgbm(0.14,0.66,0.88,1) 
    if car.rpm >= 6500 then
        C = rgbm(1,0,0,1)
    end
    
        local value = math.saturate(car.rpm / 8000)
        display.rect {
            color = rgbm(C),
            pos = vec2(77, 360), 
            size = vec2(862 * value, 259), 
            uvStart = vec2(0, 0), 
            uvEnd = vec2(value, 1) 
        }
     
        display.image {
            image = "assets/4.dds",
            pos = vec2(0, -1), 
            size = vec2(1024, 1024)
        }
    
        local value = math.saturate(math.min(math.max(car.performanceMeter, 0), 2) / 2)
        display.rect {
            color = rgbm(1,0,0,1),
            pos = vec2(674, 271), 
            size = vec2(215 * value, 24), 
            uvStart = vec2(0, 0), 
            uvEnd = vec2(value, 1) 
        }
    
        local value = math.saturate(math.min(math.max(-car.performanceMeter, 0), 2) / 2)
        display.rect {
            color = rgbm(0.35,0.73,0.29,1),
            pos = vec2(671, 271), 
            size = vec2(215 * -value, 24), 
            uvStart = vec2(0, 0), 
            uvEnd = vec2(value, 1) 
        }
    
        display.text {
            text = string.format("%0d", car.rpm), 
            pos = vec2(130, 620),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -15,
            color = rgbm(1,1,1,1)
        }
        
        display.text {
            text = string.format("%4d", car.poweredWheelsSpeed), 
            pos = vec2(790, 510),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -15,
            color = rgbm(1,1,1,1)
        }
    
        local time = car.bestLapTimeMs
        local formattedTime =
            string.format(
            "%01d:%02d:%02d",
            math.floor((time / (1000 * 60))) % 60,
            math.floor((time / 1000)) % 60,
            math.floor((time % 1000) / 100)
        )
        display.text {
            text = formattedTime,
            pos = vec2(620, 620),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -10
        }
    
        display.text {
            text = string.format("%4.1f", car.oilPressure), 
            pos = vec2(110, 750),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -25,
            color = rgbm(1,1,1,1)
        }
    
        display.text {
            text = string.format("%4.0f", car.oilTemperature), 
            pos = vec2(375, 750),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -10,
            color = rgbm(1,1,1,1)
        }
    
        display.text {
            text = string.format("%4.0f", car.fuel), 
            pos = vec2(775, 750),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -10,
            color = rgbm(1,1,1,1)
        }
    
        local gearText = tostring(car.gear) -- needs to be converted so that neutral and reverse display correctly (-1 = R, 0 = N)
        if car.gear == -1 then
            gearText = "R"
        end
        if car.gear == 0 then
            gearText = "N"
        end
        display.text {
            text = gearText,
            pos = vec2(400, 415),
            letter = vec2(160, 380),
            font = "mp4_big",
            width = 46,
            alignment = 0.5,
            spacing = 0
        }
    
    end
    
function modeE(dt)


C = rgbm(0.14,0.66,0.88,1) 
if car.rpm >= 6500 then
    C = rgbm(1,0,0,1)
end    

        display.rect {
            color = rgbm(1,1,1,1),
            pos = vec2(0, -1), 
            size = vec2(1024, 1024)
        }
        
        display.rect {
            color = rgbm(C),
            pos = vec2(0, 290), 
            size = vec2(78, 120)
        }
    
        local value = math.saturate(math.min(car.rpm, 4000) / 8000) -- saturate clamps value between 0 and 1
        display.rect {
            color =rgbm(C),
            pos = vec2(75, 285), -- coordinates of top left corner of the texture, pay attention to resolution of that texture
            size = vec2(585 * value , 130), -- size of the image, "value *" makes it expand towards that maximum value
            uvStart = vec2(0, 0), -- uv coordinate of the top left corner (default is 0, 0)
            uvEnd = vec2(1, 1) -- uv coordinate of the bottom right corner (default is 1, 1), 0-8000rpms = value, 1 as range for the "uncovering fo the texture"
        }
    
        local value = math.saturate((math.min(car.rpm, 8000)-4000) / 8000) -- saturate clamps value between 0 and 1
        display.rect {
            color =rgbm(C),
            pos = vec2(365, 285), -- coordinates of top left corner of the texture, pay attention to resolution of that texture
            size = vec2(1150 * value , 130), -- size of the image, "value *" makes it expand towards that maximum value
            uvStart = vec2(0, 0), -- uv coordinate of the top left corner (default is 0, 0)
            uvEnd = vec2(1, 1) -- uv coordinate of the bottom right corner (default is 1, 1), 0-8000rpms = value, 1 as range for the "uncovering fo the texture"
        }
    
        display.image {
            image = "assets/5.dds",
            pos = vec2(0, -1), 
            size = vec2(1024, 1024)
        }  
        
        display.text {
            text = string.format("%d", car.lapCount), 
            pos = vec2(20, 450),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -15,
            color = rgbm(1,1,1,1)
        }
    
        display.text {
            text = string.format("%d", car.poweredWheelsSpeed), 
            pos = vec2(20, 600),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -15,
            color = rgbm(1,1,1,1)
        }
    
        display.text {
            text = string.format("%3d", car.waterTemperature), 
            pos = vec2(580, 440),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -10,
            color = rgbm(1,1,1,1)
        }
        
        display.text {
            text = string.format("%3.1f", car.oilPressure), 
            pos = vec2(865, 440),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -25,
            color = rgbm(1,1,1,1)
        }
    
        display.text {
            text = string.format("%3d", car.oilTemperature), 
            pos = vec2(570, 590),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -10,
            color = rgbm(1,1,1,1)
        }
    
        display.text {
            text = string.format("%3d", car.fuel), 
            pos = vec2(830, 590),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -10,
            color = rgbm(1,1,1,1)
        }
    
        local time = car.bestLapTimeMs
        local formattedTime =
            string.format(
            "%01d:%02d:%02d",
            math.floor((time / (1000 * 60))) % 60,
            math.floor((time / 1000)) % 60,
            math.floor((time % 1000) / 100)
        )
        display.text {
            text = formattedTime,
            pos = vec2(20, 725),
            letter = vec2(50, 100),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -10
        }
    
        local time = car.lapTimeMs
        local formattedTime =
            string.format(
            "%01d:%02d:%02d",
            math.floor((time / (1000 * 60))) % 60,
            math.floor((time / 1000)) % 60,
            math.floor((time % 1000) / 100)
        )
        display.text {
            text = formattedTime,
            pos = vec2(690, 725),
            letter = vec2(50, 100),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -10
        }
    
        local value = math.saturate(math.min(math.max(car.performanceMeter, 0), 2) / 2)
        display.rect {
            color = rgbm(1,0,0,1),
            pos = vec2(520, 810), 
            size = vec2(380 * value, 24), 
            uvStart = vec2(0, 0), 
            uvEnd = vec2(value, 1) 
        }
    
        local value = math.saturate(math.min(math.max(-car.performanceMeter, 0), 2) / 2)
        display.rect {
            color = rgbm(0.35,0.73,0.29,1),
            pos = vec2(506, 810), 
            size = vec2(380 * -value, 24), 
            uvStart = vec2(0, 0), 
            uvEnd = vec2(value, 1) 
        }
        
    
        
        local gearText = tostring(car.gear) -- needs to be converted so that neutral and reverse display correctly (-1 = R, 0 = N)
        if car.gear == -1 then
            gearText = "R"
        end
        if car.gear == 0 then
            gearText = "N"
        end
        display.text {
            text = gearText,
            pos = vec2(220, 370),
            letter = vec2(180, 400),
            font = "mp4_big",
            width = 46,
            alignment = 0.5,
            spacing = 0
        }
    
    end
    
    function modeF(dt)
    
        display.rect {
            color = rgbm(1,1,1,1),
            pos = vec2(0, -1), 
            size = vec2(1024, 1024)
        }
    
        C = rgbm(0.14,0.66,0.88,1) 
        if car.rpm >= 6500 then
            C = rgbm(1,0,0,1)
        end
    
        ui.beginRotation()

        display.rect {
            color = rgbm(C),
            pos = vec2(240, 612), 
            size = vec2(200, 200)
        }
    
        ui.endRotation(15)

        ui.pathArcTo(vec2(511, 566), 205, 2.88, (math.saturate(math.min(car.rpm , 4000) / 8000) * math.pi * 0.78) + 2.88 , 40)
        ui.pathStroke(rgbm(C), false, 154)
    
        ui.pathArcTo(vec2(511, 566), 205, 4.09, (math.saturate((math.min(car.rpm , 8000) -4000) / 8000) * math.pi * 1.56) + 4.09 , 40)
        ui.pathStroke(rgbm(C), false, 154)
    
     display.image {
            image = "assets/6.dds",
            pos = vec2(0, -1), 
            size = vec2(1024, 1024)
        } 
        display.text {
            text = string.format("%3d", car.lapCount), 
            pos = vec2(850, 440),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -15,
            color = rgbm(1,1,1,1)
        }
    
        display.text {
            text = string.format("%4d", car.poweredWheelsSpeed), 
            pos = vec2(800, 310),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -15,
            color = rgbm(1,1,1,1)
        }
    
        display.text {
            text = string.format("%3d", car.waterTemperature), 
            pos = vec2(-30, 310),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -10,
            color = rgbm(1,1,1,1)
        }
        
        display.text {
            text = string.format("%3.1f", car.oilPressure), 
            pos = vec2(10, 440),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -25,
            color = rgbm(1,1,1,1)
        }
    
        display.text {
            text = string.format("%d", car.oilTemperature), 
            pos = vec2(20, 570),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -10,
            color = rgbm(1,1,1,1)
        }
    
        display.text {
            text = string.format("%3d", car.fuel), 
            pos = vec2(830, 570),
            letter = vec2(60, 120),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -10,
            color = rgbm(1,1,1,1)
        }
    
        local value = math.saturate(math.min(math.max(car.performanceMeter, 0), 2) / 2)
        display.rect {
            color = rgbm(1,0,0,1),
            pos = vec2(520, 815), 
            size = vec2(380 * value, 24), 
            uvStart = vec2(0, 0), 
            uvEnd = vec2(value, 1) 
        }
    
        local value = math.saturate(math.min(math.max(-car.performanceMeter, 0), 2) / 2)
        display.rect {
            color = rgbm(0.35,0.73,0.29,1),
            pos = vec2(506, 815), 
            size = vec2(380 * -value, 24), 
            uvStart = vec2(0, 0), 
            uvEnd = vec2(value, 1) 
        }
    
        local time = car.bestLapTimeMs
        local formattedTime =
            string.format(
            "%01d:%02d:%02d",
            math.floor((time / (1000 * 60))) % 60,
            math.floor((time / 1000)) % 60,
            math.floor((time % 1000) / 100)
        )
        display.text {
            text = formattedTime,
            pos = vec2(20, 700),
            letter = vec2(50, 100),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -10
        }
    
        local time = car.lapTimeMs
        local formattedTime =
            string.format(
            "%01d:%02d:%02d",
            math.floor((time / (1000 * 60))) % 60,
            math.floor((time / 1000)) % 60,
            math.floor((time % 1000) / 100)
        )
        display.text {
            text = formattedTime,
            pos = vec2(690, 700),
            letter = vec2(50, 100),
            font = "c7_new",
            width = 46,
            alignment = 1,
            spacing = -10
        }
    
        local gearText = tostring(car.gear) -- needs to be converted so that neutral and reverse display correctly (-1 = R, 0 = N)
        if car.gear == -1 then
            gearText = "R"
        end
        if car.gear == 0 then
            gearText = "N"
        end
        display.text {
            text = gearText,
            pos = vec2(430, 370),
            letter = vec2(160, 360),
            font = "mp4_big",
            width = 46,
            alignment = 0.5,
            spacing = 0
        }
        
    end



    function modeG(dt) 
    
   
        C = rgbm(1,0.64,0,1) 
        if car.rpm >= 6500 then
            C = rgbm(1,0,0,1)
        end
        
            local value = math.saturate(car.rpm / 8000)
            display.rect {
                color = rgbm(C),
                pos = vec2(77, 360), 
                size = vec2(862 * value, 259), 
                uvStart = vec2(0, 0), 
                uvEnd = vec2(value, 1) 
            }
         
            display.image {
                image = "assets/7.dds",
                pos = vec2(0, -1), 
                size = vec2(1024, 1024)
            }
        
            local value = math.saturate(math.min(math.max(car.performanceMeter, 0), 2) / 2)
            display.rect {
                color = rgbm(1,0,0,1),
                pos = vec2(674, 271), 
                size = vec2(215 * value, 24), 
                uvStart = vec2(0, 0), 
                uvEnd = vec2(value, 1) 
            }
        
            local value = math.saturate(math.min(math.max(-car.performanceMeter, 0), 2) / 2)
            display.rect {
                color = rgbm(0.35,0.73,0.29,1),
                pos = vec2(671, 271), 
                size = vec2(215 * -value, 24), 
                uvStart = vec2(0, 0), 
                uvEnd = vec2(value, 1) 
            }
        
            display.text {
                text = string.format("%0d", car.rpm), 
                pos = vec2(130, 620),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -15,
                color = rgbm(1,1,1,1)
            }
            
            display.text {
                text = string.format("%4d", car.poweredWheelsSpeed), 
                pos = vec2(790, 510),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -15,
                color = rgbm(1,1,1,1)
            }
        
            local time = car.bestLapTimeMs
            local formattedTime =
                string.format(
                "%01d:%02d:%02d",
                math.floor((time / (1000 * 60))) % 60,
                math.floor((time / 1000)) % 60,
                math.floor((time % 1000) / 100)
            )
            display.text {
                text = formattedTime,
                pos = vec2(620, 620),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -10
            }
        
            display.text {
                text = string.format("%4.1f", car.oilPressure), 
                pos = vec2(110, 750),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -25,
                color = rgbm(1,1,1,1)
            }
        
            display.text {
                text = string.format("%4.0f", car.oilTemperature), 
                pos = vec2(375, 750),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -10,
                color = rgbm(1,1,1,1)
            }
        
            display.text {
                text = string.format("%4.0f", car.fuel), 
                pos = vec2(775, 750),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -10,
                color = rgbm(1,1,1,1)
            }
        
            local gearText = tostring(car.gear) -- needs to be converted so that neutral and reverse display correctly (-1 = R, 0 = N)
            if car.gear == -1 then
                gearText = "R"
            end
            if car.gear == 0 then
                gearText = "N"
            end
            display.text {
                text = gearText,
                pos = vec2(400, 415),
                letter = vec2(160, 380),
                font = "mp4_big",
                width = 46,
                alignment = 0.5,
                spacing = 0
            }
        
        end
        
    function modeH(dt)

C = rgbm(1,0.64,0,1) 
if car.rpm >= 6500 then
    C = rgbm(1,0,0,1)
end        
            
            display.rect {
                color = rgbm(1,1,1,1),
                pos = vec2(0, -1), 
                size = vec2(1024, 1024)
            }
            
           
            display.rect {
                color = rgbm(C),
                pos = vec2(0, 290), 
                size = vec2(78, 120)
            }
        
            local value = math.saturate(math.min(car.rpm, 4000) / 8000) -- saturate clamps value between 0 and 1
            display.rect {
                color =rgbm(C),
                pos = vec2(75, 285), -- coordinates of top left corner of the texture, pay attention to resolution of that texture
                size = vec2(585 * value , 130), -- size of the image, "value *" makes it expand towards that maximum value
                uvStart = vec2(0, 0), -- uv coordinate of the top left corner (default is 0, 0)
                uvEnd = vec2(1, 1) -- uv coordinate of the bottom right corner (default is 1, 1), 0-8000rpms = value, 1 as range for the "uncovering fo the texture"
            }
        
            local value = math.saturate((math.min(car.rpm, 8000)-4000) / 8000) -- saturate clamps value between 0 and 1
            display.rect {
                color =rgbm(C),
                pos = vec2(365, 285), -- coordinates of top left corner of the texture, pay attention to resolution of that texture
                size = vec2(1150 * value , 130), -- size of the image, "value *" makes it expand towards that maximum value
                uvStart = vec2(0, 0), -- uv coordinate of the top left corner (default is 0, 0)
                uvEnd = vec2(1, 1) -- uv coordinate of the bottom right corner (default is 1, 1), 0-8000rpms = value, 1 as range for the "uncovering fo the texture"
            }
        
            display.image {
                image = "assets/8.dds",
                pos = vec2(0, -1), 
                size = vec2(1024, 1024)
            }  
            
            display.text {
                text = string.format("%d", car.lapCount), 
                pos = vec2(20, 450),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -15,
                color = rgbm(1,1,1,1)
            }
        
            display.text {
                text = string.format("%d", car.poweredWheelsSpeed), 
                pos = vec2(20, 600),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -15,
                color = rgbm(1,1,1,1)
            }
        
            display.text {
                text = string.format("%3d", car.waterTemperature), 
                pos = vec2(580, 440),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -10,
                color = rgbm(1,1,1,1)
            }
            
            display.text {
                text = string.format("%3.1f", car.oilPressure), 
                pos = vec2(865, 440),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -25,
                color = rgbm(1,1,1,1)
            }
        
            display.text {
                text = string.format("%3d", car.oilTemperature), 
                pos = vec2(570, 590),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -10,
                color = rgbm(1,1,1,1)
            }
        
            display.text {
                text = string.format("%3d", car.fuel), 
                pos = vec2(830, 590),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -10,
                color = rgbm(1,1,1,1)
            }
        
            local time = car.bestLapTimeMs
            local formattedTime =
                string.format(
                "%01d:%02d:%02d",
                math.floor((time / (1000 * 60))) % 60,
                math.floor((time / 1000)) % 60,
                math.floor((time % 1000) / 100)
            )
            display.text {
                text = formattedTime,
                pos = vec2(20, 725),
                letter = vec2(50, 100),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -10
            }
        
            local time = car.lapTimeMs
            local formattedTime =
                string.format(
                "%01d:%02d:%02d",
                math.floor((time / (1000 * 60))) % 60,
                math.floor((time / 1000)) % 60,
                math.floor((time % 1000) / 100)
            )
            display.text {
                text = formattedTime,
                pos = vec2(690, 725),
                letter = vec2(50, 100),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -10
            }
        
            local value = math.saturate(math.min(math.max(car.performanceMeter, 0), 2) / 2)
            display.rect {
                color = rgbm(1,0,0,1),
                pos = vec2(520, 810), 
                size = vec2(380 * value, 24), 
                uvStart = vec2(0, 0), 
                uvEnd = vec2(value, 1) 
            }
        
            local value = math.saturate(math.min(math.max(-car.performanceMeter, 0), 2) / 2)
            display.rect {
                color = rgbm(0.35,0.73,0.29,1),
                pos = vec2(506, 810), 
                size = vec2(380 * -value, 24), 
                uvStart = vec2(0, 0), 
                uvEnd = vec2(value, 1) 
            }
            
        
            
            local gearText = tostring(car.gear) -- needs to be converted so that neutral and reverse display correctly (-1 = R, 0 = N)
            if car.gear == -1 then
                gearText = "R"
            end
            if car.gear == 0 then
                gearText = "N"
            end
            display.text {
                text = gearText,
                pos = vec2(220, 370),
                letter = vec2(180, 400),
                font = "mp4_big",
                width = 46,
                alignment = 0.5,
                spacing = 0
            }
        
        end
        
        function modeI(dt)
        
            display.rect {
                color = rgbm(1,1,1,1),
                pos = vec2(0, -1), 
                size = vec2(1024, 1024)
            }
        
            C = rgbm(1,0.64,0,1) 
            if car.rpm >= 6500 then
                C = rgbm(1,0,0,1)
            end
        
            ui.beginRotation()

            display.rect {
                color = rgbm(C),
                pos = vec2(240, 612), 
                size = vec2(200, 200)
            }
        
            ui.endRotation(15)

            ui.pathArcTo(vec2(511, 566), 205, 2.88, (math.saturate(math.min(car.rpm , 4000) / 8000) * math.pi * 0.78) + 2.88 , 40)
            ui.pathStroke(rgbm(C), false, 154)
        
            ui.pathArcTo(vec2(511, 566), 205, 4.09, (math.saturate((math.min(car.rpm , 8000) -4000) / 8000) * math.pi * 1.56) + 4.09 , 40)
            ui.pathStroke(rgbm(C), false, 154)
        
         display.image {
                image = "assets/9.dds",
                pos = vec2(0, -1), 
                size = vec2(1024, 1024)
            } 
            
            display.text {
                text = string.format("%3d", car.lapCount), 
                pos = vec2(850, 440),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -15,
                color = rgbm(1,1,1,1)
            }
        
            display.text {
                text = string.format("%4d", car.poweredWheelsSpeed), 
                pos = vec2(800, 310),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -15,
                color = rgbm(1,1,1,1)
            }
        
            display.text {
                text = string.format("%3d", car.waterTemperature), 
                pos = vec2(-30, 310),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -10,
                color = rgbm(1,1,1,1)
            }
            
            display.text {
                text = string.format("%3.1f", car.oilPressure), 
                pos = vec2(10, 440),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -25,
                color = rgbm(1,1,1,1)
            }
        
            display.text {
                text = string.format("%d", car.oilTemperature), 
                pos = vec2(20, 570),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -10,
                color = rgbm(1,1,1,1)
            }
        
            display.text {
                text = string.format("%3d", car.fuel), 
                pos = vec2(830, 570),
                letter = vec2(60, 120),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -10,
                color = rgbm(1,1,1,1)
            }
        
            local value = math.saturate(math.min(math.max(car.performanceMeter, 0), 2) / 2)
            display.rect {
                color = rgbm(1,0,0,1),
                pos = vec2(520, 815), 
                size = vec2(380 * value, 24), 
                uvStart = vec2(0, 0), 
                uvEnd = vec2(value, 1) 
            }
        
            local value = math.saturate(math.min(math.max(-car.performanceMeter, 0), 2) / 2)
            display.rect {
                color = rgbm(0.35,0.73,0.29,1),
                pos = vec2(506, 815), 
                size = vec2(380 * -value, 24), 
                uvStart = vec2(0, 0), 
                uvEnd = vec2(value, 1) 
            }
        
            local time = car.bestLapTimeMs
            local formattedTime =
                string.format(
                "%01d:%02d:%02d",
                math.floor((time / (1000 * 60))) % 60,
                math.floor((time / 1000)) % 60,
                math.floor((time % 1000) / 100)
            )
            display.text {
                text = formattedTime,
                pos = vec2(20, 700),
                letter = vec2(50, 100),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -10
            }
        
            local time = car.lapTimeMs
            local formattedTime =
                string.format(
                "%01d:%02d:%02d",
                math.floor((time / (1000 * 60))) % 60,
                math.floor((time / 1000)) % 60,
                math.floor((time % 1000) / 100)
            )
            display.text {
                text = formattedTime,
                pos = vec2(690, 700),
                letter = vec2(50, 100),
                font = "c7_new",
                width = 46,
                alignment = 1,
                spacing = -10
            }
        
            local gearText = tostring(car.gear) 
            if car.gear == -1 then
                gearText = "R"
            end
            if car.gear == 0 then
                gearText = "N"
            end
            display.text {
                text = gearText,
                pos = vec2(430, 370),
                letter = vec2(160, 360),
                font = "mp4_big",
                width = 46,
                alignment = 0.5,
                spacing = 0
            }
            
end    

function modeJ(dt)
 
    display.image {
        image = "assets/10.dds",
        pos = vec2(0, -1),
        size = vec2(1024, 1024)
    }

    ui.beginRotation()
    ui.beginRotation()
    display.image {
        image = "assets/p.dds",
        pos = vec2(85, 360),
        size = vec2(485, 485)
    }
    ui.endRotation(-math.saturate(car.rpm / 8000)* 160)
    ui.endRotation(279)

    local value = math.saturate(math.min(math.max(car.performanceMeter, 0), 2) / 2)
    display.rect {
        color = rgbm(1,0,0,1),
        pos = vec2(674, 271), 
        size = vec2(215 * value, 24), 
        uvStart = vec2(0, 0), 
        uvEnd = vec2(value, 1) 
    }

    local value = math.saturate(math.min(math.max(-car.performanceMeter, 0), 2) / 2)
    display.rect {
        color = rgbm(0.35,0.73,0.29,1),
        pos = vec2(671, 271), 
        size = vec2(215 * -value, 24), 
        uvStart = vec2(0, 0), 
        uvEnd = vec2(value, 1) 
    }  

    local gearText = tostring(car.gear) 
    if car.gear == -1 then
        gearText = "R"
    end
    if car.gear == 0 then
        gearText = "N"
    end
    display.text {
        text = gearText,
        pos = vec2(465, 520),
        letter = vec2(95, 240),
        font = "mp4_big",
        width = 46,
        alignment = 0.5,
        spacing = 0,
        color = rgbm(0,0,0,1)
    }
    
    local time = car.bestLapTimeMs
    local formattedTime =
        string.format(
        "%01d:%02d:%02d",
        math.floor((time / (1000 * 60))) % 60,
        math.floor((time / 1000)) % 60,
        math.floor((time % 1000) / 100)
    )
    display.text {
        text = formattedTime,
        pos = vec2(640, 350),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -10,
        color = rgbm(0,0,0,1)
    }

    display.text {
        text = string.format("%4d", car.poweredWheelsSpeed), 
        pos = vec2(800, 470),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -15,
        color = rgbm(0,0,0,1)
    }

    display.text {
        text = string.format("%4d", car.waterTemperature), 
        pos = vec2(800, 595),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -15,
        color = rgbm(0,0,0,1)
    }

    display.text {
        text = string.format("%4d", car.fuel), 
        pos = vec2(800, 750),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -15,
        color = rgbm(0,0,0,1)
    }   

    display.text {
        text = string.format("%4d", car.oilTemperature), 
        pos = vec2(390, 750),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -15,
        color = rgbm(0,0,0,1)
    }   

    display.text {
        text = string.format("%4.1f", car.oilPressure), 
        pos = vec2(110, 750),
        letter = vec2(60, 120),
        font = "c7_new",
        width = 46,
        alignment = 1,
        spacing = -25,
        color = rgbm(0,0,0,1)
    }  

end   

local listOfModes = {modeA, modeB, modeC, modeD, modeE, modeF, modeG, modeH, modeI, modeJ} 
local currentMode = tonumber(ac.loadDisplayValue("displayMode", 1))
local lastExtraCState = false

function script.update(dt)
    ac.debug("Update Delta", dt)
    if car.extraC ~= lastExtraCState then 
        currentMode = currentMode + 1 
        if currentMode > #listOfModes then 
            currentMode = 1
        end
        ac.saveDisplayValue("displayMode", currentMode)
    end
    ac.debug("Current Page", currentMode)
    lastExtraCState = car.extraC
    listOfModes[currentMode](dt)
end



