2019年12月12日 星期四

WEEK14

今天天氣晴12/12
這次教的程式碼
import processing.net.*;
Client client;
void setup(){
  size(300,300);
  client = new Client(this,"127.0.0.1",7777);
}
void draw(){
  if(mousePressed){
   line(mouseX,mouseY,pmouseX,pmouseY);
   client.write(mouseX+" "+mouseY+" "+pmouseX+" "+pmouseY+"\n");
  }
}
上面是服務端要先開這個。
下面是客戶端
import processing.net.*;
Server server=null;這邊是將Server或是Client先設為空值
Client client=null;
void setup(){
  size(300,300);
  server = new Server(this,7777);
}
void draw(){
   Client temp = server.available();
   if(temp !=null){
    client = temp; 
   }
   if(client !=null){
     String now=client.readString();
     if(now!=null) {
       String []xyxy = splitTokens(now);
       line(int(xyxy[0]),int(xyxy[1]),int(xyxy[2]),int(xyxy[3]));
       }
   }
}
運用連線將A畫,畫到B的地方,讓兩個有所連接
紅色的為連線程式碼。
第三個程式碼
import processing.net.*;
Client client;
ArrayList<PVector>points;
void setup(){
  size(300,300);
  client = new Client(this,"120.125.70.32",7777);
  points= new ArrayList<PVector>();
}
void draw(){
  background(255);
  for(int i=0;i<points.size();i++){
    ellipse(points.get(i).x,points.get(i).y,5,5); 
  }
}
void mouseDragged(){
  if(mouseButton==LEFT)points.add(new PVector(mouseX,mouseY));
  上面是畫出來。
  if(mouseButton==RIGHT)points.remove(points.size()-1);
  這邊是擦掉最後一個畫圖。
}
用P語言當小畫家然後若是畫錯可以消除。

下面的有點忘記先寫上來
import processing.net.*;
Server server=null;
Client client=null;
void setup(){
  size(300,300);
  server = new Server(this,7777);
}
void draw(){
  background(255);
   Client temp = server.available();
   if(temp !=null){
    client = temp; 
   }
   if(client !=null){
     String now=client.readString();
     if(now!=null) {
       String []xyxy = splitTokens(now);
       for(int i=0;i< xyxy.length;i+=4)
       line(int(xyxy[i+0]),int(xyxy[i+1]),int(xyxy[i+2]),int(xyxy[i+3]));
       }
   }
}

沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

回顧這學期的作品:  期中作業:LANDING:PLANET 賣點&特點: 炫麗的特效 物理(星球重力及降落)及粒子系統(噴射) 世界地圖可根據視角縮放 困難點: 重寫3次最終改寫成物件導向的CLASS寫法...