Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 1.0 (and below)

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-20-2004, 01:17 AM   #1
hognav2t
member
 
hognav2t's Avatar
 
Join Date: Jul 2003
Location: CA
Posts: 442
Default yin & yang : better/shorter way?

there's gotta be a better and shorter way 2 do this right?

PHP Code:
// Basic YinYang routines - Jim Bumgardner
//
Math.sqrt(300*300+300*300)*2;
Rh R/2;
degToRad Math.PI/180;
sqrt2 Math.sqrt(2);

++
initCtr;
if (
initCtr 1)
    
trace("Script called twice");

function 
drawArc(mcx,y,radius,bA,eA)
{
    var 
radius;
    var 
theta 45*degToRad;
    var 
cr radius/Math.cos(theta/2);
    var 
angle = (ba+45)*degToRad;
    var 
cangle angle-theta/2;
    var 
= (ea-ba)/45;

    for (var 
i=0;n;i++,angle += theta,cangle += theta
    {
        var 
endX r*Math.cos (angle);
        var 
endY r*Math.sin (angle);
        var 
cX cr*Math.cos (cangle);
        var 
cY cr*Math.sin (cangle);
        
mc.curveTo(cX+x,cY+yendX+x,endY+y);
    }
}

function 
drawNegArc(mcx,y,radius,bA,eA)
{
    var 
radius;
    var 
theta 45*degToRad;
    var 
cr radius/Math.cos(theta/2);
    var 
angle = (ba+45)*degToRad;
    var 
cangle angle-theta/2;
    var 
= (ea-ba)/45;

    for (var 
i=0;n;i++,angle += theta,cangle += theta
    {
        var 
endX r*Math.cos (angle);
        var 
endY r*Math.sin (angle);
        var 
cX cr*Math.cos (cangle);
        var 
cY cr*Math.sin (cangle);
        
mc.curveTo(x+cX,y-cYx+endX,y-endY);
    }
}

function 
drawYin(mcxyradiusfCfAwithHole)
{
    var    
rad2 radius/2;
    
mc.moveTo(x+radius,y);  // same as x+cos(0)*r, y+sin(0)*r
    
mc.beginFill(fC,fA);
    
drawArc(mcxyradius0180);
    
drawArc(mcx-rad2,yrad2180360);
    
drawNegArc(mcx+rad2,yrad2180360);

//
    
if (withHole) {
        var 
radC rad2*(sqrt2-1);
        
mc.moveTo(x+radC-rad2,y);
        
drawArc(mcx-rad2yradC0360);
    }
    
mc.endFill();
}

// Unused - use this to fill in the other half of a 2-color design
function drawYang(mcxyradiusfCfAwithHole)
{
    var 
rad2 radius/2;
    
mc.moveTo(x-radius,y);  // same as x+cos(0)*r, y+sin(0)*r
    
mc.beginFill(fC,fA);
    
drawArc(mcxyradius180360);
    
drawArc(mcx+rad2,yrad20180);
    
drawNegArc(mcx-rad2,yrad20180);

    if (
withHole) {
        var 
radC rad2*(sqrt2-1);
        
mc.moveTo(x+rad2+radC,y);
        
drawArc(mcx+rad2yradC0360);
    }
    
mc.endFill();
}

function 
drawCircle(mcx,y,radiusfC,fA)
{
    
mc.moveTo(x+radius,y);  // same as x+cos(0)*r, y+sin(0)*r
    
mc.beginFill(fC,fA);
    
drawArc(mcxyradius0360);
    
mc.endFill()
}

function 
drawCircleOutline(mcx,y,radiusfC,fA,thick,bA,eA)
{
    
mc.lineStyle(thick,fC,fA);
    
mc.moveTo(x+radius*Math.cos(bA*degToRad),y+radius*Math.sin(bA*degToRad));  // same as x+cos(0)*r, y+sin(0)*r
    
drawArc(mcxyradiusbAeA);
    
mc.lineStyle(0);
}


var 
g_alphas = [100,0];
var 
g_ratios = [0x0,0xFF];
var 
radians 0;
// build our matrix using the "box" method
var g_matrix = { matrixType:"box"x:-Ry:-Rw:R*2h:R*2rradians }

function 
drawGradCircle(mcx,y,radiusfC)
{
  var 
colors = [fC,fC];

  
mc.moveTo(x+radius,y);  // same as x+cos(0)*r, y+sin(0)*r
  
mc.beginGradientFill("radial",colors,g_alphas,g_ratios,g_matrix);
  
// mc.beginFill(fC,0x1000000 - fC);
  
drawArc(mcxyradius0360);
  
mc.endFill()
}

function 
drawSprite()
{
    var 
getTimer() * .05;
    
// t = 0;
    
var red 128 127 Math.sin((this.cphase t) * degToRad);
    var 
grn 128 127 Math.sin((120 this.cphase t) * degToRad);
    var 
blu 128 127 Math.sin((240 this.cphase t) * degToRad);
    var 
tint = (red << 16) | (grn << 8) | blu;

    
this.clear();
    
drawGradCircle(this,0,0,R,tint);    // cicle within Yin
}

function 
drawYinYang()
{
    var 
sr Rh*.125;
    var 
sr2 sr/2;
    var 
0;
    var 
0;
    
this.clear();

    
// These are the componenet parts of the yin-yang symbol, use which
    // ever ones you want...
    
drawYin(this00sr0x00000025,true);
    
// drawYang(this, 0, 0, sr, 0x0000FF, 50,true);
    // drawCircle(this,x-sr2,0,sr2*(sqrt2-1),0x0000FF,50);    // cicle within Yin
    
drawCircle(this,x+sr2,0,sr2*(sqrt2-1),0x000000,25);    // circle within Yang
    
drawCircleOutline(this,0,0,sr,0x000000,25,0,0,360);    // outline around whole
}


function 
updateFrame()
{
    
this._rotation += 1;
}

function 
init()
{
    
trace("Init 1");
    if (
inited != undefined)
        return;
    
// var h = this.attachMovie("dummy", "yin", 0);
    
var nbrSprites 3;
    var 
cont this.createEmptyMovieClip("container"0);
    
cont._x 150;
    
cont._y 150;
    
// cont._width = 300;
    // cont._height = 300;
    
cont.onEnterFrame updateFrame;
    for (var 
0nbrSprites; ++n) {
        var 
mc cont.createEmptyMovieClip("sprite"n);
        
mc.cphase = (n*360/nbrSprites);
        
mc._x Math.sin(mc.cphase degToRad) * R/2;
        
mc._y Math.cos(mc.cphase degToRad) * R/2;
        
mc.onEnterFrame drawSprite;
    }
    var 
mc cont.createEmptyMovieClip("yinyang"nbrSprites);
    
mc._x 0;
    
mc._y 0;
    
mc.onEnterFrame drawYinYang;
    
// h.Play();
    
inited true;
}

init(); 
__________________
1+1=1;
hognav2t is offline   Reply With Quote
Old 06-20-2004, 11:37 AM   #2
pixelwit
village halfwit
 
pixelwit's Avatar
 
Join Date: Jul 2001
Location: USA, PA
Posts: 3,330
Default

Yes there is. Draw the symbol in the Flash authoring environment and turn it into a MovieClip then give it an onEnterFrame event that does something like "this._rotation += 2".



-PiXELWiT
http://www.pixelwit.com
__________________
There are no answers, only choices.
pixelwit is offline   Reply With Quote
Old 06-20-2004, 12:14 PM   #3
hognav2t
member
 
hognav2t's Avatar
 
Join Date: Jul 2003
Location: CA
Posts: 442
Default

i read ur response & been laughin ever since

that IS a much shorter & easier way, isn't it?
__________________
1+1=1;
hognav2t is offline   Reply With Quote
Old 06-20-2004, 12:45 PM   #4
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Haha... Same here... I was thinking how many times did the author have to run trial and error to get the shape right... Indeed... Drawing it and making a movieClip out of it is way simpler than those math stuff that gives me headache... Nice effect though...
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 06-20-2004, 01:06 PM   #5
pixelwit
village halfwit
 
pixelwit's Avatar
 
Join Date: Jul 2001
Location: USA, PA
Posts: 3,330
Default

I doubt the person who wrote that code was trying to do it the "easiest" way possible. It was probably done more as a learning experience for personal satisfaction or as an educational tool. I know I've done plenty of things "the hard way" just to see if it could be done.

-PiXELWiT
http://www.pixelwit.com
__________________
There are no answers, only choices.
pixelwit is offline   Reply With Quote
Old 06-20-2004, 01:09 PM   #6
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Oh... I didn't mean it that way, pixelwit...
I am really bad at the drawing api as I am with many other things...
I just get amazed to see how people use drawing api to make complicate things with the script so easily... (I am sure there are big trial and error sesseion involved in it...)
That's all I am saying... I wasn't saying what is good or bad way of doing it...
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 06-20-2004, 01:14 PM   #7
pixelwit
village halfwit
 
pixelwit's Avatar
 
Join Date: Jul 2001
Location: USA, PA
Posts: 3,330
Default

I know you didn't mean anything by it CyanBlue. I'm not out to get you. I was only trying to explain why people sometimes do the things they do.

-PiXELWiT
http://www.pixelwit.com
__________________
There are no answers, only choices.
pixelwit is offline   Reply With Quote
Old 06-20-2004, 01:18 PM   #8
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

How did you know that I have nightmare everynight and some weird shape of poligons chasing me every night yet I don't get to lose anything in my tummy???
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 06-20-2004, 01:26 PM   #9
pixelwit
village halfwit
 
pixelwit's Avatar
 
Join Date: Jul 2001
Location: USA, PA
Posts: 3,330
Default

A comment that's little more on-topic for Hognav2t...

Not sure why you would need a drawNegArc function or why you'd need both a yin and yang function since you could just draw one or the other in separate clips then rotate the clip 180 degrees. Or better yet, just draw one of them over top of a plain circle.

But then again, writing less code may not have been one of the author's goals.

-PiXELWiT
http://www.pixelwit.com
__________________
There are no answers, only choices.
pixelwit is offline   Reply With Quote
Old 06-21-2004, 02:04 AM   #10
hognav2t
member
 
hognav2t's Avatar
 
Join Date: Jul 2003
Location: CA
Posts: 442
Default

this guy actually teaches flash AS, may b u guys should consider it 2. i know a good-
handfull of members in this forum who r well qualified 2 teach AS.
__________________
1+1=1;
hognav2t is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:53 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.