ต่อจาก Lab ที่แล้ว คำสาปดาวหกแฉกมันเป็นวงแหวนเวทย์ เวลาร่ายเวทย์ ถ้าวงแหวนเวทย์อยู่นิ่งๆเฉยๆมันจะดูไม่ใช่ เพราะงั้น วงแหวนเวทย์มันต้องขยับได้ !!! งั้นผมจะร่ายเวทย์ให้มันขยับได้บัดเดี๋ยวนี้
void setup()
{
// initialization
size(300,300);
background(0);
strokeWeight(4);
stroke(255,255,0);
frameRate(60);
}
int y=49;
int check=0;
void draw()
{
background(0);
translate(width/2,height/2);
if(check==0)
{
y = y-1;
}
if(check==1)
{
y = y+1;
}
// variable
int CenterStarX,CenterStarY;
int WidthStar,HeightStar;
int d;
int SpaceBetweenCircle;
float RVertical,RSqrt,RCircle;
// assign variable
CenterStarX = 0;
CenterStarY = 0;
WidthStar = 160+y;
HeightStar = 184+y;
d = 100; //space between base of both triangle
SpaceBetweenCircle = 40; //space between inside and outside circle
RVertical = HeightStar/2; //radius from center of star to top vertex of star
RSqrt = sqrt((pow((d/2),2))+(pow((WidthStar/2),2))); //radius from center of star to side vertex of star
if(RVertical > RSqrt)
{
RCircle = RVertical;
}
else
{
RCircle = RSqrt;
}
// draw outside circle
fill(0,120,0);
ellipse(CenterStarX,CenterStarY,(RCircle*2)+(SpaceBetweenCircle*2),(RCircle*2)+(SpaceBetweenCircle*2));
// draw inside circle
fill(0,0,100);
ellipse(CenterStarX,CenterStarY,(RCircle*2),(RCircle*2));
// draw top vertex triangle
noFill();
triangle(CenterStarX,CenterStarY-(HeightStar/2)+3,CenterStarX-(WidthStar/2)+3,CenterStarY+(d/2),CenterStarX+(WidthStar/2)-3,CenterStarY+(d/2));
// draw bottom vertex triangle
noFill();
triangle(CenterStarX,CenterStarY+(HeightStar/2)-3,CenterStarX-(WidthStar/2)+3,CenterStarY-(d/2),CenterStarX+(WidthStar/2)-3,CenterStarY-(d/2));
if(y==50)
{
check = 0;
}
if(y==0)
{
check = 1;
}
}