December 4, 2017
Morning, it’s Monday, I wish it wasn’t. I’ve been in the process of writing a new website for myself for what seems like about 500 years now (about six months in your human time), it’s going to (hopefully) be an interactive art site using the Organic Contrast abstract nature compositions I’ve been putting together. I’m very nearly there but then I think of an improvement and knock myself back by a few weeks.
As I’ve been paying for the hosting and domain for about six months now (I was sure I would have the site built in a week so I just bought them when I had the idea) I’ve started to put things up on there. At the moment there’s two things:
A landing page for my current postcard set This was really hard to do, not because of the design or code but I wanted to experiment with writing about myself with a SERIOUS face. I’ve been prodded by a couple of people again recently about trying to do something sensible with my images to try and get them in front of people so I wanted to try and see if I could write about them in a more formal manner. It makes me squirm reading it back but it’s the kind of thing I already write for clients so it makes sense.
The second thing is my matching pairs demo I put this together as a client asked if I could write basic games suitable for small children so I tried. Apparently I can, so that’s nice. I went with a selection of the Organic Contrast images because they work quite well at that scale. It was also an experiment to see what I could do quickly with SVG animated with CSS and HTML canvas. It works quite nicely in most browsers and has fallback for those that don’t fully support the animation.
It’s quite addictive. I also included it at the bottom of the landing page. I’m working on some similar widgets which I’ll pop up shortly.
I’m trying to not distract myself with these and get back into finishing off the site with it’s intended purpose, I’d like it up before Christmas if possible (no real reason, just an arbitrary deadline) so I can get back to other projects which are slowly gathering dust.
Enjoy your week!
January 18, 2014
I’ve been learning how to code for mobile devices, (mostly for commercial purposes) as part of the process I realised I could write games for Alexander so I created one with all his favourite things (windmills, bees, bubbles, butterflies). I released it on the app store a week or so back. It’s for 2-3 year olds (although anyone might enjoy it).
It’s an interactive picture of a garden, with various things you can click to make them animate.
July 25, 2010
Recent attempts to work smarter rather than harder have been an utter failure. As the business grows and we get busier and busier I’ve needed to look at our business practices and workflow. It’s so far not worked out so brilliantly.
I used to write a fair amount of our tools and all of the frameworks and code for our websites and applications. Originally this was because there was little option, there were no free or cheap versions of the tools we needed and the frameworks available were challenging at best. Of course this wasn’t all bad it gave me a greater understanding of the underlying technology and probably increased my coding skills far more than downloading plugins and other people’s code ever would. But, as many people pointed out it did make development a relatively slow and arduous process which in the new age of Agile Development would see me left behind.
It took a while for me to change my ways, I still have an OC like obsession with understanding exactly how everything works and will still rip a framework or plugin to pieces on occasion to make sure it does what it claims. I’m now a complete jQuery convert and massively happy with WordPress. I went halfway with PHP, I tried a bunch of frameworks but just couldn’t get on with any of them so wrote my own, it took about six months (mostly research) but works perfectly for us and allows us to put together full online applications in a matter of hours. It’s not ‘finished’ and never will be, I constantly add to it and improve it but it’s lightweight and flexible and does exactly what we need (and nothing more).
We now have two choices: 1) Use a whole bunch of unrelated tools in a haphazard manner, tying them together with apis where possible or 2) write it ourselves.
Working smarter and faster is fine if the quality tools are available but if you have standards you may be better off doing it the long way.
In case you may be able to suggest anything, our primary requirement right now is a decent project/task manager which supports:
That’s it. To be fair we did find one piece of software that covers it pretty well but it was way outside of our current budget.
May 22, 2010
A bit more arsing about with HTML5. Purely decorative, completely non-interactive this time. An animated fountain based on one I wrote in AS3 which in turn was based closely on one from the absolutely brilliant Foundation ActionScript 3 Animation: Making Things Move! (seriously, if you need a good basis in programmed animation/interaction this book is a godsend, explained in simple terms and with a brilliant separation of concept from code so the information and tutorials can be easily applied to languages other than Actionscript 3).
The app is pretty simple, it generates a load of circles, each with it’s own direction, velocity, colour and size which move away from the center, when they are off the screen they are reset with new velocity, colour, size, etc and put back to the center again. That’s it. Here’s the code, it’s not very polished but it works…
Just the required bits…
That was easy. You just need a canvas tag. I’ve given it the original id of ‘MyCanvas’. Next up…
Once again, I’ve used jQuery to get things moving quickly, you don’t need to but it makes life easier.
First we set some global variables as follows:
Define a ‘Ball’ class. The xPos/yPos determine the ball’s current position in the canvas. vx and vy are the Ball’s x and y velocity. Wind and Gravity and horizontal and vertical force. The strangely named ‘sizeWobble’ is the amount the ball radius changes each frame. The reset function sets up the ball, most parameters are randomly generated, xPos and yPos are set to the center of the canvas.
The core of the script. Wrapped up in a nice jQuery document ready handler. First we set the globals for the canvas dimensions (as used by the reset method in the Ball class). Then we loop as many times as we want balls, create a new ball each loop instance, add it to the balls array and reset it.
Once our balls are created we use setInterval to call the ‘drawBalls’ function every 50 microseconds.
This is the function that’s called each ‘frame’ by the setInterval command. First we clear the canvas. Next we get a context for the canvas. Then we loop through the array of balls. For each one we:
That’s pretty much it, the remaining three functions are helpers. clearCanvas clears the canvas by setting it’s width (must find a more logical method of doing this). randomColour returns a random colour in the appropriate format and drawCircle draws a circle to the canvas…
April 27, 2010
Been having a play with HTML5, very excited by the new semantics and especially keen on the new canvas tag. Aware that it’s not going to be supported everywhere in the immediate future but it’s a great step in the right direction. I don’t think it’s going to be the immediate flash killer some have made it out to be anytime soon (I love flash and AS and have no desire to see them go), but it can certainly work as a good alternative to flash for simple animation and interactivity. Once the decent JS frameworks add more functionality to support it it’s going to make life a lot more interesting.
I’ve not written any sort of tutorial/code article before, so bear with me, feel free to just download the source.
View the source of the demo for the full HTML, I’ll just include the pertinent parts here:
This sets up two canvases, one for each graph, I’ve named them the imaginative ‘Graph1’ and ‘Graph2’. The controls div contains four divs to be converted to jQuery UI sliders (one for each point / bar on the graphs).
First off we set up a couple of global variables:
graphPadding is just a number to use for spacing items of the graphs out. I’ve just set a single number to use for all margins, spacing, etc to keep things simple. colours is an array of colour codes, one for each of the graph points.
Next we initialise with the nice jQuery document.ready function:
The first command sets up the jQuery UI sliders including giving them the appropriate event handler to redraw the graph whenever any of them are changed. The second command just sets each slider to a random value. Next we call drawGraphs to draw their initial state.
Now we have the main graph drawing function, this is set up to draw both graphs in one go.
First we get the canvas dimensions, these could be stored as constants/globals somewhere or hard coded but I like the flexibility of checking on the fly. Really we should check each one individually and split the graph drawing into two functions but it’s a demo and I don’t care. Then we clear each canvas to start drawing on it using a function which will be defined below.
Prepare to draw the first graph by getting a reference to the appropriate canvas then calling getContext on it. Then we set the stroke style to black.
Draw the axis, a simple case of drawing two straight lines. We use a combination of the canvas dimensions and the graphPadding global to work out the positions.
Work out how much space we actually have to draw the points in. The first point is two sets of graphPadding from the left and the last is two from the right hence the * 4. Same applies vertically.
The points will be equally spaced horizontally so we just need to get their vertical position. Loop through the sliders, get the value for each one (0 – 100), work out the percentage of the available vertical space and add it to the points array.
Draw the graph lines. We separate the line drawing and point drawing as when we draw a circle it calls closePath which knackers up our lines (there’s probably a better way). To draw the lines we loop through the points and draw a line between each one.
To draw the points we just loop through the points array again, drawing a circle at each one, again the horizontal position of each point is fixed.
I’ll cut out most of the code for Graph 2 as it’s identical. The part of interest is:
Here we work out the available space for the bars by subtracting the appropriate number of graphPaddings from the total available space then dividing the result by the number of bars. We work out the max height of each bar by deleting 4 * graphPadding from the total available height.
Then we loop through the sliders, get the percentage value from each one and set it’s bar to the given percentage of the total height.
That’s pretty much it. I’ve used two additional helper functions which are based on those found at the Mozilla Canvas tutorial, they shouldn’t need any explanation:
So, there you go. Dynamic graphs without flash or server side graphics libraries. These could of course be achieved pretty much entirely with CSS and JS but it’s been a nice intro to HTML5 and the canvas tag.
I’ve not given this a huge amount of testing (or thought) as really for my own entertainment but hope it’s of interest.
I am Bob. This is my blog. It is an outlet and a substitute for real life. It contains my art, photography, illustration and thoughts on mental health (I deal with anxiety on a pretty much constant basis).
Help fund my existence. Buy my stuff (t-shirts, art prints, stock images & graphics)
Enter your details below for updates on art and photography projects, discount codes on merchandise and other esoterica.
Your information will absolutely not be shared with any third parties and you can unsubscribe at any time. I use Campaign Monitor to manage my mailing list.No thanks. Stop pestering me.