mirror of
https://github.com/SleepingInsomniac/pixelfaucet
synced 2024-11-17 07:48:20 +01:00
Add linear interpolation function to line
This commit is contained in:
parent
304a8a8830
commit
2e3d2b67b5
2 changed files with 9 additions and 4 deletions
|
@ -61,6 +61,11 @@ module PF
|
|||
(y - p1.y) / slope + p1.x
|
||||
end
|
||||
|
||||
# Linearly interpolate
|
||||
def lerp(t : Float64)
|
||||
(@p2 - @p1) * t + @p1
|
||||
end
|
||||
|
||||
def length
|
||||
Math.sqrt((run.abs * 2) + (rise.abs * 2))
|
||||
end
|
||||
|
|
|
@ -53,19 +53,19 @@ module PF
|
|||
end
|
||||
|
||||
def *(n : Float64)
|
||||
PF::Pixel.new((@r * n).to_u8, (@g * n).to_u8, (@b * n).to_u8, @a)
|
||||
Pixel.new((@r * n).to_u8, (@g * n).to_u8, (@b * n).to_u8, @a)
|
||||
end
|
||||
|
||||
def /(n : Float64)
|
||||
PF::Pixel.new((@r / n).to_u8, (@g / n).to_u8, (@b / n).to_u8, @a)
|
||||
Pixel.new((@r / n).to_u8, (@g / n).to_u8, (@b / n).to_u8, @a)
|
||||
end
|
||||
|
||||
def +(n : Float64)
|
||||
PF::Pixel.new((@r + n).to_u8, (@g + n).to_u8, (@b + n).to_u8, @a)
|
||||
Pixel.new((@r + n).to_u8, (@g + n).to_u8, (@b + n).to_u8, @a)
|
||||
end
|
||||
|
||||
def -(n : Float64)
|
||||
PF::Pixel.new((@r - n).to_u8, (@g - n).to_u8, (@b - n).to_u8, @a)
|
||||
Pixel.new((@r - n).to_u8, (@g - n).to_u8, (@b - n).to_u8, @a)
|
||||
end
|
||||
|
||||
def to_u
|
||||
|
|
Loading…
Reference in a new issue