Archive for the ‘Code’ Category

Confrunting my fears of blank paper

Tuesday, November 22nd, 2011

It’s not that I am not a good developer (I like to bill myself as a great developer) – but i have a morbid fear of the ‘blank paper’ that is a project just before I start coding. I have kind of got it pinned down to the fact that there are so many ways that a project could be built that I am concerned that whichever one I choose will be the wrong one. The thing is – I need to get over this. I have always been a great person to have working in the middle or end of the development cycle. My ability to isolate and fix bugs is a well honed skill – I just need to have the same level of confidence about starting projects.

So this week I have started an AS3 project (little things) but making sure that I totally understand the underlying reasons for choosing the architecture that I have gone for. So back to the online community and reading coded 101 sites but it has been really beneficial.

No time spent learning is ever wasted – no time spent making sure that you fully understand the life cycle of your development is ever wasted either.

Javascript Fractals

Monday, September 19th, 2011

I want to get involved with JavaScript Fractals too

Javascript preloaders

Monday, September 19th, 2011

I love these and hope to be able to create something as good soon!

A Triangle – minor change

Thursday, August 11th, 2011

function addTriangle(x, y, z, w, h) {
this.addLine(x, y, z,
x + w/2, y, z,
x, y - h, z,
x- w/2, y, z,
x, y, z);
}

perfection!! no matter how wide the line. Instead of drawing the triangle from 3 points (left, right, top) I am using 4 – mid to right, right to top, top to left, left to mid.

Thanks to Lori for just lying there girggling while I got this down!!

:)

Javascript to control a layered 360

Thursday, August 11th, 2011

This is still a work in progress but I wanted to get it up here so that I could see what needs work.

The comments below are for the proof of concept that is available here.

I have a love / hate relationship with code 360s. On the one hand they seem to appear in pretty much every site I have worked on and so effectively they pay the bills. On the other hand – same shit – different day.

So what happens if you take a 360 player and try to make it do new things?
First lets build it with JavaScript instead of Flash – that should be fun …. I did this for the fordCmax site.

Next – how to just change the tint of an object. I had a bit of a mess around and here is the result

It needs a bit of work still – there are issues with the load management – I need to write something for this but it wasn’t obvious until I put the demo online.

How is it working – the image is created as a composite of 4 layers – base, mask, reflection and shadows. The colour is changed by dynamically changing the background

A Triangle

Thursday, August 11th, 2011

So I have been watching Torchwood. The bad guys have this cool spinning triangle (very sinister).

I wanted to harness the power of this but in JavaScript and HTML5 as I haven’t had enough chance to play around with this.

I did my usual swift search – which of the coding giants can help – why Bit101 has been monkeying around too. I shall stand on his shoulders to create my masterpiece!

First off I needed read his tutorials. I got to day 3 before needing to just get on with stuff (I only get to build stuff during Lori’s nap times so I have an excuse for my impatience).

Next I added my new triangle primative to the wirelib.js.
function addTriangle(x, y, z, w, h) {
this.addLine(x - w/2, y, z,
x + w/2, y, z,
x, y - h, z,
x- w/2, y, z);
}

Then I create my aTriangle.js file (whilst humming James Blunt’s Triangle)


var x = 30;
var y = 40;
wirelib.strokeStyle = '#ffffff';
wirelib.lineWidth = lineW;
wirelib.addTriangle(x, y, 0, 500, 500);

Nice ! but narrow

so i add width
and that screws with it – I have still to sort this out but have a look and feel its power

Amended AE Expression – to work between two markers

Wednesday, July 20th, 2011

Countdown text initially reads 100 but once playhead reaches first marker (“1″) count down begins counting back from 100 to 0
Countdown text will reach 0 when the playhead reaches the second marker (“2″) and will stay at 0 thereafter

or to put it in a more simplistic way – it does exactly what the client wants.

var tTF = timeToFrames();
var frDuration = thisComp.frameDuration;
var endTime = thisComp.marker.key("2").time;
var stTime = thisComp.marker.key("1").time;
var currentTime = tTF*frDuration;
var totalTime = endTime - stTime;

var content = 100-(((currentTime-stTime)/totalTime)*100);

if (currentTime > stTime)
{

if (content > 0)
content
else
0
}
else
100

little note for later gotchas – can’t use the variable name ‘startTime’ as it appears to be reserved – it kept giving me the number 6 though i am not sure why

My Fyrst AfterEffects Expression

Wednesday, July 20th, 2011

So like the fool that I am I agreed to add some content to a friends video that he is creating for a book launch.

Initially I had planned to use Flash to create the video but then there were issues – I couldn’t get the video as an flv to start with – then Pete told me that the video would need to be distributed via youTube and the usual channels – so I started doubting that the creation of an swf file would be the best approach.

But I still needed to create a timer.

I blagged a bit of knowledge from Ivan Pinto Bravo who told me that I needed to use something called Expressions in AfterEffects and showed me the basics of getting time info from a movie clip.

So here it is – it probably isn’t the best bit of Java ever but to say that it does the job intended makes me happy and proud

100-(((timeToFrames()*(thisComp.frameDuration))/(thisComp.marker.key("1").time))*100)

But there’s more!

I don’t want the display to start showing negative values so I experimented with a bit of variable adding and guess what! it worked


var tTF = timeToFrames();
var frDuration = thisComp.frameDuration;
var markerTime = thisComp.marker.key("1").time;
var content = 100-(((tTF*frDuration)/markerTime)*100);

if (content > 0)
content
else
0

Javascript IE bug – in for ( in ) loop

Tuesday, October 12th, 2010

So the following code works fine in FF etc

for (var k in _data)
{
// execute
}

but IE never gets into the loop.

Solution – declare the variable k outside of the for statement

var k;
for (k in _data)
{
//execute
}

360 JavaScript

Wednesday, September 15th, 2010

Some code written for a site I am working on. The site isn’t live yet but this 360 works brilliantly and the best bit is i wrote it

// Provides: PROJECT.three-sixty

PROJECT = (function( cmax )
{
var me = project.threeSixty = project.threeSixty|| {};

var _totalImage = 174;
var _imageArray=[];

var _rotateLeft; // anticlockwise
var _rotateRight; // clockwise

var _imageContainer;

var _currentImage=0;
var _previousX;
var _currentX;

var _canRotate;

var _rotateTimer;

me.init = function() {
$$( '#Gallery .galleryVideoPlayer' ).addClass( 'loading' );
me.setImageArray();

// create control buttons
_rotateRight = $$( '#Gallery .three-sixtyControl a.right' );
_rotateLeft = $$( '#Gallery .three-sixtyControl a.left' );

_imageContainer = $( 'PROJECT360' );

// bind the control buttons
_rotateRight.addEvent('mousedown', moveRight);
_rotateLeft.addEvent('mousedown', moveLeft);

_rotateRight.addEvent('mouseup', stopRotate);
_rotateLeft.addEvent('mouseup', stopRotate);

// bind event to the actual image - going to
_imageContainer.addEvent('mousedown', startDrag);
_imageContainer.addEvent('mouseup', stopRotate);
_imageContainer.addEvent('mouseout', stopRotate);

// and a key listner
this.addEvent('keydown', startMove);
this.addEvent('keyup', stopMove);
}

me.setImageArray = function() {
// remembering that Paul started the image array from 1 not 0!
for (i=1; i<=_totalImage; i++){
var iString = i;
if (i<10){
iString = '00'+i;
}else if (i<100 && i>=10){
iString='0'+i;
}
var imageString = 'content/images/360/image_360 001 '+iString+'.jpg';
_imageArray.push(imageString);
}
loadImages();
}

loadImages = function(){
for (i=0; i<_imageArray.length; i++){
$$( '#image-load-holder' ).set('src', _imageArray[i]);
}
}

moveRight = function(e){
_canRotate = true;
rotateRight();
}

moveLeft = function(e){
_canRotate = true;
rotateLeft();
}

rotateLeft = function(){
if (_currentImage ==0)
_currentImage = _totalImage-1;
else
_currentImage --;
updateImage();
if (_canRotate)
_rotateTimer = rotateLeft.delay(100);
}

rotateRight = function()
{
if (_currentImage ==_totalImage-1)
_currentImage = 0;
else
_currentImage ++;
updateImage();
if (_canRotate)
_rotateTimer = rotateRight.delay(100);
}

updateImage = function(){
var image = _imageArray[_currentImage];
$$( '#CMAX360 img' ).set('src', image);
}

startDrag = function(e){
e.preventDefault();
_currentX = [e.page.x];
// watch the mouse
_previousX = _currentX;
_imageContainer.addEvent('mousemove', dragging);
}

dragging = function(e){
_currentX = [e.page.x];
if (_currentX != _previousX)
{
// either moving left or right!
if (_currentX > _previousX)
rotateLeft();
else
rotateRight();
_previousX = _currentX;
}
}

stopRotate = function(e){
e.preventDefault();
_rotateTimer = $clear(_rotateTimer);
_imageContainer.removeEvent('mousemove', dragging);
_canRotate = false;
}

startMove = function(e){
// listen for left and right arrows
if(e.key == "right"){
rotateRight();
}
else{
if(e.key== "left"){
rotateLeft();
}
}
}

stopMove = function(e)
{
//alert("keyup")
}

window.addEvent( 'domready', me.init );

return project;

})( window.PROJECT || {} );