วันอาทิตย์ที่ 2 พฤศจิกายน พ.ศ. 2557

Lab 5 : Task#1 - Class Balloon

int w=500,h=500,count=0;
float v=1,r=50;

class balloon
{
  float r;
  float px;
  float py;
  balloon(float r,float px,float py)
  {
    this.r=r;
    this.px=px;
    this.py=py;
  }
  void moveUp()
  {
    if(py!=height+999)
    {
      this.py=this.py-v;
    }
    if(this.py<0-r)
    {
      this.py=height+r;
    }
  }
  void display()
  {
    line(this.px,this.py,this.px,this.py+100);
    ellipse(this.px,this.py,r*2,r*2);
  }
}

balloon[] a=new balloon[100];

void setup()
{
  for(int i=0;i<100;i++)
  {
    a[i]=new balloon(50,0,height+999);
  }
  size(w,h);
}

void draw()
{
  background(155);
  for(int i=0;i<a.length;i++)
  {
    a[i].display();
    a[i].moveUp();
  }
}

void mousePressed()
{
  count++;
  a[count]=new balloon(50,mouseX,mouseY);
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น