I’m trying to draw some Bézier curves for starters. i’m mainly just experimenting with how to draw pixel-based lines and curves.

for example:

This little roundRect class I wrote. I’d like to add the ability for visual feedback when the mesh is touched, but i’m not sure if meshes are the way to go. maybe image() is. I’m just thinking that meshes are triangles, which are native to the graphics card processor, so i’m assuming they’ll always be faster than regular images. but I don’t know

```
RoundRect = class()
--RoundRect oobject constructed from Points for the curves
-- and mesh rects for the straight line
function RoundRect:init(x, y, w, h, r, lineWidth, c)
-- you can accept and set parameters here
self.x = x -- center x
self.y = y -- center y
self.w = w -- overall width
self.h = h -- overall height
self.r = r -- corner radius
self.lineWidth = lineWidth
self.c = c -- colors
a = w-2*r
b = h-2*r
self.m = mesh()
self.m:addRect( x, y + h/2, a, lineWidth )
self.m:addRect( x, y - h/2, a, lineWidth )
self.m:addRect( x-w/2, y, lineWidth, b )
self.m:addRect( x+w/2, y, lineWidth, b )
--this lineWidth stuff is intended to make the curves match the width of the straight lines, but it doesn't
--that's why it's commented out for now
--for lw=0, lineWidth do
-- r = r + lw -- 1st: r, 2nd: r+1, 3rd: r+2, etc
numPoints = math.ceil( math.pi * r * r )
offset = numPoints/4
for i=1, numPoints/4 do
_x = x-a/2 + r * math.sin( 2 * math.pi * ((i + offset*3)/numPoints))
_y = y+b/2 + r * math.cos( 2 * math.pi * ((i + offset*3)/numPoints))
self.m:addRect( _x, _y, 1, 1 )
_x = x+a/2 + r * math.sin( 2 * math.pi * ((i )/numPoints))
_y = y+b/2 + r * math.cos( 2 * math.pi * ((i )/numPoints))
self.m:addRect( _x, _y, 1, 1 )
_x = x+a/2 + r * math.sin( 2 * math.pi * ((i + offset*1)/numPoints))
_y = y-b/2 + r * math.cos( 2 * math.pi * ((i + offset*1)/numPoints))
self.m:addRect( _x, _y, 1, 1 )
_x = x-a/2 + r * math.sin( 2 * math.pi * ((i + offset*2)/numPoints))
_y = y-b/2 + r * math.cos( 2 * math.pi * ((i + offset*2)/numPoints))
self.m:addRect( _x, _y, 1, 1 )
end
--end
self.m:setColors( c )
end
function RoundRect:draw()
-- Codea does not automatically call this method
self.m:draw()
end
function setup()
r = RoundRect( WIDTH/2, HEIGHT/2, 200, 200, 50, 1, color( 255, 0, 0, 255) )
end
function draw()
background(0, 0, 0, 255)
r:draw()
end
```