Friday, October 25, 2013

quick and dirty javascript sounds

I've written about HTML5 audio before, but the quickest/dirtiest way is:

var fx = document.createElement('audio');
fx.setAttribute('src', 'soundfile.mp3');
fx.setAttribute('loop', 'loop'); //optional

//...
fx.play();
//... 
fx.pause();

non-looping and resetting variants are left as an exercise for the reader.

Thursday, October 10, 2013

the welcoming details of old macpaint

Making the rounds is CloudPaint, a fairly faithful reproduction of the old MacPaint that you can use in the browser!

MacPaint really set the model most paint programs would use, especially the toolboxes. "Zoom" was relegated to a "FatBits", an option under "Goodies", rather than the magnifying glass used today, and there is only a hand to move to different parts of the image rather than scrollbars, but overall everything is quite recognizable and usable.

Folklore.org has the history of Bill Atkinson's creation of the program, including the "marching ants" style of showing area selection. The Computer History Museum also has a page about its development including a shot of its predecessor (it was based on a Lisa program called LisaSketch or SketchPad) before the toolboxes were added.

One lovely detail of the program is starting off with the big wide paintbrush selected-- it is so much more engaging than skritching out individual pixels with the pencil tool. (It also probably influenced the choice to use "hello." written in cursive for early promotional shots.) That kind of consideration to first user experience goes along way (especially with something as innovative of the Macintosh, which for many people was the first time they would have tried a computer mouse.)

Another fun thing is Painting and Filling with patterns. Once color came on the scene, these patterns sort of fell by the wayside, but there is something satisfying about seeing the swatch of area filled with a pattern that is fixed independent of the line used to draw it, almost like one is brushing a path of snow from a windshield and then seeing what is underneath.

I still haven't found a modern-day paint program with powerful features and an easy interface for OSX... Paint.NET for Windows was excellent in this regard. "Pixelmator" comes close, though has several annoyances (some of which I just found out were configurable settings, but overall it aims too high, UI-wise, trying to be Photoshop-Lite rather than MacPaint-Pro)

Tuesday, October 1, 2013

calling Ajax-derived telephone numbers in iOS javascript

Previously I mentioned a little demo iOS app that just wrapped a web widget. Part of the demo was to pull down a phone # from the server via an Ajax call and let the user try to dial it. This seemed to run afoul of Apple's "user initiated action" type of rules... my code worked if I triggered it from a button directly, but if I tried to make the call as the result of an Ajax call, no dice. 

Problem was I was using 
window.open('tel:######'); 
-- turns out doing 
window.location = 'tel:######'; 
face no such restriction. 

Phew! I was worried I was going to have to build a button and have the user press that one, too.

Monday, September 30, 2013

quick hit: minimal war building with ant

Sometimes I want a .war file but just with a few static files. While I have been known to use the hack of "zip the folder, rename it .war", that really requires a few extra files be inserted by hand into the folder (like META-INF etc) to do properly. Since I have ant on my system, I should use that.

If I have a folder of files, I just add this build.xml, and then typing ant makes me my "mything" war...

<project name="mything" default="build">
        <target name="build">
                <delete file="mything.war"/>

                <war destfile="mything.war" needxmlfile="false">
                        <fileset dir=".">
                                <exclude name="build.xml"/>
                                <exclude name="mything.war"/>
                        </fileset>
                </war>
        </target>
</project>

That's about as simple as it can get and still be doing the right thing, I think.

Thursday, September 26, 2013

seeker and you shall finder

Something I had to look up "how did I do that again?" in my little toy/gamemaking: have an object that will gradually turn to a target.

I made a really pretty version of this in an art game called aRTSeroids which I cribbed for this entry...

It's easy enough to get a seeker to snap instantly to its target, just do atan2(deltaY,deltaX); -- figuring out "which direction should I turn to get my angle closer to it" is a little tricker.



You can see the source here. The seeker object has an x and y propery for its position on the screen, and then an a property with its current angle. It also has a MAXTURN that sets how far it can turn per click...

  void seek(float rtx, float rty) { 
    float dx = (rtx - x);
    float dy = ( rty - y);
    //this trick seems to work to deal with the overlap..
    //they consider the shortest path even if other side of screen
    if (abs(dx) > width/2) {
      dx *= -1.0;
    }
    if (abs(dy) > height/2) {
      dy *= -1.0;
    }


    float wantangle = atan2(dy, dx);
    float anglediff = (a - wantangle);  
    anglediff /= PI; //I prefer thinking in multiples of PI...
    //this next bit catches the "runaround"
    if (anglediff > 1) {
      anglediff -= 2;
    }
    if (anglediff < -1) {
      anglediff += 2;
    }
    if (abs(anglediff) > .1) {  //arbitrary value to ignore
       if (anglediff > 0) {
        a -= smaller(abs(anglediff*PI),MAXTURN);
      } else {
        a += smaller(abs(anglediff*PI),MAXTURN);;
      } //could just be MAXTURN if you don't mind oversteer
    }
  }
}
float smaller(float a, float b){
 if(a < b) return a;
return b; 
}  

The first trick is the "deal with the overlap". This is optional, but nice for games that feature screen wraparound-- (i.e. fly left, show up right)-- if you want to have definitive borders you can leave those lines out.

The next bit is just the hack I got to normalize the difference in the angle... esentially we try to make sure the difference between the angle it "wants" and where it is now is normalized between PI and -PI. 

Finally, that smaller() code says it will either go MAXTURN or the difference in the angle. If it just went MAXTURN, it sometimes will do a little vibrate pattern as it overshoots the angle. (Come to think of it, I think that vibration is why I did that "arbitrary value to ignore")

Anyway, the code is a little clunky and weird but it works well, and should be useful to me in future projects.

quick and dirty iOS-web demos

If you're more experienced with html5 than xcode, or if you have another project need that means a mobile app is going to be primarily driven by a web view, http://conecode.com/news/2011/05/ios-tutorial-creating-a-web-view-uiwebview/ is very good.

Also, on the actual webpage, I built assuming for a width of 320px and had the following meta tags:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name = "format-detection" content = "telephone=no"/>
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
<meta name="apple-mobile-web-app-capable" content="yes" />
So that's limited because it only works in iPhone portrait mode, but still, for a quick and dirty demo, not bad.

(For a quicker and dirtier demo of the idea: just add the webpage to the homescreen. When they start it up it will be in fullscreen, no-safari-random-widgets, and to the unaided eye looks about the same, except the icon will be a screenshot rather than something you can set.)

UPDATE: My buddy Jonathan Zaleski says 
You can control the home-screen icon w/ the following:

<link href="favicon.ico" rel="apple-touch-icon">

Good to know!

Wednesday, September 25, 2013

color schemes!

If you design things, and don't know a ton about color theory, you should know this exists:
Color Scheme Designer.

For example, I was given a logo, and was able to mockup some more attractive webpages by grabbing the hexcode for its background color and using one of the schemes from it. There's a science towards knowing what colors have compatible "feels", and then an art to making it all work together.