Pattern formation during mixing and segregation of flowing granular materials