psychopyko welcome to psychopyko.com

19Aug/12

Sandbox: CSS transforms and animations

CSS Cube

Cube - created by CSS!

You are now reading the first of my "Sandbox" posts :)

The idea of this "Sandbox" is that there are so many cool things on the web that I keep seeing and wanting to learn/try out. I'm very much a hands-on learning person, so the sandbox is going to be a collection of my random explorations of things that have caught my attention. Hopefully I'll be able to regularly update the sandbox!

The first thing to go into my sandbox is an exploration of CSS transforms and animations. On Thursday, I went to "What do you know?" (it's awesome!) and listened to Patrick talked about "Moving to a 3D web with CSS", in which he showed us how easy it was to make a cube using CSS.

Been meaning to look into CSS transforms for a long time, so this was a sign! Thus I spent most of my Saturday hacking at CSS :) For the impatient, here's the source code (under 2012-08-18).

Here are two tutorials that I found extremely helpful when poking around with the CSS:

The above two links will give you a good start on your CSS animation journey, so instead of writing a tutorial, I'm going to highlight some "gotchas" that I hit yesterday.

Animation is cool - but you have to define it!

When you see something like this:

-webkit-animation: spin 8s infinite linear;

Don't be tricked! The "spin" is actually not a built-in animation, you have to define it yourself. At first, it might seem like more work, but it's quite simple and it also means you can specify how the animation works. For example, here is my 'spin' definition:

@-webkit-keyframes spin {
   from { -webkit-transform: rotateY(0) rotateX(0); }
   to { -webkit-transform: rotateY(360deg) rotateX(360deg); }
}

I've decided to rotate on both the X and Y axis to make the rotation more interesting. The syntax is fairly simple (but powerful) once you get the hang of it. For a detailed explanation of the syntax have a look at: Keyframe Animation Syntax

Required properties

Now I could be wrong here (please correct me if I'm wrong!), but at least from my experience so far it appears that you need these two properties for things to work:

  1. position: absolute;
    Seems to be needed for both 2D and 3D animations, otherwise the transforms don't seem to have something to 'anchor' to.
  2. -webkit-transform-style: preserve-3d;
    Needed for 3D animations if you want your shape to keep it's 3D-ness when it's being transformed/animated

The axes rotate with the element when you transform it

By default, if you are looking at a webpage, the x-axis is the horizontal axis, the y-axis is the vertical axis and the z-axis the one coming out of the screen. The origin is the '-webkit-transform-origin' of the element, and like the cartesian plane, right is positive x, up is positive y, and out of the screen towards you is positive z.

Now, when you transform your element, the axes for that element rotates with it - that is, each element has it's own set of axes. So, if you rotate an element 90deg by the x-axis '-webkit-transform: rotateX(90deg)', the positive y-axis is now pointing out behind the screen (away from you) and the z-axis is now what the y-axis used to be.

Each element can only have one transform property

A transform property for an element, looks something like this:

-webkit-transform: rotateX(90deg) translateZ(100px);

Now, if you apply another transform to this element (maybe via animation) that new transform property will override the initial property. It is quite annoying that you can't stack the transform properties, but the 'transform' property is actually a single property (and not shorthand) so you can't specify to change just one type of transform.

This means, if you want a more complicated animation, you will need to wrap the element in a div and animate both the inner and outer div. This can cause your HTML to become quite ugly, but can't see a way around this.

Upgrade your browsers!

I did all my development using Chrome, and after everything was working, added the '-moz' versions to the CSS, opened it in Firefox and the cube didn't rotate! After spending some 15min of debugging, realised I was using an old-ish version of Firefox (version 8). Upgraded to version 12 and the cube magically rotates :)

 

That's all I've got for now, hopefully it has been helpful and/or made you want to go and try some CSS for yourself. If you missed it, you can see the code here (under 2012-08-18).

12Jul/11

Puzzle is awesome!

A long time ago in a galaxy far, far away... many CokeUnleashed coupons were collected to obtain the long sought after 1500 piece 'Coca-Cola' Puzzle. An unknown number of weeks later the long awaited puzzle finally arrived. Not long after it's arrival, two crazy friends took up the challenge to assemble it. After roughly five nights of sorting, colour matching, confusion and awesome fun the puzzle was completed :) Some photos for all to enjoy...

...if piecing together 1500 pieces wasn't enough, I was crazy enough to make a stop motion video. After approximately 5 hours, 270 photos later, some iMovie magic and awesome music knowledge from awesome friends...

22Sep/10

Clean hands? Paper towel please!

Washing hands is something we all do on a daily basis. Whether you are at work, at home or when you are out and about, you are bound to wash your hands at least once in a day - I hope! So, what do you do after you finish washing your hands? Well, you have to dry them of course! We've all been told that bacteria strives on damp surfaces, so we have to dry our hands. Question is how?

Well, according to research you don't need those fancy hand drying machines that you might find in a shopping centre or at work, all you need is disposable paper towels! In fact, paper towels work better than those high-tech hand dyers - be it the traditional ones that blow warm air, or the cool looking and insanely loud Dyson Airblade.

...the use of paper towels consistently out-performed all the other drying techniques, especially with regard to bacteria left on the palms and fingertips. -Snelling, 2010

Not only do paper towels trump everything else, the study conducted by Snelling found that if you rub your hands while drying your hands with the warm-air hand dryers you can actually increase the bacteria count. The Dyson Airblade fares better than the traditional hand dryers at drying your hands and keeping bacteria at bay; but at the end of the day, paper towels are still the most suited for the job.

So next time when you've finished washing your hand, go and grab a paper towel. Or if none are available, look for a Dyson Airblade. If that is not an option either, go for the traditional hand dryer - remember to leave you hands under it for at least 30 seconds and most importantly, don't rub your hands!

10Jun/10

Quirks of being human

We are all human, yet we are all different from each other, we are all unique; or as someone put it "You are unique, just like everyone else." However, for the majority of us, no matter how "unique" we are, we are still human...which means most of us are susceptible to quirks in how our brain works.

So what is all this random rambling about? Well for those that are unaware, I enjoy understanding and learning how the human mind works - especially when it doesn't quite work as expected, such as when we see optical illusions. So here are a few that I would like to share.

Impossible Motion: Magnet-Like Slopes

Our brain doesn't always decipher what we see with our eyes in the real world properly. It tries to be too smart and often fails. But that's ok, since it means we can see awesome optical illusions!

Change Blindness

You've probably heard of this before - as humans we can be very "blind" to how our environment changes around us. Some rather big changes can occur and we don't notice at all.

Another change blindness example - just for fun :)

Leaning Tower Illusion

So what about a still image, no videos, just a plain old image. How will your eyes (or should I say brain) trick you now?

Leaning Tower Illusion

The two images are identical...really!

That's it for now - hope you enjoyed the random selection above :) What I find most interesting is that for many of these "brain quirks" even though you know what is happening, even though you know the trick you still can't un-trick your brain to see what is really there.

1Apr/10

Oz slang and Street View in 3D!

So, it's April Fools today, and as usual, Google has come up with some random stuff...

Oz slang for directions in Google Map...Chuck a left! (Directions from Max Brenner to San Churro!)

Street View...now in 3D!

There seems to be a couple of other April Fool hoaxes Google has provided this year :)

8Mar/10

Which search engine do you use?

My answer: Google. Why? Because it's simple, loads quickly and most of the time gives me results that are relevant to what I want. Chances are a good majority of people will also answer Google. As far as I know people use 'Google' as a verb, while other search engines, eg. Yahoo, Bing do not get the same treatment.

To be honest, I just took the use of Google for granted and never really thought much about it until I went to Ignite Sydney last week. One of the awesome talks "Everything I know about you" by Michael Kordahi tested to see if our perceptions to the search results (he comapred Bing, Google, Yahoo) would be the same if the branding was removed. The results of preference (and the search terms people looked for) are indeed very interesting - definitely worth watching!

Interesting thing was after the night I went home and gave it a go myself. For simple/basic searches (which were essentially keyword searches) all three search engines were roughly the same for me - but in picking the preferred one I actually rarely picked Google! Though for more complex searches (eg. ones which I just typed in a question) Google was the clear winner. The other two were nowhere close.

Random footnote - I hear some of you may be asking, what is Ignite Sydney? No, it is not an event where pyromaniacs go and set fire to Sydney landmarks. Ignite Sydney is a series of presentations with one very simple idea behind every presentation:

Make the presenters stick to a rigid format of 20 slides, each of which changes automatically after 15 seconds, giving a guaranteed 5 minute presentation.

This means no death by powerpoint - yay! and generally very interesting, entertaining and well thought out presentations - double yay! If you don't live in Sydney then don't worry - there are Ignite events all around the world. Have a look here for the full list

5Aug/08

Google Maps – Street View…in Australia!

Google Maps Street View of UNSW mainwalkway

When Google Maps was released in early 2005 it was quite cool to be able to see a birds-eye view of various places (even if you could only zoom in so far). Since then, there has been many improvements - more view types, clearer pictures, closer zoom etc.

In mid 2007, a new view type: Street View was made available. I must say, it is quite cool - Street View allows you to actually see the street as if you were there at the place. This view was only available to a selection of cities in the USA and Australia (the 'birth' place of Google Maps) was left out...until today!

Yes, as of today (5th August 2008) there is Street View in Google Maps for pretty much all of Australia! At first I was quite excited, as I've had a look at Street View in USA before (1 Infinite Loop :) ) and thought "Wouldn't it be cool if this was in Australia?". Now that it is in Australia I must say it is cool, but definitely also scary! In my opinion, being able to see your own house on Google Maps and with the correct (or a very close) address feels scary!

» Continue reading "Google Maps – Street View…in..."

23Jun/08

creating a time capsule

Quite some time ago (about late 2007) I saw this documentary called "21 Up Japan" which is similar to the "Up Series". The idea of the documentary is the follow a group of children from when they were 7 years old, and then every 7 years they go back to them and see how they are going. The interviewers had a set of semi-structured questions which they asked, and it was very interesting to see how everyone's answers changed from when they were 7, 14, and 21.

Time Capsule

After seeing this documentary I decided I wanted to do something similar - make my own time capsule :) However it wasn't until a few months later in early 2008 when I found an old exercise book which had some short stories that I had written in 1995 that really got me started. Reading those stories made me realise how much can change in a few years (and how much we can forget!). My time capsule is bit different to 21 Up Japan - it does have a set of questions which I plan on answering once every year or so, but the majority of entries are more diary-like entries of times when I feel like something important has happened.

» Continue reading "creating a time capsule"

26Feb/08

blutack pig

On Sunday I decided to make a small pig out of blutack :) Probably sounds very random, but it was because earlier in the weekend I had saw similar small pigs at Paddy's Market and they just looked so cute! Here is the result of my procrastination:

blutack pig

The pig itself is actually quite small - about 1cm in diameter, though I think that is what makes it cute. At first I was worried that using blutack would be very hard since blutack sticks to itself (and your fingers!), but in the end it wasn't that bad. A toothpick is a must though - not just to poke the holes for the eyes/nose but also to push and shape the ears.

Since the pig was quite small it was rather hard to take a nice close-up photo, so as usual I took several shots. However, this time while flipping through all the blurred photos I remembered a Stop Motion Video tutorial I had read on Photojojo few months back - so alas, more procrastination...my first stop motion video attempt!

19Sep/07

dragon illusion

Another great illusion - and this time you get to make it! Have a look at the Three Dragons from Grand Illusions - the movie clip is really quite cool! After seeing the clip I actually went and made it straight away (much easier to make than the penguin) but sadly it didn't turn out as nice as the illusion in the video clip. It seems like you need some light behind the dragon for it to work. Though I'll still put it on my desk at work and see if I get any weird looks :)

» Continue reading "dragon illusion"

Tagged as: , 2 Comments