2018年11月22日 星期四
week 11. drawing mandala
Basic sample 1:
float resolution;
float radius = 100;
float circleX;
float circleY;
float offset;
void setup() {
size(700, 700);
circleX = 0;
circleY = 0;
}
void draw() {
fill(0,0,0,25);
rect(0,0,width,height);
translate(width/2, height/2);
fill(255);
noStroke();
offset++;
resolution = map(sin(offset*0.005), -1, 1, 2, 20);
// resolution = 20;
for (int i = 0; i < resolution; i++) {
float angle = map(i, 0, resolution, 0, TWO_PI);
// float waveOffset = sin(angle*circles) * 200;
float circleOffsetX = cos(angle) * (radius); //xposition
float circleOffsetY = sin(angle) * (radius); //yposition
// float circleOffsetX = cos(angle) * (radius + waveOffset); //xposition
// float circleOffsetY = sin(angle) * (radius + waveOffset); //yposition
float x = circleX + circleOffsetX;
float y = circleY + circleOffsetY;
ellipse(x, y, 10, 10);
}
}
Sample 2:
float resolution;
float radius = 100;
float circleX;
float circleY;
float circles;
float circleW;
float circleH;
float offset;
void setup() {
size(700, 700);
circleX = 0;
circleY = 0;
}
void draw() {
fill(0,0,0,25);
rect(0,0,width,height);
translate(width/2, height/2);
fill(255);
noStroke();
offset++;
resolution = map(sin(offset*0.00025), -1, 1, 11, 13);
//resolution = 50;
circles = 400;
circleW = map(sin(offset*0.05), -1, 1, 1, 8);
circleH = map(sin(offset*0.05), -1, 1, 1, 8);
for (int i = 0; i < resolution; i++) {
float scale = 200;
float waveAngle = map(i, 0, resolution, 0, TWO_PI * circles);
float waveOffset = sin(waveAngle) * scale; //scale the -1 to 1 up
float angle = map(i, 0, resolution, 0, TWO_PI * 156); //multiply for weirdness
float circleOffsetX = cos(angle) * (radius + waveOffset); //xposition
float circleOffsetY = sin(angle) * (radius + waveOffset); //yposition
float x = circleX + circleOffsetX;
float y = circleY + circleOffsetY;
ellipse(x, y, circleW, circleH);
}
}
example 3:
float resolution;
float radius = 100;
float circleX;
float circleY;
float circles;
float offset;
void setup() {
size(700, 700);
circleX = 0;
circleY = 0;
}
void draw() {
fill(0,0,0,25);
rect(0,0,width,height);
translate(width/2, height/2);
fill(255, 255, 0);
noStroke();
offset++;
resolution = map(cos(offset*0.0002), -1, 1, 2, 200);
circles = 100;
beginShape();
noFill();
for (int i = 0; i < resolution; i++) {
float scale = 400;
float waveAngle = map(i, 0, resolution, 0, TWO_PI * circles);
float waveOffset = sin(waveAngle) * scale; //scale the -1 to 1 up
float angle = map(i, 0, resolution, 0, TWO_PI * 156); //multiply for weirdness
float circleOffsetX = cos(angle) * (radius + waveOffset); //xposition
float circleOffsetY = sin(angle) * (radius + waveOffset); //yposition
float x = circleX + circleOffsetX;
float y = circleY + circleOffsetY;
stroke(255);
//line(x, y, 0, 0);
vertex(x,y);
}
endShape(CLOSE);
}
reference:
search "mandala" on
https://www.openprocessing.org/
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言