Sine grid with gaps

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);
if ((i % 2) == 0) {
// hide one out of two
_root["square" + i]._alpha = 0;
}
}
}
square0._visible = 0;
function sine(x) {
// sine conversion for values 0 - 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]); if ((i % 2) == 0) { // hide one out of two Squares[i].alpha = 0; } } } square0.visible = false; 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, where every other one is hidden. The size of each square is determined by the wave-shaped sine-function. The functions sine and stretch are supposed 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: