Processing=007=arraylist

Page 1

Processing

07 ArrayList & Class 矩陣列 以及 克拉斯


Little Warm-up 一點點暖身


http://blog.algorith micdesign.net/


http://computationalmatter.com/Magneto


How to Draw it



import peasy.test.*; import peasy.org.apache.commons.math.*; import peasy.*; import peasy.org.apache.commons.math.geometry.*; PeasyCam cam; void setup(){ size(500,500,P3D); cam = new PeasyCam(this,0,0,0,500); } void draw(){ background(0); for(int i =0; i< 125; i+=25){ for(int j=0; j<125; j+=25){ for(int k=0; k<125; k+=25){ pushMatrix(); translate(i,j,k); if((i+j+k)%3==1){ box(20); } else{ sphereDetail(50); sphere(20); } } } } }



import peasy.test.*; import peasy.org.apache.commons.math.*; import peasy.*; import peasy.org.apache.commons.math.geometry.*; PeasyCam cam; void setup(){ size(500,500,P3D); cam = new PeasyCam(this,0,0,0,500); } void draw(){ background(0); noStroke(); //stroke(255); for(int i =0; i< 125; i+=25){ for(int j=0; j<125; j+=25){ for(int k=0; k<125; k+=25){ pushMatrix(); fill(i,j,k); translate(i,j,k); if((i+j+k)%3==1){ box(20); } else{ sphereDetail(10); sphere(20); } popMatrix(); } } } }


Add the Slider



void draw() {

import peasy.*; import controlP5.*; float sphereSize = 20; float boxSize = 20; PeasyCam cam; ControlP5 controlP5; PMatrix3D currCameraMatrix; PGraphics3D g3;

void setup() { size(800,600,P3D); g3 = (PGraphics3D)g; cam = new PeasyCam(this, 600); controlP5 = new ControlP5(this); controlP5.addSlider("sphereSize",20,100,10,10,200,20); controlP5.addSlider("boxSize",20,100,10,40,200,20); controlP5.setAutoDraw(false); }

if (controlP5.window(this).isMouseOver()) { cam.setActive(false); } else { cam.setActive(true); } background(0); noStroke(); for(int i =0; i< 125; i+=25){ for(int j=0; j<125; j+=25){ for(int k=0; k<125; k+=25){ pushMatrix(); fill(i,j,k); translate(i,j,k); if((i+j+k)%3==1){ box(boxSize); } else{ sphereDetail(10); sphere(sphereSize); } popMatrix(); } } } gui(); }

Put your code here

void gui() { currCameraMatrix = new PMatrix3D(g3.camera); camera(); controlP5.draw(); g3.camera = currCameraMatrix; }


Array 矩陣


0

Like a bag to put things in. But with certain Amount 像個袋子 可是只能裝特定數量

1

2 5 3 4

6 Array


Declare Array 宣告陣列

Function bag name Open bag

Things that side the bag

Close bag

int[]x = { 200,100,300,500 }; this is an array called “x” and there are all integers inside of it. 這是一個陣列X 裡面放的是整數


void setup(){ size(500,500); smooth(); } void draw(){ background(0); int [] x1 = {200,400,300}; int [] y1 = {300,400,200}; ellipse(x1[0], y1[0], 200, 200); ellipse(x1[1], y1[1], 100, 100); ellipse(x1[2], y1[2], 50, 50); }

x1[0]=200, x1[1]=400, x1[2]=300 y1[0]=300, y1[1]=400, x1[2]=200



Conceptually talking about

ArrayList 概念上說明 矩陣列


ArrayList


Putting more Balls in the bag

And still, we can pick up the ball

可以不斷在袋子 裡加東西 仍舊 可以取出我們要 的那一顆 ArrayList


Conceptually talking about

CLASS 概念上說明 克拉斯


Class

Structure Data

Function

OBJECT white

Color Legs (Long or Short)

DOG

RUN();

ears (Long or Short)

BARK();

Length (Long or Short)

JUMP();

blacky

Weight (heavy, light) spot


name

class dog{

open

//declare global variables int legs,color,size; //input value dog( int _legs, int _color, int _size){ legs = _legs; color = _color; size = _size; }

//function of the class(what this class can do) void run(){ run as a dog; }

}

close


ArrayList circleList; void setup(){ size(500,500); smooth(); circleList = new ArrayList(); }

class pulse{ PVector loc; float randomR; pulse(PVector _loc, float _randomR){ loc = _loc; randomR = _randomR; } }

Basic Setup 基本設定


ArrayList circleList; void setup(){ size(500,500); smooth(); circleList = new ArrayList(); }

Making Object 產生物件

void draw(){ PVector location = new PVector(random(0,width), random(0,width), 0); pulse heart; heart = new pulse( location, random(20,200)); } class pulse{ PVector loc; float randomR; pulse(PVector _loc, float _randomR){ loc = _loc; randomR = _randomR; } }


ArrayList circleList; void setup(){ size(500,500); smooth(); circleList = new ArrayList(); } void draw(){ PVector location = new PVector(random(0,width), random(0,width), 0); pulse heart; heart = new pulse( location, random(20,200)); heart.display(); } class pulse{ PVector loc; float randomR;

pulse(PVector _loc, float _randomR){ loc = _loc; randomR = _randomR; } void display(){ fill(random(0,255),random(0,255),random(0,255)); ellipse(loc.x, loc.y, randomR, randomR); } }

Adding Function 增加功能



ArrayList circleList; void setup(){ size(500,500); smooth(); circleList = new ArrayList(); } void draw(){ } void mousePressed(){ PVector location = new PVector(random(0,width), random(0,width), 0); pulse heart; heart = new pulse( location, random(20,200)); circleList.add(heart); } class pulse{ PVector loc; float randomR;

pulse(PVector _loc, float _randomR){ loc = _loc; randomR = _randomR; } void display(){ fill(random(0,255),random(0,255),random(0,255)); ellipse(loc.x, loc.y, randomR, randomR); } }

Control by Mouse 用滑鼠控制


Make the Pulse ArrayList circleList; void setup(){ size(500,500); smooth(); circleList = new ArrayList(); }

class pulse{ PVector loc; float randomR; float t =0; pulse(PVector _loc, float _randomR){ loc = _loc; randomR = _randomR; }

void draw(){ background(0); for(int i=0; i<circleList.size(); i++){ pulse newHeart = (pulse)circleList.get(i); newHeart.beat(); } } void mousePressed(){ PVector location = new PVector(mouseX, mouseY, 0); pulse heart; heart = new pulse( location, random(20,200)); circleList.add(heart); }

製造心跳

void display(){ ellipse(loc.x, loc.y, randomR, randomR); } void beat(){ ellipse(loc.x, loc.y, sin(t)*randomR, sin(t)*randomR); t =t +1; if(t>2*PI){t=0;} } }



Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.