Pixel Art Algorithm: Pixel Perfect

Created: 2021-12-09T21:33:50-06:00

Return to the Index

This card pertains to a resource available on the internet.

Filter out and don't dab a pixel if it would result in creating a degenerate section of pixel art.

pub fn pixel_perfect(path: &[Pixel]) -> Vec<Pixel> {
if path.len() == 1 || path.len() == 0 {
return path.iter().cloned().collect();
}
let mut ret = Vec::new();
let mut c = 0;

while c < path.len() {
if c > 0 && c+1 < path.len()
&& (path[c-1].point.x == path[c].point.x || path[c-1].point.y == path[c].point.y)
&& (path[c+1].point.x == path[c].point.x || path[c+1].point.y == path[c].point.y)
&& path[c-1].point.x != path[c+1].point.x
&& path[c-1].point.y != path[c+1].point.y
{
c += 1;
}

ret.push(path[c]);

c += 1;
}

ret
}