Truncate a value to an integer

Hello:

I have an array with 10 patterns. I would like to use the slider function to manually shift to any of the 10 patterns. Multiplying the slider value by 10 gives me the integer portion for the arrayMode. How do I truncate everything to the right of the decimal point?

export var arrayMode = 0
export function sliderMyArraySlider(v) {
arrayMode = v * 10
}

modes = array(10)
modes[0] = (f) => f % 1
modes[1] = (f) => triangle(f)
modes[2] = (f) => wave(f)
modes[3] = (f) => square(f, .5)
modes[4] = (f) => triangle(triangle(f))
modes[5] = (f) => wave(triangle(f))
modes[6] = (f) => triangle(wave(f))
modes[7] = (f) => wave(wave(f))
modes[8] = (f) => square(wave(triangle(f)), .7)
modes[9] = (f) => wave(f) * triangle(f*1.3)

export function render(index) {

v = modes[arrayMode % 9](4 * index / pixelCount)
hsv(0, 0, v)
}

I’m not sure you actually need to truncate an index, but I’ve used the following for similar reasons

export function sliderOnRate(v) {rateval = floor(v*5)}

2 Likes

Thank you for the information.

1 Like