Run-time instances
Project 7. Computer Art
During this project we will generate some "pseudoartistic" pictures.
We will need some symbols in the library, which we will "breed" on the stage. User will be able to change appearance of the movie by "seeding" initial parameters, like size, transparency, position, rotation and how they changes with each step
- Open new file and make a quite large stage – may be 600*500 px or more.
- Extend the timeline of the movie – make it 2 frames.
- Create several movie symbols - those may be circles, colour spots, wavy lines, small bitmaps – anything. Give those symbols linkage identifiers like mv1, mv2, mv3, mv4, mv5, mv6 .
- All interface elements are entered into the first frame. Second frame is empty – it's where the picture will be generated.
- Add as many buttons as many movie symbols you have and add the following code for their event handlers. Use "mv1, mv2" and so on for various buttons.
on(release) { thesource ="mv1"; } - Add the dynamic text box and assign it the variable thesource in the var property box
- Add 12 input textboxes and assign them all variables shots, thex, they, xshift, yshift, thewidth, theheight, widthshift, heightshift, rotshift, thealpha, alphashift . They will be used to input the "seeding" parameters
- Add the button and enter play()script in it's event handler
- We have user interface completed. Now we will be working with code
- Enter the following code in the first frame
stop(); shots=100; thenumber = 0; thedepth=0; thewidth = 15; theheight=15; thex=50; they=20; thealpha=100; xshift=5; yshift=3; widthshift=3; heightshift=2; alphashift=-1; therot=0; rotshift=7; thesource = "mv1"
The code initialize parameters we need to generate movie. We will consider them as default. All values are approximate and may be changed - Enter the following code in the second frame
function doIt() { attachMovie(thesource, "caterpillar" + thenumber ,thedepth); setProperty("caterpillar" + thenumber,_x,parseInt(thex)); setProperty("caterpillar" + thenumber,_y,parseInt(they)); setProperty("caterpillar" + thenumber,_width, parseInt(thewidth)); setProperty("caterpillar" + thenumber,_height,pareseInt(theheight)); setProperty("caterpillar" + thenumber,_alpha,parseInt(thealpha)); setProperty("caterpillar" + thenumber,_rotation,parseInt(therot)); thenumber++; thedepth++; thex = parseInt(thex) + parseInt(xshift); they = parseInt(they) + parseInt(yshift); thewidth = parseInt(thewidth) + parseInt(widthshift); theheight = parseInt(theheight) + parseInt(heightshift); thealpha +=parseInt(alphashift); therot = parseInt(rotshift) + therot; if (thenumber>=shots) {clearInterval(breed);} } var breed; breed = setInterval( doIt, 100);This code is very similar to what we use for "caterpillar" example, but with much more parameters to change. Note also extensive use of parseInt() function. It makes integer number from the string. The reason for doing it that information entered to text boxes is represented as a text by default. Compare: if we add numbers 3 and 4 we got 7 as a result, but if "3" and "4" are texts – result will be "37". - Test the movie. It must generate "computer art" picture. Play with the parameters and various movie source symbols. You will need to refresh movie each time you want to generate new one.
If your videocard is not modern, symbols are large and steps are numerous, this generator may slow down drastically.