1. Mandala Project Demo
Project reference:
http://sciencefictioninterfaces.tumblr.com/
2. object oriented programming:
https://processing.org/tutorials/objects/
https://www.youtube.com/watch?v=YcbcfkLzgvs
EXercise:
draw 'array-like' object with OOP
2017年11月30日 星期四
2017年11月16日 星期四
week 10. 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/
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/
2017年11月9日 星期四
week 9. using Recursion
float radius;
int segment = 6;
float centerX;
float centerY;
int recursionLevel = 3;
void setup(){
size(600,600);
background(0);
stroke(255);
centerX = height/2;
centerY = width/2;
}
void draw(){
background(0);
radius = dist(centerX, centerY, mouseX, mouseY);
spiral(centerX,centerY,radius,segment, recursionLevel);
}
void spiral(float x_c,float y_c, float r, int seg,int level){
level -= 1;
noFill();
ellipse(x_c,y_c,2*r,2*r);
for(int i =0;i < seg; i++){
float x = x_c+cos(i*2*PI/seg)*r;
float y = y_c+sin(i*2*PI/seg)*r;
point(x,y);
ellipse(x,y,2*r,2*r);
if(level > 0){
spiral(x,y,r,seg, level);
}
}
}
References:
https://www.youtube.com/watch?v=zoqTNpok6zw
int segment = 6;
float centerX;
float centerY;
int recursionLevel = 3;
void setup(){
size(600,600);
background(0);
stroke(255);
centerX = height/2;
centerY = width/2;
}
void draw(){
background(0);
radius = dist(centerX, centerY, mouseX, mouseY);
spiral(centerX,centerY,radius,segment, recursionLevel);
}
void spiral(float x_c,float y_c, float r, int seg,int level){
level -= 1;
noFill();
ellipse(x_c,y_c,2*r,2*r);
for(int i =0;i < seg; i++){
float x = x_c+cos(i*2*PI/seg)*r;
float y = y_c+sin(i*2*PI/seg)*r;
point(x,y);
ellipse(x,y,2*r,2*r);
if(level > 0){
spiral(x,y,r,seg, level);
}
}
}
The Illusions of Reality & The Basics of Sacred Geometry (The Patterns of Consciousness)
訂閱:
文章 (Atom)