Note that there are some explanatory texts on larger screens.

plurals
  1. PODraw a Bucket with multiple liquids
    text
    copied!<p>I need to draw a bucket and fill it with two different liquid colours (yellow and red).</p> <p>I have got so far in a hard coded version but I need to be able to specify the % of the bucket filled, so for instance 50% yellow then 10% red.</p> <p>I have never done graphics in C# so any and all help on this is appreciated. I also need a cleaner way of doing the bottom of the bucket as it draws a black line ontop of the yellow in the below example. <img src="https://i.stack.imgur.com/67B9H.png" alt="Current output of code"></p> <pre><code>private Bitmap drawBucket2() { Bitmap img = new Bitmap(200, 200); using (Graphics g = Graphics.FromImage(img)) { try { Pen penBlack = new Pen(Color.Black, 1); Pen penYellow = new Pen(Color.Yellow, 1); Brush brushYellow = new SolidBrush(Color.Yellow); Brush brushRed = new SolidBrush(Color.Red); Point[] pts = new Point[4]; pts[0] = new Point(11, 115); pts[1] = new Point(170, 115); pts[2] = new Point(162, 180); pts[3] = new Point(21, 180); g.FillEllipse(brushYellow, 11, 90, 160, 50); g.FillPolygon(brushYellow, pts); pts = new Point[3]; pts[0] = new Point(21, 180); pts[1] = new Point(91, 195); pts[2] = new Point(162, 180); g.FillClosedCurve(brushYellow, pts); /*outline */ g.DrawEllipse(penBlack, 2, 10, 180, 50); g.DrawLine(penBlack, 1, 35, 21, 180); g.DrawLine(penBlack, 182, 35, 162, 180); pts = new Point[3]; pts[0] = new Point(21, 180); pts[1] = new Point(91, 195); pts[2] = new Point(162, 180); g.DrawClosedCurve(penBlack, pts); } catch (Exception ex) { MessageBox.Show(ex.Message); } } return img; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload