Processing Examples - Drawing Programs

Moderator: BenChang

Processing Examples - Drawing Programs

Postby BenChang » Tue Nov 11, 2014 7:22 pm

Drawing Programs
Code: Select all
void setup()
{
   size(800,600);
}

void draw()
{
   
  if (mousePressed)
  {
    ellipse(mouseX,mouseY,20,20);
    ellipse(800-mouseX,mouseY,20,20);
    ellipse(mouseX,600-mouseY,20,20);
    ellipse(800-mouseX,600-mouseY,20,20);
  }
}
User avatar
BenChang
 
Posts: 176
Joined: Mon Jan 17, 2011 4:48 pm

Lines

Postby BenChang » Tue Nov 11, 2014 7:22 pm

Code: Select all
[code]
void setup()
{
   size(800,600);
}

void draw()
{
   
  if (mousePressed)
  {
    line(pmouseX, pmouseY, mouseX, mouseY);
  }
}
User avatar
BenChang
 
Posts: 176
Joined: Mon Jan 17, 2011 4:48 pm

Velocity

Postby BenChang » Tue Nov 11, 2014 7:22 pm

Code: Select all
void setup()
{
   size(800,600);
}

void draw()
{
   
  float dx;
  float dy;
 
  dx=mouseX-pmouseX;
  dy=mouseY-pmouseY;
 
  if (mousePressed)
  {
      strokeWeight (abs (dy) );
      line (pmouseX, pmouseY, mouseX, mouseY);
  }
}
User avatar
BenChang
 
Posts: 176
Joined: Mon Jan 17, 2011 4:48 pm

Velocity, line width, distance function

Postby BenChang » Tue Nov 11, 2014 7:24 pm

Code: Select all
void setup()
{
   size(800,600);
}


float distance (float x1, float y1, float x2, float y2)
{
   float d;    // final result
   float dx = x2-x1;
   float dy = y2-y1;
   
   d = sqrt(dx*dx + dy*dy);
   return d;
}

void draw()
{
  float d;
  float w;
  if (mousePressed)
  {
    d = distance (mouseX, mouseY, pmouseX, pmouseY);
    w = 20-d;
    if (w<1)
      w=1;
     
    strokeWeight(w);
    stroke(w*10,0,d*10);
    line (pmouseX, pmouseY, mouseX, mouseY);
  }
}
User avatar
BenChang
 
Posts: 176
Joined: Mon Jan 17, 2011 4:48 pm


Return to Art and Animation

Who is online

Users browsing this forum: No registered users and 1 guest

cron