


// 마우스 클릭할때 렌덤으로 다양한 패턴이 생성
// Made by zhangbo0037 2017.03.23
// Media Art class in Soongsil University
void setup()
{
size(500,800);
Draw();
}
void draw()
{
}
void mousePressed()
{
Draw();
}
void Draw()
{
background(236,216,192);
color Color[];
Color = new color[9];
Color[0] = color(186,36,64);
Color[1] = color(214,95,25);
Color[2] = color(34,138,102);
Color[3] = color(240,95,59);
Color[4] = color(181,176,63);
Color[5] = color(12,79,72);
Color[6] = color(186,43,25);
Color[7] = color(230,203,70);
Color[8] = color(50,50,50);
int Count=0;
for (int i=0; i<30 i="" p=""> {
Count++;
int Num = int(random(1,9));
switch(Num)
{
case 1 :
{
Triangle( random(20,25), random(20,25), // Bottom & Height of Triangle
Color[int(random(0,9))], // Triangle's Color
30, // The number of Same Triangles
2, // The space of each Triangles
0, (Count-1)*28, // Translation of Triangle's line
1, // Scaling of all Triangle
1); // Choose different type of Triangles
break;
}
case 2 :
{
Triangle( random(20,25), random(20,25), // Bottom & Height of Triangle
Color[int(random(0,9))], // Triangle's Color
30, // The number of Same Triangles
2, // The space of each Triangles
0, (Count-1)*28, // Translation of Triangle's line
1, // Scaling of all Triangle
2); // Choose different type of Triangles
break;
}
case 3 :
{
Triangle( random(10,15), random(10,15), // Bottom & Height of Triangle
Color[int(random(0,9))], // Triangle's Color
50, // The number of Same Triangles
2, // The space of each Triangles
0, (Count-1)*28, // Translation of Triangle's line
1, // Scaling of all Triangle
3); // Choose different type of Triangles
break;
}
case 4 :
{
Triangle( random(10,15), random(10,15), // Bottom & Height of Triangle
Color[int(random(0,9))], // Triangle's Color
50, // The number of Same Triangles
2, // The space of each Triangles
0, (Count-1)*28, // Translation of Triangle's line
1, // Scaling of all Triangle
4); // Choose different type of Triangles
break;
}
case 5 :
{
Circle( int(random(10,15)), // Radius of each Circle
Color[int(random(0,9))], // Circle's Color
50, // The number of Same Circle
5, // The space of each Circle
0, (Count-1)*28, // Translation of all Circles
1); // Scaling of all Circles
break;
}
case 6 :
{
Diagonal( int(random(15,20)), // Longth of Diagonal
Color[int(random(0,9))], // Diagonal's Color
80, // The number of Same Diagonals
8, // The space of each Diagonal
0, (Count-1)*28, // Translation of all Diagonals
1, // Scaling of all Diagonals
1); // Choose different type of Diagonals
break;
}
case 7 :
{
Rectangle(Color[int(random(0,9))], // Rectangle's Color
0, (Count-1)*28, // Translation of all rectangles
1); // Scaling of all rectangles
break;
}
case 8 :
{
Diamond(random(15,20), random(15,20), // Width & Height of Diamond
Color[int(random(0,9))], // Diamond's Color
80, // The number of Same Diamonds
10, // The space of each Diamond
0, (Count-1)*28, // Translation of all diamonds
1); // Scaling of all diamonds
break;
}
}
}
}
//----------------------------------------------------------------------------------------
// Fuction_1: Draw Triangle
//----------------------------------------------------------------------------------------
void Triangle(float Bottom, float Height, // Bottom & Height of Triangle
color Color, // Triangle's Color
int n, // The number of Same Triangles
float Space, // The space of each Triangles
float TransX, float TransY, // Translation of all Triangle
float Scale, // Scaling of all Triangle
int Switch) // Choose different type of Triangles
{
pushMatrix();
// Translation
translate(TransX, TransY);
scale(Scale);
// Contents
stroke(Color);
strokeWeight(2);
fill(Color);
// Repeating
for (int i=0; i < n; i++)
{
if (Switch == 1)
{
triangle( 0 + i*(Bottom) , Height,
Bottom/2 + i*(Bottom) , 0
, Bottom + i*(Bottom) , Height);
}
if (Switch == 2)
{
triangle( 0 + i*(Bottom) , 0,
Bottom/2 + i*(Bottom) , Height
, Bottom + i*(Bottom) , 0);
}
if (Switch == 3)
{
triangle( 0 + i*(Height) , 0 ,
Height + i*(Height) , Bottom/2,
0 + i*(Height) , Bottom);
}
if (Switch == 4)
{
triangle( Bottom + i*(Height) , 0 ,
0 + i*(Height) , Bottom/2,
Bottom + i*(Height) , Bottom );
}
translate(Space, 0);
}
popMatrix();
}
//----------------------------------------------------------------------------------------
// Fuction_2: Draw Circle
//----------------------------------------------------------------------------------------
void Circle(float Radius, // Bottom & Height of Triangle
color Color, // Triangle's Color
int n, // The number of Same Triangles
float Space, // The space of each Triangle
float TransX, float TransY, // Translation of all Triangle
float Scale) // Scaling of all Triangle
{
pushMatrix();
// Translation
translate(TransX, TransY);
scale(Scale);
// Contents
stroke(Color);
fill(Color);
// Repeating
for (int i=0; i < n; i++)
{
ellipse(i*Radius, 10, Radius, Radius);
translate(Space, 0);
}
popMatrix();
}
//----------------------------------------------------------------------------------------
// Fuction_3: Draw diagonal
//----------------------------------------------------------------------------------------
void Diagonal(float Longth, // Longth of Triangle
color Color, // Diagonal's Color
int n, // The number of Same Diagonals
float Space, // The space of each Diagonal
float TransX, float TransY, // Translation of all Diagonals
float Scale, // Scaling of all Diagonals
int Switch) // Choose different type of Diagonals
{
pushMatrix();
// Translation
translate(TransX, TransY);
scale(Scale);
// Contents
stroke(Color);
fill(Color);
// Repeating
for (int i=0; i < n; i++)
{
if (Switch == 1) line(0, 0, 0+Longth, 0+Longth);
if (Switch == 2) line(0+Longth, 0, 0, 0+Longth);
translate(Space, 0);
}
popMatrix();
}
//----------------------------------------------------------------------------------------
// Fuction_4: Draw rectangle
//----------------------------------------------------------------------------------------
void Rectangle(color Color, // rectangle's Color
float TransX, float TransY, // Translation of all rectangles
float Scale) // Scaling of all rectangles
{
pushMatrix();
// Translation
translate(TransX, TransY);
scale(Scale);
// Contents
stroke(Color);
fill(Color);
// Repeating
rect(0, 0, width, int(random(5,10)));
popMatrix();
}
//----------------------------------------------------------------------------------------
// Fuction_5: Draw diamond
//----------------------------------------------------------------------------------------
void Diamond(float Bottom, float Height, // Width & Height of Diamond
color Color, // Diamond's Color
int n, // The number of Same diamonds
float Space, // The space of each Diamond
float TransX, float TransY, // Translation of all diamonds
float Scale) // Scaling of all diamonds
{
pushMatrix();
// Translation
translate(TransX, TransY);
scale(Scale);
// Contents
stroke(Color);
fill(Color);
PShape diamond;
diamond = createShape();
diamond.beginShape();
diamond.vertex(Bottom/2, 0); //top
diamond.vertex(0, Height/2); //Left
diamond.vertex(Bottom/2, Height); //Bottom
diamond.vertex(0, Height/2);//Right
diamond.endShape(CLOSE);
// Repeating
for (int i=0; i < n; i++)
{
shape(diamond, 0, 0);
translate(Space, 0);
}
popMatrix();
}30>


