# FrameBuffer.poly(x, y, coords, c\[, f\]) - help needed

**URL:** https://forums.pimoroni.com/t/framebuffer-poly-x-y-coords-c-f-help-needed/23573
**Category:** Support
**Created:** [December 20, 2023, 3:34pm UTC](https://forums.pimoroni.com/t/framebuffer-poly-x-y-coords-c-f-help-needed/23573 "2023-12-20T15:34:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Tonygo2](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonygo2/32/7814_2.png) [@Tonygo2](https://forums.pimoroni.com/u/Tonygo2)
#### Post date: [December 20, 2023, 3:34pm UTC](https://forums.pimoroni.com/t/framebuffer-poly-x-y-coords-c-f-help-needed/23573/1 "2023-12-20T15:34:43Z")

</div>

I’ve been trying to get this to draw a filled rectangle on a mono oled (ssd1306 SPI / I2C and similar)

The MicroPython documentation for Pico in Read-the-Docs provides:

**FrameBuffer.poly** (x, y, coords, c[, f])¶

Given a list of coordinates, draw an arbitrary (convex or concave) closed polygon at the given x, y location using the given color.

The coords must be specified as a array of integers, e.g. array(‘h’, [x0, y0, x1, y1, … xn, yn]).

The optional f parameter can be set to True to fill the polygon. Otherwise just a one pixel outline is drawn.

I’ve not needed to use **array** before and cannot get the syntax right. [10,10,120,30,30,61] are the coordinates I want to use.

Has anyone got this to work?

---

<div class="post-metadata">

### Author: ![Shoe](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shoe](https://forums.pimoroni.com/u/Shoe)
#### Post date: [December 20, 2023, 10:23pm UTC](https://forums.pimoroni.com/t/framebuffer-poly-x-y-coords-c-f-help-needed/23573/2 "2023-12-20T22:23:12Z")

</div>

> [@Tonygo2](#):
>
> The coords must be specified as a array of integers, e.g. array(‘h’, [x0, y0, x1, y1, … xn, yn]).

So I’ve not done this, but it looks like it would be easiest to define the array separately first. The MicroPython documentation also seems to point to [the Python documentation for arrays](https://docs.python.org/3.5/library/array.html#module-array).

I’m not sure what you’ve tried, but it looks like you need to create an object of type `array`.

```auto
import array
myData = array.array()

```

You also need to declare the type of data in the array. `h` looks like it is for a signed short, which I’m assuming makes no sense as your coordinates will always be positive integers, so unsigned int (‘I’) or unsigned char (?) (‘B’) might make more sense.

```auto
import array
myData = array.array('I')

```

And then add your data

```auto
import array
myData = array.array('I', [10,10,120,30,30,61])

```

Then call the `FrameBuffer` function:

```auto
import array
myData = array.array('I', [10,10,120,30,30,61])

FrameBuffer.poly(x, y, myData, c)

```

That’s what I’d take away from that anyway.

---

<div class="post-metadata">

### Author: ![Tonygo2](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonygo2/32/7814_2.png) [@Tonygo2](https://forums.pimoroni.com/u/Tonygo2)
#### Post date: [December 21, 2023, 7:57am UTC](https://forums.pimoroni.com/t/framebuffer-poly-x-y-coords-c-f-help-needed/23573/3 "2023-12-21T07:57:23Z")

</div>

Thank you, Shoe

```auto
import time, math
from machine import Pin, I2C, ADC
import ssd1306
import framebuf
import array

WIDTH = 128 # oled display width
HEIGHT = 64 # oled display height

sda=machine.Pin(8)
scl=machine.Pin(9)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)

oled = ssd1306.SSD1306_I2C(128, 64, i2c)

myData = array.array('I', [10,10,120,30,30,61])

oled.poly(0, 0, myData, 1,1)
oled.show()

```

That has got it working.

Rather strange that we need to include an offset from the origin as the first two numbers, x and y. Could use it to move the triangle about without a load of adjustments to the array.

---

<div class="post-metadata">

### Author: ![Shoe](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shoe](https://forums.pimoroni.com/u/Shoe)
#### Post date: [December 21, 2023, 10:23am UTC](https://forums.pimoroni.com/t/framebuffer-poly-x-y-coords-c-f-help-needed/23573/4 "2023-12-21T10:23:43Z")

</div>

Glad you got it working. Like you said, I assume the x/y offset is for animating an object around the screen or duplicating it in several places.
