Posted 11 June 2015 - 12:54 PM
awsumben13 and I have been experimenting with drawing bezier curves for when Dan hopefully unveils these shiny new graphic options.
Drawing the line is almost trivial really (although note while in this code we do each point one by one we'll be using less points and drawing lines between them).
Here's the code for that:
That hard bit is filling them. We'll have closed subdivided paths later.
This page linked to by Bomb Bloke on SquidDev's Font API is the kind of technique we are thinking of using. The issue is actually finding the intersection points and y = 2, for example.
Is there some maths wizardry we can use, or do we have to use triangles, which most other libraries seem to use. We thought that using triangles would be far slower in Lua. Although asking Mr Wolfram Alpha shows that solving for t (I used x here) isn't really that… friendly.
Drawing the line is almost trivial really (although note while in this code we do each point one by one we'll be using less points and drawing lines between them).
Here's the code for that:
Spoiler
term.clear()
function calculateBezierPoint( t, p1, p2, p3, p4 )
local u = 1 - t
local tt = t * t
local ttt = tt * t
local uu = u * u
local uuu = uu * u
return uuu * p1.x + 3 * uu * t * p2.x + 3 * u * tt * p3.x + ttt * p4.x, -- x
uuu * p1.y + 3 * uu * t * p2.y + 3 * u * tt * p3.y + ttt * p4.y -- y
end
local SEGMENT_COUNT = 1000
local p1 = { x = 2, y = 2 }
local p2 = { x = 17,y = 2 }
local p3 = { x = 50,y = 19 }
local p4 = { x = 7,y = 12 }
term.setBackgroundColour( colours.green )
for i = 0, SEGMENT_COUNT do
t = i / SEGMENT_COUNT;
local x, y = calculateBezierPoint( t, p1, p2, p3, p4)
term.setCursorPos( x, y )
term.write( ' ' )
end
term.setCursorPos( 1,1 )
That hard bit is filling them. We'll have closed subdivided paths later.
This page linked to by Bomb Bloke on SquidDev's Font API is the kind of technique we are thinking of using. The issue is actually finding the intersection points and y = 2, for example.
Is there some maths wizardry we can use, or do we have to use triangles, which most other libraries seem to use. We thought that using triangles would be far slower in Lua. Although asking Mr Wolfram Alpha shows that solving for t (I used x here) isn't really that… friendly.
Edited on 11 June 2015 - 10:56 AM