@@ -190,6 +190,24 @@ module UnicodePlot
190190 self
191191 end
192192
193+ # Plot a vector of points with per-point colors
194+ def points !(xs : Array (Float64 ), ys : Array (Float64 ), colors : Array (UInt32 ), blend : Bool ) : self
195+ unless xs.size == ys.size
196+ raise ArgumentError .new(" xs and ys must have the same length" )
197+ end
198+
199+ unless xs.size == colors.size
200+ raise ArgumentError .new(" colors must have the same length as xs and ys" )
201+ end
202+
203+ xs.each_with_index do |x , i |
204+ y = ys[i]
205+ next unless x.finite? && y.finite?
206+ points!(x, y, colors[i], blend)
207+ end
208+ self
209+ end
210+
193211 # Digital differential analyser (DDA) line drawing
194212 def lines !(
195213 x1 : Float64 , y1 : Float64 ,
@@ -246,6 +264,26 @@ module UnicodePlot
246264 self
247265 end
248266
267+ # Vector line drawing (polyline) with per-segment colors
268+ def lines !(xs : Array (Float64 ), ys : Array (Float64 ), segment_colors : Array (UInt32 ), blend : Bool ) : self
269+ unless xs.size == ys.size
270+ raise ArgumentError .new(" xs and ys must have the same length" )
271+ end
272+
273+ expected = xs.size > 0 ? xs.size - 1 : 0
274+ unless segment_colors.size == expected
275+ raise ArgumentError .new(" segment_colors must have xs.size - 1 elements" )
276+ end
277+
278+ (1 ...xs.size).each do |i |
279+ x, y = xs[i], ys[i]
280+ xm1, ym1 = xs[i - 1 ], ys[i - 1 ]
281+ next unless x.finite? && y.finite? && xm1.finite? && ym1.finite?
282+ lines!(xm1, ym1, x, y, segment_colors[i - 1 ], blend)
283+ end
284+ self
285+ end
286+
249287 # Annotate a character at canvas coords (x, y)
250288 def annotate !(x : Float64 , y : Float64 , char : Char , color : UInt32 , blend : Bool ) : self
251289 return self unless valid_x?(x) && valid_y?(y)
0 commit comments