Friday, February 1, 2013

My Tribute to Nyan Cat and Pokemon

I came across the Nyan Cat internet meme program on khanacademy and decided to make my own version as a tribute.

//Code:

var nyanscale=1.5;



var nyany=200;



var nyanx=0;







var drawStar = function(state, x, y) {

    switch (state) {

    case 0:

        point(x, y);

        break;

    case 1:

        line(x - 10, y, x - 8, y);

        line(x + 10, y, x + 8, y);

        line(x, y - 10, x, y - 8);

        line(x, y + 10, x, y + 8);

        break;

    case 2:

        point(x - 15, y);

        point(x + 15, y);

        point(x, y - 15);

        point(x, y + 15);

        point(x - 10, y - 10);

        point(x + 10, y + 10);

        point(x - 10, y + 10);

        point(x + 10, y - 10);

        break;

    case 3:

        point(x - 20, y);

        point(x + 20, y);

        point(x, y - 20);

        point(x, y + 20);

    }

};



var drawStars = function(state, dx) {

    stroke(0, 255, 183);

    drawStar(state, 400 - (dx % 400), 30);

    stroke(0, 255, 9);

    drawStar((state + 2) % 4, 400 - ((dx + 100) % 400), 100);

    stroke(255, 0, 255);

    drawStar((state + 1) % 4, 400 - ((dx - 60) % 400), 150);

    drawStar((state + 3) % 4, 400 - ((dx + 200) % 400), 230);

    stroke(255, 0, 0);

    drawStar((state + 2), 400 - ((dx + 300) % 400), 290);

    stroke(255, 255, 0);

    drawStar((state + 1), 400 - ((dx - 175) % 400), 370);

};



var drawRainbowStreak = function(shift, color, dy) {

    // each rainbow streak is sin wave

    stroke(color);

    var x = 0;

    var y = 10 * sin(x * 2 + shift);

    for (var i = 0; i < 134; i++) {

        y = 5 * sin(4 * x + shift);

        point(x, y + dy);

        x += 1;

    }

};



var drawRainbow = function(shift) {

    var red = color(0, 0, 0);

    var orange = color(255, 92, 71);

    var yellow = color(247, 189, 163);

    var green = color(255, 92, 71);

    var blue = color(247,189,163);

    var purple = color(0, 0, 0);



    strokeWeight(20);

    drawRainbowStreak(shift, red, 125);

    drawRainbowStreak(shift, orange, 145);

    drawRainbowStreak(shift, yellow, 165);

    drawRainbowStreak(shift, green, 185);

    drawRainbowStreak(shift, blue, 205);

    drawRainbowStreak(shift, purple, 225);

};



var drawNyanTail = function(state) {

    fill(247, 255, 0);

    switch (state) {

    case 1:

        strokeWeight(27);

        stroke(0, 0, 0);

        bezier(147, 204, 114, 211, 97, 198, 90, 186);

        strokeWeight(15);

        stroke(255, 234, 0);

        bezier(147, 204, 114, 211, 97, 198, 90, 186);

        break;

    case 3:

        strokeWeight(27);

        stroke(0, 0, 0);

        bezier(147, 204, 148, 196, 104, 197, 97, 218);

        strokeWeight(15);

        stroke(247, 255, 0);

        bezier(147, 204, 148, 196, 104, 197, 97, 218);

        break;

    default: // 0 and 2

        strokeWeight(27);

        stroke(0, 0, 0);

        bezier(147, 204, 114, 211, 97, 203, 88, 199);

        strokeWeight(15);

        stroke(247, 255, 0);

        bezier(147, 204, 114, 211, 97, 203, 88, 199);

    }

};



var drawNyanLegs = function(state) {

    stroke(0, 0, 0);

    strokeWeight(6);

    fill(255, 255, 0);

    switch (state) {

    case 0:

        // front legs

        translate(300, 251);

        rotate(-50);

        ellipse(0, 0, 28, 42);

        ellipse(-28, -28, 29, 44);

        resetMatrix();

        // back legs

        translate(194, 251);

        rotate(-46);

        ellipse(0, 0, 26, 43);

        ellipse(-26, -25, 25, 41);

        resetMatrix();

        break;

    case 1:

        ellipse(296, 252, 28, 37);

        ellipse(256, 252, 29, 37);

        ellipse(187, 252, 29, 37);

        ellipse(148, 252, 29, 37);

        break;

    case 2:

        // front legs

        translate(282, 251);

        rotate(31);

        ellipse(0, 0, 28, 42);

        ellipse(-35, 20, 31, 44);

        resetMatrix();

        // back legs

        translate(187, 255);

        rotate(51);

        ellipse(0, 0, 29, 43);

        ellipse(-27, 31, 29, 41);

        resetMatrix();

        break;

    case 3:

        ellipse(290, 240, 28, 37);

        ellipse(253, 240, 29, 37);

        ellipse(187, 240, 29, 37);

        ellipse(148, 240, 29, 37);

    }

};



var drawNyanPoptart = function(state) {

    stroke(0, 0, 0);

    strokeWeight(6);



    // poptart

    var poptartDeltY = 0;

    if (state === 3) {

        poptartDeltY = -5;

    }



    fill(238, 255, 0);

    ellipse(215, 185 + poptartDeltY, 163, 135);

    



    

};



var drawNyanHead = function(state) {

    strokeWeight(6);

    stroke(0, 0, 0);

    

    // head

    var headDeltY = 0;

    var headDeltX = 0;

    switch(state) {

    case 0:

        headDeltX = 10;

        headDeltY = -6;

        break;

    case 2:

        headDeltX = -2;

        headDeltY = -6;

        break;

    case 3:

        headDeltY = -15;

    }



    fill(238, 255, 0);    

    ellipse(275 + headDeltX, 209 + headDeltY, 108, 80);



    // ears

    bezier(223 + headDeltX,

            197 + headDeltY,

            3 + headDeltX,

            158 + headDeltY,

            215 + headDeltX,

            133 + headDeltY,

            262 + headDeltX,

            171 + headDeltY);

    

    bezier(329 + headDeltX,

            199 + headDeltY,

            450 + headDeltX,

            149 + headDeltY,

            321 + headDeltX,

            133 + headDeltY,

            285 + headDeltX,

            169 + headDeltY);



    // eyes

    strokeWeight(14);

    point(252 + headDeltX, 207 + headDeltY);

    point(300 + headDeltX, 207 + headDeltY);



    // nose

    strokeWeight(8);

    point(283 + headDeltX, 217 + headDeltY);



    // mouth

    strokeWeight(4);

    bezier(259 + headDeltX,

            225 + headDeltY,

            262 + headDeltX,

            235 + headDeltY,

            287 + headDeltX,

            231 + headDeltY,

            284 + headDeltX,

            226 + headDeltY);

  

    bezier(300 + headDeltX,

            225 + headDeltY,

            300 + headDeltX,

            232 + headDeltY,

            282 + headDeltX,

            232 + headDeltY,

            284 + headDeltX,

            226 + headDeltY);



    // cheeks

    strokeWeight(16);

    stroke(255, 0, 0);

    point(244 + headDeltX, 225 + headDeltY);

    point(313 + headDeltX, 222 + headDeltY);



    // eye highlights

    strokeWeight(8);

    stroke(255, 255, 255);

    point(250 + headDeltX, 205 + headDeltY);

    point(298 + headDeltX, 205 + headDeltY);

    

        noStroke();



    if (mouseIsPressed) {



        fill(255, 0, 0);



    } else {



        noFill();



    }



   rect(headDeltX+245,headDeltY+202,3310,10,90);



};



var drawNyanCat = function(state) {

    drawNyanTail(state);

    drawNyanLegs(state);

    drawNyanPoptart(state);

    drawNyanHead(state);

};



var state = 0;

var draw = function() {

    background(8, 52, 107);



    // there are only 4 states in the animation:

    //      0, 1, 2, and 3

    drawStars(state % 4, frameCount * 20);

    drawRainbow(frameCount * 20);

    drawNyanCat(state % 4);



    // only increase the state every 4 frames, to slow

    // down the animation

    if (frameCount % 4 === 0) {

        state += 1;

    }

};




Friday, June 17, 2011

Total Cost

2 Logitech mice - $24
Linksys switch - $15
Cat 6 cables - $22
Padded steel chair (needed to upgrade from steel) - $12
Table from a thrift store - $30
Replacement power supply (the other one was fried) - $50
Speakers - $12
Surge Protector - $18
 I rounded it up to the dollar.

Total: $183


If using this as an example for your own home server, you will possibly need to add the cost of two desktops, and hopefully won't need a extra power supply.

UPDATE: Just a note for the Linux server flavors, I'd highly recommend CentOS it seems to be much more geared towards servers than trying to force Ubuntu or Fedora to act like one.

Friday, March 19, 2010

Server Area





Where the magic happens.
























<--- Gateway running Ubuntu Server.










<--- Compaq running Fedora, kind of difficult to see with power supply cables.

Tuesday, August 4, 2009

Server End Game Plan

I am getting close to being finished setting up everything with the server and I have attempted to document most of the more interesting things that happened. My plan is to edit and touch the existing posts up a bit (e.g. I have replaced the Dell with a newer "hand-me-down"), as well as add a final one.

UPDATE: Not being a writer, or playing one on tv, putting all this together is taking longer than I thought it would. Not to worry though, it shall be completed!
It has also dawned on me that this server is completely ran by Linux. Having not spent much time with any Windows servers besides a class on 2003, I am unsure if that is more that Linux is overall better (perhaps, or maybe more so for developers, but I have no interest in the "religious" part of operating systems) or if it is just that free is so much more appealing than the pricey Windows server OS's when being on a low budget.

Sunday, July 5, 2009

Home Server Part 6

As a side-note I was very lucky to receive another computer from a friend of family, that also happened to be old. So I decided to set that up with the server as just a desktop computer alongside it with another open source operating system.

Second Computer Specs:
  • Dell Dimension L600CX
  • Intel Celeron
  • 312 MB RAM
  • 10 GB HD
  • Windows ME (now Ubuntu 9.04)
Other Parts:
  • Dell Quietkey keyboard
  • Logitech laser mouse

Back to the server part though; I have been having some trouble with the Ubuntu Server 8.04 OS. It may just be my nowhere near complete knowledge of how the OS works, but nevertheless thankfully there is an abundance of documentation and I shall dive into it. If I am still unsuccessful then I am planning on seeing how capable Fedora 10 would be to use for server applications. This has turned out to be much more difficult then I thought it would be, but is a very good learning experience. :)

Tuesday, June 23, 2009

Home Server Part 5

Once again I scourged the internet for an operating system, this time for a server instead of just a desktop. After once again glimpsing at the Windows Server editions, I decided that the $240 minimum (Server 2003) was not very practical just for software.

I think it's worth noting that even though I generally prefer Open Source Software for several reasons, I have no real problem with Windows or Mac. It simply did not seem practical.

So I looked at a couple of the more popular Linux flavor options:

  • Ubuntu Server
  • Fedora
  • SUSE
After looking at them I figured it would be the simplest to try Ubuntu Server (8.04) since I was already running Ubuntu.

I also bought a Linksys 5-port switch ($15) to connect to the router I have upstairs along with two 10ft and one 50ft cat-6 cables.


My running total is - $66


Monday, June 22, 2009

Home Server Part 4

So now I had everything I needed to have one whole computer, now I just needed a place to put it. Luckily, I soon found that place.
I got a medium size cave like corner of the basement to use, and started setting up shop. It didn't take me long to realize the 2x4 table that I was using was not going to cut it. In the end I bit the bullet and bought a six feet table ($30) and an all steel chair ($8). After I had those things I got everything set up.

Once I had everything up and running I finally started thinking about making the computer into a little home server, and began searching for an OS again.