Kept thinking about yesterday's setTimeout and how to chain it into a a color show. Inspired the by the Trippy RGB Waves kit. I wanted to create a Javascript simulation of the rgb color show. The Trippy RGB Waves kit uses an array called lightTab to hold information about the hold time, fade time, and the rgb color values. So I took that array an implemented in Javascript. In order to display values I built a test page, test css, test Javascript. I ran out of time to write the fader. So I have a color show based on the lightTab array. setTimeout is used in a recursive fashion. The issues run into were needing to make sure the lightTab was global, and that an anonymous function was used to call the function in the site time out. Here's the example:
setTimeout("runShow(" + (i + 1) + ")", holdTime);
setTimeout(function () {runShow(i + 1);}, holdTime);
If I was executing more code or had more values in my function then anonymous function route is much easier to type, and less error prone. Other thing, I love jQuery, but none of my Javascript entries have used it. Sort of just checking out the plain old DOM and seeing what can be done.
Without further ado here is the html, css, and js.
test.html
====
====
rgb.css
====
====
rgb.js
====
====
Thursday, March 04, 2010
Wednesday, March 03, 2010
March Madness Challenge - Day 3
Another long day, but I did come. up with something that I needed for another project. It turns out the closest thing Javascript has to sleep(ms) or delay(ms) is setTimeout. Which is nice but is tricky to use in a synchronous environment. So in terms of matching what happens on an AVR chip or an Arduino. It's time for a delay(ms) script.
Well not really. I wrote the delay function, but it's not the recommended technique. Why block all actions on a page waiting for one thing to happen. The above code is closer. But doesn't solve the key issues. The setTimeout needs to have values assigned for red, green, and blue for the showColor function. Additionally, this code requires a web page. I needed to upload that. I needed to assign an event listener, and lastly had to resolve an issue about setTimeout being inside a loop. The issue being the loop sets all the "setTimeout"s as quickly as possible, so all time outs occur almost in parallel. I could be wrong about that, but I did have some kind of issue. I needed to examine Javascript fader examples more closely, and I would have figured it out, but ran out of time.
Ok. I wrote a super quick brute force demonstration of the problem. This requires Firebug in order to run. Paste the following code into the Firebug console. Warning whatever web page you are viewing in firebug will go through some awful color contortions.
So nesting the setTimeout inside SetTimeout should be interesting. Onto the next challenge.
setTimeout("showColor(red,green,blue)",holdTime);
function showColor(red, green, blue)
{
document.getElementById("leddisplay").style.backgroundColor="rgb(" + red + "," + green + "," + blue + ")";
}
Well not really. I wrote the delay function, but it's not the recommended technique. Why block all actions on a page waiting for one thing to happen. The above code is closer. But doesn't solve the key issues. The setTimeout needs to have values assigned for red, green, and blue for the showColor function. Additionally, this code requires a web page. I needed to upload that. I needed to assign an event listener, and lastly had to resolve an issue about setTimeout being inside a loop. The issue being the loop sets all the "setTimeout"s as quickly as possible, so all time outs occur almost in parallel. I could be wrong about that, but I did have some kind of issue. I needed to examine Javascript fader examples more closely, and I would have figured it out, but ran out of time.
Ok. I wrote a super quick brute force demonstration of the problem. This requires Firebug in order to run. Paste the following code into the Firebug console. Warning whatever web page you are viewing in firebug will go through some awful color contortions.
function showColor(red, green, blue)
{ document.body.style.backgroundColor="rgb(" + red + "," + green + "," + blue + ")";
console.log("Color set");
}
console.log("Start");
console.log('setTimeout("showColor(0,0,0)",10000);');
setTimeout("showColor(0,0,0)",10000);
console.log('setTimeout("showColor(10,10,10)",9000);');
setTimeout("showColor(10,10,10)",9000);
console.log('setTimeout("showColor(100,100,100)",8000);');
setTimeout("showColor(100,100,100)",8000);
console.log('setTimeout("showColor(200,200,200)",7000);');
setTimeout("showColor(200,200,200)",7000);
console.log('setTimeout("showColor(200,0,0)",6000);');
setTimeout("showColor(200,0,0)",6000);
console.log('setTimeout("showColor(100,0,0)",5000);');
setTimeout("showColor(100,0,0)",5000);
console.log('setTimeout("showColor(0,100,0)",4000);');
setTimeout("showColor(0,100,0)",4000);
console.log('setTimeout("showColor(0,100,100)",3000);');
setTimeout("showColor(0,100,100)",3000);
console.log("Done")
So nesting the setTimeout inside SetTimeout should be interesting. Onto the next challenge.
Tuesday, March 02, 2010
March Madness Challenge - Day 2
Ok. Time was a bit of challenge today. I wanted to learn more about getopt, and figure out how it differed from optparse. I definitely learned about some of those differences. So tonights program uses getpass to collect a username, password combination. This is pretty unoriginal, but it did help me learn about getopt. I would like to try variation on determining mandatory fields, optional fields, and fields in combination.
#
# Hello World Get Opt for Python
#
#
import getopt
import sys
import getpass
#Describe usage
def usage():
print "-h, --help\n -v, --verbose\n -u, --username\n -p, --password\n"
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "h:u:pv", ["help", "username=", "password"])
except getopt.GetoptError, err:
#print help information and exit:
print str(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
username = None
password = None
verbose = False
for o, a in opts:
if o == "-v":
verbose = True
elif o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-u", "--username"):
username = a
print "username: " + username
elif o in ("-p", "--password"):
password = getpass.getpass("Enter password: ")
print "password: " + password
else:
assert False, "unhandled option"
if __name__ == "__main__":
main()
Monday, March 01, 2010
March Madness Challenge - Day 1
Several of my partners in craziness at FUBAR Labs, the local New Jersey Hackerpsace. Have taken on March Madness. Write a program a day for a month. Well I'm jumping in on day one with a piece of code that solves one of PIAs I experience when trying to get the emails off of Google Calendar Events. Wish there was a feature that allowed you to make a group based off of an event. Anyway, the following code is how to get a list of guests from a Google Calendar event. Pop the list into an alert box, then cut and paste for your own use.
Another way to run this would be as a Greasemonkey script. Hey, that might be a good project for tomorrow.
I did discover the source code for Google Hosted applications is not quite the same as it's standard gmail offerings. To run this in a hosted environment you would need to use the following to select the guests:
---
/** Get list of emails address from the guests invited to a Google event
*/
(function () {
var guests, emails;
//Handily there is class associated to each guest
guests = document.getElementsByClassName("guest");
emails = "";
//iterate the guests
for (var i in guests)
{
if (guests.hasOwnProperty(i))
{
//each guest name/email is the first child textContent of guest element
emails = emails + guests[i].childNodes[0].textContent + ",\n";
}
}
alert(emails);
})();
---In order to run this you need to can run it in the Firebug console. Testing this, you need to create a Google Calendar Event add a few people to it. Find an old event with people in the guest list.Another way to run this would be as a Greasemonkey script. Hey, that might be a good project for tomorrow.
I did discover the source code for Google Hosted applications is not quite the same as it's standard gmail offerings. To run this in a hosted environment you would need to use the following to select the guests:
(function () {//Final Note: Not Happy with editor at Blogger.com
var guests, emails, guest, tmp;
guests = document.getElementsByClassName("ep-gl-guest");
emails = "";
guest = "";
tmp = "";
for ( var i in guests)
{
if (guests.hasOwnProperty(i))
{
guest = guests[i].id;
tmp = guest.split(":i");
emails = emails + tmp[1] + ",\n";
}
}
alert(emails);
})();
Sunday, December 20, 2009
Bug in the fire
Bug in the fire
Originally uploaded by flirianders.
Played around with a glue gun, and an led at the Fubarlabs Hackathon. Ended up with atmega168 powered LED that lit up chilled hot glue, and formed a fire breathing bug.
Monday, June 04, 2007
Iron Man Kills Dr. Lucky's dog
Iron Man Kills Dr. Lucky's dog
Originally uploaded by flirianders.
Kill Dr. Lucky is a great Cheapass game. We scavenged both the Marvel Monopoly and the classic Monopoly pieces for this game. The variation we played was Kill Dr. Lucky and his dog. I as Iron man finally killed Dr. Lucky's dog. I was so satisfied with the moment, it had to have a photo. I no longer remember the final outcome, but that pesky dog was finally eliminated.
Saturday, April 14, 2007
Thoughts on Django
I've just started really looking into Django and so far I've been impressed. I've bee pleasantly surprised that things were easier than I thought and nicely organized. I really like the Models, Templates, and Admin interface. The model concept provides a nice database independent data structure. For simple test projects it's really simple to use SQLite. The key feature I like about the Templates is the ability to create base templates and extend them for specific task. Allows for efficient coding of pages. The automatically generated Admin interface has received a lot of deserved attention it's a great concept.
Areas that I'm looking into more. If the Admin interface is based off a template structure can it be extended for basic user/member of the site. So a regular user could change their profile without me having to duplicate the coding that would be auto generated in the Admin interface.
Also, as a new user it looks like I need to build a base set of templates that can be used and reused through out all my Django projects. Once that basic set is created I could stamp out a lot of variations on a theme for projects I'd like to build in django. It would be nice to have an application theme that could be modded. It might make Django more cookie cutter but it would awesome to not have test projects look junky while the admin interface is clean and usable.
As for test projects I've been enamored with creating a list of lists project. I have simple prototype that was fun. Now I want to revise it and make it have user registration, RSS, atom, and list sharing. As this goes I'd like to examine how the Model resolves recursion. Lists of lists of lists, etc.
Another project that I've been terribly interested in is using an interpreted environment to dynamically build applications and interact with applications from interpreted shell type environment.
Figured I get these thoughts written down before I forgot.
Areas that I'm looking into more. If the Admin interface is based off a template structure can it be extended for basic user/member of the site. So a regular user could change their profile without me having to duplicate the coding that would be auto generated in the Admin interface.
Also, as a new user it looks like I need to build a base set of templates that can be used and reused through out all my Django projects. Once that basic set is created I could stamp out a lot of variations on a theme for projects I'd like to build in django. It would be nice to have an application theme that could be modded. It might make Django more cookie cutter but it would awesome to not have test projects look junky while the admin interface is clean and usable.
As for test projects I've been enamored with creating a list of lists project. I have simple prototype that was fun. Now I want to revise it and make it have user registration, RSS, atom, and list sharing. As this goes I'd like to examine how the Model resolves recursion. Lists of lists of lists, etc.
Another project that I've been terribly interested in is using an interpreted environment to dynamically build applications and interact with applications from interpreted shell type environment.
Figured I get these thoughts written down before I forgot.
Subscribe to:
Posts (Atom)