저번 주 상현이 형이 알려준 식대로 프로그래밍하는 습관을 들이기 위해 해봤습니다.
=======================================
float mx;
float my;

void setup() {
size(400, 400);
colorMode(RGB, 100);
smooth();
frameRate(25);
}

void draw() {
background(100);
float a = 2.2;// Acceleration

float x = mouseX; //mouse x
float y = mouseY; //mouse y

float dx = x - mx; //distance
if(abs(dx) > 1) {
mx = x - dx/a;//move to mousex
}
float dy = y - my;
if(abs(dy) > 1) {
my = y - dy/a;
}

noStroke();
fill(0);
ellipse(mx, my, 30, 30);

}
====================
이런 식으로 좀더 부드러운 운동을 만들기 위해 공을 또 다른 공이 따라 다니는 것을
만들수도 있습니다. 응용해서 해보시길~
Posted by 알 수 없는 사용자
int value = mouseX;
void setup(){
size(800,800);
colorMode(RGB,255);
frameRate(30);
}
void draw(){
background(255,255,255);
fill(mouseX ,mouseY ,value);
noStroke();
rect(mouseX, mouseY,30,30);

}
void mousePressed() {
if(value == 0) {
value =255;
}else{
value = 0;
}
}
=======================================

int value = 0;
void setup(){
size(800,800);
colorMode(RGB,255);
frameRate(30);
}
void draw(){
background(255,255,255);

fill(mouseX/10,mouseY/10,(mouseX+mouseY)/10);
noStroke();
rect(mouseX, mouseY,mouseX/20,mouseY/20);
}
Posted by 알 수 없는 사용자
PImage a;

void setup() {
  a=loadImage("a.jpg");
  size(200,200);
}
void draw()
{
  background(255,255,255);
  image(a,mouseX-100, mouseY-100);

if(mousePressed == true) {
  fill(200);
  rect(mouseX-100,mouseY-100,200,200);
}else{
image(a,mouseX-100, mouseY-100);
}

}
 

Posted by 알 수 없는 사용자
--출석: 김정운, 김남윤, 전주영, 유승환,변수홍, 최주영, 김동후, 박상현, 양정애, 김아진, 진다 빈


--주제:저희조는 물리적인 현상을 구현해보자는 제안이 나와 공을 topview에서 본듯한 효과  를 만들어 보았습니다.


PImage ball;
int x,y;
float ballSize;
int stayOnHand;

float a,v,s; // a는 가속도 v는 속도 s 는 높이.
// float t;

void setup(){ 
  size(300,300);
  x=y=150;
  ballSize =50;
  a= -9.8;
  v= 0;
  s = 1000;
  stayOnHand = 1;
 
  ball = loadImage("ball.jpg");
}


void draw(){
  background(255);
 
 if (mousePressed == true ){
    if (stayOnHand != 0) stayOnHand = 0;
    else if (stayOnHand == 0) {v=-100;}
     dribble();
    }
 
  if (stayOnHand == 1){
    x= mouseX;
    y= mouseY;
   
  }else if (stayOnHand == 0){
    if (s<=0 ){v=-v-5;s=0;} // 공이땅에 닿은 경우 속도가 reverse, 이때 -5는 마찰에 의한 자연 감속
   // t = t+0.001;
   {
     v = v+ a;
    s = s + v;
   }
  }
 
 ballSize = s/10+10; 
 image(ball, x-(ballSize/2),y-(ballSize/2), ballSize, ballSize); 
}

void dribble(){
  if (mouseX < x && mouseX > x-ballSize/2){x=x+2;}
  if (mouseX > x && mouseX < x+ballSize/2){x=x-2;}
  if (mouseY < y && mouseY > y-ballSize/2){y=y+2;}
  if (mouseY > x && mouseY < y+ballSize/2){y=y-2;}
 
}
ball



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

수업중에 한것

 PImage ball;
 boolean isItOnHand;
 int x,y;
 
 float a,v,s;
 float ballSize;

void setup(){
  size(600,600);
  x=y= 300;
  isItOnHand = true;
  a = -9.8;
  v = 0;
  s = 1000;
  ballSize = 110;
  ball = loadImage("ball.jpg");
}

void draw(){
  background(255);
 
  if (mousePressed == true){
    if (isItOnHand == true) isItOnHand = false;
    else{
      if (mouseX >x-ballSize/2 && mouseX < x+ballSize/2)
        if (mouseY >y-ballSize/2 && mouseY < y+ballSize/2)
        dribble();
    }
  }
  
  if (isItOnHand == true){
    x = mouseX;// 마우스 따라 움직임
    y = mouseY;
  }else{
 
    if (s <= 0){v = -v-5;s= 0;}
    v = v + a;
    s = s + v;
    ballSize = s/10+10;
  
    // 공의 높이 계산
  }
 
  image(ball,x-(ballSize/2),y-(ballSize/2),ballSize,ballSize);
 
}

void dribble(){
  v = -100;
  if (mouseX < x && mouseX > x-ballSize/2) x = x+2;
  if (mouseX > x && mouseX < x+ballSize/2) x = x-2;
  if (mouseY < y && mouseY > y-ballSize/2) y = y+2;
  if (mouseY > y && mouseY < y+ballSize/2) y = y-2;
}

Posted by 알 수 없는 사용자
Etc2007. 10. 20. 23:25
azuremous
sans
JNANA
gngong
영국인
부엉
기린코
유승환

그 외 다른 sig멤버들도 가입하시기 바랍니다. 방법은 티스토리에 가입된 이메일 주소를
저에게 알려주시거나 talk 메뉴에 써주시면 되겠습니다. 가입이 안 된 상태에서도 보기와
talk에 글을 쓰는 것은 가능합니다.
티스토리 가입이 안되어 있을 시는 초대장을 받아 가입하시기 바랍니다.
Posted by 알 수 없는 사용자