The following sketch ying & yang class takes the sketch feeling alittle ying and yang made for week 3 and turns the circle elements into a class.
Code:
/*
pause = false
because drawing should play at start of sketch but paus when the user so chooses
it is NOT currently paused
*/
boolean pause = false;
Circles circles1;
void setup(){
// sets the background color
background(255);
// sets the canvas size
size(800,400,P3D);
// sets anti-aliased
smooth();
// removes the stroke
noStroke();
// sets the fill for the rectangle
fill(0);
rect(400,0,800,400);
}
void draw(){
}
void mouseMoved() {
if (pause == false){
//if it is not paused, then I make the circles
circles1 = new Circles();
circles1.display();
}
}
void mousePressed()
{
// if pause == true make it false
if (pause) {
pause = false;
}
else
{
pause = true;
}
}
Code for Class:
class Circles
{
// Variables
float diam;
float spread1;
float spread2;
float a;
// Constructor
Circles()
{
// sets the diameter of circles within this range
diam = random(1,20);
// sets the distance between circles in the x direction
spread1 = random(-10,10);
// sets the distance between circles in the y direction
spread2 = random(-10,10);
//
a = random(100,255);
}
void display()
{
// set the fill values per location on canvas. In this case the fill is a variance of black
if (mouseX < width/2){
fill(0,a);
}
// set the fill values per location on canvas. In this case the fill is a variance of white
else{
fill(255,a);
}
ellipse(mouseX + spread1,mouseY + spread2,diam,diam);
}
}