Difference between revisions of "CSC103 Processing Programs"

From dftwiki3
Jump to: navigation, search
(leftCirclesRedRightCirclesBlue)
 
Line 117: Line 117:
 
<br />
 
<br />
 
::<source lang="java">
 
::<source lang="java">
 +
// leftCirlesRedRightCirclesBlue
 +
// D. Thiebaut
 +
// follows the mouse and draws cirles
 +
// left side of window: red
 +
// right side of window: blue
 +
 +
void setup() {
 +
  size( 500, 500 );
 +
  smooth();
 +
}
 +
 +
void draw() {
 +
if (  mouseX < 250 ) {
 +
      // set fill color to red
 +
      fill( 242, 66, 213  );
 +
}
 +
else {
 +
      // set fill color to blue
 +
      fill( 49, 132, 245 );
 +
}
 +
ellipse( mouseX, mouseY, 80, 80 );
 +
}
 
</source>
 
</source>
 
<br />
 
<br />
 +
 
= mouseButtonPressed =
 
= mouseButtonPressed =
 
<br />
 
<br />

Latest revision as of 08:27, 18 October 2017

--D. Thiebaut (talk) 08:21, 18 October 2017 (EDT)


Loop1


void setup() {
  for ( int i=0;  i <= 10;  i=i+1 ) {
      println( i );
  }
}

void draw() {
}


Loop2


void setup() {
  
  int sum = 0;

  for ( int counter=0; counter <= 10; counter++ ) {
      sum = sum + counter;
  }

  println( "sum = ", sum );
}


Loop3


void setup() {
    size( 500, 500 );
    smooth();
}
  
void draw() {
   fill( 200, 100, 0 );

   for ( int x=50; x<500; x = x + 100 ) {
       ellipse( x, 100, 40, 40 );
   }
   
   //ellipse( mouseX, mouseY, 80, 80 );
}


Loop5


void setup() {
    size( 500, 500 );
    smooth();
}
  
void draw() {
   fill( 200, 100, 0 );
   for ( int x=50; x<500; x = x + 100 ) {
       for ( int y=50; y<500; y = y + 100 ) {
           ellipse( x, y, 40, 40 );
       }
   }
}


blackCatsAndMoon

BlackCat.png


PImage dtImage;
void setup() {
   dtImage = loadImage( "cat2.png" );
   size( 1000, 700 );
   smooth();
   frameRate( 5 );
}

void draw() {
    // draw circles
    //image( dtImage, mouseX, mouseY );
    fill( 255, 242, 95 );
    float size = random(50,mouseX); //random( 50, 500 );
    image( dtImage, random(width), random(height),
               size, size );
    float radius = random( 200 );
    ellipse( random(width), random(height), 
             radius, radius );
    
    // draw caption
    textSize( 32 );
    fill( 188, 13, random( 0, 255 ) );
    text( "Happy Friday the 13!", 100, 400 );
}


circlesAndText


void setup() {
   size( 500, 500 );
   smooth();
}

void draw() {
    // draw circles
    fill( 188, 13, random( 0, 255 ) );
    ellipse( mouseX, mouseY, 80, 80 );
    
    // draw caption
    textSize( 32 );
    fill( 255, 242, 95 );
    text( "Processing is fun!", 100, 400 );
}


leftCirclesRedRightCirclesBlue


// leftCirlesRedRightCirclesBlue
// D. Thiebaut
// follows the mouse and draws cirles
// left side of window: red
// right side of window: blue

void setup() {
  size( 500, 500 );
  smooth();
}

void draw() {
if (  mouseX < 250 ) {
      // set fill color to red
      fill( 242, 66, 213  );
}
else {
      // set fill color to blue
      fill( 49, 132, 245 );
}
ellipse( mouseX, mouseY, 80, 80 );
}


mouseButtonPressed


// mouseButtonPressed
// D. Thiebaut
// Draws only  if mouse button is pressed

void setup() {
  size( 500, 500 );
  smooth();
}

void draw() {
  if (  mouseX < 250 ) {
      // set fill color to red
      fill( 242, 66, 213  );
  }
  else {
      // set fill color to blue
      fill( 49, 132, 245 );
  }

  if ( mousePressed == true ) {
      ellipse( mouseX, mouseY, 5, 5 );
  }

}


rectangularBlocks


void setup() {
    size( 500, 500 );
    smooth();
}

void draw() {
   fill( 200, 100, random(255) );
   ellipse( random(100, 200), random(100, 200),  //<>//
            mouseX, mouseX );
   fill( 200, random(255), 80 ); 
   ellipse( random(300, 400), random(300, 400), 
            mouseY, mouseY );

}