in the open source project I work on we use "more than half" as our rule of thumb for a rewrite that adds a name to the copyright. and "nearly all" to remove a name. these are likely reasonably conservative guidelines. And it isn't lines of code strictly, but more of an implied "of the content" where different bits can have different weights as to what went into the "work" that was created. plus we tend to bias towards keeping attribution when in doubt to be polite and neighborly.
it is a thorny problem to get an absolute answer. legally, it's when the "reduced form" of the work differs enough to not infringe. there are many tests in legal cases, but they all involve breaking to code down to basic blocks, ignoring differences in variable names, removing the things that can only be done one way, etc.
so a color line, like the example you gave, has no copyright protection because red is red, you can't copyright facts (eg the numbers that make up a color) and there is one or a small number of ways in the language to say red.