abs

.abs()

Returns the 'absolute' of this number. The absolute is the positive version of a number. So if it is negative, it will return it as a positive value.

For example the absolute of 3 and -3, are both 3.

n = -9.abs() // set to 9
n =  9.abs() // also set to 9

Advanced Example

Draws a ball bouncing along the 'absolute' of a sine wave.

x = 100
angle = 0
size = 120

onEachFrame() do |delta|
    fill( :green )
    
    angle = angle + delta/30
    
    x = (x + delta*2) % getScreenWidth()
    y = getScreenHeight() * angle.sin().abs()
    
    setColor( :white )
    
    fillCircle( x, getScreenHeight() - y, size, :center, :bottom )
    
    // draw the circles ahead and behind, for screen wrapping
    fillCircle( x-getScreenWidth(), getScreenHeight() - y,
            size, :center, :bottom )
    fillCircle( x+getScreenWidth(), getScreenHeight() - y,
            size, :center, :bottom )
end