I believe in binary Zen. You're either at one with everything, or at zero with everything.

:: Next Page >>

April Fools Flash Tutorial: Embed a Sound File

Date/Time Permalink: 04/01/09 10:14:22 am
Category: Flash

What, you don't know how to play a song from a Flash file in SWFTools? Easy stuff. Takes a minute.

Make a source.sc file with this in it:

.flash bbox=50x50 fps=36
  .sound SONG "./AFD.wav"
  .action:
    songFX=new Sound();
    songFX.attachSound("SONG");
    songFX.setVolume(500);
    songFX.Start();
  .end
.end

compile:

swfc -o AFD.swf source.sc

Where 'AFD' is the name of whatever .wav sound you want to play for your April Fool's Day joke. Then embed the Flash file somewhere on your web-page, with small height and width arguments, or hidden with a CSS trick, or buried behind an image - whatever it takes so the user cannot possibly find it to shut it off!

Bonus Buck Today and today only I support the grassroots effort to save Internet Explorer 6.

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

New Poker Game in the Flash Gallery

Date/Time Permalink: 03/21/09 09:57:44 am
Category: Flash

After a few false starts on this, my most ambitious Blogsquares Flash item yet, it's time to turn it loose. So, look for a video poker game down there in the sidebar on this blog.

PPPoker screenshot

It's a simulation of the video poker variation known commonly as "Jacks or Better". I followed the example in Wikipedia for the pay table, so it should have the same theoretical return of 99.54%.

Of course, in typical rounds of play, it will usually gobble your 100 credits within 30 plays or so, with a few hits of pairs and three of a kind in the mix. Having lived in Vegas and having experienced the average video poker machine on the average casino front on Freemont Street, I am reasonably sure that it plays like the same thing. When the credits reach zero, the only way to reset it is to refresh the page!

GPL licensed, source package here. Run free, my little toy!

Oh, and a related project is my Flash card-shuffling demo.

As always with gambling games, I must state that this is an entertainment device only.

And my conscience won't let me post a gambling simulator without pointing out that gambling for real money in real life is, point blank, a stupid thing to do, and should only be approached after a thorough mastery of probability mathematics has been undertaken and then only in the spirit of research. Casinos do not make money when you lose; they make money when you win, and they do that by not paying you the winnings you're entitled to for beating the odds you just beat.

That's enough being Mr. Heavy. Have fun, and report glitches and bugs in the comments!

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

New Flash Demo #11: A Card Shuffler

Date/Time Permalink: 02/24/09 10:22:46 am
Category: Flash

It's nothing to get too excited about, but I've made up a small deck of Poker card graphics and some Actionscript to shuffle them. Check the card shuffling demo and grab the GPL'd source code here, if you'd find it useful.

Note, however, that the card graphics are just suits and ranks. I did that to have them be small and yet readable, with an eye towards making a BlogSquare-sized Poker game for the sidebar later. If you want bigger, better cards, Wikimedia Commons has a whole playing-card category, to say nothing of the deck graphics that come with KDE and Gnome card games which should be reusable.

This is one of those classic "should be solved only once" type problems. So now everybody has a deck of cards and a way to shuffle them already pre-built for open-source Flash development, all you have to do is write the game around it. The code isn't brilliant or elegant, but "stupid and robust".

One note about the code that needs explaining: Actionscript uses zero-indexing when creating an array. But SWFTools doesn't seem to allow a "frame zero"; sprites have to start with 1. So I create the Actionscript arrays with an extra space at the beginning (NULL or 0) to avoid having Card_Value[x] correspond to card frame x-1.

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

Some Completely Meaningless Flash Animation Loops

Date/Time Permalink: 02/18/09 12:20:09 pm
Category: Flash

Every now and then, playing with Flash animations is an itch I've just got to scratch. This time, I looked back on the method I used in one of my earlier tutorials. The next logical step was to write a script that automates the whole process, turning a POVRay scene into a Flash animation in a single step.

The script method I used is quite simple: It takes a POVRay scene with the variable "FACT" declared in various places, loops through 0-to-350 for the variable (changing the rotation of abjects controlled by "FACT"), generates the frames, uses Image Magick to crop the frames to 240x240 squares, saves them in sequence, builds the Flash script, and calls the swfc compiler to compile it.

Before anybody asks "Why don't you just use png2swf for that last step?" - I tried it, but the animation comes out much choppier.

Very efficient, although limited in what it can produce without some fancier POVRay programming. But I think I've lost everybody now, so I'll just post what I've produced so far.

First a simple heart animation, done just a tad late for Valentine's:

>

Next, one of those "I wonder what this would look like?" moments hit, and I slapped some multicolored nodes into a blob object and ran the script:

>

I have no idea what I made there, but I promise not to let it get loose and terrorize the world. Next, I put a little effort into designing some clockwork gears:

>

Ooooh! This last one is a keeper. I'll drop that into the sidebar Flash gallery after it falls off the front page.

By the way, b2evolution's software hates embedded objects with a passion and I have to hack it mercilessly to get it to display at all, so if you don't see anything, let me know on what browser/platform. Sloppy of me today, I know.

Here's a tarball of the script, hereby known as "POV2SWF.sh". I'm only putting it up to say I did; I don't expect it to be useful to anybody. To make it work, you need POVRay (and some coding savvy), Image Magick, and SWFTools.

Why do I get the feeling, whenever I work with POVRay and SWFTools, that I'm blazing my own trail into the wilderness here that's too far out for anybody to even catch up with me?

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

New Flash drawing toy - DrawDemon

Date/Time Permalink: 09/06/08 03:52:14 pm
Category: Flash

DrawDemon, down there in the sidebar to your right. As if yesterday's demo weren't pointless enough, I took the same idea and ran with it to produce the next step. This time, in addition to mousing over the black square to draw and clicking to clear it, you hit "L" (on the keyboard... keep up with me) to turn Lines on and off, "C" for Circles, and "S" for Squares.

Thanks again to SWFTools. It's going to save the world.

It makes pictures. Like screen shot 1
screen shot 2 screen shot 3
There's no way to save images directly. Your screenshot program is your friend.

Get the source code here, GPL licensed. Turn it loose!

I have no idea what I'm doing, but it's making things that keep me occupied. This is KBilly's Super Sounds of the Seventies Weekend.

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

New Flash toy - Circlerama

Date/Time Permalink: 09/05/08 08:56:27 am
Category: Flash

Holy smoke - it's been four months since I put up a new SWFTools Flash example. This is inexcusable. From now on, readers, you'll have to nag me when I go that long.

This time it's a toy, as opposed to a game, because you just mouse over it and it makes pretty pictures and you click anywhere to clear it and draw some more. It's called Circlerama, follow the link or scroll down to the bottom of the blog sidebar where the Flash BlogSquares usually are, and look for a mysterious black square.

It makes images like this. screen shot 1
Or this. screen shot 2
Or even this. screen shot 3
The source code is too small to bother with a tarball, so I'll just post it here.

#
#  GNU GPL license blah blah blah
#

.flash bbox=240x240 fps=60 background=black

.action:

  function Draw_Circle(CX, CY, RAD)
  {
    this.moveTo(CX+RAD,CY);
    for(l=0;l<=100;l++)
      this.lineTo((CX+Math.cos((l/100)*2*Math.PI)*RAD),
                  (CY+Math.sin((l/100)*2*Math.PI)*RAD));
  }

  function Init()
  {
    counter=0;
    countTo=random(64)+8;
    Radius=countTo;
    colorR=random(255);
    colorG=random(255);
    colorB=random(255);
    Rfact=20-(random(40)+5);
    Gfact=20-(random(40)+5);
    Bfact=20-(random(40)+5);
  }

  Init();

  _root.onMouseMove=function()
  {
    beginFill(colorR<<16|colorG<<8|colorB<<0);
    M1X=(120-(_xmouse-120));
    M1Y=(120-(_ymouse-120));
    Draw_Circle(_xmouse,_ymouse,Radius);
    Draw_Circle(M1X,_ymouse,Radius);
    Draw_Circle(_xmouse,M1Y,Radius);
    Draw_Circle(M1X,M1Y,Radius);
    if(counter<=countTo)
    {
      counter++;
      Radius--;
      colorR=colorR-Rfact;
      colorG=colorG-Gfact;
      colorB=colorB-Bfact;
    }
    else
    {
      Init();
    }
  };

  _root.onMouseDown=function()
  {
    _root.clear();
    Init();
  };

.end
.end

Compile with:

"swfc -o Circlerama.swf ./source.sc"

...assuming you saved it as 'source.sc' of course.

Note that it's pure ActionScript through and through. And hiding within this lame little toy is the formula for two things I've never seen done in a raw-source ActionScript example on the web before - drawing a circle and automatically changing a color. Since the color has to be in hex, we adjust the variables for red, green, and blue independently, then form the color hex code inline with the bitwise formula you see as an argument to 'beginFill'.

As for the circle, we cheat by simply drawing with the built-in moveTo/drawTo commands 100 times, with our trigonometry friends 'cos' and 'sin' to bend it around the circumference. If it looks too scary, I made it compact so you can just cut 'n' paste and use its voodoo.

It's randomized, so you don't have too much control, but once it picks a new random circle and color, it shrinks it and changes the hue slightly for a few iterations each time. So you can somewhat control the outcome, yet still be surprised.

I hope it's fun for the people who don't find the code educational, and educational for the people who don't find it fun.

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

New Flash game: IQ Blocks

Date/Time Permalink: 05/07/08 08:26:11 am
Category: Flash

I might as well turn this one loose while I'm at it. New Flash game in the sidebar, name of IQ Blocks. It looks like this:

I can haz new flash game

The idea is that you click go, starting the timer and changing the pattern in the upper right, and then you have to click the squares in the big place on the lower left until it matches the pattern which will stop the timer. That's it. Try to contain your excitement.

Source code here. GNU GPL'd, graphics included.

OK, this is inspired by those IQ tests you get in school where they give you red-and-white blocks and a card with a pattern on it, and you use the blocks to assemble the pattern. But I have no idea if these blocks used in IQ tests have a name, if one company makes them, or what. Any teachers out there who can fill me in?

Anyway, I thought people might find it cool to have a chance to play with these in a non-school environment, maybe for the nostalgia kick from school. It could be that nobody's ever thought of this before because it's a non-obvious concept for a game, or it could be nobody's done it before because it's a dumb idea for a game. I don't know yet, but that's why it's called "experimentation"!

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

New Flash Game: Drop-A-Block

Date/Time Permalink: 05/03/08 06:54:03 pm
Category: Flash

I've been hedging around on this one because I wanted to beta-test in the side bar for a couple of days, but now that somebody's mentioned it: yes, I've had a new Flash game in the sidebar of this blog. Wa-a-ay down there on the right.

drop-a-block screen shot

It's called "Drop A Block" and you play it by moving the arrow keys to move the paddle back and forth to collect and position blocks, and down arrow to drop the block into the rack below. Three-or-more of the same color in any direction makes those blocks disappear, and combos are possible. The concept is very similar to the arcade game Klax. There's no sound, saving of high scores, or even a way for the game to recognize when you're stuck. Hitting the little 'reset' button in the top left clears the board and makes the score 0 again.

Want the source code? Here yah go! GPL-licensed, includes graphics and README, and if anybody out there rebuilds this into a fuller game and posts it online, be my guest and drop the link to it in the comments. And to any ActionScript wizards out there who have ideas on how I could have done it better, I await your wisdom!

This is part of a series of little Flash toys I want to do which I'm calling "Blog Squares". The idea is to make small, simple games and toys that fit perfectly in the sidebar of a blog, on a MySpace or FaceBook page, or possibly even in a mobile device such as a cell phone, portable game console, or a Chumby. I'm working on another such project, and I have ideas for dozens more.

I like this little format, because it makes me think small and light. Also, I don't expect to make full-featured games with it, so I'm free to experiment with the concept of what makes a fun toy. Like Drop-A-Block, these would all be good for a few minute's amusement, without trying to be a blockbuster production.

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

Flash Mish Mash

Date/Time Permalink: 04/17/08 07:47:58 am
Category: Flash

Just a random batch of utterly pointless Flash animations I've been doodling out lately. Click the image below to go to the page where they're running, which may take a minute or two to load, as always. Or click here. Or even click the title. You'll probably want to control-click and open it in a new tab and then go amuse yourself for a minute until it finishes loading.

shot of four Flash doohickeys running caddywumpus

Made with the ever-amazing SWFTools FOSS Flash toolkit for Linux. In this case, there really isn't any code to show for it - I generated these using the same techniques I outlined way back here. Just draw something and then script a loop to increment some numbers to render the next frame, compile all the image frames into Flash, add cheese and serve.

Bonus Buck: We have a new pioneer in FOSS-Flash, and the site is here. In the examples, there's a very nice tutorial on making a pure SVG animation in SWFC.

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

:: Next Page >>
suddenly the moon