Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

St2 #1

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions STriangle.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
class STriangle {
private int truex;
private int truey;
private float my;
private float mx;
private int leng;
private int trianglenumt;
private STriangle St1, St2, St3;
private float dmy, dmx;
public STriangle(int x, int y, int len, int trianglenum)
{
dmy = 0;
dmx = 0;
truex = x;
truey = y;
leng = len;
trianglenumt = trianglenum;
my = y + (int)(Math.random()*300 -150);
mx = x + (int)(Math.random()*300 -150);
if (my < 900/4) {
int temp = 900/4;
int tempb = (int)my - 0;
stroke(255, (255 * tempb)/temp, 0);
} else if (my < 900/2) {
int temp = 900/4;
if (temp == 0) {
temp = 1;
}
int tempb = (int)my - 900/4;
stroke(127 - (127 * tempb)/temp, 255, (255 * tempb)/temp);
} else if (my < 900*3/4) {
int temp = 900/4;
if (temp == 0) {
temp = 1;
}
int tempb = (int)my - 900/2;
stroke(0, 255 - (255 * tempb)/temp, 255);
} else {
int temp = 900/4;
if (temp == 0) {
temp = 1;
}
int tempb = (int)my - 900*3/4;
stroke(255-(127 * tempb)/temp, 0, 255);
}
beginShape();
vertex(mx+leng/2, my);
vertex(mx-leng/2, my);
vertex(mx, (float)(my+leng/2*Math.sqrt(3)));
vertex(mx+leng/2, my);
endShape();
beginShape();
vertex(x+len/2, y);
vertex(x-len/2, y);
vertex(x, (float)(y+len/2*Math.sqrt(3)));
vertex(x+len/2, y);
endShape();
if (trianglenum < maxtri) {
St1 = new STriangle(x - len/4, y, len/2, trianglenum+1);
St2 = new STriangle(x, (int)(y+len/4*Math.sqrt(3)), len/2, trianglenum+1);
St3 = new STriangle(x+len/4, y, len/2, trianglenum+1);
}
}
public void moveBack() {
my += (truey-my)/10;
mx += (truex-mx)/10;
if (trianglenumt < maxtri) {
St1.moveBack();
St2.moveBack();
St3.moveBack();
}
}
public void seperate(float multi) {
float distance = (dist(mx, (float)(my + leng * (Math.sqrt(3)/4)), 600, 386));
if (distance < 1) {
distance = 1;
}
my += 5*multi*Math.sqrt(trianglenumt) * (Math.random() * 3)*(10)/((distance)/20)* (Math.abs(my - 386)/(my-386));
mx += 5*multi*Math.sqrt(trianglenumt) * (Math.random() * 3)*(10)/((distance)/20)* (Math.abs(mx - 600)/(mx-600));
if (trianglenumt < maxtri) {
St1.seperate(multi);
St2.seperate(multi);
St3.seperate(multi);
}
}
public void move() {
if (!changeColor) {
if (truey < 900/4) {
int temp = 900/4;
int tempb = (int)truey - 0;
stroke(255, (255 * tempb)/temp, 0);
} else if (truey < 900/2) {
int temp = 900/4;
if (temp == 0) {
temp = 1;
}
int tempb = (int)truey - 900/4;
stroke(127 - (127 * tempb)/temp, 255, (255 * tempb)/temp);
} else if (truey < 900*3/4) {
int temp = 900/4;
if (temp == 0) {
temp = 1;
}
int tempb = (int)truey - 900/2;
stroke(0, 255 - (255 * tempb)/temp, 255);
} else {
int temp = 900/4;
if (temp == 0) {
temp = 1;
}
int tempb = (int)truey - 900*3/4;
stroke(255-(127 * tempb)/temp, 0, 255);
}
} else {
if (my < 900/4) {
int temp = 900/4;
int tempb = (int)my - 0;
stroke(255, (255 * tempb)/temp, 0);
} else if (my < 900/2) {
int temp = 900/4;
if (temp == 0) {
temp = 1;
}
int tempb = (int)my - 900/4;
stroke(127 - (127 * tempb)/temp, 255, (255 * tempb)/temp);
} else if (my < 900*3/4) {
int temp = 900/4;
if (temp == 0) {
temp = 1;
}
int tempb = (int)my - 900/2;
stroke(0, 255 - (255 * tempb)/temp, 255);
} else {
int temp = 900/4;
if (temp == 0) {
temp = 1;
}
int tempb = (int)my - 900*3/4;
stroke(255-(127 * tempb)/temp, 0, 255);
}
}
beginShape();
vertex(mx+leng/2, my);
vertex(mx-leng/2, my);
vertex(mx, (float)(my+leng/2*Math.sqrt(3)));
vertex(mx+leng/2, my);
endShape();
if (trianglenumt < maxtri) {
St1.move();
St2.move();
St3.move();
}
}
}
63 changes: 55 additions & 8 deletions SierpinskiTriangle.pde
Original file line number Diff line number Diff line change
@@ -1,16 +1,63 @@
import processing.sound.*;
Amplitude amp;
AudioIn in;


int maxtri = 9;
boolean changeColor = false;
STriangle MasterTriangle;
boolean toggle = true;
public boolean increase = false;
float multiplier = 1;
public void setup()
{

noFill();
amp = new Amplitude(this);
in = new AudioIn(this,0);
in.start();
amp.input(in);
background(255);
size(1200, 1200);
MasterTriangle = new STriangle(600, 150, 900, 0);
maxtri = 6;
}
public void draw()
{

background(255);
MasterTriangle.move();
//if (amp.analyze()>.01) {
MasterTriangle.seperate(amp.analyze());
multiplier += .05;
//}
MasterTriangle.moveBack();
}
public void mouseDragged()//optional
public void mousePressed()
{

increase = true;
}
public void mouseReleased() {
increase = false;
}
public void keyPressed() {
if (key == 'w') {
if (maxtri < 9) {
maxtri++;
}
}
if (key == 's') {
if (maxtri > 1) {
maxtri--;
}
}
if (key == 'e') {
if (toggle) {
changeColor = !changeColor;
toggle = false;
}
}
}
public void keyReleased() {
if (key == 'e') {
toggle = true;
}
}
public void sierpinski(int x, int y, int len)
{

}
10 changes: 6 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Title</title>
<title>Wen's Project :3</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="styles.css">
<script src="processing.js"></script>
</head>
<body>
<header>
<h1>Headline</h1>
<h1>Tria</h1>
</header>
<section id="content">
<canvas id="SierpinskiTriangle" data-processing-sources="SierpinskiTriangle.pde">
<canvas id="SierpinskiTriangle" data-processing-sources="SierpinskiTriangle.pde STriangle.pde">
</canvas>
</section>
<footer>
Footer
<p>W to increase triangle S to decrease</p>
<p>Press E to toggle color change based on location</p>
<p>Click around for magic</p>
</footer>
</body>
</html>