week12-0
//使用class Card移動方塊
int x, y;
Card card1;
class Card {
int x, y;
Card(int _x, int _y) {
x = _x;
y = _y;
}
void draw() {
rect(x-50, y-75, 100, 150);
}
}
void setup() {
size(500, 400);
}
void draw(){
background(0);
if (card1 != null) {
card1.draw();
}
}
void mouseDragged(){
if (card1 == null) {
x = mouseX;
y = mouseY;
card1 = new Card(x, y);
} else {
x = mouseX;
y = mouseY;
card1 = new Card(x, y);
}
}
//強制停止關掉視窗
void setup(){
size(500,400);
}
int click=0;
int press=0;
void draw(){
if(press==1){
print(""+click);
press=0;
}
if(click==9){
exit();
}
}
void mousePressed(){
click+=1;
if(press==0)press+=1;
}
week12-1
//week12_01_libraries_sound_SoundFile_sound_isPlaying
import processing.sound.*;
SoundFile sound1,sound2;
int playing=2;
void setup(){
size(640,360);
background(255);
sound1 = new SoundFile(this,"Intro Song_Final.mp3");
sound2 = new SoundFile(this,"In Game Music.mp3");
}
void draw(){
if(sound1.isPlaying()){
playing=1;
}else if(sound1.isPlaying()){
playing=2;
}else{
if(playing==1)sound2.play();
else sound1.play();
}
}
//week12_02_bezier_sample
size(500,500);
noFill();
stroke(255, 102, 0);
line(340, 80, 40, 40);
line(360, 360, 60, 320);
stroke(0, 0, 0);
bezier(340, 80, 40, 40, 360, 360, 60, 320);
//(340,80)是第一條向量起始點(40,40)是第一條向量終點
//(60,320)是第二條向量起始點(360,360)是第二向量線終點
//week12_03_bezier_1_3_3_1_equation_mouseDragged_change_t
void setup() {
size(500, 500);
}
PVector p0=new PVector(340,80);
PVector p1=new PVector(40,40);
PVector p2=new PVector(360,360);
PVector p3=new PVector(60,320);
float t=0.0;
void draw() {
background(255);
noFill();
stroke(255, 102, 0);
line(340, 80, 40, 40);
line(360, 360, 60, 320);
stroke(0, 0, 0);
bezier(340, 80, 40, 40, 360, 360, 60, 320);
float x= p0.x*(1-t)*(1-t)*(1-t)+3*p1.x*t*(1-t)*(1-t)+3*p2.x*t*t*(1-t)+p3.x*t*t*t;
float y= p0.y*(1-t)*(1-t)*(1-t)+3*p1.y*t*(1-t)*(1-t)+3*p2.y*t*t*(1-t)+p3.y*t*t*t;
ellipse(x,y,10,10);
}
void mouseDragged(){
t+=0.01*(mouseX-pmouseX);
}
//week12_04_bezier_t0_for_t_many_ellipse
void setup() {
size(500, 500);
}
PVector p0=new PVector(120, 80);
PVector p1=new PVector(320, 20);
PVector p2=new PVector(320, 300);
PVector p3=new PVector(120, 300);
float t0=0.0;
void draw() {
background(255);
noFill();
stroke(255, 102, 0);
line(120, 80, 320, 20);
line(320, 300, 120, 300);
stroke(0, 0, 0);
bezier(120, 80, 320, 20, 320, 300, 120, 300);
for (float t= t0; t>=0; t-=0.05) {
float x= p0.x*(1-t)*(1-t)*(1-t)+3*p1.x*t*(1-t)*(1-t)+3*p2.x*t*t*(1-t)+p3.x*t*t*t;
float y= p0.y*(1-t)*(1-t)*(1-t)+3*p1.y*t*(1-t)*(1-t)+3*p2.y*t*t*(1-t)+p3.y*t*t*t;
ellipse(x, y, 10, 10);
}
}
void mouseDragged() {
t0+=0.01*(mouseX-pmouseX);
}
//week12_05_vezier_ArrayList_class_Ball_draw_ArrayList_add
void setup() {
size(500, 500);
}
PVector p0=new PVector(120, 80);
PVector p1=new PVector(320, 20);
PVector p2=new PVector(320, 300);
PVector p3=new PVector(120, 300);
float t0=0.0;
ArrayList<Ball> balls = new ArrayList<Ball>();
void draw() {
background(255);
noFill();
stroke(255, 102, 0);
line(120, 80, 320, 20);
line(320, 300, 120, 300);
stroke(0, 0, 0);
bezier(120, 80, 320, 20, 320, 300, 120, 300);
for (Ball ball : balls) {
ball.draw();
}
if (frameCount%50==0)balls.add(new Ball(p0, p1, p2, p3));
}
void mouseDragged() {
t0+=0.01*(mouseX-pmouseX);
}
class Ball {
PVector p0, p1, p2, p3;
float t=0.0;
Ball(PVector _p0, PVector _p1, PVector _p2, PVector _p3) {
p0 = _p0;
p1 = _p1;
p2 = _p2;
p3 = _p3;
}
void draw() {
float x= p0.x*(1-t)*(1-t)*(1-t)+3*p1.x*t*(1-t)*(1-t)+3*p2.x*t*t*(1-t)+p3.x*t*t*t;
float y= p0.y*(1-t)*(1-t)*(1-t)+3*p1.y*t*(1-t)*(1-t)+3*p2.y*t*t*(1-t)+p3.y*t*t*t;
ellipse(x, y, 10, 10);
t+=0.001;
}
}
//week12_06_vezier_ArrayList_balls_size_get_remove
void setup() {
size(500, 500);
}
PVector p0=new PVector(120, 80);
PVector p1=new PVector(320, 20);
PVector p2=new PVector(320, 300);
PVector p3=new PVector(120, 300);
float t0=0.0;
ArrayList<Ball> balls = new ArrayList<Ball>();
void draw() {
background(255);
noFill();
stroke(255, 102, 0);
line(120, 80, 320, 20);
line(320, 300, 120, 300);
stroke(0, 0, 0);
bezier(120, 80, 320, 20, 320, 300, 120, 300);
for (Ball ball : balls) {
ball.draw();
}
if (frameCount%50==0)balls.add(new Ball(p0, p1, p2, p3));
if(balls.size()>0&&balls.get(0).t>1.0)balls.remove(0);
}
void mouseDragged() {
t0+=0.01*(mouseX-pmouseX);
}
class Ball {
PVector p0, p1, p2, p3;
float t=0.0;
Ball(PVector _p0, PVector _p1, PVector _p2, PVector _p3) {
p0 = _p0;
p1 = _p1;
p2 = _p2;
p3 = _p3;
}
void draw() {
float x= p0.x*(1-t)*(1-t)*(1-t)+3*p1.x*t*(1-t)*(1-t)+3*p2.x*t*t*(1-t)+p3.x*t*t*t;
float y= p0.y*(1-t)*(1-t)*(1-t)+3*p1.y*t*(1-t)*(1-t)+3*p2.y*t*t*(1-t)+p3.y*t*t*t;
ellipse(x, y, 10, 10);
t+=0.001;
}
}
沒有留言:
張貼留言