2020年12月21日 星期一

week ╯15 ╮

 week15👅💓👿😡


♥輸入一張圖片,印出pt的x=10

♥程式碼-

size(600,600);

PImage img=loadImage("img.jpg");

PVector pt=new PVector(10,20,0);

image(img,0,0);//顯示image

println(pt.x);//印出pt的x

float userX=10,userY=20,userZ=0;

float use2X=30,user2Y=40,user2Z=0;///before

PVector user=new PVector(10,20,0);

PVector user2=new PVector(30,40,0);//after


---

♥畫出一顆球

♥程式碼-

PVector user;

void setup(){

  size(600,600);

  user = new PVector(10,20);

}

void draw(){

  background(255);

  ellipse( user.x,user.y,20,20):

}


---




♥Y為彈弓,拖移滑鼠就能射出球(無限)

♥程式碼-

PVector user;

PVector Y,v=null;

void setup(){

  size(600,400);

  user = new PVector(100,300);

  Y = new PVector(100,300);

}

void draw(){

  background(255);

  line( user.x,user.y,Y.x,Y.y);

  textSize(40);

  fill(255,0,0); text("Y",Y.x,Y.y);

  fill(255); ellipse( user.x,user.y,20,20);

  if(v!=null) user.add(v);

}

void mouseDragged(){

  user.x=mouseX;

  user.y=mouseY;

}

void mouseReleased(){

  PVector diff = PVector.sub(Y,user);

  v =diff.div(10);

}


---



♥會印出東西

♥程式碼-

void setup() {

 pinMode(2,INPUT_PULLUP);

 Serial.begin(9600);

}


void loop() {

  int x = analogRead(A0);

  int y = analogRead(A1);

  int sw = digitalRead(2);


  Serial.write(x);

  Serial.write('+');

  Serial.write(y);

  Serial.write('+');

  Serial.write(sw);

  Serial.write(' ');

  delay(20);

}

---

processing

♥程式碼-

PVector user;

PVector Y,v=null;

void setup(){

  size(600,400);

  user = new PVector(100,300);

  Y = new PVector(100,300);

}

void draw(){

  background(255);

  line( user.x,user.y,Y.x,Y.y);

  textSize(40);

  fill(255,0,0); text("Y",Y.x,Y.y);

  fill(255); ellipse( user.x,user.y,20,20);

  if(v!=null) user.add(v);

}

void mouseDragged(){

  user.x=mouseX;

  user.y=mouseY;

}

void mouseReleased(){

  PVector diff = PVector.sub(Y,user);

  v =diff.div(10);

}

---

♥程式碼-

void setup() {

 pinMode(2,INPUT_PULLUP);

 Serial.begin(9600);

}


void loop() {

  int x = analogRead(A0);

  int y = analogRead(A1);

  int sw = digitalRead(2);


  Serial.write(x/4);

  Serial.write(y/4);

  Serial.write(sw);

  delay(20);

}

---

processing

♥程式碼-

import processing.serial.*;

Serial myPort;

void setup(){

  size(256,256);

  myPort = new Serial(this,"COM4",9600);

}

int ballX=0, ballY=0;

void draw(){

  if(myPort.available()>=3){

    int x = myPort.read();

    int y = myPort.read();

    int sw = myPort.read();

    ballX = x;

    ballY = y;

  }

  ellipse( ballX, ballY, 10, 10);

}

---

♥程式碼-

import processing.serial.*;

Serial myPort;

void setup(){

  size(256,256);

  myPort = new Serial(this,"COM4",9600);

}

int ballX=0, ballY=0;

void draw(){

  if(myPort.available()>=3){

    int x = myPort.read();

    int y = myPort.read();

    int sw = myPort.read();

    ballX = x;

    ballY = y;

  }

  ellipse( ballX, ballY, 10, 10);

}


沒有留言:

張貼留言