Dif­f­e­r­e­n­t Code

by Scott Simon

Some bits of code from the tutorials and classes. Note that this code is modified from other sources including Processing Handbook (by Rheas and Fry) and tutorials by Rob.

  • Show Code
/** @peep sketch */
 
int num=50;
 
 //an array of circles...(from the circle class
Circle [] circles;
 
void setup() {
  size(400, 300);
 
   circles= new Circle[num];
   for (int i=0; i < num; i++) {
    //PVector p = new PVector(width/2+stickLen*i, height/2);
    circles[i] = new Circle((int) random(width),(int) random(height),width/20);}
}
 
 
void draw() {
  //circle.update();
   //update();
  background(255);
//circle.rtf();
    for (int i=0; i < num; i++) {
 
    circles[i].rtf();
     circles[i].update();
      //polys[i].move();
  }
}
 //circle class - this is called from the array above "num" times.
class Circle {
  float x;
  float y;
  float radius;
  float heading;
  float speed;
 
  Circle(float _x, float _y, float _radius) {
    x = _x;
    y = _y;
    radius = _radius;
    heading = random(TWO_PI);
    speed = random(0.25, 0.50);
  }
 
  void update() {
    // Behaviour 1: Move in a straight line
    x += speed * cos(heading);
    y += speed * sin(heading);
  }
 
  void rtf() {
    noFill();
    stroke(0);
    strokeWeight(0.1);
    ellipse(x, y, 2*radius, 2*radius);
    float dx = radius * (1 + speed) * cos(heading);
    float dy = radius * (1 + speed) * sin(heading);
    line(x, y, x + dx, y + dy);
  }
 
 
}
  • Show Code
/** @peep sketch */
 
void setup(){
 
size(800, 800);
background(240);
fill(255);
stroke(0);
strokeWeight(1);
//star(45,45,40,80,5);}
 
 
 
 
// for (int j = 0; j < 80; j = j+5) {
//   point(i, j);}}
//star(50,50,10,40,5);}
for(int i=0;i<width;i+=20){
for(int j=0;j<height;j+=20){
    float b=map(i,0,width,0,2.0);
  //float c=map(j,0,height,0,2.0);
  //scale(b, c);
  pushMatrix();
 
translate(i,j);
 
 
star(0,0,5,10,(int)random(4,8),b);
 
popMatrix();
 
 
}}
 
}
 
void star(float x, float y,float inner,float outer,int points,float scalez) {
 scale(scalez);
  beginShape();
 
  float delta = radians(360/points);
  for (int i = 0; i < points; i++) {
    // Draw the outer point
    float ox = x + outer * cos(i*delta);
    float oy = y + outer * sin(i*delta);
    vertex(ox, oy);
    // Draw the inner point
    float ix = x + inner * cos(i*delta + delta/2);
    float iy = y + inner * sin(i*delta + delta/2);
    vertex(ix, iy);
 
  }
 
  endShape(CLOSE);
}
  • Show Code
/** @peep sketch */
 
float [] plottings ={0.0,141.4214,200.0,141.4214,0.0,
-141.4214,-200.0,-141.4214,0.0,141.4214,200.0,141.4214,0.0,-141.4214,-200.0,-141.4214,0};
 
float [] plottings2 ={0.0,76.5366,141.4214,184.7759,200.0,184.7759,141.4214,76.5366,0,-76.5366,-141.4214,-184.77594,
-200.0,-184.7759,-141.4214,-76.5366,0};
 
float [] azz;
 
  float y=0;
  int i=0;
  int z=0;
     int zxz=0;
 
 
void setup(){
size(600,600);
frameRate(10);
 
  //noStroke();
 
 
 
 //translate(300,50);
 
 
}
void draw(){
 
 
  rect(0,0,width,height);
  fill(0,23);
  if(frameCount%60==0){
   circle(width/2, height/2, width/2, 6);}
 
azz=circle(plottings2);
  pushMatrix();
   translate(300,50);
    azz2(plottings2);
    y= (y+20)%height;
    z=i++%16;
 
     fill(20,123,123,167);
 
       ellipse(plottings2[z],y,15+i%30,15);
       pushStyle();
       strokeWeight(3);
       for(int i=0;i<100;i++)
       {
         fill(i+23,123+i,123,54-i);
         strokeWeight(1);
          stroke(23,123+i);
        ;
       }
 
       popStyle();
        noFill();
        fill(120,123,223,123);
        ellipse(plottings[z],y,15+i%30,15+i%30);
        //println(plottings[z]+" "+y);
 
         pushStyle();
          fill(150,123);
 
           zxz=(zxz+1)%15;
 
              if(azz[zxz]!=0){
                 fill(azz[zxz]%200,12,azz[zxz]%100,azz[zxz]%156);
                 stroke(azz[zxz]%6);
                 strokeWeight(azz[zxz]%2.0);
         ellipse(azz[zxz],y,10,10);
         pushStyle();
            if(azz[zxz]<90&& azz[zxz]>70){
                fill(123,223,178,189);
               ellipse(azz[zxz],y,10,10);
               noStroke();
               fill(250,64);
                ellipse(azz[zxz],y,15,15);
 
      }}
       popStyle();
       popMatrix();
         fill(0,23);
 
 
 
 
 
 
 
 
 
 
}
 
 
float [] circle(float [] zz) {
 
 float[] numbers=new float[zz.length];
 arrayCopy(zz,numbers);
 
 for(int i=0;i<numbers.length;i++){
   if(numbers[i]>numbers[8]){
   numbers[i]=numbers[i]/2.0;
 
 }
 else{numbers[i]=0;}
 
 }
 
 return numbers;
  } 
 
float[] azz2(float [] asa){
 
 
       if(asa[z]==asa[15]){
   pushStyle();
     fill(250);
   ellipse(asa[z],y,30,30);
   pushStyle();
   noStroke();
    fill(250,123,45,67);
   ellipse(asa[z],y,50,50);
   fill(250,123,45,17);
    ellipse(asa[z],y,60,60);
     fill(255,8);
    ellipse(asa[z],y,80,80);
 
    fill(255,34);
    ellipse(asa[z],y,10,10);
 
   popStyle();
       }
       return asa;
 }
 
 
 void mousePressed() {
 background(0); 
}
 
void mouseReleased() {
  //loop();
}
 
 
 
 
 void circle(float x, float y, int r, int num) {
   pushStyle();
   fill(123,23,234,16);
   ellipse(x, y, r*2, r*2);
   if (num > 0) {
     int branches = int(random(2, 6));
     for (int i = 0; i < branches; i++) {
       float a = random(0, TWO_PI);
       float newx = x + cos(a) * 6.0 * num;
       float newy = y + sin(a) * 6.0 * num;
       circle(newx, newy, r/2, num-1);
      // println(newx+ " " +i);
} }
popStyle();
}

oops - this doesn't run in peep - Code is there though. Uses recursion and arrays to create animation.

  • Show Sketch
/** @peep sketchcode */
 
 
float angle,angle2,angle3,angle4,z = 0.0;    // Current angle
float speed = 0.05;   // freq
float radius = 100.0;  // amp
float sx = 2.0;
float sy = 2.0;
 
 
void setup() {
  size(600, 600);
  noStroke();
}
 
void draw() {
  fill(0, 4);
  rect(0, 0, width, height); 
  translate(width/2,height/2);
  angle += speed;
 
 
  if(angle>=TWO_PI){
   //440/44100 =0.009977
   //0.5/60=0.00833
    angle=0.0;
  }
 
 
 
    z=z+speed*16;
 
    if(z>=100){
      z=-100;
 
    }
  // Update the angle
  float sinval = sin(angle);
  float cosval = cos(angle);
   float sinval2 = sin(angle+PI/2);
  float cosval2 = cos(angle+PI/2);
   float sinval3 = sin(angle+PI);
  float cosval3 = cos(angle+PI);
  float sinval4 = sin(angle+(3*PI)/2);
  float cosval4 = cos(angle+(3*PI)/2);
  // Set the position of the small circle based on new
  // values from sine and cosine
  float x = cosval*radius;
 
  float y = (sinval * radius)+(sinval2 * radius/2)+(sinval3 * radius/3)+ (sinval4 * radius/4);
   float x2 = (cosval * radius);
  float y2 = (sinval * radius);
  float y3 = (sinval2 * radius);
  float y4 = (sinval3 * radius);
  float y5 = (sinval4 * radius);
   //float x = (y2 + y4);
  fill(255);
 
    ellipse(x, y2, 2, 2);
     ellipse(x, y3, 2, 2);
     ellipse(x, y4, 2, 2);
      ellipse(x, y5, 2, 2);
 
 
   ellipse(z, y2, 2, 2);
 
 
    ellipse(z, y3, 2, 2);
     ellipse(z, y4, 2, 2);
     ellipse(z, y5, 2, 2);
  //float x2 = x + cos(angle * sx) * radius/2;
  //float y2 = y + sin(angle * sy) * radius/2;
  //ellipse(x2, y2, 6, 6);  // Draw larger circle
}

Sine structure that we will turn into a class.

  • Show Sketch
/** @peep sketchcode */
 
Sining [] sinething;
int unit = 40;
int count;
float angle = 0.0; 
//float radius = 100.0;
float speed = 0.05; 
//float cosval=0.0;
 
void setup() {
   size(800, 800);
   //background(0);
 
     int wideCount = width / unit;
  int highCount = height / unit;
   count = wideCount * highCount;
    sinething = new Sining[count];
 
 
    int index = 0;
  for (int y = 0; y < highCount; y++) {
    for (int x = 0; x < wideCount; x++) {
        sinething[index++] = new Sining(20,x*unit, y*unit);
    }
  }
 
 
   }
 
 
 
 void draw() {
  // background(0);
  fill(0, 7);
 rect(0, 0, width, height); 
 
 
  //translate(width/2,height/2);
     angle += speed;
 
 
  if(angle>=TWO_PI){
 
    angle=0.0;
  }
 
   for (int i = 0; i < sinething.length; i++) { 
     sinething[i].display(); 
      sinething[i].motion(); 
       sinething[i].speedz();
 
   }
 
 }
 
class Sining{
  float x,y;
    float sinval =0; 
  float cosval = 0;
   float sinval2=0;
  float z=0;
   float  sinval3=0;
    float sinval4 = 0;
      float y3 = 0;
  float y4 = 0;
  float y5 = 0;
  float radius=0;
  float zz=0;
 
 
  float Cpos,Dpos;
  Sining(float radius,float Cpos,float Dpos){
 
  this.radius=radius;
  this.Cpos=Cpos;
  this.Dpos=Dpos;
  }
 
    Sining(float radius){
 
  this.radius=radius;
 
  }
 
  void motion(){
 
    sinval=sin(angle);
    cosval=cos(angle);
    sinval2 = sin(angle+PI/2);
    sinval3 = sin(angle+PI);
    sinval4 = sin(angle+(3*PI)/2);
 
     x = (cosval*radius);
      y = (sinval * radius);
     y3 = (sinval2 * radius);
  y4 = (sinval3 * radius);
  y5 = (sinval4 * radius);
 
 
 
  }
 
  void display(){
    fill(10,145,123,134+x); 
    noStroke();
    //pushMatrix();
 
   // translate(Cpos,Dpos);
        ellipse(x+Cpos, y+Dpos, 2, 2);
     ellipse(x+Cpos, y3+Dpos, 2, 2);
    ellipse(x+Cpos, y4+Dpos, 2, 2);
      ellipse(x+Cpos, y5+Dpos, 2, 2);
 
 
  ellipse(z+Cpos, y+Dpos, 2+zz, 2);
 
 
    ellipse(z+Cpos, y3+Dpos, 2, 2);
     ellipse(z+Cpos, y4+Dpos, 2, 2);
     ellipse(z+Cpos, y5+Dpos, 2, 2);
   // popMatrix();
 
  }
 
  void speedz(){
      z=z+speed*16;
 
    if(z>=radius){
      z=-radius;
 
    }
 
  }
 
}

Comments

Nobody has said anything yet.