Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Class: Segment
- Author: Me a.k.a. Creator
- ]]--
- local Internal, Nano, NanoPath, ApplicationPath, ClassPath = ...
- local function Segment(x1,y1,x2,y2)
- --Private
- local x1 = x1
- local x2 = x2
- local y1 = y1
- local y2 = y2
- local maxX = x1 > x2 and x1 or x2
- local minX = x1 < x2 and x1 or x2
- local maxY = y1 > y2 and y1 or y2
- local minY = y1 < y2 and y1 or y2
- --Public
- local self = {}
- function self.render(resolution)
- local path = {}
- for i=0,1,1/resolution do
- path[#path + 1] = {x1*(1-i)+x2*i, y1*(1-i)+y2*i}
- end
- return path
- end
- --get x
- function self.getX(y)
- index = (y - y1)/(y2 - y1)
- print("Index:",index)
- if index <= 1 and index >= 0 then
- local toret = x1 + index*(x2 - x1)
- return toret
- end
- end
- --get y
- function self.getY(x)
- index = (x - x1)/(x2 - x1)
- print("Index:",index)
- if index <= 1 and index >= 0 then
- return y1 + index*(y2 - y1)
- end
- end
- --scanLine
- function self.scanRender()
- local path = {}
- local counter = 1
- for i=minY, maxY do
- path[counter] = self.getX(i)
- path[counter + 1] = i
- counter = counter + 2
- end
- return path
- end
- --Constructor
- return self
- end
- Internal.Graphics.Segment = Segment
- Nano.Segment = Segment
- --[[
- bluey = blacky1 + f*(blacky2 - blacky1)
- bluey - blacky1 = f*(blacky2 - blacky1)
- (bluey - blacky1)/(blacky2 - blacky1) = f
- ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement