Starfield

J

Jack Nielsen

Hi !

I'm new to C# and want to start by making a starfield with stars coming from
the middle and ou while getting brighter.

First of all, how to I make a single pixel ? And secondly, how to do this
fast without any flicker at all ?

I made alot of this stuff in assembler in C64 and C Amiga, with the speed of
computers today it should be possible to have alot of stars without any
flicker at all

I have searched the web alot and one example I found on how to make a pixel
seems kinda silly and slow, see this

Drawing a single pixel in C#

I am writing a control that needs to display a grid (similar to the VS.NET
IDE) as the background. Now in the "old days" you could call the function
SetPixel to draw a single pixel on a device context. However, the .NET
Graphics object does not have such an API, so how do you do it without
resorting to P/Invoke? I found a solution on the web and here it is...


// Create a 1 x 1 bitmap and set the color
Bitmap pt = new Bitmap(1, 1);
pt.SetPixel(0, 0, Color.Gray);


// Draw bitmap on Graphics surface
e.Graphics.DrawImageUnscaled(pt, x, y);


It's pretty simple, but it took me a few minutes of experimentation before
looking to the web for an answer. To quote Star Trek, "Engineers love to
change things."


How can this be make better !

Also if anyone know of graphic demos made with c# please share the link !

Hope some of you can guide me in the right direction ( Using VS2005 )

Thanx

Jack
 
M

Mick Doherty

Jack Nielsen said:
Hi !

I'm new to C# and want to start by making a starfield with stars coming
from the middle and ou while getting brighter.

First of all, how to I make a single pixel ? And secondly, how to do this
fast without any flicker at all ?

Fill a 1*1 pixel Rectangle.
e.Graphics.FillRectangle(Brushes.White, 0, 0, 1, 1);

Double Buffer for flickerless painting.
Aren't stars supposed to flicker ;-)

Take a look at Bob Powells GDI+ FAQ, where you should find the answers to
these as well as some of your follow up questions:
http://www.bobpowell.net/faqmain.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top