2016年11月29日 星期二
week 12, array objects
https://processing.org/examples/arrayobjects.html
Exercise:
1.
change 1-dimension array into 2-dimension
Module [] mods; v.s. Module[][] mods;
2. change objects into 3D
3. Change update() to respond to mouseX, mouseY
Sample codes for 2D array of objects
---------------------------------------------------------
int unit = 40;
int count;
int wideCount;
int highCount;
Module[][] mods;
void setup() {
size(640, 360, P3D);
lights();
//noStroke();
wideCount = width / unit;
highCount = height / unit;
//count = wideCount * highCount;
mods = new Module[highCount][wideCount];
// int index = 0;
for (int y = 0; y < highCount; y++) {
for (int x = 0; x < wideCount; x++) {
mods[y][x] = new Module(x*unit, y*unit, unit/2, unit/2, random(0.05, 0.8), unit);
}
}
}
void draw() {
background(0);
for (int y = 0; y < highCount; y++) {
for (int x = 0; x < wideCount; x++) {
mods[y][x].update();
mods[y][x].display();
}
}
/* for (Module mod : mods) {
mod.update();
mod.display();
}
*/
}
class Module {
int xOffset;
int yOffset;
float x, y;
int unit;
int xDirection = 1;
int yDirection = 1;
float speed;
// Contructor
Module(int xOffsetTemp, int yOffsetTemp, int xTemp, int yTemp, float speedTemp, int tempUnit) {
xOffset = xOffsetTemp;
yOffset = yOffsetTemp;
x = xTemp;
y = yTemp;
speed = speedTemp;
unit = tempUnit;
}
// Custom method for updating the variables
void update() {
}
// Custom method for drawing the object
void display() {
fill(255);
ellipse(xOffset + x, yOffset + y, 6, 6);
pushMatrix();
translate(xOffset, yOffset, -random(100));
rotateY(1.25);
rotateX(-0.4);
box(30);
popMatrix();
}
}
2016年11月22日 星期二
2016年11月8日 星期二
week 9. abstract machine
Turing machine
abstract machine
infosthetic physical
dataisnature
ACG at MIT concept film: visual machine
curve
Q & A , review
abstract machine in Processing
Midterm :
3 pairs of abstract machine with contrasts
deadline Nov. 16, 2016
a pair of machine sample codes:
void setup()
{
size(1200, 400);
fill(0,0,0);
rect(0,0,width/2, height);
fill(128,128,128);
rect(width/2, height, width, height);
}
void draw()
{
if (mouseX< width/2)
{
machine1();
}
else
{
machine2();
}
}
void machine1()
{
if (mousePressed)
{
fill(0,0,0);
rect(0,0,width/2, height);
fill(255, 255,255);
rect(mouseX, mouseY, 10, 10);
}
}
void machine2()
{
if (mousePressed)
{
fill(128,128,128);
rect(width/2, 0, width, height);
fill(255, 255,255);
ellipse(mouseX, mouseY, 20, 20);
}
}
2016年11月2日 星期三
week 8. NTUST Logo
week 8. rotate
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);
radius = 50;
pushMatrix();
translate(centerX, centerY);
rotate(frameCount / 50.0);
spiral(0,0,radius,segment, recursionLevel);
popMatrix();
}
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);
}
}
}
2016年11月1日 星期二
week 8. rotate
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);
radius = 50;
pushMatrix();
translate(centerX-100, centerY);
rotate(frameCount / 50.0);
spiral(0,0,radius,segment, recursionLevel);
popMatrix();
}
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
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);
}
}
}
see example: https://processing.org/examples/regularpolygon.html
EX: 創造一個陣列,讓每個物件旋轉。
week 8. rotate
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);
radius = 50;
pushMatrix();
translate(centerX, centerY);
rotate(frameCount / 50.0);
spiral(0,0,radius,segment, recursionLevel);
popMatrix();
}
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{
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);
}
}
}
EX: 創造一個陣列,讓每個物件旋轉。
week 8. rotate
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);
radius = 50;
pushMatrix();
translate(centerX, centerY);
rotate(frameCount / 50.0);
spiral(0,0,radius,segment, recursionLevel);
popMatrix();
}
void spiral(float x_c,float y_c, float r, int segm, int level){
level -= 1;
noFill();
ellipse(x_c,y_c,2*r,2*r);
for(int i =0; i
float y = y_c+sin(i*2*PI/segm)*r;
point(x,y);
ellipse(x,y,2*r,2*r);
if(level>0){
spiral(x,y,r,segm, level);
}
}
}
EX: 創造一個陣列,讓每個物件旋轉。
week 8. rotate
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);
radius = 50;
pushMatrix();
translate(centerX-100, centerY);
rotate(frameCount / 50.0);
spiral(0,0,radius,segment, recursionLevel);
popMatrix();
}
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);
}
}
}
EX: 創造一個陣列,讓每個物件旋轉。