Sine grid

Code Actionscript 2.0

Frame action

i = 1;
for (gy = 0; gy <= 8; gy = gy + 1) {
for (gx = 0; gx <= 8; gx = gx + 1) {
i = i + 1;
square0.duplicateMovieClip("square" + i, i);
_root["square" + i]._x = gx * 50;
_root["square" + i]._y = gy * 50;
_root["square" + i]._xscale = stretch(sine(gx * 22), 60, 30);
_root["square" + i]._yscale = stretch(sine(gx * 22), 60, 30);
}
}
square0._visible = 0;
function sine(x) {
// sine between 0 und 360°
s = Math.sin(x * 2 * Math.PI / 360);
return s;
}
function stretch(value, center, amplitude) {
// scales and shifts value
st = int(value * amplitude + center);
return st;
}

Code Actionscript 3.0

var Squares:Array = new Array(); var i = 1; for (var gx = 0; gx <= 8; gx = gx + 1) { for (var gy = 0; gy <= 8; gy = gy + 1) { i = i+1; //important: square has to be exported for actionscript //go to "linkage" in library menu Squares[i] = new squareObject(); Squares[i].x = gx * 50; Squares[i].y = gy * 50; Squares[i].scaleX = stretch(sine(gx * 22), 60, 30)/100; Squares[i].scaleY = stretch(sine(gx * 22), 60, 30)/100; addChild(Squares[i]); } } square0.visible = 0; function sine(x) { // sine between 0 und 360Â° var s = Math.sin(x * 2 * Math.PI / 360); return s; } function stretch(value, center, amplitude) { // scales and shifts value var st = int(value * amplitude + center); return st; }

Description

A basic element is arranged into an 8x8 grid structure. The size of each square is determined by the wave-shaped sine-function. The functions sine and stretch are there to make the code easier to read. Sine converts angles from degrees to radians, and calculates the sine. Stretch scales and shifts the sine values, which are somewhere between -1 and 1.

related to: Sine-function