イメージからアプレットを起動
Lines12をもとに、線が伸びていくときにアルファ値を設定
ただアルファ値を設定してあげるだけ。
見た目にもあまりおもしろくないので、Lines14の回転も加えた。こっちのがおもしろい。
p43_Lines16.pde
[java]
int leftBounds = 20;
int topBounds = 20;
float x = leftBounds;
float y = topBounds;
int rightBounds = 380;
int bottomBounds = 380;
int baseMax = 20;
int randomMax = 10;
int maxLines = 1000;
int counter = 0;
//int steps = 20;
//boolean nextLine = false;
//int alpha = 0;
Line[] Lines;
//Ellipse[] Ellipses;
void setup(){
size(400, 400);
frameRate(30);
colorMode(HSB, 360, 100, 100);
background(0, 0, 100);
Lines = new Line[maxLines];
// Ellipses = new Ellipse[maxLines];
strokeWeight(1);
smooth();
}
void draw(){
background(0,0,100);
// if(steps > 20 && !nextLine) nextLine = true;
if(counter < maxLines){// && nextLine){
float maxDistance = baseMax * random(0, 1) * randomMax;
float minDistance = 2;
int direction = random(0, 1) < 0.5 ? -1 : 1;
float xEnd = x + (direction * (minDistance + ( random(0, 1) * maxDistance)) );
direction = random(0, 1) < 0.5 ? -1 : 1;
float yEnd = y + (direction * (minDistance + ( random(0, 1) * maxDistance)) );
if(xEnd < leftBounds) xEnd = leftBounds;
if(xEnd > rightBounds) xEnd = rightBounds;
if(yEnd < topBounds) yEnd = topBounds;
if(yEnd > bottomBounds) yEnd = bottomBounds;
Lines[counter] = new Line(x, y, xEnd, yEnd);
// Lines[counter].setAlpha(alpha);
// Ellipses[counter] = new Ellipse(x, y, maxDistance * .2, maxDistance * .2);
x = xEnd;
y = yEnd;
// steps = 0;
// nextLine = false;
counter++;
}
// steps++;
// alpha++;
// if(alpha > 255) alpha = 0;
// if(counter >= 10 && counter
// Lines[counter-10].disappear();
// }
// else if(counter > maxLines+10) noLoop();
if(counter < maxLines){
for(int i=0; i
// Ellipses[i].bdraw();
}
}
else{
for(int i=0; i< maxLines; i++){
Lines[i].bdraw();
// Ellipses[i].bdraw();
}
}
}
void keyPressed(){
if(key == 'r'){
background(255);
counter = 0;
Lines = new Line[maxLines];
// Ellipses = new Ellipse[maxLines];
}
if(key =='q'){
saveFrame("p43_Lines16.jpg");
exit();
}
}
[/java]
Line.pde
[java]
public class Line{
//member
float x, y, xEnd, yEnd;
int alpha;
int steps;
float[] scl;
float r;
float nowR;
//constructor
Line(float x, float y, float xEnd, float yEnd){
this.x = x;
this.y = y;
this.xEnd = xEnd;
this.yEnd = yEnd;
alpha = 255;
steps = 0;
// r = 2*PI/20;
// nowR = 0;
// scl = new float[steps];
// scl[0] = 0;
// for(int i=0; i < steps; i++){
// float pre = 100000/(i+1);
// scl[i] = pre/100000;
// println(i+" = "+scl[i]);
// }
}
//method
void setAlpha(int alpha){
this.alpha = alpha;
bdraw();
}
void bdraw(){
// stroke(0, alpha);
// if(steps > 0){
if(steps < 20){
pushMatrix();
translate(x, y);
// scale(scl[steps-1]);
// line(0, 0, (xEnd – x)/steps, (yEnd – y)/steps);
// nowR += r;
// rotate(nowR);
stroke(0, 255/20 * steps);
line(0, 0, ((xEnd – x)/20)*steps, ((yEnd – y)/20)*steps);
popMatrix();
// steps–;
steps++;
}
else {
stroke(0, alpha);
line(x, y, xEnd, yEnd);
}
}
void disappear(){
x = y = xEnd = yEnd = 1000;
bdraw();
}
}
[/java]
タグ: processing
