Updated Star Background!

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 6968 Views - Last Post: 30 June 2011 - 04:53 PM Rate Topic: -----

#1 Gleave  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 46
  • Joined: 06-December 10

Updated Star Background!

Posted 27 June 2011 - 09:09 PM

Ok I'm back with the Starry Background code redone. Only problem is that it seems when it's done drawing the stars in the array it pauses for a second before "retwinkling" them. Heres the code feel free to help out and offer suggestions, thanks!

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace TwinkleStars
{
    public partial class Form1 : Form
    {
        Graphics paper;
        Color c = Color.Black;
        Star star = new Star( );

        public Form1( )
        {
            //double buffer use here helps with the flicker reduction
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint |
                     ControlStyles.UserPaint, true);
            Cursor.Hide( );
            BackColor = c;
            InitializeComponent( );
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            paper = e.Graphics;
            star.drawStars(paper);
            //uses less processor than invalidate
            this.Refresh( );
            //Invalidate( );
        }
        protected override void onkeydown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Dispose( );
                Close( );
            }
            base.onkeydown(e);
        }
    }
    public class Star
    {
        private int x, y, w, h;
        private int numStars = 300;
        Random r = new Random( );
        Brush b = Brushes.Gray;
        Brush [] bArray = { Brushes.WhiteSmoke, Brushes.DimGray };
        public Rectangle [] starRec = new Rectangle [300];

        public Rectangle starRecs
        {
            get { return starRec [300]; }
        }

        public Star( )
        {
            for (int i = 0; i < numStars; i++)
            {
                x = r.Next(1024);
                y = r.Next(790);
                h = w = r.Next(1, 3);
                starRec [i] = new Rectangle(x, y, w, h);
            }
        }
        public void drawStars(Graphics paper)
        {
            for (int i = 0; i < numStars; i++)
            {
                int x = r.Next(0, 2);
                if (i % (numStars / 2)  == 0)
                {
                    paper.FillEllipse(b, starRec [i]);
                }
                else
                {
                    paper.FillEllipse((Brush) bArray [x], starRec [i]);
                }
            }            
        }
    }
}



Help is appreciated!

Is This A Good Question/Topic? 0
  • +

Replies To: Updated Star Background!

#2 ragingben  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 164
  • View blog
  • Posts: 612
  • Joined: 07-October 08

Re: Updated Star Background!

Posted 28 June 2011 - 01:31 AM

I have copied your code, and on my PC it doesn't wait a second, it all works smoothly. It does pause a second when the form loads (while the stars are generated), but after that they twinkle smoothly. If I add more stars then it does chug up a bit, so maybe try reducing the amount of stars you have until they twinkle smoothly?

However I think that you should add a constructor to your Star class that takes width and height as parameters instead of using 1024 for width and 790 for height - that way you can specify the area of the star's random placement based on the size of the form - as it is now some of the stars are placed off of the form.

This post has been edited by ragingben: 28 June 2011 - 01:39 AM

Was This Post Helpful? 0
  • +
  • -

#3 Gleave  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 46
  • Joined: 06-December 10

Re: Updated Star Background!

Posted 28 June 2011 - 05:31 AM

Thank you raging! I will incorporate h and w into the constructor. Do you think that this will help performance? I don't know if its just my PC but it seems like it could be just a TAD smoother, but that's just me.
Was This Post Helpful? 0
  • +
  • -

#4 ragingben  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 164
  • View blog
  • Posts: 612
  • Joined: 07-October 08

Re: Updated Star Background!

Posted 28 June 2011 - 05:36 AM

Incorporating height and width into the costructor wont improve performance, it will just mean that you are placing every stars x and y withing the forms boundaries rather than the screen boundaries, which means that all the stars will be visible. Cutting down the quantity of stars should help performance. I really only noticed a drop in performance when upping the quantity of stars significantly.
Was This Post Helpful? 0
  • +
  • -

#5 Gleave  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 46
  • Joined: 06-December 10

Re: Updated Star Background!

Posted 28 June 2011 - 05:48 AM

Here's the updated.
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace TwinkleStars
{
    public partial class Form1 : Form
    {
        Graphics paper;
        Color c = Color.Black;
        //fill the constructor with any number, because its 
        //going to create the star in regards to the boundary 
        //of the form 
        Star star = new Star(1,1);

        public Form1( )
        {
            //makes the control redraw after it finishes the array
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint |
                     ControlStyles.UserPaint, true);
            Cursor.Hide( );
            BackColor = c;
            InitializeComponent( );
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            paper = e.Graphics;
            star.drawStars(paper);
            //uses less processor than invalidate
            this.Refresh( );
            //Invalidate( );
        }
        protected override void onkeydown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Dispose( );
                Close( );
            }
            base.onkeydown(e);
        }
    }
    public class Star
    {
        Screen s = Screen.PrimaryScreen;
        private int x, y, w, h;
        private int numStars = 200;
        Random r = new Random( );
        Brush b = Brushes.Gray;
        Brush [] bArray = { Brushes.WhiteSmoke, Brushes.DimGray };
        public Rectangle [] starRec = new Rectangle [200];

        public Rectangle starRecs
        {
            get { return starRec [200]; }
        }

        public Star(int height, int width)
        {
            for (int i = 0; i < numStars; i++)
            {
                x = width = s.Bounds.Width;
                y = height = s.Bounds.Height;
                h = w = r.Next(1, 3);
                starRec [i] = new Rectangle(x, y, w, h);
            }
        }
        public void drawStars(Graphics paper)
        {
            for (int i = 0; i < numStars; i++)
            {
                int x = r.Next(0, 2);
                if (i % (numStars / 2)  == 0)
                {
                    paper.FillEllipse(b, starRec [i]);
                }
                else
                {
                    paper.FillEllipse((Brush) bArray [x], starRec [i]);
                }
            }            
        }
    }
}



I figured out what you meant raging, but the x and y needed to be changed not the height and width, but in the constructor I named them height, width because they would correspond to the x and y. Thanks again!
Was This Post Helpful? 0
  • +
  • -

#6 ragingben  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 164
  • View blog
  • Posts: 612
  • Joined: 07-October 08

Re: Updated Star Background!

Posted 28 June 2011 - 05:59 AM

I see, that's not really what I meant.

Your star field is now drawn to whatever the screens width and height is. That is fine if the app is running full screen. Are you always running it this way? Is it a screen saver or something? Else you need to make your star field the width and height of the form, or you will have stars that are placed outside the bounds of the form, which would be a waste. Something like this is what I meant:
public Star(int height, int width)
{
   for (int i = 0; i < numStars; i++)
   {
       x = r.Next(0, width);
       y = r.Next(0, height);
       h = w = r.Next(1, 3);
       starRec [i] = new Rectangle(x, y, w, h);
   }
}


This post has been edited by ragingben: 28 June 2011 - 06:00 AM

Was This Post Helpful? 0
  • +
  • -

#7 Gleave  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 46
  • Joined: 06-December 10

Re: Updated Star Background!

Posted 28 June 2011 - 06:04 AM

Ahh, I see. Well, I cut the number of stars down a 1/3, this should increase performance. I am running the program in full screen, but I altered the properties of the form manually. When I was setting the form size it said it was 1070, 800 or something like that, so I figured if I didn't let the random number be more than that I wouldn't have a problem, but I will take your advice.
Was This Post Helpful? 0
  • +
  • -

#8 ragingben  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 164
  • View blog
  • Posts: 612
  • Joined: 07-October 08

Re: Updated Star Background!

Posted 28 June 2011 - 06:08 AM

Sure. I only said it because when I run the form was something like 300x300, while the stars were being allocated a space of 1080x790 or something, so I was only seing maybe 100 of theose stars, but they were all being updated in the loop.
Was This Post Helpful? 0
  • +
  • -

#9 Gleave  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 46
  • Joined: 06-December 10

Re: Updated Star Background!

Posted 28 June 2011 - 06:09 AM

Gotcha, thanks for the help too! I want to make a Graphics library for 2D space games, so any suggestions on what I should try to work on next? It is only me coding and designing graphics, so it could take a while but I want my software to be worth something, you know what I mean?
Was This Post Helpful? 0
  • +
  • -

#10 ragingben  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 164
  • View blog
  • Posts: 612
  • Joined: 07-October 08

Re: Updated Star Background!

Posted 28 June 2011 - 06:25 AM

Ah I see. If you want to make something worthwile make sure it is as reusable as possible, and that you can specify as much as you would ever want (and then some more) for each class. For example, for your Star class you should make every field a full blown parameter, that can be get and (normally) set. Or atleast make methods so that you can change everything. You would want to be able to change the star field area, the density of the stars, the colour of the stars, maybe a colour variance for the stars, the size range of the stars, the background of the stars, and maybe even the density ratio of the stars (so that they were more densse towards the middle. and were sparse towards the edges). You may also want to be able to start and stop them twinkling. I would work on getting some really solid and customisable classes to base your library on. Also comment the hell out of your code, and add Xml comments (the ones with 3 /// that intellisense uses

This post has been edited by ragingben: 28 June 2011 - 06:27 AM

Was This Post Helpful? 0
  • +
  • -

#11 Gleave  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 46
  • Joined: 06-December 10

Re: Updated Star Background!

Posted 28 June 2011 - 06:31 AM

Hmm...that's a good idea! I wanna start testing stuff like that. Do you think that using button presses for debugging with the U.I. is a good idea? For instance, if I wanted to change star color, I would press '1', if I wanted to change the star density I would press '2' and so on. Usually I work with algorithms in Console, not Form...so I want to do something cause I see how much easier it is to use objects but I want a good AGILE method for doing so.
Was This Post Helpful? 0
  • +
  • -

#12 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 1948
  • View blog
  • Posts: 8,666
  • Joined: 29-May 08

Re: Updated Star Background!

Posted 28 June 2011 - 07:08 AM

Reworked your star to use Tasks.
public class Stars
    {
        private  const int numStars = 3000;
        Brush[] bArray = { Brushes.WhiteSmoke, Brushes.DimGray };
        public Rectangle[] starRec = new Rectangle[numStars];
        [ThreadStatic ]
        Random r = new Random();
        public Stars()
        {
            Parallel.For(0,numStars,(i)=>
            {  lock(r){
              int  x = r.Next(1024);
              int  y = r.Next(790);
              int  h =  r.Next(1, 3);
                starRec[i] = new Rectangle(x, y, h, h);}
            });
               
        }
        public void drawStars(Graphics paper)
        {  Parallel.For(0, numStars, (i) =>
           {  lock (paper)
              {  int x = 0;
                 lock (r)
                 {  x = r.Next(0, 2); }
                 if (i % (numStars / 2) == 0)
                 {  paper.FillEllipse(Brushes.Gray, starRec[i]);
                 }
                 else
                 {  paper.FillEllipse((Brush)bArray[x], starRec[i]);
                 }
              }
           });
        }
    }



Was This Post Helpful? 0
  • +
  • -

#13 ragingben  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 164
  • View blog
  • Posts: 612
  • Joined: 07-October 08

Re: Updated Star Background!

Posted 28 June 2011 - 07:09 AM

I think that is a very good idea. Really good idea. As an example of my previous post I have done a quick rewrite of the Star class, and called it StarField. It is by no means complete, and does not offer any more functionality than your Star class does at current, but is more modifable and reusable. I have also added a SizeChanged event handler to the form to handle resizing, and any keypressing other than escape doubles the density of stars. I reitterate - this is not a complete example - there is no error handling, and no new functions, but I just wanted to give you an example of my previous post, rather than risk the possibility of misdirecting you.

Heres the revised class
/// <summary>
/// Represents a twinkling star field
/// </summary>
public class StarField
{
    #region Properties

    /// <summary>
    /// Get or set the width of the field
    /// </summary>
    public Int32 Width
    {
        get { return this.width; }
        set 
        { 
            // set value
            this.width = value;

            // handle property changed
            this.onpropertychanged();
        }
    }

    /// <summary>
    /// Get or set the width of the field
    /// </summary>
    private Int32 width;

    /// <summary>
    /// Get or set the height of the field
    /// </summary>
    public Int32 Height
    {
        get { return this.height; }
        set 
        {
            // set value
            this.height = value;

            // handle property changed
            this.onpropertychanged();
        }
    }

    /// <summary>
    /// Get or set the height of the field
    /// </summary>
    private Int32 height;

    /// <summary>
    /// Get or set the light foreground colour
    /// </summary>
    public Brush LightForeground
    {
        get { return this.lightForeground; }
        set { this.lightForeground = value; }
    }

    /// <summary>
    /// Get or set the light foreground colour
    /// </summary>
    private Brush lightForeground = Brushes.WhiteSmoke;

    /// <summary>
    /// Get or set the dark foreground colour
    /// </summary>
    public Brush DarkForeground
    {
        get { return this.darkForeground; }
        set { this.darkForeground = value; }
    }

    /// <summary>
    /// Get or set the dark foreground colour
    /// </summary>
    private Brush darkForeground = Brushes.DimGray;

    /// <summary>
    /// Get or set the background
    /// </summary>
    public Brush Background
    {
        get { return this.background; }
        set { this.background = value; }
    }

    /// <summary>
    /// Get or set the background
    /// </summary>
    private Brush background = Brushes.Gray;

    /// <summary>
    /// Get the star rectangles
    /// </summary>
    public Rectangle[] Stars
    {
        get { return this.stars; }
        protected set { this.stars = value; }
    }

    /// <summary>
    /// Get or set the star rectangles
    /// </summary>
    private Rectangle[] stars;

    /// <summary>
    /// Get or set the star density
    /// </summary>
    public Int32 Density
    {
        get { return this.density; }
        set 
        {
            // set value
            this.density = value;

            // handle property changed
            this.onpropertychanged();
        }
    }

    /// <summary>
    /// Get or set the star density
    /// </summary>
    private Int32 density;

    /// <summary>
    /// Get if the stars have been populated
    /// </summary>
    public Boolean HaveStarsBeenPopulated
    {
        get 
        {
            // get if some stars
            return ((this.Stars != null) && (this.Stars.Length > 0)); 
        }
    }
    
    /// <summary>
    /// Get or set the random generator
    /// </summary>
    protected Random randomGenerator = new Random();

    #endregion

    #region Methods

    /// <summary>
    /// Initializes a new instance of the StarField class
    /// </summary>
    public StarField()
    {
    }

    /// <summary>
    /// Initializes a new instance of the StarField class
    /// </summary>
    /// <param name="width">The width of the star field</param>
    /// <param name="height">The height of the star field</param>
    /// <param name="density">The density of stars</param>
    public StarField(Int32 width, Int32 height, Int32 density)
    {
        // set width
        this.Width = width;

        // set height
        this.Height = height;

        // set the density
        this.Density = density;
    }

    /// <summary>
    /// Draw the stars to a graphics object
    /// </summary>
    /// <param name="graphics">The graphics object to draw the stars onto</param>
    public virtual void DrawStars(Graphics graphics)
    {
        // is stars not been populated
        if (!this.HaveStarsBeenPopulated)
        {
            // create stars
            this.CreateStars();
        }

        // itterate all stars
        for (Int32 index = 0; index < this.Stars.Length; index++)
        {
            // get if the star should be bright
            switch (this.randomGenerator.Next(0, 3))
            {
                case (0):
                    {
                        // fill ellipse as background
                        graphics.FillEllipse(this.Background, this.Stars[index]);

                        break;
                    }
                case (1):
                    {
                        // fill ellipse as dim
                        graphics.FillEllipse(this.DarkForeground, this.Stars[index]);

                        break;
                    }
                default:
                    {
                        // fill ellipse as bright
                        graphics.FillEllipse(this.LightForeground, this.Stars[index]);

                        break;
                    }
            }
        }
    }

    /// <summary>
    /// Create all stars for this object
    /// </summary>
    protected virtual void CreateStars()
    {
        // create new array
        this.Stars = new Rectangle[this.Density];

        // hold uniform size
        Int32 uniformSize;

        // itterate for each star
        for (Int32 index = 0; index < this.Density; index++)
        {
            // generate new uniform size
            uniformSize = this.randomGenerator.Next(1, 3);

            // add star
            this.Stars[index] = new Rectangle(this.randomGenerator.Next(0, this.Width), this.randomGenerator.Next(0, this.Height), uniformSize, uniformSize);
        }
    }

    /// <summary>
    /// Clear all stars
    /// </summary>
    protected virtual void ClearStars()
    {
        // clear stars
        this.Stars = null;
    }

    /// <summary>
    /// Handle property changes
    /// </summary>
    protected virtual void onpropertychanged()
    {
        // if stars have been populated
        if (this.HaveStarsBeenPopulated)
        {
            // clear stars
            this.ClearStars();

            // create stars
            this.CreateStars();
        }
    }

    #endregion
}


Heres all code
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        Graphics paper;
        Color c = Color.Black;
        StarField star;

        public Form1()
        {
            //double buffer use here helps with the flicker reduction
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint |
                     ControlStyles.UserPaint, true);
            Cursor.Hide();
            BackColor = c;
            InitializeComponent();
            star = new StarField(this.Width, this.Height, 300);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            paper = e.Graphics;
            star.DrawStars(paper);
            //uses less processor than invalidate
            this.Refresh();
            //Invalidate( );
        }
        protected override void onkeydown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Dispose();
                Close();
            }
            else
            {
                star.Density *= 2;
            }
            base.onkeydown(e);
        }

        private void Form1_SizeChanged(object sender, EventArgs e)
        {
            this.star.Width = this.Width;
            this.star.Height = this.Height;
        }
    }

    /// <summary>
    /// Represents a twinkling star field
    /// </summary>
    public class StarField
    {
        #region Properties

        /// <summary>
        /// Get or set the width of the field
        /// </summary>
        public Int32 Width
        {
            get { return this.width; }
            set
            {
                // set value
                this.width = value;

                // handle property changed
                this.onpropertychanged();
            }
        }

        /// <summary>
        /// Get or set the width of the field
        /// </summary>
        private Int32 width;

        /// <summary>
        /// Get or set the height of the field
        /// </summary>
        public Int32 Height
        {
            get { return this.height; }
            set
            {
                // set value
                this.height = value;

                // handle property changed
                this.onpropertychanged();
            }
        }

        /// <summary>
        /// Get or set the height of the field
        /// </summary>
        private Int32 height;

        /// <summary>
        /// Get or set the light foreground colour
        /// </summary>
        public Brush LightForeground
        {
            get { return this.lightForeground; }
            set { this.lightForeground = value; }
        }

        /// <summary>
        /// Get or set the light foreground colour
        /// </summary>
        private Brush lightForeground = Brushes.WhiteSmoke;

        /// <summary>
        /// Get or set the dark foreground colour
        /// </summary>
        public Brush DarkForeground
        {
            get { return this.darkForeground; }
            set { this.darkForeground = value; }
        }

        /// <summary>
        /// Get or set the dark foreground colour
        /// </summary>
        private Brush darkForeground = Brushes.DimGray;

        /// <summary>
        /// Get or set the background
        /// </summary>
        public Brush Background
        {
            get { return this.background; }
            set { this.background = value; }
        }

        /// <summary>
        /// Get or set the background
        /// </summary>
        private Brush background = Brushes.Gray;

        /// <summary>
        /// Get the star rectangles
        /// </summary>
        public Rectangle[] Stars
        {
            get { return this.stars; }
            protected set { this.stars = value; }
        }

        /// <summary>
        /// Get or set the star rectangles
        /// </summary>
        private Rectangle[] stars;

        /// <summary>
        /// Get or set the star density
        /// </summary>
        public Int32 Density
        {
            get { return this.density; }
            set
            {
                // set value
                this.density = value;

                // handle property changed
                this.onpropertychanged();
            }
        }

        /// <summary>
        /// Get or set the star density
        /// </summary>
        private Int32 density;

        /// <summary>
        /// Get if the stars have been populated
        /// </summary>
        public Boolean HaveStarsBeenPopulated
        {
            get
            {
                // get if some stars
                return ((this.Stars != null) && (this.Stars.Length > 0));
            }
        }

        /// <summary>
        /// Get or set the random generator
        /// </summary>
        protected Random randomGenerator = new Random();

        #endregion

        #region Methods

        /// <summary>
        /// Initializes a new instance of the StarField class
        /// </summary>
        public StarField()
        {
        }

        /// <summary>
        /// Initializes a new instance of the StarField class
        /// </summary>
        /// <param name="width">The width of the star field</param>
        /// <param name="height">The height of the star field</param>
        /// <param name="density">The density of stars</param>
        public StarField(Int32 width, Int32 height, Int32 density)
        {
            // set width
            this.Width = width;

            // set height
            this.Height = height;

            // set the density
            this.Density = density;
        }

        /// <summary>
        /// Draw the stars to a graphics object
        /// </summary>
        /// <param name="graphics">The graphics object to draw the stars onto</param>
        public virtual void DrawStars(Graphics graphics)
        {
            // is stars not been populated
            if (!this.HaveStarsBeenPopulated)
            {
                // create stars
                this.CreateStars();
            }

            // itterate all stars
            for (Int32 index = 0; index < this.Stars.Length; index++)
            {
                // get if the star should be bright
                switch (this.randomGenerator.Next(0, 3))
                {
                    case (0):
                        {
                            // fill ellipse as background
                            graphics.FillEllipse(this.Background, this.Stars[index]);

                            break;
                        }
                    case (1):
                        {
                            // fill ellipse as dim
                            graphics.FillEllipse(this.DarkForeground, this.Stars[index]);

                            break;
                        }
                    default:
                        {
                            // fill ellipse as bright
                            graphics.FillEllipse(this.LightForeground, this.Stars[index]);

                            break;
                        }
                }
            }
        }

        /// <summary>
        /// Create all stars for this object
        /// </summary>
        protected virtual void CreateStars()
        {
            // create new array
            this.Stars = new Rectangle[this.Density];

            // hold uniform size
            Int32 uniformSize;

            // itterate for each star
            for (Int32 index = 0; index < this.Density; index++)
            {
                // generate new uniform size
                uniformSize = this.randomGenerator.Next(1, 3);

                // add star
                this.Stars[index] = new Rectangle(this.randomGenerator.Next(0, this.Width), this.randomGenerator.Next(0, this.Height), uniformSize, uniformSize);
            }
        }

        /// <summary>
        /// Clear all stars
        /// </summary>
        protected virtual void ClearStars()
        {
            // clear stars
            this.Stars = null;
        }

        /// <summary>
        /// Handle property changes
        /// </summary>
        protected virtual void onpropertychanged()
        {
            // if stars have been populated
            if (this.HaveStarsBeenPopulated)
            {
                // clear stars
                this.ClearStars();

                // create stars
                this.CreateStars();
            }
        }

        #endregion
    }
}



You may have to change the namespace back to whatever it was before.

Note for some reason onpropertychanged has been put to all lower case - camel case this.

This post has been edited by ragingben: 28 June 2011 - 07:11 AM

Was This Post Helpful? 0
  • +
  • -

#14 Gleave  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 46
  • Joined: 06-December 10

Re: Updated Star Background!

Posted 28 June 2011 - 07:39 AM

Your right, your code is super reusable. Well this gives me an idea of what I'm looking at in terms of depth and time that is going to be put into this. Thank you for your help so much! I appreciate it.
Was This Post Helpful? 0
  • +
  • -

#15 Gleave  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 46
  • Joined: 06-December 10

Re: Updated Star Background!

Posted 28 June 2011 - 07:45 AM

Ah, when I hit another button besides esc, the program freezes. I changed the star.Density *= 2, to star.Density += 2 this fixed it.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2