2016-03-26 00:47:20 +01:00
# Width
2016-04-02 01:22:47 +02:00
The width function.
2016-03-26 00:47:20 +01:00
2016-04-16 00:02:26 +02:00
Get the width of an [Image ](/reference/images/image ) in columns.
2016-03-26 00:47:20 +01:00
2016-04-18 17:33:09 +02:00
```sig
images.createImage().width();
2016-03-26 00:47:20 +01:00
```
### Parameters
* none
### Returns
2016-04-13 17:27:45 +02:00
* [Number ](/reference/types/number ) - the number of columns in a image. This function returns 5 if the image has 1 frame, 10 for 2 frames, 15 for 3 frames and so on. Divide the number of columns by 5 to find out how many frames an image has (see example below).
2016-03-26 00:47:20 +01:00
The following example gets the width of `img` and stores it in the `w` variable:
### ~hide
```
let img = images.createImage(`
. . # . . . . . . .
. # . # . . . # . .
. . # . . . . . . .
. # . # . . . # . .
. . # . . . . . . .
`)
```
### ~
```
let w = img.width()
```
### Example: show each frame
2016-06-14 23:20:45 +02:00
The following example uses the `width` function with a [for ](/blocks/loops/for ) loop to show each image frame on the screen:
2016-03-26 00:47:20 +01:00
```
let img2 = images.createImage(`
. . # . . . # # # # . # # # .
. # # . . . . . . # . . . # .
. . # . . . . . # . . . # . .
. . # . . . . # . . . . . # .
. . # . . . # # # # . # # # .
`)
for (let i = 0; i < img2.width ( ) / 5 ; i + + ) {
img2.showImage(i * 5)
basic.pause(1000)
}
```
### See also
2016-04-13 17:27:45 +02:00
[show image ](/reference/images/show-image ), [image ](/reference/image/image ), [create image ](/reference/images/create-image ), [scroll image ](/reference/images/scroll-image ), [show animation ](/reference/basic/show-animation )
2016-03-26 00:47:20 +01:00