# Notes to Lesson 6

 It would be difficult to cut down on the gradient coding without sacrificing quality, especially with rainbow gradients. Below are some gradient functions for your reference. Gradient Function Sample: setDimension(450,100); \$myMovie->setBackground(0,0,0); //LINEAR GRADIENT-SINGLE COLOR function gradient(\$r, \$g, \$b, \$W, \$H){ \$GRAD=new SWFGradient(); \$GRAD->addEntry(0.0,\$r-\$r,\$g-\$g,\$b-\$b); \$GRAD->addEntry(0.2,\$r/2,\$g/2,\$b/2); \$GRAD->addEntry(0.4,\$r/1.15,\$g/1.15,\$b/1.15); \$GRAD->addEntry(0.5,\$r,\$g,\$b); \$GRAD->addEntry(0.6,\$r/1.15,\$g/1.15,\$b/1.15); \$GRAD->addEntry(0.8,\$r/2,\$g/2,\$b/2); \$GRAD->addEntry(1.0,\$r-\$r,\$g-\$g,\$b-\$b); \$GRADsquare=new SWFShape(); \$GRADsquare->setLine(1,0,0,0,0); \$GRADfill=\$GRADsquare->addFill(\$GRAD, SWFFILL_LINEAR_GRADIENT); \$GRADfill->scaleTo(0.05); \$GRADfill->moveTo(\$W/2,\$H/2); \$GRADsquare->setLeftFill(\$GRADfill); \$GRADsquare->drawLine(\$W, 0); \$GRADsquare->drawLine(0, \$H); \$GRADsquare->drawLine(-\$W, 0); \$GRADsquare->drawLine(0, -\$H); return \$GRADsquare; } //gradient(r,g,b,width,height) \$GREENtube=\$myMovie->add(gradient(0,255,0,50,100)); \$GREENtube->moveTo(0,0); //GRADCIRCLE, SINGLE COLOR function gradCircle(\$rd, \$gr, \$bl, \$size){ \$inputR = \$r-(\$r/1.2); \$rr = ceil(\$inputR); if (\$rr < 0) { \$rr = 0; }; \$inputG = \$g-(\$g/1.2); \$gg = ceil(\$inputG); if (\$gg < 0) { \$gg = 0; }; \$inputB= \$b-(\$b/1.2); \$bb = ceil(\$inputB); if (\$bb < 0) { \$bb = 0; }; \$GRAD=new SWFGradient(); \$GRAD->addEntry(0.0,\$rd,\$gr,\$bl); \$GRAD->addEntry(1.0,\$rr,\$gg,\$bb); \$GRADcircle=new SWFShape(); \$GRADcircle->setLine(1,0,0,0,0); \$GRADfill=\$GRADcircle->addFill(\$GRAD, SWFFILL_RADIAL_GRADIENT); \$GRADfill->scaleTo(0.15); \$GRADfill->moveTo(0,0); \$GRADcircle->setLeftFill(\$GRADfill); \$GRADcircle->drawCircle(\$size/2); return \$GRADcircle; } //\$PINKball=\$myMovie->add(gradCircle(r,g,b,size)); \$PINKball=\$myMovie->add(gradCircle(255,0,255,100)); \$PINKball->moveTo(120,50); //RAINBOW CIRCLE 3 COLORS. LINEAR FILLS STRAIGHT UP AND DOWN. RADIAL FILLS ANGLED function RainbowCir( \$red,\$green,\$blue,\$red2,\$green2,\$blue2,\$red3,\$green3,\$blue3,\$ra,\$DIRECT){ \$myGradient=new SWFGradient(); \$myGradient->addEntry(0.0,\$red,\$green,\$blue); \$myGradient->addEntry(0.2,\$red2,\$green2,\$blue2); \$myGradient->addEntry(0.4,\$red3,\$green3,\$blue3); \$myGradient->addEntry(0.6,\$red,\$green,\$blue); \$myGradient->addEntry(0.8,\$red2,\$green2,\$blue2); \$myGradient->addEntry(1.0,\$red3,\$green3,\$blue3); \$RainbowRound=new SWFShape(); \$RainbowRound->setLine(1,0,0,0,0); \$myFill=\$RainbowRound->addFill(\$myGradient, \$DIRECT); \$myFill->scaleTo(0.1); \$myFill->moveTo(10,10); \$RainbowRound->setRightFill(\$myFill); \$ra = \$ra; \$x = \$ra; \$y = \$ra; \$a = \$ra * 0.414213562; // = tan(22.5 deg) \$b = \$ra * 0.707106781; // = sqrt(2)/2 = sin(45 deg) \$RainbowRound->movePenTo(\$x+\$ra, \$y); \$RainbowRound->drawCurveTo(\$x+\$ra, \$y-\$a, \$x+\$b, \$y-\$b); \$RainbowRound->drawCurveTo(\$x+\$a, \$y-\$ra, \$x, \$y-\$ra); \$RainbowRound->drawCurveTo(\$x-\$a, \$y-\$ra, \$x-\$b, \$y-\$b); \$RainbowRound->drawCurveTo(\$x-\$ra, \$y-\$a, \$x-\$ra, \$y); \$RainbowRound->drawCurveTo(\$x-\$ra, \$y+\$a, \$x-\$b, \$y+\$b); \$RainbowRound->drawCurveTo(\$x-\$a, \$y+\$ra, \$x, \$y+\$ra); \$RainbowRound->drawCurveTo(\$x+\$a, \$y+\$ra, \$x+\$b, \$y+\$b); \$RainbowRound->drawCurveTo(\$x+\$ra, \$y+\$a, \$x+\$ra, \$y); return \$RainbowRound; } // RainbowCir(\$r,\$g,\$b,\$r2,\$g2,\$b2,\$r3,\$g3,\$b3,\$ra,\$DIRECT) \$RadialCircle=\$myMovie->add(RainbowCir(255,0,0,255,255,0,0,0,255,50,SWFFILL_RADIAL_GRADIENT)); \$RadialCircle->moveTo(200,0); \$LinearCircle=\$myMovie->add(RainbowCir(255,0,0,255,255,0,0,0,255,50,SWFFILL_LINEAR_GRADIENT)); \$LinearCircle->moveTo(320,0); //RAINBOW GRADIENT function RainGradient(\$rd,\$gr,\$bl,\$rd2,\$gr2,\$bl2,\$w,\$h){ \$GRAD=new SWFGradient(); \$GRAD->addEntry(0.0,\$rd,\$gr,\$bl); \$GRAD->addEntry(1.0,\$rd2,\$gr2,\$bl2); \$GRADsquare=new SWFShape(); \$GRADsquare->setLine(1,0,0,0,0); \$GRADfill=\$GRADsquare->addFill(\$GRAD, SWFFILL_LINEAR_GRADIENT); \$GRADfill->scaleTo(0.05); \$GRADfill->moveTo(\$w/2,\$h/2); \$GRADsquare->setleftFill(\$GRADfill); \$GRADsquare->drawLine(\$w, 0); \$GRADsquare->drawLine(0, \$h); \$GRADsquare->drawLine(-\$w, 0); \$GRADsquare->drawLine(0, -\$h); return \$GRADsquare; } //(RainGradient(r,b,g,r2,b2,g2,width,height) \$RedGreen=\$myMovie->add(RainGradient(255,0,0,0,255,0,60,100)); \$RedGreen->moveTo(430,0); \$myMovie->save("Note6.swf"); ?>