Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

Matthew Butler 0

@Matthew Butler 0
About
Posts
52
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • I started programming at age 13
    M Matthew Butler 0

    The first 'program' I wrote (if you call it a program) was when I was 7 in junior school, using a flowchart to control various motors and read from sensors etc... I believe the first build was a pedestrian crossing simulation. The first time I did some real programming was when I was 9 when I bought a PIC16F84 kit (I don't miss them at all) and made a light sequencer... the first time I actually used the PIC's machine code and wrote the .hex file directly. (Understandably I got a proper assembler soon after as the kit didn't contain one!) Then Delphi when I was 11, then C# at 13... my current choice.

    Matthew Butler

    The Lounge question

  • SetPixel() too slow?
    M Matthew Butler 0

    There is an incredibly fast way of doing this... LockBits; the first time I needed to do something like this it took me a while to get the indexing right... but it pays off in the end. The MSDN page on it... http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx[^] A good example... http://blog.paranoidferret.com/index.php/2007/08/31/csharp-tutorial-convert-a-color-image-to-greyscale/[^]

    Bitmap image = (Bitmap)oldimage.Clone();
    BitmapData bmpData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
    unsafe
    {
    byte* ptr = (byte*)bmpData.Scan0.ToPointer();
    for (int Y = 0; Y < image.Height; Y++)
    {
    for (int X = 0; X < image.Width; X++)
    {
    // alter the colours here
    *ptr++ = 0; // blue
    *ptr++ = 0; // green
    *ptr++ = 0; // red
    }
    ptr += bmpData.Stride - image.Width * 3;
    }
    }
    image.UnlockBits(bmpData);

    *ptr++ is the current byte representing a 'sub-pixel' of the current pixel at image position [x, y]: the reason why the pointer is incremented three times. Hope this helps.

    Matthew Butler

    Graphics data-structures question

  • Factorials
    M Matthew Butler 0

    Got it!... after about 10 mins of tinkering...

    static int fac_last_digit(int x)
    {
    int res = x;
    int mod = 10;
    while (x > 1)
    {
    if ((res * (x - 1)) % mod == 0) mod *= 10;
    res = (res * (--x)) % mod;
    }
    return (res / (mod / 10));
    }

    The trick is to use the % operator with increasing powers of 10 depending on if the result is a multiple of the original modulus value... (Needs tidying up a little)... why you need this is a mystery though.

    Matthew Butler

    Algorithms question

  • How to stop updating a PictureBox? [modified]
    M Matthew Butler 0

    To update position and size at the same time, you can use...

    .SetBounds(left, top, width, height);

    [also: .Scale may be of use] Hope this helps.

    Matthew Butler

    Windows Forms tutorial question announcement

  • problem with increment decimal value
    M Matthew Butler 0

    Mr.Kode wrote:

    decimal sum = due++;

    due is incremented after is is assigned to sum... you want... decimal sum = ++due; That should fix it.

    Matthew Butler

    C# help

  • Simultaneous posting on forums
    M Matthew Butler 0

    Just a suggestion, Would it be possible to give a notification in the 'reply form' whilst writing a response if a new message has already been posted: I've seen it happen many times where there have been two almost identical replies to the same message within a few minutes. I realise that having a seperate browser window/tab open pointing at the original message would solve this 'problem', but could a more elegant method be encorperated into the reply form? Thanks.

    Matthew Butler

    Site Bugs / Suggestions help question

  • How to determine the next x,y coordinate for a tank in a 2-D game...
    M Matthew Butler 0

    Beat me to it. (Within 3 minutes, more than 3 hours from the original question, what are the chances of that?)

    Matthew Butler

    Algorithms tutorial question game-dev help

  • How to determine the next x,y coordinate for a tank in a 2-D game...
    M Matthew Butler 0

    Just use basic geometry/maths... nextXpos = lastXpos + speed * sin(angle); nextYpos = lastYpos - speed * cos(angle); [angle is measured from the vertical, clockwise] The only things you need to remember are: > Math.Sin and Math.Cos take the angle argument in radians not degrees. > Sin and Cos return double precision numbers: which may round to 0 or 1 if you are using integer positions and therefore the tank will not move as you want. Hope this helps.

    Matthew Butler

    Algorithms tutorial question game-dev help

  • Simple shape recognition
    M Matthew Butler 0

    Oops. So much for testing... I missed that one. -one quick copy and paste later- // bail out if first point not near to last point if (CalcLength(points[0], points[points.Length - 1]) > maxDev) return false; Checkmate.:cool:

    Matthew Butler

    Algorithms com

  • Simple shape recognition
    M Matthew Butler 0

    I was refurring to the maximum and minimum distances between the points and the geometric centre... not the bounds of the ellipse.

    ......ooooooooooo......
    ...ooo.....|.....ooo...
    ..o........m........o..
    .o.........|.........o.
    .o.........X----M----o.
    .o...................o.
    ..o.................o..
    ...ooo...........ooo...
    ......ooooooooooo......

    m is the 'minimum' radius of the ellipse. M is the 'maximum' radius of the ellipse. If it was an ellipse, the average distance between each point and the centre, X, would be approximately equal to the (M + m) / 2; This was my original idea... I posted my alternative method (my prefured way and the method I actually got running - in a past program) as a different reply. I believe I saw this method a while ago, but I can't remember where.

    Matthew Butler

    Algorithms com

  • Simple shape recognition
    M Matthew Butler 0

    To solve the 'random mouse speed' you could only draw the next point when it is a pre-determined distance from the last... however that may not fit in with your design. However a better way may be to look at the angles between successive points... (This is how I did it)... For a line, the angles would be around 180 degrees. For a rectangle, there will be (over a few points), 3 x 90 degree turns, with the rest 180 degrees. (The end point will be in proximity to the first). For an ellipse, the angles will always be either below or above 180 degrees... depending on whether it is drawn clockwise or not. And a polygon will not follow any of the previous patterns. ... self explanitory. I stored each shape's pattern and iterated through them looking for a match... similar to a regex... but geometrically, with an 'accuracy' value. If not accurate enough (<75%), I assumed it to be random. Hope this helps.

    Matthew Butler

    Algorithms com

  • Simple shape recognition
    M Matthew Butler 0

    Assuming the ellipse, rectangle and line will be made from points ordered uniformly around their 'perimeter'... If they represent... 1) An ellipse: the distances from the geometric centre to each point will be linearly distributed... ie: the average distance from the centre should be within an epsilon amount to half way between the maximum and minimum distances. 2) A line: take any two points and calculate the 'linear line equation' y=mx+c... then see if all other points fit the equation. 3) A rectangle: the points would fit into four 'linear line equations', one for each side; find a pair of points that at least one other points fits into, repeat with the remaining points until four sides have been found and there are no points left. (This is the hardest of the three... there may be a better way). 4) A polygon... if none of the other conditions apply. Calculating the bounding rectangle is simple... look for maximum/minimum points in both the vertical/horizontal directions. I believe I've done something like this before... I'll see if I can find some code. Hope this helps.

    Matthew Butler

    Algorithms com

  • Working with Decimals
    M Matthew Butler 0

    I'm sure there is an even better way, but... decimal d = 10.1234; int dp = (d - decimal.Truncate(d)).ToString().Length - 2; int val = (int)(d * (decimal)Math.Pow(10, dp)); This method, although still converting it to a string, doesn't 'search' the string for a particular character... just gets its length... which is relatively efficient. As I said... there will be a better way... what it is I cannot immediately say. Hope this helps.

    Matthew Butler

    C# graphics help question

  • Check if GDI+ bitmap has transparency
    M Matthew Butler 0

    There are two things you could do (first way will not speed up the processing but is just a method improvement): 1) Only need to check the alpha channel (assuming any transparent colour is counted)... If objColor.A != 255 Then ... (As the alpha channel IS the 'trasparency' aspect of the colour, you only need to check this). 2) Lock the Bitmap and loop through the raw data (this is REALLY fast)... loads of examples on web... from msdn[^] Also... if all you want to know is if the image could contain transparency... check the PixelFormat of the bitmap for transparency. Hope this helps.

    Matthew Butler

    Graphics graphics question winforms help

  • Make picturebox image mirror vertical
    M Matthew Butler 0

    Before you load the PictureBox with the image... theImage.RotateFlip(RotateFlipType.RotateNoneFlipY); Hope this helps.

    Matthew Butler

    Graphics question

  • What's the meaning of @ character in Regular expression pattern ?
    M Matthew Butler 0

    Hi, The @ symbol is 'nothing' to do with the actual pattern... it is placed in front of a string to tell the compiler to ignore all escape characters (backslashes: \) contained within the string. "\n" <- newline character @"\n" <- \n

    Matthew Butler

    C# regex question

  • Counting bricks from image
    M Matthew Butler 0

    I would say you have it spot on... filter the image and then apply a region counting algorithm. The filtering is relatively simple... but the region finding could be harder (I've never used/made one). If you get the original image down to just the outlines of the bricks (via the filters), then you could use a Monte-Carlo based search to look for borders surrounding each point. [I wish I had a school project as interesting as yours!]

    Matthew Butler

    Algorithms question algorithms help

  • OpenFileDialog and SaveFileDialog [modified]
    M Matthew Butler 0

    If it helps... OpenFileDialog and SaveFileDialog have a RestoreDirectory property... if true, it restores the chosen directory when the dialog closes. (The 'restored' directory is the InitialDirectory). I don't know if that is what you mean.

    Matthew Butler

    C# help question database tutorial

  • [Message Deleted]
    M Matthew Butler 0

    Hi, (condition ? result_if_true : result_if_false) represents a value... Console.WriteLine(x > y ? "X bigger" : "Y bigger (or equal to)"); is what you're looking for (note that if x > y is false... it doesn't necessarily mean that y > x). Hope this helps.

    Matthew Butler

    C#

  • Taking a screen shot of a control
    M Matthew Butler 0

    Use... PointToScreen(control.Location);

    Matthew Butler

    C# graphics help question learning
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups