2019年12月12日 星期四

06160396_互動技術_W13

1.這是類似小畫家的程式碼是可以讓我們用滑鼠在上面畫畫,並且左邊是CLIENT端,而右邊是SERVER端
client的程式碼如下
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");
  }
}
server的程式碼如下
import processing.net.*;
Server server=null;
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) print(now);
  }
}

沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

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