Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function intY(a,b,y)
- return a.x + ((y - a.y) * (b.x - a.x)) / (b.y - a.y)
- end
- --get the t value for a point (p) somewhere between the line formed from two give points (a,b)
- local function getT(a,b,p)
- local v1 = vector.new( a.x-b.x, a.y-b.y )
- local v2 = vector.new( a.x-p.x, a.y-p.y )
- return (v1:dot(v2)) / (v1:dot(v1))
- end
- --use the t value of a point to interpolate between two given values (v1,v2)
- --for interpolating between z's, v1 = starting z value, v2 = ending z value
- local function lerp(v1,v2,t)
- return (1 - t) * v1 + t * v2
- end
- local function pPix(x,y,c)
- term.setCursorPos(x,y)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.write(c)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- local function fill(a,b,c)
- if a.y < b.y then a,b = b,a end
- if a.y < c.y then a,c = c,a end
- if b.x > c.x then b,c = c,b end
- for y = b.y, a.y-1 do
- local xStart = intY(a,b,y)
- local xEnd = intY(a,c,y)
- local p1 = vector.new(xStart,y)
- local p2 = vector.new(xEnd,y)
- local t1 = getT(a,b,p1)
- local t2 = getT(a,c,p2)
- local z1 = lerp(a.z,b.z,t1)
- local z2 = lerp(a.z,c.z,t2)
- for x = xStart, xEnd do
- local t3 = (x - xStart) / (xEnd - xStart)
- local z = math.floor(lerp(z1,z2,t3))
- pPix(x,y,z)
- end
- end
- end
- local a = vector.new(20,20,9)
- local b = vector.new(2,2,1)
- local c = vector.new(30,2,4)
- term.clear()
- fill(a,b,c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement