Fuze Arena Logo
  • Forum
  • Creations
    Catalogue Showcase
  • Help

lerp()

Purpose

Linear interpolation

Description

Returns an interpolation between two inputs (v0, v1) for a parameter (t) in the closed unit interval [0, 1]. This lerp function is commonly used for alpha blending (the parameter "t" is the "alpha value"), and the formula may be extended to blend multiple components of a vector (such as spatial x, y, z axes or r, g, b colour components) in parallel.

Syntax

result = lerp( v0, v1, t )

Arguments

result linear interpolation

v0 first value

v1 second value

t t parameter from 0 to 1

Example

image = loadImage( "Untied Games/Knight", false )
sprite = createSprite()
setSpriteImage( sprite, image )
setSpriteAnimation( sprite, 8, 11, 10 )
setSpriteScale( sprite, 5, 5 )
sprite.y = 100
start_x = 0
end_x = gWidth()
t = 0
duration = 5
reverse = false
loop
    clear()
    t += deltaTime() // duration
    if t >= 1 then
        t = 0
        //reverse direction by swapping start and end
        temp = start_x
        start_x = end_x
        end_x = temp
        //reverse the character graphics direction
        sprite.xscale *= -1
    endIf   
    sprite.x = lerp( start_x, end_x, t )
    updateSprites()
    drawSprites()
    update()
repeat

Associated Commands

bezier(), smoothStep()

logo

©2019 FUZE Technologies Ltd. FUZE is a registered trademark of FUZE Technologies Ltd. All rights reserved.

Useful links

  • Fuze Main Site
  • Fuze Arena on Twitter
  • Fuze Arena on Youtube
  • Download Buyer

Contact Information

  • FUZE Technologies Ltd
    15 Clearfields Farm
    Wotton Underwood
    Aylesbury, Buckinghamshire
    ​England, HP18 0RS

  • +44 (0) 1844 239 432

  • contact@fuze.co.uk

© Copyright FUZE Technologies Ltd. All rights reserved.