@@ -91,7 +91,8 @@ func DefaultBuiltins(rt Runtime) Builtins {
9191 "colour" : stringBuiltin ("colour" , rt .Color ),
9292 "clear" : {Func : clearFunc (rt .Clear ), Decl : clearDecl },
9393
94- "poly" : {Func : polyFunc (rt .Poly ), Decl : polyDecl },
94+ "poly" : {Func : polyFunc (rt .Poly ), Decl : polyDecl },
95+ "ellipse" : {Func : ellipseFunc (rt .Ellipse ), Decl : ellipseDecl },
9596
9697 "stroke" : stringBuiltin ("stroke" , rt .Stroke ),
9798 "fill" : stringBuiltin ("fill" , rt .Fill ),
@@ -152,6 +153,7 @@ type GraphicsRuntime interface {
152153
153154 // advanced graphics functions
154155 Poly (vertices [][]float64 )
156+ Ellipse (x , y , radiusX , radiusY , rotation , startAngle , endAngle float64 )
155157 Stroke (s string )
156158 Fill (s string )
157159 Dash (segments []float64 )
@@ -197,6 +199,9 @@ func (rt *UnimplementedRuntime) Text(s string) { rt.Unimplemented("t
197199func (rt * UnimplementedRuntime ) Textsize (size float64 ) { rt .Unimplemented ("textsize" ) }
198200func (rt * UnimplementedRuntime ) Font (s string ) { rt .Unimplemented ("font" ) }
199201func (rt * UnimplementedRuntime ) Fontfamily (s string ) { rt .Unimplemented ("fontfamily" ) }
202+ func (rt * UnimplementedRuntime ) Ellipse (x , y , rX , rY , rotation , startAngle , endAngle float64 ) {
203+ rt .Unimplemented ("ellipse" )
204+ }
200205
201206var readDecl = & parser.FuncDeclStmt {
202207 Name : "read" ,
@@ -607,6 +612,40 @@ func polyFunc(polyFn func([][]float64)) BuiltinFunc {
607612 }
608613}
609614
615+ var ellipseDecl = & parser.FuncDeclStmt {
616+ Name : "ellipse" ,
617+ VariadicParam : & parser.Var {Name : "n" , T : parser .NUM_TYPE },
618+ ReturnType : parser .NONE_TYPE ,
619+ }
620+
621+ func ellipseFunc (ellipseFn func (x , y , radiusX , radiusY , rotation , startAngle , endAngle float64 )) BuiltinFunc {
622+ return func (_ * scope , args []Value ) (Value , error ) {
623+ argLen := len (args )
624+ if argLen < 3 || argLen == 6 || argLen > 7 {
625+ return nil , fmt .Errorf ("%w: 'ellipse' requires 3, 4, 5 or 7 arguments, found %d" , ErrBadArguments , argLen )
626+ }
627+ x := args [0 ].(* Num ).Val
628+ y := args [1 ].(* Num ).Val
629+ radiusX := args [2 ].(* Num ).Val
630+ radiusY := radiusX
631+ rotation := 0.0
632+ startAngle := 0.0
633+ endAngle := 360.0
634+ if argLen > 3 {
635+ radiusY = args [3 ].(* Num ).Val
636+ }
637+ if argLen > 4 {
638+ rotation = args [4 ].(* Num ).Val
639+ }
640+ if argLen > 6 {
641+ startAngle = args [5 ].(* Num ).Val
642+ endAngle = args [6 ].(* Num ).Val
643+ }
644+ ellipseFn (x , y , radiusX , radiusY , rotation , startAngle , endAngle )
645+ return nil , nil
646+ }
647+ }
648+
610649var dashDecl = & parser.FuncDeclStmt {
611650 Name : "dash" ,
612651 VariadicParam : & parser.Var {Name : "segments" , T : parser .NUM_TYPE },
0 commit comments