ref: f4c7c756294c31500e69f267deac932a65ebd7e9
parent: b1fa4d619f1ffab63ffa774489900192bf17996a
author: phil9 <telephil9@gmail.com>
date: Fri Dec 2 11:37:54 EST 2022
implement bezier()
--- a/api.c
+++ b/api.c
@@ -378,6 +378,29 @@
}
int
+cbezier(lua_State *L)
+{
+ Point p0, p1, p2, p3;
+ int x1, y1, x2, y2, x3, y3, x4, y4;
+
+ x1 = luaL_checkinteger(L, 1);
+ y1 = luaL_checkinteger(L, 2);
+ x2 = luaL_checkinteger(L, 3);
+ y2 = luaL_checkinteger(L, 4);
+ x3 = luaL_checkinteger(L, 5);
+ y3 = luaL_checkinteger(L, 6);
+ x4 = luaL_checkinteger(L, 7);
+ y4 = luaL_checkinteger(L, 8);
+ p0 = canvaspt(x1, y1);
+ p1 = canvaspt(x2, y2);
+ p2 = canvaspt(x3, y3);
+ p3 = canvaspt(x4, y4);
+ if(!nostroke)
+ bezier(canvas, p0, p1, p2, p3, strokecap, strokecap, strokeweight, stroke, ZP);
+ return 0;
+}
+
+int
ctriangle(lua_State *L)
{
Point p[4];
@@ -557,6 +580,7 @@
registerfunc(L, "circle", ccircle);
registerfunc(L, "ellipse", cellipse);
registerfunc(L, "arc", carc);
+ registerfunc(L, "bezier", cbezier);
registerfunc(L, "triangle", ctriangle);
registerfunc(L, "quad", cquad);
registerfunc(L, "translate", ctranslate);
--- /dev/null
+++ b/samples/bezier.lua
@@ -1,0 +1,16 @@
+#!/bin/slug
+
+function setup()
+ size(400, 400)
+end
+
+function draw()
+ background(220)
+ noFill()
+ stroke(255, 102, 0)
+ line(340, 80, 40, 40)
+ line(360, 360, 60, 320)
+ stroke(0, 0, 0)
+ bezier(340, 80, 40, 40, 360, 360, 60, 320)
+end
+