Archive for the 'code' Category

JavaScript Getters and Setters: Why U No Use Dem?

Javascript has always had properties but recently support for property accessors and mutators was added, or rather it is finally supported in enough browsers that we can reliably use it. Property accessors and mutators are what we would call in the Java world “getters and setters”.  The cool thing about the new JavaScript version is that you don’t call the getX method. Rather you can set a property the way you always have, as a variable assignment, but the accessor method is called underneath.

This is a very powerful feature, and yet my research indicates that they are rarely used in practice. In fact I can find almost no reference to them beyond how the syntax works. Where are the cool crazy things you can do with them?  They seem incredibly useful.

Continue reading ‘JavaScript Getters and Setters: Why U No Use Dem?’

at 12:03 pm

code

Genetic Programming: AI Opening Disappointment

For some reason the concept of Genetic Programming got stuck in my head the other evening. At midnight, after spending about four hours reading up on the topic around the web, I came away disappointed.  The concept of evolving code the way genes do is fascinating but the results in the field seem to be very narrow and limiting.  Thus began this rant.

Continue reading ‘Genetic Programming: AI Opening Disappointment’

at 8:34 am

code and rant

iBooks and an HTML Experiment

With all of the hoopla last week about the innovative features in the new iBooks 2 I thought it would be instructive to see what could be done with pure HTML 5.  I put together a little demo which adapts to screen sizes and has simple interactive content. Here’s what it looks like:

ebook prototype

View the live demo here. I highly suggest you load it up on an iPad as well. Try rotating the screen (or make the browser window narrow if you are on a desktop.) Keep in mind this is just a prototype. It’s not skinned or made to look pretty at all.

You can spin the little sphere tree by dragging with your mouse. If you view this on a tablet it will respond to touch events as well.  You can click on the photo to see a large fullscreen version. The footer will stay fixed to the bottom. The inline photo and canvas will resize and move to the left edge if you switch to portrait mode.

My goal for this effort is use pure semantic HTML. If we want to scale this up to a full book then the markup needs to be as close to pure text as possible.  I’m using only divs with paragraphs and headers for all textual content. The interactive stuff is canvas or img tags.  All interaction is standardized and put into reusable javascript files except for the actual dot tree itself (though it does use reusable components). I had to add a little hack to make the canvas resize properly, but that is also reusable.  The footer and general layout is pure CSS.

I think the prototype turned out pretty well. It would be easy scale up to a full book with one page per chapter. Table of contents, index, and glossary would have to be written by hand unless we have some automated tool to do it, though I think such tools already exist.

So far I haven’t found much that the new iBooks 2 format does that couldn’t be done with plain HTML.  They did add nice columns and shaped floats, but that is part of the CSS 3 specs and could be implemented in the renderer quite easily. (And shaped floats have been hacked into CSS2 for over a decade!)

I do like the look of iBooks Author. It’s a very nice visual tool that should let people create books without any programming experience.  The new terms of service are a different issue, but after thinking about it I’ve decided I don’t care. iBooks Author is a tool for formatting content to be sold in the iBookstore.  It really has no purpose other than that so the terms of use don’t make much difference. Amazon has their own tools for their own store as well, and I expect them to get better with the advent of the Kindle Fire.

While I would love to see a beautiful visual editor like iBooks Author that formats content for all possible bookstores I don’t really expect Apple to build it for me.  Such a solution will have to come from a third party. Fortunately third parties now know that Apple won’t compete with them to build such a tool, so I expect we’ll see something like it soon.

Anyway, back to my HTML 5 prototype. Anything else you’d like to see it do?

Please send feedback and comments to my twitter account @joshmarinacci instead of on the blog. Thanks!

 

 

 

 

 

at 5:06 pm

code and ebooks

HTML Canvas Deep Dive

Today I’m doing a three hour hands on tutorial at OSCON on HTML Canvas. All you need is a text editor, Chrome, and basic JavaScript knowledge. By the end of the session you’ll know a ton about Canvas and have built your own little video game that can run almost anywhere. The full lecture notes and hands on lessons are here.

at 11:00 am

code and travel

Playing with Noise

While I have many projects in progress right now, including Amino, Leonardo, getting the TouchPad out the door, and having my first baby (only a few weeks left!); every now and then I just get something into my head and have to code it out. Last night it was noise functions.

Since I’ve been using little bits of noise in my designs I thought it was high time to really learn how it works. Following code & articles from here and here I’ve managed to create a simple noise and turbulence generator in Java. With a few different settings you can get textures that range from completely random to something that looks like marble.

com.joshondesign.texgen.Test1ScreenSnapz004.png

pure random grayscale noise

com.joshondesign.texgen.Test1ScreenSnapz002.png

high turblence

com.joshondesign.texgen.Test1ScreenSnapz001.png

medium turbulence + one sinewave

com.joshondesign.texgen.Test1ScreenSnapz003.png

medium turbulence + three sinewaves

It’s actually simpler than I thought. Noise is just a bitmap filled with random values from 0 to 1 (or a grayscale value between black and white). Turbulence is created by stacking multiple layers of noise, each stretched to different amounts. Add in a bit of linear smoothing and you get some quality texture. The marble effect is just a turblence texture merged with a sine wave.

Next up, making the noise repeat so we can have tileable textures. Then I might make a simple app to generate noise with various colors. If it all turns out okay I might make a plugin for Leonardo to create your own textures.

at 1:06 pm

code and graphics

Josh’s Quick Intro to RegEx

You may be a new programmer, or a web designer, or just someone who’s heard the word ‘RegEx’, and asked: What is a Regex? How do I use it? And why does it hurt my brain? Well, relax. The doctor is in. Here’s two aspirin and some water.

What is it doctor?

Oh, it’s two parts hydrogen and one part oxygen; but that’s not important right now. We’re here to talk about RegEx. RegEx is short for Regular Expressions, but that’s also not important right now. Regexs are just patterns for matching bits of text. Whenever you hear RegEx, just think: pattern. In fact, I’ll stop using the word regex right now, since it mainly sounds like the kind of medicine you’ll need after trying to write a complex regex.

Continue reading ‘Josh’s Quick Intro to RegEx’

at 11:00 am

code and programming

Amino and Leonardo: Next Steps

Another month has gone by with no update to Leonardo, or a real release of Amino. It’s interesting how life changes. When I started this projects last summer I had no idea Jen and I would be having a baby in a month, nor did I truly have any notion how much my life would change. Everyone always says having children will change your life, but you never really understand it until you do it yourself, and our journey has just begun.

So, the upshot of all this rambling is that kids take time, and when you have to distribute a finite resource between multiple buckets, something has to get less. Sadly this time the short straw goes to my open source projects. It doesn’t mean I won’t work on them anymore, just at a slower pace. However, in order to feel at peace with myself I need to leave them in a state where they can still progress without my large time commitment. That’s what this post is about.

Continue reading ‘Amino and Leonardo: Next Steps’

at 9:30 pm

amino, code, leonardo and personal

Amino 2: Overall Design

When redesigning Amino I had a few core goals. These goals are in place to guide the product and ensure we created something genuinely useful, and not become “yet another gfx lib”.

Continue reading ‘Amino 2: Overall Design’

at 1:04 pm

code

SideHatch

Below is a screenshot of a debugging app I’ve been working on called SideHatch. It essentially lets you open up your Amino app from the side and poke around at the innards.

org.joshy.gfx.test.control.TranslationTestScreenSnapz005.png

In the screenshot you can see the two main tools: the Translator and the Inspector. The Translator shows all strings in your application that have been translated, broken down by category and locale. From here you can update translations and switch locales on the fly. The app will automatically refresh itself to show the changes without a restart.

The Inspector puts an overlay into every window showing the bounds of every control in your scene. Then you can move the mouse around to get info on particular components, like it’s dimensions and translation. In the screenshot the indicator is telling me that the button I’ve hovered over doesn’t have a translation yet.

SideHatch is currently in the ‘translation’ branch of the repo if you are interested in playing with it.

at 4:20 pm

code

HTML Canvas Export for Leonardo

Jen was working today, so I spent the day fixing bugs and coding new features in Leonardo. Today’s awesome feature: HTML Canvas Export. Yes, oh yes! You can draw anything you want in Leonardo, then export it to JavaScript code that draws into Canvas. Why would you want such a feature. Lots of reasons:

  • Maybe you need to draw vector graphics in a browser that supports Canvas, but not SVG.
  • Maybe you want to learn Canvas and have some code to start with.
  • Maybe you are just simply too lazy to draw your own damn pictures in code.

Whatever your reason, Leonardo will be there for you. Look for it in our next release!

Check out this demo output page.

at 8:48 pm

code