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
```
2019-12-02 05:58:26 +01:00
## Returns
2016-03-26 00:47:20 +01:00
2019-12-02 05:58:26 +01:00
* [Number ](/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:
2019-12-02 05:58:26 +01:00
## ~hide
2016-03-26 00:47:20 +01:00
2016-08-09 17:52:24 +02:00
```blocks
2016-03-26 00:47:20 +01:00
let img = images.createImage(`
. . # . . . . . . .
. # . # . . . # . .
. . # . . . . . . .
. # . # . . . # . .
. . # . . . . . . .
`)
```
2019-12-02 05:58:26 +01:00
## ~
2016-03-26 00:47:20 +01:00
2016-08-10 14:43:48 +02:00
```typescript-ignore
2016-03-26 00:47:20 +01:00
let w = img.width()
```
2019-12-02 05:58:26 +01:00
## Example: show each frame
2016-03-26 00:47:20 +01:00
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
2016-08-10 14:43:48 +02:00
```typescript
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)
}
```
2019-12-02 05:58:26 +01:00
## See also
2016-03-26 00:47:20 +01:00
2016-06-19 14:28:46 +02:00
[show image ](/reference/images/show-image ), [image ](/reference/images/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