0

I'm trying to create a very simple example of a for steps in [] loop using a Polyline() inside an IronPython WPF application. Each iteration of the loop should draw a different colour however Brushes implements a set of predefined System.Windows.Media.SolidColorBrush objects. I can't work out how to swap Red for my steps variable.

def polylineShape(self):

    x = self.myCanvas.Width/2
    y = self.myCanvas.Height/2
    polyline = Polyline()
    polyline.StrokeThickness = 5


    for steps in ['Red','Blue','Green','Black']:
        x = x
        y = x            
        polyline.Points.Add(Point(x,y))
        x = x + 40
        polyline.Points.Add(Point(x,y))
        polyline.Stroke = Brushes.Red        #change colour on iteration

    self.myCanvas.Children.Add(polyline)
  • Thanks for your input, I've developed my original effort but couldn't figure a way of passing the colour without passing the brush. My source is here if interested. [https://github.com/drillep/U14EDP](https://github.com/drillep/U14EDP) – Gary Davies Oct 30 '15 at 00:56

1 Answers1

0

I created a solution with some trial and error, I couldn't work out how to pass colours directly to the Brushes type.

def polylineShape(self):
    x = 0
    y = 0

    for steps in [Brushes.SteelBlue, Brushes.DarkOrange, Brushes.DarkSeaGreen, Brushes.Honeydew]:
        polyline = Polyline()                                           
        polyline.StrokeThickness = self.myCanvas.Height/4               
        x = 0                                                           
        y = y + self.myCanvas.Height/4                                  
        polyline.Points.Add(Point(x,y))                                 

        x = self.myCanvas.Width                                         
        polyline.Points.Add(Point(x,y))                                 

        polyline.Stroke = steps                                         

        self.myCanvas.Children.Add(polyline)