Let the $i$th line be given by $a_i x + b_i y + c_i=0$. Note that $a_i x + b_i y + c_i$ is positive on one side of the line and negative on the other side. Thus
$$f(x,y)=\prod_i\left(a_i x + b_i y + c_i\right)$$
is a function which changes sign whenever you cross a line. Color red if $f$ is positive and green if $f$ is negative.
In simpler terms, for every line you can construct a function which is positive on one side of the line and negative on the other side. Say for the $i$th line this function is $f_i(x,y)$.
If you multiply all these functions together, you get a function which changes sign whenever you cross a line, i.e. no two adjacent regions have the same sign. This is precisely the function you are asked to construct.