TUT­O­R­I­A­L 6

by Sonia White
  • Show Code
/** @peep sketch */
float y = 50.0;
float speed = 3;
float angle=0;
 
void setup() {
  size(400, 400);
  background(0);
  noStroke();
  frameRate(80)
}
 
void draw() {
  fill(0, 12);
  rect(0, 0, width, height);
  fill(255);
  translate(100, y);
 
    pushMatrix();
    fill(250,200,150)
    rotate(angle);
    translate(-50,25);
    rect(-50,-50,20,20);
    angle=angle+0.02;
    popMatrix();
 
    pushMatrix();
    fill(200,250,100)
    rotate(angle);
    translate(50,-50);
    rect(-50,-50,20,20);
    angle=angle+0.02;
    popMatrix();
 
    pushMatrix();
    fill(100,200,250)
    rotate(angle);
    translate(125,50);
    rect(-50,-50,20,20);
    angle=angle+0.02;
    popMatrix();
 
    pushMatrix();
    fill(200,200,250)
    rotate(angle);
    translate(-1,50);
    rect(-50,-50,20,20);
    angle=angle+0.02;
    popMatrix();
 
  rotate(angle);
  fill(255);
  rect(-60, -60, 120, 120);
  angle = angle + 0.02;
 
 
 
  y += speed;
  if (y > height + 120) {
    y = -240;
  }
}
  • Show Code
/** @peep sketch */
float angle = 0.0; // Current angle
float speed = 0.01; // Speed of motion
float radius = 80.0; // Range of motion
 
void setup() {
  size(200, 200);
  background(0);
  noStroke();
}
 
void draw() {
  fill(0, 12);
  rect(0, 0, width, height);
  fill(250,100,100);
//fluctuating size of the radius
  float sizeoffset = sin(angle) * radius;
//the x & y corodinates for ellipse 1
  float x = width/2 + (cos(angle) * radius);
  float y = height/2 + (sin(angle) * radius);
  ellipse(x, y, 20+sizeoffset, 20+sizeoffset);
 
//x & y for second ellipse
  float x = width/2 - (cos(angle) * radius);
  float y = height/2 - (sin(angle) * radius);
  ellipse(x, y, 20+sizeoffset, 20+sizeoffset);
  angle += speed;
 
}
  • Show Code
/** @peep sketch */
int numLines = 50;
float[] x = new float[numLines];
float[] speed = new float[numLines];
float offset = 5; // Set space between lines
 
void setup() {
  size(200, 200);
  strokeWeight(10);
  for (int i = 0; i < numLines; i++) {
    x[i] = i; // Set initial position
    speed[i] = 0.3 + (i/offset); // Set initial speed
  }
}
 
void draw() {
  background(204);
  for (int i = 0; i < x.length; i+=8) {
    x[i] += speed[i]/5; // Update line position
    float y = i * offset; // Set y-coordinate
    stroke(100+(i*4),100,100);
    line(x[i]%width, y, x[i]%width + offset, y + offset);
    line(x[i]%width - width, y, x[i]%width - width + offset, y + offset);
    line(x[i]%width + width, y, x[i]%width + width + offset, y + offset);
  }
}

Comments

Nobody has said anything yet.