last day (15 days later) » 

7:39 AM
-1
Q: Fill a circle that follows the cursor with more small circles

CleavenI'm creating a program for fun just to see what you can do with drawings on winforms and I thought of something but have no idea how to do it. I draw a circle around the cursor as it moves like this: protected override void OnPaint(PaintEventArgs e) { DrawTest(e.Graphics); base.OnPaint(...

 
TaW
part 1: Look into the tools you have. You want a TextureBrush. Part 2: This is really hard and you will need to clarify the events for yourself. Animantions are usually done with a Timer. - Do note that your drawing is non-persistent as it is not done in the Paint event. So it will be lost upon minimzing the form. - You could store a series of circles and in the Paint event draw them with varying colors, though, so they fade not in time but in moving around.
 
ok without the fading part and, just the drawing of many circles in the first one, how can i fill it?
 
TaW
- Do note that your drawing is non-persistent as it is not done in the Paint event. So it will be lost upon minimzing the form. - You could store a series of circles and in the Paint event and draw them with varying colors (goping from white for the oldest to black for the youngest ones), though, so they fade not in time but in moving around.
Do look into the TextureBrush. You can create a nice bitmap (or more than one) and use it to FillEllipse the same data.
 
I will look into the texture brush and play around with it thank you. It is done in the paint event, I'll update my code quick.
 
TaW
If you run into probelms feel free to ask and I'll show you an example..
 
7:39 AM
@TaW Hey, so i used a HatchBrush for now just as a quick example, is there a way to get the flickering away?
 
TaW
What are you drawing on? The Form? It exposes DoubleBuffering so you can turn it on. PictureBox has it on and shouldn't flicker. Panel and all other controls need to be sublassed to turn it on: class DrawPanel : Panel { public DrawPanel() { DoubleBuffered = true; } } . Instead of a Brush you can also use DrawImage and a set of prepared Bitmaps..
 
I'm gana try the bitmap way now and see how it goes :)
I'm drawing on the form and it is double buffered yes
 
8:05 AM
I think the flickering is because its redrawn all the time. cause the mouse is moving all the time
 
TaW
8:15 AM
Hi!, Yes, it is redrawn rather often, but with double-buffering and a machine from this century it shouldn't flicker. How large is the brush/circle you use?
Btw: Your posted code still contains Graphics myGraphics1 = base.CreateGraphics(); Not used in the drawing but still quite useless and (almost) always wrong. Do replace by e.Graphics. And don't set PixelOffsetMode unless you really need it. Set SmoothingMode.AntiAlias if you want to..
 
8:31 AM
public Form1()
{
timer1.Tick += timer1_Tick;
}

Timer timer1 = new Timer() { Interval = 15, Enabled = true };

protected override void OnPaint(PaintEventArgs e)
{
DrawTest(e.Graphics);
base.OnPaint(e);
}

private void DrawTest(Graphics g)
{
var p = PointToClient(Cursor.Position);
Image image = new Bitmap("Untitled.png");
TextureBrush tBrush = new TextureBrush(image);
tBrush.Transform = new Matrix(
75.0f / 640.0f,
0.0f,
0.0f,
75.0f / 480.0f,
0.0f,
0.0f);
g.FillEllipse(tBrush, p.X - 75, p.Y - 75, 150, 150);
That is literally my code, I know it not muh but its my first time working with brushes and stuff so im just using examples ill post my image on imgur for you
Then you can see if it flickers by you :)
 
TaW
9:13 AM
Ah, I see. Well the flicker is really just the enforced painting from the tick. Simply Invalidate from the MouseMove, maybe like this: `private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button.HasFlag(MouseButtons.Left))
{ mLoc = e.Location;
Invalidate();
}
}`
I stored the mouse location but your code doesn't need it. The SO chat editor is a pice of crap and I can#t delete the line :-(
The Timer is one way to achieve a fading effect, not meant to be used here.
 
TaW
9:27 AM
To make it work either with or without a timer you would need to store a list of old locations and in the draw paint the brush onto all locations but with a color that fades in from background to foreground
This is all without a timer but with a list is Bitmaps (going from white to black) and a list of Points; the list have a length of 44.
 
9:40 AM
If i take out my timer, i get nothing on my screen unless resize the form, check here
That is exactly what I wana do xD
 
TaW
Did you code (and hook up) the he mousemove code above? It check for the left button to be pressed.
 
9:57 AM
Wait, it was my mistake, I took out my override method and then just used the normal paint method.
Ok so
Step 1: create bitmaps of my image fading
Step 2: store a list of locations where the mouse was
Step 3: Put the images in those locations
 
TaW
Right, that how the screenshot was created. This is the drawing loop in the Paint event: `for (int i = 0; i < points.Count; i++)
if (cbx_timerFade.Checked)
{
e.Graphics.DrawImage(textures[i], points[i].X - dia/2, points[i].Y - dia/2);
}
else
{
using (TextureBrush tbr = new TextureBrush(textures[i], WrapMode.Tile))
{
tbr.RotateTransform(i*4);
Rectangle r2 = new Rectangle(points[i].X - dia / 2, points[i].Y - dia / 2, dia, dia);
e.Graphics.FillEllipse(tbr, r2);
}
}`
And this is my MouseMove: `if (e.Button.HasFlag(MouseButtons.Left))
{
mLoc = e.Location;
points.Add(mLoc);
if (points.Count > tail) points.RemoveAt(0);
drawPanel1.Invalidate();
}`
Using these variables `List<Point> points = new List<Point>();
List<Bitmap> textures = new List<Bitmap>();
int tail = 44;
int density = 77;
`
 
and you store the fading bitmaps in the texture list?
 
TaW
right.
 
10:13 AM
Ok, Let me use my head and figure this out and I'll get back to you :D how many images did you make?
 
TaW
screentogif.codeplex.com - Good luck. I'll be away for 2 days now..
My tail length was 44
 

  last day (15 days later) »