Articles Tagged "ActionScript"

Draw an Arc with ActionScript

Drawing an arc (a segment of a circle’s circumference) is very similar to drawing a complete circle. Just like drawing a circle, drawing an arc requires you to specify the center, the radius, and the number of steps to take from the first point to the last. But drawing an arc also requires additional information such as the angle of the first point on the arc, the direction (clockwise or counter-clockwise) to travel around the circle’s circumference, and the angle of the last point on the arc.
Read More

Basic Circle Drawing ActionScript

Do you know how to draw a circle with ActionScript code? It’s a handy thing to know. You can use it to draw pie charts, equilateral polygons, analog clock faces… you can even use it to script motion. If you use Flash for any type of drawing purposes, knowing the math behind the circles (trigonometry) can be very helpful. In the simplest of terms, drawing a circle can be as easy as counting from 0 to 1.
Read More

ActionScript Easing Functions

Unlike most other easing equations or functions, my easing functions are 0 to 1 based (like the “Math.random” function). This makes it easier to isolate the concept of “easing” from the concept of “tweening”. Tweening is responsible for creating a series of equidistant values between an initial state and a final state. Easing is responsible for shifting those values so they are no longer equally spaced.

There are times when you may want to weight a single random value to favor one number over another. For example, you may want a random number between 0 and 100 but you would prefer a number closer to 0 than to 100. In this situation, there is no need for a “tween” as you are only generating one number and there is nothing to go be”tween”. This is where easing functions which have been isolated from their tweening counterparts can come in handy.

Here are my most frequently used easing functions:
Read More

Improving the Limit Function

As a continuation of a previous post “How to Limit a Number Between Two Values” I thought I’d make my “limiting” code a little more versatile.

The previous post used the following code to ‘limit’ or ‘constrain’ a number between a low and high value:

//
// Limit a number between two values.
function limit (num, lo, hi){
    if (num < lo) return lo;
    if (num > hi) return hi;
    return num;
}
//

But what if you don’t want to, or can’t, control the order of the “lo” and “hi” arguments?
Read More

How to Limit a Number Between 2 Values

Limiting or constraining a number to a specified range of values isn’t the most common task you’ll have to perform in Flash, but it does pop up from time to time. If you encounter such a situation here is a little bit of code for your consideration:
Read More

Random Candy Colors

If you saw my recent “Candy Cosmos” post, you may have noticed that the randomly generated colors tend to be rather “vibrant”.

rainbbowgradient.jpg

Pure red, green, blue, cyan, magenta and yellow colors appear frequently, while pure black and white colors occur occasionally, and colors near 50% gray tend to be the least common. The bright candy colors are a side effect caused by
Read More

Hexadecimal Color Fading

A while ago, I wrote a Color Fading tutorial for ActionScript.org which provided nearly all the functions you’d ever want for fading colors. Did you notice that I said “nearly”? Well, today I’ve added yet another weapon to my color-fading code arsenal called “fadeHex”. The name probably won’t put fear in the hearts of fellow code warriors but it’s a powerful tool none the less. In essence, it lets you specify two colors, then creates a color gradient from the first color to the second and lets you choose a color at any point on that gradient.
Read More

© Sean O'Shell 2007-2024