-- Ellipse and Circle Maker, variation 2
-- lua script for drawing ellipse or circle
-- some basic constants

local w_mid = width / 2
local h_mid = height / 2
local screen_radius = math.sqrt((w_mid * w_mid) + (h_mid * h_mid))
local r2d = 180 / 3.14159265

-- allow the user to change the settings.
-- Note the sliders have range is 0 .. 1.0 for reading but have range 1..100 for setting
--@TBCONFIG SLIDER: Horizontal Stretch, 50
--@TBCONFIG SLIDER: Vertical Stretch, 50
--@TBCONFIG SLIDER: Size of Figure Drawn, 40
--@TBCONFIG SLIDER: Arc Length, 100

local ucenterX = math.floor(.50 * width)
local ucenterY = math.floor(.50 * height)
local uscale = sliderVal3 * 1000
local revolutions = sliderVal4 * math.pi * 2

function ellipse(centerX, centerY)
local current_x = 0
local current_y = 0
local new_x, new_y
local o, t

for t = 0, revolutions , 0.01 do
new_x = math.cos(t) + uscale * (sliderVal1 * math.cos(t))
new_y = math.sin(t) - uscale * (sliderVal2 * math.sin(t))
new_x = new_x + centerX
new_y = new_y + centerY

if current_x == 0 then current_x = new_x end
if current_y == 0 then current_y = new_y end

paint_stroke_pos(current_x, current_y, 100)

current_x = new_x
current_y = new_y
end
end

paint_open(1)
paint_stroke_start(0, 0)
ellipse(ucenterX, ucenterY)
paint_stroke_stop()
paint_close()