Wednesday, March 27, 2013

Data Structures

This post is written for people who are familiar with the basics of computer science and a little javascript. If this is not you, feel free to read the code below (which contains extra comments.)

There is an entire field within computer science dedicated to finding efficient ways to store information. I was not satisfied with how I was storing data in an early version of fractal canvas, specifically how points in the template needed frequent updates to keep them in sync with their representations under the hood. My solution is to create a data structure that stores each point with an Id that is unique for the lifetime of the page.

Warning: it gets more technical


//hashedArray is my new data structure gives each element an ID that is unique for the lifetime of the page
function hashedArray(){
    this.id = 0; //the ID of the newly inserted element
    this.elements = []; //holds the data
    
    //gets the length of the elements (needed because array is sparse)
    this.length = function(){
        var cnt = 0;
        for(var i in this.elements) cnt++;
        return cnt;
    };
    
    //index is optional - defaults to the end of the array
    this.insert = function(elem, index){
        index = ((typeof index === 'undefined') ? this.elements.length : index);
        this.elements.splice(index, 0, {hash: this.id, data: elem});
        return this.id++;
    };
    
    //getter
    this.get = function(){
        return this.elements.map(function(elem){ return elem.data; })
    };
    
    //get an element by its hash
    this.getElementByHash = function(hash){
        for(var elem in this.elements) if(this.elements[elem].hash === hash) return this.elements[elem]; //find the element
    };
}
//create an object to hold the sketch points
this.sketchPoints = new hashedArray();

Sunday, March 24, 2013

SVG

There are countless languages that are used in web development. One of these is called SVG. It is actually misleading to call it a language. According to Wikipedia, it is
[...] an XML-based vector image format for two-dimensional graphics
 Previously, for the Fractasketch template, I drew a dot at the end of each line segment in the template and then drew lines connecting the dots on a template.



This is not flexible at all though when designing the UI. I only have access to events on the dots (mouse over, clicking on etc.) By switching to SVG for the template drawing, I will be able to write a highly interactive UI where users can click on the lines, points, and arrows that make up the template.

I will post pictures of tests and demos as I learn how to incorporate dynamic SVG content into my page.

Istvan.

Thursday, March 21, 2013

Mentor Meeting

Today I had my weekly mentor meeting with Mr. Drix. I showed him the final version of Iterative Canvas which we played with for a period.

In my experience, some teachers only use Smart Boards as projectors, some have them but don't use them at all, and a handful use Smart Boards to enhance their lessons beyond what an overhead can do. There are, however, some teachers and some lessons that feature a Smart Board so effectively it amazes me in the way only powerful tools that are used so effectively they become transparent can. Today, I think Iterative Canvas made it to the short list of lessons that are effective on Smart Boards.

While he ran through his lesson and I pointed out technical tips, I also discovered some small things to update. For example, now the grid updates resolution as you type, custom points are reverted to auto when you switch tabs, and changing the number of auto points and their scale are both immediately reflected.

I fixed a few typos in the text below the canvas that I found as we read through them together.

Progress is going well as I create an FUnit from the alpha Fractasketch template UI. More posts on this soon.

Istvan.

Walls of Text

Writing the documentation is turning out to be more difficult than I thought.I'm trying to make it interesting and thorough enough that people can appreciate what's going on. That amount of detail builds a formidable wall of text which easily surpasses what I would be willing to read if I stumbled upon this page.

In my meeting with Mr. Drix I will ask him how he approaches boiling this down in his class.

Istvan.

Tuesday, March 19, 2013

Wait... documentation

I need to take a break from Fractasketch... I forgot something!

My Chaos Game (the old version of Iterative Canvas) has some poorly written, un-proofed documentation... which is still more than Iterative Canvas has now!

I'm going to get started now, and hopefully have at least a 'getting started' done by tomorrow.

Also, check out the new collapsing feature I added to the controls.

Istvan.

Iterative Canvas Code

As promised, here is a sampling of code from Iterative Canvas. This is the 'meat' of the program. While it makes up a fraction of the program's code, this is what generates and draws the output when running the game. It may be a little tough to follow, but any line that starts with two slashes (//) is a comment describing in English what is going on (the computer ignores these lines.)


this.addPoint = function(){
    if(endPoints.length > 0){
        
        //gets settings from the control panel
        var distChange = parseFloat(eval(document.getElementById('step').value));
        
        //randonly choose a target point
        var targetPoint = nextTarget;
        nextTarget = Math.floor (Math.random() * endPoints.length);
        
        //find the X's position after jumping the set distance to that target point
        curPoint[0] = curPoint[0] + ((endPoints[targetPoint][0]-1)-curPoint[0])*distChange;
        curPoint[1] = curPoint[1] + ((endPoints[targetPoint][1]-1)-curPoint[1])*distChange;
        
        //draw the new black dot
        context.fillRect(curPoint[0], curPoint[1], 1, 1);
        
        //call other code to move the X to the new location
        funitfciterativecanvas.updateXdraw();
        
        //if the program is running to infinity keep track of how far
        if(remainingPoints == 'inf') infRunCount++;
        
        //if the program isn't running to infinity, subtract one from the number of times this has to run
        if(remainingPoints != 'inf' && remainingPoints != 0) remainingPoints--;
        
        //if this has to be run more times
        if(remainingPoints != 0){
            //if drawing normally (not quickly) then delay and run again - also a hack to solve overflow problems in recursion
            if((document.getElementById('quickDraw').checked === false && (!remainingPoints || remainingPoints == 'inf'))
                    || remainingPoints == 1 || (infRunCount == 200 && document.getElementById('quickDraw').checked === true)){
                setTimeout(funitfciterativecanvas.addPoint, 0);
                infRunCount = 0;
            }
            
            //continue drawing points quickly
            else{
                funitfciterativecanvas.addPoint();
            }
        }
    }
}

What's Next?

I have mentioned my next project, Fractasketch, before. The attached images are a teaser of what you will be able to do. These were created by the current fractals and chaos students (I will credit them when their names are released).

Istvan.

Monday, March 18, 2013

Scary Code

When I was a young kid I always thought programming was all in cryptic numbers and symbols without any semblance to natural language. As it turns out, this is indeed (usually) largely untrue. For example:

<if:Empty $%username>
...
</if:Empty>

That is relatively straight forward - if the username is empty, then run what ever code is between those lines.
This segment stores the value 0 on the computer for use later:
remainingPoints = 0;
There are times, however, that code really does resemble my preconceptions. The following code comes from the configuration file of my server:
 #apps
RewriteRule ^apps/([^/.]+)(?!.)$ $1.sfw.php [L]
#app resources
RewriteRule ^apps/(.*(?=\.).*)$ $1 [L]
I wrote it to tidy up the web addresses (URLs) that my users visit.
Now,
http://www.fractalcanvas.com/apps/iterativecanvas
is the same page as
http://www.fractalcanvas.com/iterativecanvas.sfw.php
except a much nicer address. In fact, other applications I develop will have similar URLs now, of the form:
http://www.fractalcanvas.com/apps/some_app_name

There is a little insight into what programming really looks like- granted, each of those examples was hand-picked to prove a point. I'll be posting some code segments soon that are more representative of what my project entails.
Istvan.

Thoughts From a Project Past

As part of an assignment, I read the project materials of a former student. Reading the project was particularly interesting to me because I know the student and had a lot in common with him; we were both presidents of Code Red Robotics (I still am), took the Project Lead The Way tech classes, and both hope to become engineers (he did!)

The project I read was making a robotic arm that plays checkers against you. The student's journal showed several examples of the problem solving involved in his project, for example detecting stacked up pieces. The journal explained the problems in light detail, but explained the basic technical principles behind their solutions. Being familiar with these principles, and in fact having learned them from the same teacher on the same machines as he used, I particularly appreciated these posts.

The idea of having a blog be 'for your own benefit' has been advised to my class several times; but I will not be the only one who reads mine. The blog I read was littered with spelling errors, but was also hard to follow as a reader. I also would have benefited from benchmarks or some overall view of the project and occasional sign letting me know where he is.

From these conclusions I am starting two new habits in my own blog: milestone posts and posts that explain what I'm doing to a non-technical reader.

Istvan.

Sunday, March 17, 2013

Home Page

I created a (temporary) home page a few days ago, but when you went to www.fractalcanvas.com the home page didn't show up. Instead it created an automatic listing of all the pages on the site, but it didn't automatically choose the right one for the home page. A little research showed that adding the following line to my configuration would solve the problem (without messing several other things up, which was the problem with other solutions I had tried):
DirectoryIndex index.php index.sfw.php
 I need to put some more substance on the home page soon. I will start drafting an "about this site"  blurb to add to that page in the coming few days.

Istvan.

How Meta Can You Go?

In reading journals from previous projects, talking to a friend about his blog, and in reading my own I got thinking about how abstract my blog is/should be. Here is the conundrum:

If I talk very specifically about the problems I encounter, the solutions I find, and technical perspectives of the work I do my journal becomes a very useful tool to me... and an unintelligible, boring log with occasional pictures to everybody else.

If I talk generically about the progress I am making it will sound very, very repetitive and serve little purpose to me. However, the comment was made to me, that people are interested in what I am doing, not necessarily how I am doing it.

Here is a template for every abstract post I might or could make:

I started with the goal of [some feature to implement]. I ran into some problems with the programs I'm using [list a couple of bugs, like "the sidebar is too wide in Firefox"]. I found a fix for [some problem I had before] - it works now. Next I need to [perhaps some goals].

At first glance, that seems like a thoughtful and perhaps even interesting blog post. As a tool to me, however, this post offers little help. 'The sidebar is too wide in Firefox' is the kind of bug developer hate. Its not really a bug, it's a symptom. A useful description of the bug might be "Firefox doesn't support the box-style CSS property. The style was written to use border-box, which is valid in Chrome. Using a temporary Firefox-specific style instead."

As a compromise, I might start prefacing some technical posts with a summary (following the above template roughly) and then getting into the technical details after.

Practice

The exact benefit of practicing is a skittish creature to define. Over the past week I have been considering examples of practicing, some that relate to my project and some that don't, to help nail down what it is exactly that practicing does for me.

Learning new things

Being a learn-on-the-fly type of guy, the first (few) times I practice something, it is akin to bushwhacking. As part of the research for Fractal Canvas, I am learning a new language (WebGL.) On my left screen I have a tutorial open on one half and the manual on the other. On my main screen, I switch between my code editor and browser to see the results. Practicing at this stage is just transcribing from the example to my own code, understanding each piece as I do (from the manual) and tweeking little things here and there to familiarize my intuitive sense with the parameters.

In an example from a completely different field, I picked up a trombone yesterday and my friend taught my the basics of how to play. Being a tubist, the fundamental sound-making came easily, but the slide was completely new. Creating relationships between partials, notes, and positions came more and more easily as I fumbled through notes in easy pieces, finding each one as I went.

Intuitive Sense

Practice can lead one to develop an 'intuitive sense' relating to some task. In programming, this may be the approach I take to solving a problem, styling a page, or making accommodations for afterthoughts. In music this intuitive sense fuels my interpretation of the ink on the page. But perhaps the most tangible example comes from my experience as a machinist on Code Red. By the end of a 6-week build I could mill 1/1000th of an inch of metal off a rod by eye, identify the thread size on bolts, and estimate parts and features to the nearest common fractional size. These abilities were developed through repetition and unconscious pattern recognition. These intuitive skills, including those in programming, music, and machining along with the countless similar skills everybody picks up every day, are clearly definable products of practice.

Maintenance

In programming there are distinctly different skills in theoretical understanding and application. Practicing writing actual code is the transition from one to the other. Each time I write a similar piece of code I become less dependent on manuals and documentation. Phrases and melodies in band pieces become muscle memory. My fingers and mouth sync up better as I practice, and my ears become more finely tuned to the music. This stage is where things become facile, "like riding a bike."

Relearning

When I take my bike out for the first time in the spring, it's obvious that some relearning is in order. It takes a moment's thought (and planning ahead) to unclip my shoes from my pedals before I stop. It takes a few miles to remember just how much to lean over when corning at race speeds.

Most programmers 'know' more than one language. Many are similar, so once you know one it may take a day or two to 'learn' another. But every time I take a hiatus from a language, it takes a day with the documentation to remember the exact syntax specific to parts of that language.

Just this Monday, in band we took out Bayou Breakdown for the first time in three weeks; we crashed and burned. We all went home, refreshed our fingers and re-attuned our ears to our parts, and made it through the piece just fine a few days later.

Practice

I considered four 'types' of practicing from my own experience. In just this last week I have had a chance to experience and contemplate each. In my project, each kind of practice is certainly present to a large degree. This weekend I have worked on learning a new language, brushed up on a familiar language (SQL), and written in SAFE/PHP/HTML/CSS, all languages with which I am very familiar.

Istvan.

Saturday, March 16, 2013

3D Page, Firefox Woes

I'm working on squashing a bug on my site in Firefox. When you manually add target points they are added far offset from where they should be. Firefox and Webkit (Chrome, Safari) handle the clicking differently, and it seems Firefox changed how they handle it recently. I'm poking around in some forums to see how to fix the problem.

In the mean time, here is a neat picture Firefox created showing all of the layers and elements in my page:



Istvan.

Thursday, March 14, 2013

Mentor Meetings

A week ago I posted:
My goals for the next week or so are to tidy up Iterative Canvas (especially the code and front end) and add snap to grid functionality for custom placement of points.
 Today I finished the second part of a two-part mentor meeting in which I showed Mr. Drix the successful completion of these goals. For a more complete summary, see the post I published this morning.

Moving forward, I will of course be tieng up loose ends for Iterative Canvas (including a style bug in which the custom points tab is nowhere to be found in Safari.) My main focus, however, is transitioning to implementing Fractasketch (under some other name.) I have been doing research about writing code in WebGL. The application of that research will come with Fractasketch as I port the alpha version I have and write the drawing engine in WebGL.

A quick, miscalculation project in the next day or two will be to add user authentication features to fractalcanvas.com so that users can save their work and create galleries online.

Istvan.

Iterative canvas updates

Last night I pushed several updates live, including features for iterative canvas,a home page, Google analytics code, and site-wide libraries.

Iterative canvas' controls now include a toggle for go to infinity/stop. The controls are all shorter so that they fit on smaller screens. A snap to grid checkbox has been added which uses a snap to grid function written in a utils FUnit.

The utils FUnit is activated by every page which inserts tracking code and makes JavaScript libraries available.

I will post later today about my mentor meetings today and Tuesday.

Istvan

Wednesday, March 13, 2013

Iterative Canvas Live

The moment that I have been promising would come for several posts now has arrived! Iterative Canvas, the first of the applications I'm deploying, is live on my new domain! Click here to go check it out. Note that I have not yet written the tutorials so for most people the "point" of the page won't be clear... but for a pretty picture just hit Go ∞

Here are some of the things it draws:


Monday, March 11, 2013

Thanks

This will be a short post, but I want to give a shout out to Raphael Reischuk, a coworker of mine on the SAFE project who has been very helpful in getting SAFE working on my shared host. He has answered my questions and helped me develop proposals/implement new features that allow the system to run on the strict requirements of my server.

Istvan.

Sunday, March 10, 2013

WISE Documentary

In class, we watched a video that was not only a WISE project, but was about a WISE project. The documented project was a prime example of what the program can do; the task, building a barn, was enormous, but the student was dedicated. The interplay between the challenges and the student's resolve set clear mile makers of the projects growth, as the student looked for trees, milled the lumber, and created the framework for the barn; each step coming with unforeseen delays and challenges.

At the end of each stretch, the student was interviewed. The student shone at the measurable, tangible progress he had made. I look forward to having my website live so that I can announce on this blog that a new feature is available for the world to test.

On that note, off to code 'snap to grid'!
Istvan.

Integrated Live

After creating a proposal for an update to SAFE that allows it to run on managed (limited) SQL setups, one of my coworkers implemented those features. Now I can run SFW on my hosted server and integrate FUnits! I have even gotten the alpha version of the Iterative Canvas (new Chaosgame) working live.

I need to complete the control panel, map the site to my domain name, and then push those changes live for the world to enjoy in the coming week!

Istvan.

Thursday, March 7, 2013

Mentor Meeting Notes

Today I had another mentor meeting. I managed to patch up a quick demo of Iterative Canvas in the few minutes before Mr. Drix and I met -- check out the picture below!


Mr. Drix also pointed out that I should make a credits page or section for these apps since I took inspiration from other people's work. I also aught to contact Peter Van Roy again and mention to himthat I will be using a name other than Fractasketch (as good as the name is, the code is completely unrelated so it seems appropriate for the name to follow suit.)

My goals for the next week or so are to tidy up Iterative Canvas (especially the code and front end) and add snap to grid functionality for custom placement of points.


    Iterative Canvas - the control section may look familiar. The styling is in-progress to match this sketch.

Istvan.

Wednesday, March 6, 2013

Scripting Mahem

I have copied Chaos Game to the new site, calling it Iterative Canvas. The page loads, looks decent, and throws no errors!
Unfortunately it still doesn't work. SAFE (as part of its security) puts each FUnit's scripts in an object. I split the game and controls into separate FUnits which, combined with the methods that call each other, have made quite a mess of function calls. This is for the to-do list tomorrow; I'll likely update the code base as I go since there are a fair number of loose ends lying around in the code.

Istvan.

Christening of Iterative Canvas

Hopefully I will officially deprecate my existing implementation of Chaos Game and launch the new version built into Fractal Canvas soon! I am porting the code over tonight. Below is a quick sketch of the control pane.


Istvan.

Tuesday, March 5, 2013

Behind the Curtain

Thus far, the actual happenings of this project have been somewhat hidden as the technical details of whats going on have been stripped away. This post is a 'peek behind the curtain'.

My experience thus far has been that the road is rocky; the solution to one problem is the cause of the next, or that another unforeseen challenge is but a few lines away. When smoothed out the progress looks slow, but then again the British coastline is not merely 11,072.76 miles long.
> The coastline is often considered a fractal, and infinitely long. Consider a small peninsula - from a satellite's
> view you might not see the feature and trace over the peninsula, affording it no length in the coast line. If
> you look more closely, however, that peninsula adds distance. Now look even more closely, and add the
> distance created by the features of the rocks, of the sand, even of the crystals that make up the sand.

Perl v10.what?

One of the first issues I grappled was that of a misleading spec on my web host's site - they claimed to be running a later version of Perl than was being called by default, causing the following error:
Sequence (?|...) not recognized in regex; marked by <-- HERE in m/((?| <-- HERE  empty \( ([^)]+) \)
                            | empty \s+ ([^\s&|)>]+)
                            | notempty \( ([^)]+) \)
                            | notempty \s+ ([^\s&|)>]+)
                            | equal \( ([^,]+)\s*,\s*([^)]+) \)
                            | notequal \( ([^,]+)\s*,\s*([^)]+) \)
                            | \s+OR\s+
                            | \s+AND\s+
                            | \s+
     at ../../sfwc/sfwc line 1480.

Can't GRANT me SUPER

My host gives me three database accounts per databsae by default... which don't really line up with the required permission levels for SAFE. Many of the SAFE features rely on individually GRANTing access within the database -- a command that none of those three users can execute. SAFE also tries to create VIEWs with DEFINERS set, requiring the SUPER privilege (which I don't have, and clearly can't GRANT myself.)

Template Page

The template has been copied into my SAFE installation and is running on a generic page! I need to separate the parts of the page into FUnits (sidebar, header, footer, content area, and activated content modules.) This came only after some wrestling with CSS inclusions, database errors (these were never 'resolved'... they just disappeared) and some updates. SAFE was not initially designed to run in directories that are children of the web root and needed some updating to make it work.

Research?

I have have familiarized myself with the basics of WebGL and have modified some of the example pages. My next adventure will be to draw thick lines with geometery shaders... features that arent provided by WebGL.

Apps

Of the three apps I am adding to this site, one is already done (only minor feature additions are required, such as snapping points to grids.) Once the template is 'expanded' I will dump the ChaosGame code into an FUnit and integrate it!

Files/Saving

One of the advantages of the new framework is that users aught to be able to save their files.... These features might be added to chaos game in parallel to the implementation of the other two apps.

When can I see this?

Good question. Once SAFE is updated to work on my host, I'll blast it up for all to see and use!


I'll periodically post these 'Behind the Curtain' posts with some technical insight for those interested. For the rest of you, pretty pictures are on their way!

Istvan.

Sunday, March 3, 2013

SAFE on a shared host, status

Installing SAFE on my shared host has turned into a headache of unexpected proportions. Still early in development, the focus has been to develop functionality to run on the dev servers, not yet on customizable deployment. As I mentioned in a previous post,  I removed all user creations, all GRANTs, and DEFINERs from VIEWS from the database initialization code. It turns out that the CRM (which manages all of the pages/users/content etc in SAFE) is written to use these features as well, which causes it to throw errors on my shared host. I have written a proposal to update the CRM to contain the customization required to make installing SAFE easier. In the mean time, I will continue to run the site locally and update the gantt to reflect these unfortunate delays.

Istvan.