Swirling Vortexes and Procedural Textures


Before I start, this is pretty much taken from FXGen. I really like that library for procedural texture generation. The code can be a bit difficult to parse through some times, but I still like it.  Anyway, I was bored and looking through their code when I came across their Vortex function.  I couldn't quite figure out what I would do with it until I started looking at items in their gallery. And since I was bored, I figured I would implement it in my own library:

 



All that the function is, really, is a rotation within a certain distance from a specified point. The closer you are to the center, the more you rotate. So basically you just find the distance from the current point to the center, determine the inverse percentage between that distance and the maximum distance, multiply that by the desired rotation, and then rotate the point. You could use cosine or something to give a smoother transition but a linear transition works just as well in my book. Anyway, I'm sure you're interested in the code:

 

Vortex.zip (1.11 kb)

 

So download the code, leave feedback, and as always happy coding. 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by James Craig on Monday, April 28, 2008 1:42 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Creating Marble Like Textures Procedurally


I've been working a lot on my texture generation library. And it's starting to shape up nicely. It will take me a while for it to be on par with the likes of .werkkzeug or FXGen (let alone some of the stuff out there like ProFX).

One of the items I recently added to the library was a turbulence function. It basically takes an image as input, creates two perlin noise images, and uses them to determine the pixel offset between the output image and the input image... For example:

 

turns into this using the function:

 

The reason we use perlin noise instead of straight random numbers is we want the noise to be coherent. The smoother the noise, the more the final image is going to look like something coherent instead of random. And since marble, wood textures, etc. all need some semblance of coherency, we need it to act in this manner. Anyway, I'm sure that you're interested in the code:

 

Turbulence.zip (2.59 kb)

 The code has both the perlin noise class (and the interface that it derives from) and the turbulence function. So download the code, leave feedback, and as always happy coding.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by James Craig on Saturday, April 26, 2008 11:20 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Getting a Users Contacts List from an Exchange Server


A request that recently popped up at work was the ability to use a person's contacts list from outlook when they were using a particular portion of the intranet site. Not that difficult to do actually. All that is required is a call using WebDAV to the exchange server and we have that user's contact's list. Actually there are a couple of ways to accomplish it but I found that to be the easiest. Anyway, as always I'm sure you're interested in the code:

public static System.Web.UI.WebControls.ListItemCollection GetContacts(string UserName,string Password,string Directory)

{
    System.Web.UI.WebControls.ListItemCollection ReturnArray = new System.Web.UI.WebControls.ListItemCollection();
    string server = "http:/ /ExchangeServer";
    NetworkCredential credentials = new NetworkCredential(UserName, Password);
    string uri = string.Format("{0}/exchange/{1}", server, credentials.UserName);
    byte[] contents = System.Text.Encoding.UTF8.GetBytes(string.Format(

       @"<?xml version=""1.0""?>

        <g:searchrequest xmlns:g=""DAV:"">

            <g:sql>

                SELECT

                    ""urn:schemas:contacts:givenName"", ""urn:schemas:contacts:sn"",

                    ""urn:schemas:contacts:email1""

                FROM

                    Scope('SHALLOW TRAVERSAL OF ""{0}/exchange/{1}/contacts""')

            </g:sql>

        </g:searchrequest>",

      server, credentials.UserName));

 

    HttpWebRequest request = HttpWebRequest.Create(uri) as HttpWebRequest;
    request.Credentials = credentials;
    request.Method = "SEARCH";
    request.ContentLength = contents.Length;
    request.ContentType = "text/xml";

    using (System.IO.Stream requestStream = request.GetRequestStream())
        requestStream.Write(contents, 0, contents.Length);

 

    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    using (System.IO.Stream responseStream = response.GetResponseStream())
    {
        XmlDocument document = new XmlDocument();
        document.Load(responseStream);
        foreach (XmlElement element in document.GetElementsByTagName("a:prop"))
        {
            if (element["d:sn"] != null && element["d:givenName"] != null && element["d:email1"] != null)
            {
                System.Web.UI.WebControls.ListItem TempItem = new System.Web.UI.WebControls.ListItem();
                TempItem.Text = element["d:sn"].InnerText+", "+element["d:givenName"].InnerText;
                TempItem.Value = element["d:email1"].InnerText;
                ReturnArray.Add(TempItem);
            }
        }
    }
    return ReturnArray;
}

Note that this code is a modified version of the code you'll find here. All this call does, is makes a call doing WebDAV asking the exchange server to search the person's contacts directory and return an item's first name, last name, and email address. We can get a lot more information if needed, you can look at the urn:schemas:contacts namespace if you want something else. Once we have the information, it just creates a ListItemCollection and drops the items in there (I was using this in a drop down list). You can of course create your own Contacts class and put the info in there if you prefer. Anyway, use the code, leave feedback, and happy coding.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by James Craig on Thursday, April 24, 2008 12:31 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Recent comments

None

Calendar

<<  January 2009  >>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

Sponsors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009