Thursday, December 29, 2011

Give JavaScript another look

So recently I've been working with JavaScript, which I have little experience in.Mostly I just go ahead Google "thing I need to do" + JavaScript.

I've decided to change that and really learn a bit about the language. I was surprised to find that JavaScript is a fully object oriented language and is hands down the best language out there to do anything on a web browser that needs user input and to provide a smooth experience (i.e. Ajax etc)

Also the Mozilla Dev Center is a great resource for JavaScript (and a few other web related languages)

So if you haven't already, give JavaScript another look.

Saturday, October 29, 2011

Let's play with OpenGL! Part 1

So yes yes I'm back after a small hiatus, but I'm back starting over fresh.

So let's talk about OpenGL!

First off what is OpenGL? OpenGL is a graphics library used to interface with your video card to issue commands to it. It might not looking it but Pong and Arkham City, Battlefield 3 and Modern Warfare all have one thing in common. They simply get graphics cards to draw a bunch of pixels on screen and add a color to them.

So OpenGL allows us to interface with the video card to draw pixels so we don't have to play with low level memory access or commands each time we want to do it. It allows us easy human readable commands to make the pixels on the screen do what we want.

DirectX is another popular graphics library that does the same thing as well, and is more popular than OpenGL as of right now, but don't be fooled; OpenGL is every bit just as powerful as DirectX. The reasons behind its lack of popularity are all in the politics that software companies play, but that's for another post.

Next up: Getting OpenGL installed and setting up your work environment!

Wednesday, August 17, 2011

Worry not I'm still here

I just started enjoying summer a bit more...you know...going outside. I've been indoors doing geek things most of the summer and now that its nearly done I just need to get outdoors some more. You know biking, rock climbing etc.

Did anyone else go to Otakon by chance? What are your thoughts of the con this year? Personally I thought the panels were a bit stale...same old same old from years gone by. Nowadays I go to the same panels every year with nothing new grabbing my interests. Maybe I'm just getting too old for an anime convention.

Tuesday, July 19, 2011

Sidenote: Programming blogs

Anyone else just love reading programming blogs? Recently I've take up reading a few programming blogs quite a bit at home (and at work too :P)

Its very enthralling to read older posts from high level bloggers from high tech companies. Some of my favorites are:

  • The Old New Thing by Raymond Chen always gives good insight into how microsoft works and how we've come up with the product we all know and love / hate.
  • Coding Horror by Jeff Atwood speaks about the lots of meta-programming stuff, stuff about comptuers that programmers are likely to be interested in, sometimes tips he posts tips on design too.
  • Joel On Software by Joel Spolsky speaks alot about management of programmers, everything from how to hire, sell your product and how to treat programmers at work.
These are my favorite 3 as they are all light and easy reading, but with lots of thought provoking information. Everytime I visit each of their blogs I end up learning something.

Do you have any favorite programming / tech blogs?

Wednesday, June 29, 2011

Pushing and Poppin'

In OpenGL when you apply any type of transformation or apply any type of texture or property, it is applied globally to everything else below it.

So if I were to do this:

for(int i = 0; i < 5; i++)
{
     glColor3f(1.0,0.0,0.0) ;
     glTranslatef(i*3,0.0,0.0);
     glutSolidTetrahedron (); // TETRAHEDRONS!!
}

We would expect to see 5 evenly spaced tetrahedrons(think pyramids) right? Of course since I'm asking you would expect its wrong, so I know you wouldn't whip out your visa and bet with me.

See the translation is applied to the entire world and it persists. Therefore instead of this:

^   ^   ^   ^   ^

You end up with this

^   ^      ^         ^            ^

How do we solve this? Simple you push and then pop before you make the translation! By pushing into a sort of matrix buffer you tell the compiler : Only apply the changes to things inside this matrix, nothing else. So if you do this instead:

for(int i = 0; i < 5; i++)
{

     glColor3f(1.0,0.0,0.0) ;
glPushMatrix();

     glTranslatef(i*3,0.0,0.0);
     glutSolidTetrahedron (); // TETRAHEDRONS!!
glPopMatrix();
}

and with that you will get the expected result.

Wednesday, June 22, 2011

OpenGL

   



So I've been working on OpenGL on the iPhone, but I'm still kinda learning Objective C and the iOS libraries so its a bit slow going. This week I started up messing around on OpenGL on a PC. The first pictures is from a projection view and the second is from an orthographic view. Gonna use open GL to work on a small project of mine in my spare time.

I also know DirectX 10, but I just have more fun in OpenGL. I'm thinking of taking it to the next level and buying the OpenGL SuperBible( The Blue Book) and learning shaders a bit better. (Shaders are hard!)

No code samples today as I feel its rather basic and just a bunch of setup stuff unless you want to watch lots of arrays initialized like this:

GLfloat cube[][3] = {{-1.0,-1.0,-1.0},{1.0,-1.0,-1.0},{1.0,-1.0,1.0},
              {-1.0,-1.0,1.0},{-1.0,1.0,-1.0},{1.0,1.0,-1.0},
              {1.0,1.0,1.0},{-1.0,1.0,1.0}};

I thought so.

Wednesday, June 15, 2011

Sleep Sort

Every so often a certain notorious image board (which shall not be named, lest it is summoned) pops out a gold nugget. I preset sleep sort:

#!/bin/bash
function f() {
    sleep 
"$1"
    echo 
"$1"
}
while [ -n "$1" ]
do
    f 
"$1" &
    shift
done
wait



It works like this: Imagine you had a room full of people and you each hand them a number between let say 1 and 100. Whatever number that person gets, they wait for that amount of time in minutes and then they write their number down on a white board.

People with the highest numbers will wait for much longer times and people with small numbers will wait less. So the person who got 1, will only wait for one minute and write down their number, the person who got 2 has to wait longer than the person who got 1 to write their number and so on. There you have it sleep sort, instead of minutes it works in seconds.


It's an interesting and new idea on sorting. The problem with it is that it has a terrible worst case and best case. It takes as long as the highest number to sort. So if you wanted to sort some numbers such as 1, 2, 3, 78943893 it would take 78943893 seconds to sort 4 numbers.


This could be fixed by calling some kind of notify whenever a number was printed. This actually seems like a perfect application for a parallel processing. Have each thread sleep, but upon printing out a sorted value, notify all the threads which are still sleeping that they can proceed to process the next one in line with the least amount of sleep time remaining.

What is more fascinating about this is the simplicity of it all. I doubt we'll see this taking over as the default sorting procedure but it is a very humorous and elegant piece of code.


I've whipped up some quick Java code which should re-create this bash script but haven't tested it. Later on I plan to see if I can write it up as a parallel program with the fixes I've suggested.


public void f(int s)
{
    Thread.sleep(s);
    system.out.println(s);
}
public void main()
{
    String sortMe = "9 0 4 56 5 9 1 2 3 64 7 9";
    StringTokenizer t = new StringTokenizer(sortMe, " ");
    while (t. hasMoreTokens())
    {
        f(t.nextElement());
    }

}

Wednesday, June 8, 2011

SideNote: Starcraft

Same as previous post I've been play starcraft too. More facts.
This graphic was designed by Lorena O'Neal, you can check out more of
her work here (http://www.onlinegraphicdesignschools.org/)

(Don't worry next post I go back to OpenGL...been procrastinating on it since its been so hot, and with no AC in my apartment its easier to play video games than it is to program...terrible excuse I know)

Side Note: WOW

So I've recently been play world of warcraft for the first time and its kinda of fun, but I think I'll be done with it once the 30 day trial is up.
Here are some interesting stats about it.
This graphic was designed by Lorena O'Neal, you can
check out more of her work here (http://videogamedesigncolleges.org/)

Wednesday, June 1, 2011

iPhone OpenGL ES

So I already know how to program on the iPhone for the most part since I took on a small project for work for a few months.

Today I decided to explore the functionality of the device a bit more by checking out OpenGL ES.

About 2 years ago I did a course on OpenGL, but I quickly realized that I wouldn't be able to just copy paste my old code and expect it to work. Things are a bit different in the iPhone setup (and the fact that my old code is written in C, the iPhone uses C++[oops I meant Objective-C])

After a bit (read: a lot) of googling, I was able to get a basic setup done. Its a shame that the default one apple provides starts the application off with using shaders, which even for someone who took a class on this 2 years ago was a bit tough. In the end though I was able to get a triangle drawn and rotate it. Pictures? I do think so!

Some of the code, there is more but these two functions are the heart of it all

The multicolored triangle

It's rotating*
*Note that  though in the last screenshot the triangle should have been rotating it rather looks like its just moving up. I'm not 100% sure why this is, but I think it might have something to do with my view projections. I'll be working on this again tomorrow and trying to get some better results.


Also 100 + followers. Yay!

Tuesday, May 24, 2011

Unmaintainable code

About to start up some Mac programming for the iPhone. Got my hands on a iMac mini, xCode and a developers license. Would rather do Android OS programming but sometimes you just deal with the cards that fall in your lap.

On another note I really wanted to post to share this:
http://www.thc.org/root/phun/unmaintain.html


Very long read but quite funny as well as enlightening:


Found on reddit.com

Wednesday, May 18, 2011

Cellular Automata Forest Fire Model Continued

So since the last post I've been thinking about how to implement the forest fire simulation.

The first thing which was necessary would be a data structure to represent a grid.  Easy enough we use a multidimensional array right? True but more is needed.

For individual processes to communicate with each other we should also include some form of message passing ability as if a grid is divided up into square regions they need to communicate with processors which are processing regions to the top, bottom, left, right and corners of them.

Also we need to ensure that when we update the grid we do not commit it right away as another process might still be using it. So thus updating the grid is a two step process, you need a temporary representation of the grid and then you need live data to which you commit when all processes are done communicate.

Getting the number of rows and columns of course would be helpful.

Thus I present you the grid data structure:

#ifndef GRID_H
#define GRID_H

struct Grid_;
typedef struct Grid_ Grid;

// Create, destroy Grid
Grid *grid_create(int n_cols, int n_rows);
void grid_destroy(Grid *grid);

// Data access
int grid_get_num_rows(Grid *grid);
int grid_get_num_cols(Grid *grid);
char grid_get(Grid *grid, int col, int row);
void grid_update(Grid *grid, int col, int row, char value);
void grid_commit_updates(Grid *grid);

// Communication
void grid_send_column(Grid *grid, int col, int dest);
void grid_send_row(Grid *grid, int row, int dest);
void grid_receive_column(Grid *grid, int col, int src);
void grid_receive_row(Grid *grid, int row, int src);
void grid_send_cell(Grid *grid, int col, int row, int dest);
void grid_receive_cell(Grid *grid, int col, int row, int src);

#endif // GRID_H

Note: This is just the header file, implementation details soon.

Monday, May 9, 2011

Cellular Automata Forest Fire Model

http://schuelaw.whitman.edu/JavaApplets/ForestFireApplet/

Just thought this forest fire simulation was interesting and wanted to share.

It is just Conway's Game of Life but with modified rules.

Would be interesting to parallelize this. You could split this up into either single rows and columns and let each processor deal with a specific row or column. Or you could split it up into various row * col block and let each processor deal with a specific block.

I might try looking into this later as as side project for something to parallelize.

Sunday, May 8, 2011

Intro to MPI


So here are some basic MPI functions that are needed for parallel computers in a cluster setup
MPI_Init
Used to initialize MPI. Without this none of the other commands will work.
MPI_Comm_rank
Gets the rank of a processor from 0 - p, where p is the total number of processors.
MPI_Comm_size
Get the total number of processes available for computing.
MPI_Send
Send a message. Messages are passed as array data, you can specify the size of an array.
MPI_Recv
Complement to MPI_Send.
MPI_Finalize
Called when program is done running. Cleans up memory to avoid leaks.
Sample intro program next post

Wednesday, May 4, 2011

Parallell Programming

So how do we take advantage of all these processors and cores that we keep getting more and more of? Parallell programming!

This can be hard. It can be difficult to properly utilize processors to divide work up and share it equally.

Most paralell programs go something like this:

Divide work up
Create memory locks
Have individual processors / threads perform the work
Consolidate the data from each processor / thread.

Gonna look into how to do this using MPI, pthreads and Java in the next few days.



Sunday, May 1, 2011

So I've been missing

So last post was about mid terms hell. Then I dropped off the face of the earth.

Truth be told school hit me and hit me hard. When I started this blog I wanted to work on learning how to program on a new micro controller I got. Turns out learning to program on a whole new board is hard work. Feels kinda like school work and I got enough of that as it is!

But alas school is nearly out for the summer! And I don't have too many finals, rather lots of projects due in the next few days. I'm gonna bang those out of the way and get back to programming recreationaly.

When I do start back up in the next few days though I'm not gonna focus all my energies on just the micro controller, rather I'm going to look at all the things I'm interested in : Parallel programming, Web Programming, Micro controllers etc. So this blog is going to have multiple focuses.

Stay tuned!

Thursday, April 14, 2011

Privacy Policy

Privacy Policy for Launch Pad

If you require any more information or have any questions about our privacy policy, please feel free to contact us.

At Launch Pad, the privacy of our visitors is of extreme importance to us. This privacy policy document outlines the types of personal information is received and collected by Launch Pad and how it is used.

Log Files
Like many other Web sites Launch Pad makes use of log files. The information inside the log files includes internet protocol (IP) addresses, type of browser, Internet Service Provider (ISP), date/time stamp, referring/exit pages, and number of clicks to analyze trends, administer the site, track user’s movement around the site, and gather demographic information. IP addresses, and other such information are not linked to any information that is personally identifiable.

Cookies and Web Beacons
Launch Pad does use cookies to store information about visitors preferences, record user-specific information on which pages the user access or visit, customize Web page content based on visitors browser type or other information that the visitor sends via their browser.

DoubleClick DART Cookie
» Google, as a third party vendor, uses cookies to serve ads on Launch Pad
» Google's use of the DART cookie enables it to serve ads to users based on their visit to  Launch Pad and other sites on the Internet.
» Users may opt out of the use of the DART cookie by visiting the Google ad and content network privacy policy at the following URL - http://www.google.com/privacy_ads.html

Some of our advertising partners may use cookies and web beacons on our site. Our advertising partners include ....
» Google AdSense
» Adbrite
» Azoogle
» Amazon


These third-party ad servers or ad networks use technology to the advertisements and links that appear on  Launch Pad send directly to your browsers. They automatically receive your IP address when this occurs. Other technologies (such as cookies, JavaScript, or Web Beacons) may also be used by the third-party ad networks to measure the effectiveness of their advertisements and / or to personalize the advertising content that you see.

Launch Pad has no access to or control over these cookies that are used by third-party advertisers.

You should consult the respective privacy policies of these third-party ad servers for more detailed information on their practices as well as for instructions about how to opt-out of certain practices. Launch Pad's privacy policy does not apply to, and we cannot control the activities of, such other advertisers or web sites.

If you wish to disable cookies, you may do so through your individual browser options. More detailed information about cookie management with specific web browsers can be found at the browsers' respective websites.Privacy P

Wednesday, March 16, 2011

Mid Term Hell

So I've been working on projects leading into mid terms as well as studying for mid terms. As such I haven't gotten a thing done with this board in a while. Working on getting some stuff up but things might be moving slowing for a bit. Keep checking back for updates.

Saturday, March 5, 2011

Temperature application code

So lets look back on what made the temperature application tick from the last post.

A series of define statements. All of the BIT# definitions come from the included msp430x20x2.h file included.
I couldn't fit the next bit of code into a screen shot so I'll have to copy paste it :
 while(1)
  {   
    ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
    __bis_SR_register(CPUOFF + GIE);        // LPM0 with interrupts enabled
   
   
    /* Moving average filter out of 8 values to somewhat stabilize sampled ADC */
    tempMeasured[tempMeasuredPosition++] = ADC10MEM;
    if (tempMeasuredPosition == 8)
      tempMeasuredPosition = 0;
    tempAverage = 0;
    for (i = 0; i < 8; i++)
      tempAverage += tempMeasured[i];
    tempAverage >>= 3;                      // Divide by 8 to get average
   
    if ((--uartUpdateTimer == 0) || calibrateUpdate )
    {
      ConfigureTimerUart();
      if (calibrateUpdate)
      {
        TXByte = 248;                       // A character with high value, outside of temp range
        Transmit();
        calibrateUpdate = 0;
      }  
      TXByte = (unsigned char)( ((tempAverage - 630) * 761) / 1024 );     
      Transmit();
      uartUpdateTimer = UART_UPDATE_INTERVAL;
      ConfigureTimerPwm();
    }
   
   
    tempDifference = tempAverage - tempCalibrated;
    if (tempDifference < -TEMP_THRESHOLD)
    {
      tempDifference = -tempDifference;
      tempPolarity = TEMP_COLD;
      LED_OUT &= ~ LED1;
    }
    else
    if (tempDifference > TEMP_THRESHOLD)
    {
      tempPolarity = TEMP_HOT;
      LED_OUT &= ~ LED0;
    }
    else
    {
      tempPolarity = TEMP_SAME;
      TACCTL0 &= ~CCIE;
      TACCTL1 &= ~CCIE;
      LED_OUT &= ~(LED0 + LED1);       
    }
   
    if (tempPolarity != TEMP_SAME)   
    {     
      tempDifference <<= 3;
      tempDifference += TIMER_PWM_OFFSET;     
      TACCR1 = ( (tempDifference) < (TIMER_PWM_PERIOD-1) ? (tempDifference) : (TIMER_PWM_PERIOD-1) );
      TACCTL0 |= CCIE;
      TACCTL1 |= CCIE;     
    }  
  } 
}
What is above is the main while loop. (Hopefully the color selection doesn't make your eyes bleed).
What it does roughly is create and array :   tempMeasured[tempMeasuredPosition++] = ADC10MEM; the purpose of which is to hold previous temperatures that it measured it seems. From there it is just a matter of looping through and getting an average of the temperature change. I'm not too sure what lots of the gritty details do, but overall it simply checks to see if the temperature is more than the TEMP_THRESHOLD or less than it. If it is increasing it lights up the LED.

Its really straight forward but lots of the bit operations hold me up.That and not knowing what every variable and function is, and what they do. Going to have to go over some bit wise operations again pretty soon.

Tuesday, March 1, 2011

Temperature Application pt. II

A few days ago I posted the temperature appliction which comes pre-programmed on the board. Temperature app basically consists of a Hello World application (flashing LEDs) as well as showing off the temperature sensor.

What I didn't know at the time was that there was a GUI app for windows as well. Watch as the numbers rise and fall. Excitement!


Monday, February 28, 2011

Tiki Gods appeased: Hello World



Last Time I attempted to please the Tiki Gods* and get hello world running,  it failed. That's due to the videos I was following were just generic instructions on how to use Code Composer Studio.

This time however I used the TI labs tutorials for students. The tutorials are really good and come in a PDF, PowerPoint and Word document. There are also videos which correlate to the previously mentioned documents.

The 2nd Lab (Lab 1 goes over installing Code Composer and plugging in the device) goes over running the code for the temperature program. It shows you how to create new projects and how to properly load the code onto the MPS430. With micro processors a flashing LED is the equivalent of a Hello World application since they don't usually come with LCD screens or any other form of output.

Analysis of code and videos to come soon.





*I have blatantly stolen the "Pleasing the Tiki Gods" reference from Beginning iPhone 4 Development: Exploring the iOS SDK which I've been using at work.