Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

Can someone help me on developing a screensaver like Windows 8 Bubble screensaver on WPF
I used the belowlink for my reference..
http://channel9.msdn.com/coding4fun/articles/WPF-Custom-Screen-Saver-Art[^]

I am facing a problem that bubbles are overlapping on each other..

Could someone guide me on how to stop overlapping the bubbles and also It should work like a
windows 8 bubble screensaver.

Any help would be sincerely appreciated..

BestRegards,
Henry
Posted
Updated 24-Oct-13 1:00am
v2
Comments
Matt T Heffron 25-Oct-13 12:44pm    
What have you tried?
We can't really help without seeing the code where the difficulties lie.
Henrynetdev 25-Oct-13 13:26pm    
I tried to compare the x and y coordinates values in the Spring() Method, which is used to in the following event CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);

When two particles x and y coordinates are met I need to move them in anti direction..
http://postimg.org/image/ayk1qbnct/
Please look into Label2 and Label9

1 solution

You will need to check if the Euclidean distance between the two bubbles' coordinates is less than or equal to the sum of the radii of the two bubbles (= diameter of one bubble if they are all the same size).
C#
var deltax = b1.x - b2.x;
var deltay = b1.y - b2.y;
if (Math.Sqrt(deltax * deltax + deltay * deltay) <= b1.radius + b2.radius)
{
  // the bubbles collide
}

This assumes the coordinates are of the center of the bubbles!!
 
Share this answer
 
v2
Comments
Henrynetdev 28-Oct-13 7:19am    
Thanks for your help..but I need to control the collision of bubbles.
Plz Let me know if you have any suggestion..
Matt T Heffron 28-Oct-13 13:49pm    
At each iteration you will be moving the bubbles by some deltaX and deltaY, this is their velocity vector.
So you need to first calculate their proposed new location.
Check if they collide with any other bubble(s) (or the edge of the drawing space),
if they collide then adjust the velocity vectors of each as an elastic collision,
After completing calculating the new locations, then make a final pass to update the actual positions and draw the bubbles in their new positions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900