'Research Topics/Processing Code share'에 해당되는 글 28건

  1. 2009.08.01 Mac에서 인식되는 웹캠들
  2. 2009.04.23 [Processing] Direct Print without dialog box
  3. 2008.05.10 [080510] 두더지게임 최종. 1
  4. 2008.05.07 두더지게임 수정 (김유정)
  5. 2008.05.03 [과제080503] 함경석
  6. 2008.04.27 [과제080426] 김유정 3
  7. 2008.04.26 [과제080426] 박정은
  8. 2008.04.20 [과제080419] 이정은
  9. 2008.04.20 [과제080419] 한재석
  10. 2008.04.20 [과제080419] 함경석


Mac 에서도 인식이 잘 되는 웹캠들을 소개합니다.

작년 전시 때는 아래 보이는 네이버캠 플러스를 많이 사용했습니다.
따로 설치 프로그램이 필요없이 꽂으면 바로 인식되는 점이 편하고,
AF기능이 있어서 자동으로 피사체에 초점을 맞춰줍니다.




아래 웹캠들은 제가 다른 작업을 하면서 알아본 웹캠들인데요, 역시 mac에서 인식이 되며, 네이버캠 처럼 별다른
설치 프로그램이 필요없습니다.

한가지 유의하실 점은 아래 네가지 제품 중 새빛마이크로 Vije Q-350만 AF 기능이 있고 나머지 3개는 수동으로 초점을
맞춰주어야 합니다.


개인적으론 AF기능이 들어있는 웹캠이 범용적으로 사용하기가 편합니다(얼굴을 인식한다거나, 피사체의 위치에 상관 없이
깨끗한 화질을 원하는 경우)

하지만 피사체와의 거리가 항상 일정한 경우라면 아래 3개의 웹캠을 써도 무방하겠지요. 가격도 싸고.^^;


이 5가지 외에도 mac에서 인식되는 웹캠이 또 있을 수 있으니, 다나와나 네이버 같은 곳에서 찾아보셔도 되구요.
그리고 네이버캠의 경우 꼭 네이버 캠 '플러스'여야 합니다. 매물이 거의 없기도 하지만 , 그냥 네이버캠은 mac을 지원안하는 것으로 알고 있습니다.
Posted by 알 수 없는 사용자

Processing 의 New Tab 을 클릭하여 PrintIt 이라는 이름으로 새로운 탭 생성 후 다음 코드 입력

// //////////////////////////////////////////////////////////////////////////
// Printer - Jpg and Text (more can easily be implemented)
//
// PrintService http://java.sun.com/j2se/1.4.2/docs/api/javax/print/PrintService.html
// DocFlavor http://java.sun.com/j2se/1.4.2/docs/api/javax/print/DocFlavor.html
// PrintRequestAttributeSet http://java.sun.com/j2se/1.4.2/docs/api/javax/print/attribute/PrintRequestAttributeSet.html
// Attribute http://java.sun.com/j2se/1.4.2/docs/api/javax/print/attribute/Attribute.html
//
//
// Yonas Sandbæk - http://seltar.wliia.org
// //////////////////////////////////////////////////////////////////////////

import javax.print.*;
import javax.print.attribute.*;
import com.sun.image.codec.jpeg.*;

class PrintIt{
  PrintService[] services;
  PrintService service;
  DocFlavor docflavor;
  Doc myDoc;
  PrintRequestAttributeSet aset;
  DocPrintJob job;
  PrintIt(){
    myDoc = null;
    job = null;
    services = null;
    setService(PrintServiceLookup.lookupDefaultPrintService());
    setDocFlavor(DocFlavor.BYTE_ARRAY.AUTOSENSE);
    aset =  new HashPrintRequestAttributeSet();
  }

  void setService(PrintService p)
  {
    service = p;
  }
 
  void setDocFlavor(DocFlavor d)
  {
    docflavor = d; 
  }

  void listPrinters(){
    services = PrintServiceLookup.lookupPrintServices(null, null);
    for (int i = 0; i < services.length; i++) {
    System.out.println(services[i].getName());
    DocFlavor[] d = services[i].getSupportedDocFlavors();
    for(int j = 0; j < d.length; j++)
      System.out.println("  "+d[j].getMimeType());
    }
    services = null;
  }

  // prints a given image
  void printJpg(PImage img){
    setDocFlavor(DocFlavor.BYTE_ARRAY.JPEG);
    print(bufferImage(img));
  }

  // prints a given string
  void printString(String s){
    setDocFlavor(DocFlavor.BYTE_ARRAY.AUTOSENSE);
    print(s.getBytes());
  }

  boolean print(byte[] b){
    if(!service.isDocFlavorSupported(docflavor)){
     println("MimeType: \""+docflavor.getMimeType()+"\" not supported by the currently selected printer");
     return false;
    }
   
    boolean ret = true;
    try{
    myDoc = new SimpleDoc(b, docflavor, null); 
    }
    catch(Exception e){
    println(e);
    ret = false;
    }   
   
    job = service.createPrintJob();
    try {
    job.print(myDoc, aset);
    }
    catch (PrintException pe) {
    println(pe);
    ret = false;
    }
   
    return ret;
  }
 
  // used with printJpg()
  byte[] bufferImage(PImage srcimg){
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    BufferedImage img = new BufferedImage(srcimg.width, srcimg.height, 2);
    img = (BufferedImage)createImage(srcimg.width, srcimg.height);
    for(int i = 0; i < srcimg.width; i++)
    {
    for(int j = 0; j < srcimg.height; j++)
    {
      int id = j*srcimg.width+i;
      img.setRGB(i,j, srcimg.pixels[id]);
    }
    }
    try{
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    JPEGEncodeParam encpar = encoder.getDefaultJPEGEncodeParam(img);
    encpar.setQuality(1,false);
    encoder.setJPEGEncodeParam(encpar);
    encoder.encode(img);
    }
    catch(FileNotFoundException e){
    System.out.println(e);
    }
    catch(IOException ioe){
    System.out.println(ioe);
    }
    return out.toByteArray();
  }

}

사용될 메인 코드에서는 다음과 같이 사용하면 됩니다.

글로벌하게 PrintIt 의 인스턴스 생성
PrintIt p = new PrintIt();

draw() 안에 다음과 같이 작성, 특정키보드를 누르면 현재화면이 프린트 되도록 함
  if(keyPressed && key == 'p') p.printJpg(get(0,0,width,height));




Posted by 알 수 없는 사용자
사용자 삽입 이미지
사용자 삽입 이미지
사용자 삽입 이미지



최종이라고 하기엔 허접하지만...

startcase라는 변수를 만들어서,
시작시 화면, 게임하면, 게임종료시 화면 3가지 나오게 만들어봤습니다.
(startcase =1이면 시작화면, 2면 게임화면 이런식으로)



void setup(){
size(400,500);
frameRate(60);
}



int [] datax = {0, 100, 200, 300,400};
int [] datay = {0, 100, 200, 300,400}; // 불러올 이미지 x,y좌표값 Arrays
int countFrame = 0;
int count = 0;
int mogurax, moguray;
int startcase = 1; // set screen mode
int colorfill = 0; // set font color



void draw(){


PFont font;
font = loadFont("Arial-BoldMT-30.vlw");
textFont (font);

PImage imgBackground;
imgBackground = loadImage("backmogura.png"); //배경풀밭
PImage startimage;
startimage = loadImage("start.png"); // start image
PImage mogura, mogura2;
mogura = loadImage("mogura.jpg"); //그냥 두더지
mogura2 = loadImage("mogura2.jpg"); //맞은 두더지


image(imgBackground,0,0); // 배경 풀밭 불러옴


if (startcase == 1) {
image(startimage,70,200,286,64);
if (mousePressed == true){
if (mouseButton == LEFT){

if (((mouseX>70)&&(mouseX<356)) && ((mouseY>200)&&(mouseY<264)))
{
startcase = startcase+1; // go to game screen
}
}
}
}
else if (startcase == 2) {



countFrame++;
if(countFrame >15)
{
mogurax = datax[int(random(0,3))];
moguray = datay[int(random(0,3))]; // 두더지 출현 위치 랜덤 16가지 지정
countFrame = 0;
}

fill(255,233,108);
text(count+" hits",300,430);
fill (colorfill,0,0);
text(" QUIT GAME ", 200,470);



image(mogura,mogurax,moguray); // 그냥 두더지가 나오게 함



if (mousePressed == true){
if (mouseButton == LEFT){
if (((mouseX>mogurax)&&(mouseX ((mouseY>moguray)&&(mouseY {
// mogurax, moguray가 이미지를 불러오는 기준점이 되기 때문에
// 각각 mouseX,mouseY의 범위를 mogurax,moguray에서 100 더해준데까지 잡았습니다

count = count+1;
image(mogura2,mogurax,moguray); // 맞는 두더지가 나오게 함
countFrame = 100;
}
}
}




if (((mouseX>200)&&(mouseX<380)) && ((mouseY>450)&&(mouseY<470)))
{
// Quit game위치
colorfill = 255;

if (mousePressed == true){
if (mouseButton == LEFT){

startcase = startcase+1; // go to score screen

}
}
}

}
else if ( startcase == 3 ) {

fill( 255,255,0);
text ("YOUR SCORE",100,150);
fill(0);
text ( count + " HITS", 150,180);
fill(colorfill,0,0);
text ("RETRY", 150,300);


if (((mouseX>150)&&(mouseX<200)) && ((mouseY>270)&&(mouseY<320)))
{
// if press Retry

colorfill = 150;

if (mousePressed == true){
if (mouseButton == LEFT){


startcase = startcase-1; // Return to game
count = 0; // Reset the score
colorfill = 0; // Reset font color

}
}
}

}

}
Posted by 알 수 없는 사용자

사용자 삽입 이미지

사용자 삽입 이미지





void setup(){
  size(400,400);

  // 마우스 체킹 빈도를 최대한 높여야 하므로 이값은 최대한 빠르게. 물론 컴퓨터속도에 의한 제한 있음
  frameRate(60);
}

int [] datax = {0, 100, 200, 300,400};
int [] datay = {0, 100, 200, 300,400}; // 불러올 이미지 x,y좌표값 Arrays
int countFrame = 0;
int count = 0;
int mogurax, moguray;


void draw(){


  PFont font;
font = loadFont("Arial-BoldMT-30.vlw");
textFont (font);


  PImage imgBackground;
  imgBackground = loadImage("backmogura.JPG"); //배경풀밭
  PImage mogura, mogura2;
  mogura = loadImage("mogura.jpg"); //그냥 두더지
  mogura2 = loadImage("mogura2.jpg"); //맞은 두더지

 image(imgBackground,0,0);                                 
 

  countFrame++;
 
  if(countFrame >15)
  {
    mogurax = datax[int(random(0,3))];
    moguray = datay[int(random(0,3))]; // 두더지 출현 위치 랜덤 16가지 지정
    countFrame = 0; 
  }

   fill(255,233,108);
   text(count,350,380);

 image(mogura,mogurax,moguray); // 그냥 두더지가 나오게 함

 if (mousePressed == true){
 if (mouseButton == LEFT){ 

   if (((mouseX>mogurax)&&(mouseX<mogurax+100)) && ((mouseY>moguray)&&(mouseY<moguray+100)))
    {
      // mogurax, moguray가 이미지를 불러오는 기준점이 되기 때문에
      // 각각 mouseX,mouseY의 범위를 mogurax,moguray에서 100 더해준데까지 잡았습니다

     count = count+1;
     image(mogura2,mogurax,moguray); // 맞는 두더지가 나오게 함
     countFrame = 100;
 
  }
 }
 }  
      
       if (countFrame>200) {
         countFrame=0;
       }
   
}

Posted by 알 수 없는 사용자



일전에 핸드폰에 있는 통화기록으로 만들어 볼 수 있는게 없을까 생각해 보았는데,

각각의 원을 통화한 전화번호로 놓고 원의 크기는 통화량, 원이 움직이는 속도는 통화 횟수에 비례하도록

하여 화면안에서 움직이면 재밌을 것 같아 만들어 본 것입니다만, 직장에 있을 때 해보던 거라 시간이 없어서

완성은 못하고 '이런 정도의 움직이 나오지 않을까' 하는 정도에서 그만두었습니다. ^^;;

이것에다가 지난 시간 배웠던  잔상이 남는 움직임을 추가해 본 것입니다.

저희가 배우지 않은 class란 것을 사용했습니다만, 기본적으로 지난 시간 배운 배열을 사용해서 각각의 원들을

만들고 원의 움직임에 필요한 함수를 따로 만들어 제작하였습니다.

(실행후 마우스로 화면을 클릭하면 원들이 움직이고 enter를 누르면 원들이 다시 배열됩니다. )
코드를 정리 못해서 좀 지저분 합니다;;


사용자 삽입 이미지
사용자 삽입 이미지
사용자 삽입 이미지

 Pcircle[] r ;
 int dn = int(random(10,50)); //decide pnumbers received and sent
 int keypad = 200;   //keypad size
 int keycheck = 1;


 void setup()
 {
  //size(147.196);
 size(147,196+keypad);
 background(255);
  smooth();
 
  float v;          // default speed
  int total = 250;   // sum of calls
 // int stotal = 3600; //sum of sec
  r = new Pcircle[dn]; // declare r of class Pcircle
 
  for(int i = 0; i<dn ; i++){
    r[i] = new Pcircle(width/2, (height-keypad)/2, i+1, int(random(1, total-(dn-i))), int(random(80, 3600)),int(random(80,220)),int(random(80,200)),int(random(20,220)),1,1,1,1);
    total = total - r[i].call;
   // stotal = stotal - r[i].sec;
  }
//framerate(70); 
/*for mouseaction(stop & go)*/
  noLoop();
/*for mouseaction(stop & go)*/ 
 }
//////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
 void draw(){
   fill(255, 12);
   rect(0,0,width,height);
   //background(255);
   if(keycheck == 1){
    for(int i = 0; i<dn ;i++){
     r[i].posUpdate();
    
    }
    for(int i = 0; i<dn ;i++){
     r[i].display();
    }
    basepad();
   }
   if(keycheck == -1){                    
     for(int i = 0; i<dn ;i++){
     r[i].lineUp();
    
    }
    for(int i = 0; i<dn ;i++){
     r[i].display();
    }
    basepad();
   }
  
 }
 ////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////
/*    mouseaction(stop & go)    */  
int lpcheck = 1;  // loop check variable
void mousePressed(){
  if(lpcheck == 1){
    loop();
   frameRate(70);
    lpcheck = lpcheck * (-1);
  }
  else{
    noLoop();
    lpcheck = lpcheck * (-1);
  }
}
/*    mouseaction(stop & go)        */


 class Pcircle
 {
     float xpos;   //x position of the circle
     float ypos;   //y position of the circle
     int   num;    // phone number
     int   call;   // number of calls
     int   sec ;   // total call time
     int tr,g,b;   // color of the circle
     int xdirection, ydirection;
     float v;      //velocity of the circle
     float cxpos;
     float cypos;
    
 
     Pcircle(float ixpos, float iypos, int inum, int icall, int isec, int itr, int ig, int ib,int ixdirection, int iydirection,float icxpos,float icypos) {
       xpos = ixpos;
       ypos = iypos;
       num = inum;
       call = icall;
       sec = isec;
       tr =itr;
       g = ig;
       b = ib;
       xdirection = ixdirection;
       ydirection = iydirection;
       cxpos = icxpos;
       cypos = icypos;
     
     }
   
     void display(){
       noStroke();
       fill(tr,g,b,190);
       //ellipse(xpos, ypos, 2*sqrt(sec), 2*sqrt(sec));  
       ellipse(xpos, ypos, sec/90, sec/90);
    
     }
     void posUpdate(){
      // float v = 50/sqrt(sec);      // velocity of the each circle
       float v = sqrt(call)/4;
       xpos = xpos + v*cos(360/dn*num)*xdirection;
       cxpos = xpos;
       ypos = ypos + v*sin(360/dn*num)*ydirection;
       cypos = ypos;
      
       if(xpos > (width-(sec/90)/2) || xpos<(sec/90)/2){
         xdirection *= -1;
       }
       if(ypos >((height-keypad)-(sec/90)/2) || ypos<(sec/90)/2){
         ydirection *= -1;
       }
     }
    
     void lineUp(){
       float a = (width/2)+60*cos(TWO_PI/dn*num);
       float b = ((height-keypad)/2)+60*sin(TWO_PI/dn*num);
       float ax = a - cxpos;
       float ay = b - cypos;
       if((abs(a-xpos)<=abs(ax/80)) && (abs(b-ypos)<=abs(ay/80))){
         xpos = a;
         ypos = b;
         }
         else{
           xpos = xpos+ax/80;
           ypos = ypos+ay/80;
           }
        }     
         
 }
 
 void keyPressed(){
   if(keyCode == ENTER){
     keycheck = -1;
   }
 }
        
    
      
 


  

Posted by 알 수 없는 사용자

사용자 삽입 이미지

두더지잡기 게임 계속 만들어보고 있는데..
될듯이 안되서 ㅠㅠ 도움을 받고자 여기에 올립니다 ㅋㅋ

어쩔때는 되고 어쩔때는 안되는데,
원래는 두더지 위에서 마우스를 클릭하면, 잡힌 두더지(?) 그림이 떴으면 좋곘는데...
마우스를 꾹~ 계속 클릭하고 있어야 될 때도 있고...
아예 안될때도 있고 하는데 어찌해야 할지 몰라서 일단 올려봅니다.

틀린데 좀 지적해주세요~ +_+;;

------------------------------------------------------------

void setup(){
  size(400,400);

}

int [] datax = {0, 100, 200, 300};
int [] datay = {0, 100, 200, 300}; // 불러올 이미지 x,y좌표값 Arrays
int x = 0, y = 0;

void draw(){

  PImage imgBackground;
  imgBackground = loadImage("backmogura.JPG"); //배경풀밭

  PImage mogura, mogura2;
  mogura = loadImage("mogura.jpg"); //그냥 두더지
  mogura2 = loadImage("mogura2.jpg"); //맞은 두더지

 image(imgBackground,0,0);
 
  frameRate(1); //이게 높아지면 난이도가 상승ㅋㅋ
 
   
  int mogurax = datax[int(random(0,3))];
  int moguray = datay[int(random(0,3))]; // 두더지 출현 위치 랜덤 16가지 지정
 

  image(mogura,mogurax,moguray); // 그냥 두더지가 나오게 함
 
 if (mouseButton == LEFT){ 

   if (((mouseX>mogurax)&&(mouseX<mogurax+100)) && ((mouseY>moguray)&&(mouseY<moguray+100)))
    {
      // mogurax, moguray가 이미지를 불러오는 기준점이 되기 때문에
      // 각각 mouseX,mouseY의 범위를 mogurax,moguray에서 100 더해준데까지 잡았습니다

 image(mogura2,mogurax,moguray); // 맞는 두더지가 나오게 함
  }
 
 }  
    
}

Posted by 알 수 없는 사용자


void setup() { size(500, 300); } int x=200, y=150; // 도형 처음 위치 int bx = 0, by = 0; // bar init void draw() { background(255); // 배경 흰색칠 x = constrain(x, 0,450); y = constrain(y, 20,280); if (keyPressed == true) // 키가 눌렸으면 { if(key == CODED) // 키보드 특수키 (ALT, CONTROL, SHIFT, UP,DOWN,LEFT,RIGHT) 이면 { if (keyCode == LEFT) // 왼쪽방향키인 경우 { x = x-1; // x 좌표 -1 해준다 } else if (keyCode == RIGHT) // 오른쪽방향키인 경우 { x = x+1; // x좌표 +1 해준다 } else if (keyCode == UP) // 윗방향키인 경우 { y = y-1; // y좌표 -1 해준다 } else if (keyCode == DOWN) // 아래방향키인 경우 { y = y+1; // y좌표 +1 해준다 } else if (keyCode == SHIFT) { bx = x+24; by = y-15; strokeWeight(5); stroke(0); line(bx, by, bx,0); } else if (keyCode == ALT) { bx = x+5; by = y; stroke(80); strokeWeight(1); line(bx,by,bx,0); line(bx+40,by,bx+40,0); } } } noStroke(); fill(100); rect(x, y, 50, 20); // 좌표 x, y 위치에 50x50 크기 네모 그리기 rect(x+17, y-15,16,15); }
Posted by 알 수 없는 사용자

사용자 삽입 이미지
사용자 삽입 이미지
사용자 삽입 이미지
사용자 삽입 이미지

void setup()
{
 size(500,500); 
  
  smooth();
  noStroke();     
}


int x;
int y=0;
int colorVar1=1,colorVar2=200,colorVar3=250;
float z=PI/500;
void leaf(int x, int y, int size, int dir)
{
pushMatrix();
translate(x, y);
scale(size);
beginShape();
vertex(1.0*dir, -0.7);
bezierVertex(1.0*dir, -0.7, 0.4*dir, -1.0, 0.0, 0.0);
bezierVertex(0.0, 0.0, 1.0*dir, 0.4, 1.0*dir, -0.7);
endShape();
popMatrix();
}


void draw(){
  background(255);  
  int a = 100;
 translate(50,50);
  for (x=0;x<100;x=x+1)
 if ( (z>0) || (z<PI/400) ){

    rotate(z);
   scale(1.05);

  colorVar1 = int(random( 255));
  colorVar2 = int(random(100, 250));
  colorVar3 = int(random(100, 255));
 
  fill(colorVar1, colorVar2, colorVar3, a);
    leaf(40,10,35,1);
   
  
}
 z=z+PI/1000;
}

Posted by 알 수 없는 사용자

사용자 삽입 이미지
사용자 삽입 이미지


float angle = 0.0;

void setup(){
  size(500,400);
  background(255);
  noStroke();
  smooth();
  frameRate(10);
}

void draw(){
  background(255);
  fill(190);
  rect(0,365, 500,400);
 
  PFont font;
  font = loadFont("BankGothic-Medium-48.vlw");
  textFont(font);
  fill(0);
  textSize(30);
  textAlign(RIGHT);
  text("sadi pd1 Han", 490, 390);

fill(255);

rythme( -PI/700, 150, 170);
rythme( PI/1000, 110, 170);
rythme( PI/650, 150, 190);
rythme( PI/1600, 90, 180);


}


void rythme( float v_angle, int waveSize, float offset) {
  for (int waveX = 0; waveX <= width ; waveX +=20){
  float unitSize = random(5,30);
  float waveY = offset + (sin(angle)* waveSize);
  fill(random(235), random(235), random(235), random(235));
  ellipse(waveX, waveY, unitSize, unitSize); 
  angle += v_angle;
  }
}

void mousePressed(){
  noLoop();
}

void mouseReleased(){
  loop();
}


 

Posted by 알 수 없는 사용자

사용자 삽입 이미지
사용자 삽입 이미지
사용자 삽입 이미지


void setup(){
  size(400,400,P3D);
  frameRate(100);
}
float i = 0.0; // rotate speed
int r = int(random(255)); // initial RGB value
int g = int(random(255));
int b = int(random(255));
int rt = r;
int gt = g;
int bt = b;
void draw(){
   background(255);
  
   fill(r,g,b,100);                 //setting box color
   stroke(r,g,b,100);
                                // random rgb color and iteration
   if(( r >= rt) || (r <= 0)) { // red
     rt = r;
     r = r + 1;
   }
   if(( r>= 255) || (r < rt)) {
     rt = r;
     r = r - 1;
   }

    if(( g >= gt) || (g <= 0)) { // green
     gt = g;
     g = g + 1;
   }
   if(( g>= 255) || (g < gt)) {
     gt = g;
     g = g - 1;
   }  
  
   if(( b >= bt) || (b <= 0)) { // blue
     bt = b;
     b = b + 1;
   }
   if(( b>= 255) || (b < bt)) {
     bt = b;
     b = b - 1;
   }  
  
   i += 0.01;
   translate(width/2, height/2 , 0);
   rotateY(i);
   box(100);
   if(i > TWO_PI) {
    i = 0.0;
  }
}


 

Posted by 알 수 없는 사용자