블로그 이미지
Leeway is... the freedom that someone has to take the action they want to or to change their plans.
maetel

Notice

Recent Post

Recent Comment

Recent Trackback

Archive

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
  • total
  • today
  • yesterday

Category

2010. 9. 7. 17:29 Computer Vision
OpenCV 함수 cvFindChessboardCorners()와 cvDrawChessboardCorners() 사용


bool findChessboardCorners(const Mat& image, Size patternSize, vector<Point2f>& corners, int flags=CV_CALIB_CB_ADAPTIVE_THRESH+ CV_CALIB_CB_NORMALIZE_IMAGE)

Finds the positions of the internal corners of the chessboard.

Parameters:
  • image – Source chessboard view; it must be an 8-bit grayscale or color image
  • patternSize – The number of inner corners per chessboard row and column ( patternSize = cvSize(points _ per _ row,points _ per _ colum) = cvSize(columns,rows) )
  • corners – The output array of corners detected
  • flags

    Various operation flags, can be 0 or a combination of the following values:

    • CV_CALIB_CB_ADAPTIVE_THRESH use adaptive thresholding to convert the image to black and white, rather than a fixed threshold level (computed from the average image brightness).
    • CV_CALIB_CB_NORMALIZE_IMAGE normalize the image gamma with EqualizeHist before applying fixed or adaptive thresholding.
    • CV_CALIB_CB_FILTER_QUADS use additional criteria (like contour area, perimeter, square-like shape) to filter out false quads that are extracted at the contour retrieval stage.



file:///Users/lym/opencv/src/cv/cvcalibinit.cpp
https://code.ros.org/trac/opencv/browser/tags/2.1/opencv/src/cv/cvcalibinit.cpp



void drawChessboardCorners(Mat& image, Size patternSize, const Mat& corners, bool patternWasFound)

Renders the detected chessboard corners.

Parameters:
  • image – The destination image; it must be an 8-bit color image
  • patternSize – The number of inner corners per chessboard row and column. (patternSize = cvSize(points _ per _ row,points _ per _ colum) = cvSize(columns,rows) )
  • corners – The array of corners detected
  • patternWasFound – Indicates whether the complete board was found or not . One may just pass the return value FindChessboardCorners her



Learning OpenCV: Chapter 11. Camera Models and Calibration: Chessboards
381p


chessboard.bmp

640x480





console:
finding chessboard corners...
what = 1
chessboard corners: 215.5, 179
#0=(215.5, 179)    #1=(237.5, 178.5)    #2=(260.5, 178)    #3=(283.5, 177.5)    #4=(307, 177)    #5=(331.5, 175.5)    #6=(355.5, 174.5)    #7=(380.5, 174)    #8=(405.5, 173.5)    #9=(430.5, 172.5)    #10=(212.5, 201.5)    #11=(235.5, 201.5)    #12=(258, 200.5)    #13=(280.5, 200.5)    #14=(305.5, 199.5)    #15=(330, 198.5)    #16=(354.5, 198)    #17=(379.5, 197.5)    #18=(405.5, 196.5)    #19=(430.5, 196)    #20=(210, 224.5)    #21=(232.5, 224.5)    #22=(256, 223.5)    #23=(280, 224)    #24=(304, 223)    #25=(328.5, 222.5)    #26=(353.5, 222)    #27=(378.5, 221.5)    #28=(404.5, 221.5)    #29=(430.5, 220.5)    #30=(207, 247.5)    #31=(230.5, 247.5)    #32=(253.5, 247.5)    #33=(277.5, 247)    #34=(303, 247)    #35=(327, 246.5)    #36=(352, 246.5)    #37=(377.5, 246)    #38=(403.5, 245.5)    #39=(430, 245.5)    #40=(204.5, 271.5)    #41=(227.5, 271.5)    #42=(251.5, 271.5)    #43=(275.5, 271.5)    #44=(300, 272)    #45=(325.5, 271.5)    #46=(351, 271)    #47=(376.5, 271.5)    #48=(403, 271.5)    #49=(429.5, 271)    #50=(201.5, 295.5)    #51=(225.5, 295.5)    #52=(249.5, 296)    #53=(273.5, 296.5)    #54=(299, 297)    #55=(324, 296)    #56=(349.5, 296.5)    #57=(375.5, 296.5)    #58=(402.5, 296.5)    #59=(429, 297)   

finished









finding chessboard corners...
what = 0
chessboard corners: 0, 0
#0=(0, 0)    #1=(0, 0)    #2=(0, 0)    #3=(0, 0)    #4=(0, 0)    #5=(0, 0)    #6=(0, 0)    #7=(0, 0)    #8=(0, 0)    #9=(0, 0)    #10=(0, 0)    #11=(0, 0)    #12=(0, 0)    #13=(0, 0)    #14=(0, 0)    #15=(0, 0)    #16=(0, 0)    #17=(0, 0)    #18=(0, 0)    #19=(0, 0)    #20=(0, 0)    #21=(0, 0)    #22=(0, 0)    #23=(0, 0)    #24=(0, -2.22837e-29)    #25=(-2.22809e-29, -1.99967)    #26=(4.2039e-45, -2.22837e-29)    #27=(-2.22809e-29, -1.99968)    #28=(4.2039e-45, 1.17709e-43)    #29=(6.72623e-44, 1.80347e-42)    #30=(0, 0)    #31=(4.2039e-45, 1.45034e-42)    #32=(-2.2373e-29, -1.99967)    #33=(4.2039e-45, 2.52094e-42)    #34=(-2.2373e-29, -1.99969)    #35=(-2.22634e-29, -1.99968)    #36=(4.2039e-45, 1.17709e-43)    #37=(6.72623e-44, 1.80347e-42)    #38=(0, 0)    #39=(0, 1.80347e-42)    #40=(3.36312e-44, 5.46787e-42)    #41=(6.45718e-42, 5.04467e-44)    #42=(0, 1.80347e-42)    #43=(6.48101e-42, 5.48188e-42)    #44=(0, 1.4013e-45)    #45=(4.2039e-45, 0)    #46=(1.12104e-44, -2.22837e-29)    #47=(-2.22809e-29, -1.99969)    #48=(4.2039e-45, 6.72623e-44)    #49=(6.16571e-44, 1.80347e-42)    #50=(0, 0)    #51=(1.4013e-45, -2.27113e-29)    #52=(4.56823e-42, -1.99969)    #53=(4.2039e-45, -2.20899e-29)    #54=(-2.2373e-29, -1.9997)    #55=(-2.22619e-29, -1.99969)    #56=(4.2039e-45, 6.72623e-44)    #57=(-1.9997, 1.80347e-42)    #58=(0, -2.22957e-29)    #59=(-2.23655e-29, -2.20881e-29)   

finished










finding chessboard corners...
what = 0
chessboard corners: 0, 0
#0=(0, 0)    #1=(0, 0)    #2=(0, 0)    #3=(0, 0)    #4=(0, 0)    #5=(0, 0)    #6=(0, 0)    #7=(0, 0)    #8=(0, 0)    #9=(0, 0)    #10=(0, 0)    #11=(0, 0)    #12=(0, 0)    #13=(0, 0)    #14=(0, 0)    #15=(0, 0)    #16=(0, 0)    #17=(0, 0)    #18=(0, 0)    #19=(0, 0)    #20=(0, 0)    #21=(0, 0)    #22=(0, 0)    #23=(0, 0)    #24=(0, -2.22837e-29)    #25=(-2.22809e-29, -1.99967)    #26=(4.2039e-45, -2.22837e-29)    #27=(-2.22809e-29, -1.99968)    #28=(4.2039e-45, 1.17709e-43)    #29=(6.72623e-44, 1.80347e-42)    #30=(0, 0)    #31=(4.2039e-45, 1.45034e-42)    #32=(-2.2373e-29, -1.99967)    #33=(4.2039e-45, 2.52094e-42)    #34=(-2.2373e-29, -1.99969)    #35=(-2.22634e-29, -1.99968)    #36=(4.2039e-45, 1.17709e-43)    #37=(6.72623e-44, 1.80347e-42)    #38=(0, 0)    #39=(0, 1.80347e-42)    #40=(3.36312e-44, 5.46787e-42)    #41=(6.45718e-42, 5.04467e-44)    #42=(0, 1.80347e-42)    #43=(6.48101e-42, 5.48188e-42)    #44=(0, 1.4013e-45)    #45=(4.2039e-45, 0)    #46=(1.12104e-44, -2.22837e-29)    #47=(-2.22809e-29, -1.99969)    #48=(4.2039e-45, 6.72623e-44)    #49=(6.16571e-44, 1.80347e-42)    #50=(0, 0)    #51=(1.4013e-45, -2.27113e-29)    #52=(4.56823e-42, -1.99969)    #53=(4.2039e-45, -2.20899e-29)    #54=(-2.2373e-29, -1.9997)    #55=(-2.22619e-29, -1.99969)    #56=(4.2039e-45, 6.72623e-44)    #57=(-1.9997, 1.80347e-42)    #58=(0, -2.22957e-29)    #59=(-2.23655e-29, -2.20881e-29)   

finished







source code:
// Test: chessboard detection

#include <OpenCV/OpenCV.h> // frameworks on mac
//#include <cv.h>
//#include <highgui.h>

#include <iostream>
using namespace std;


int main()
{

    IplImage* image = cvLoadImage( "DSCN3310.jpg", 1 );
   
/*    IplImage* image = 0;
    // initialize capture from a camera
    CvCapture* capture = cvCaptureFromCAM(0); // capture from video device #0
    cvNamedWindow("camera");
                
    while(1) {
        if ( !cvGrabFrame(capture) ){
            printf("Could not grab a frame\n\7");
            exit(0);
        }
        else {
            cvGrabFrame( capture ); // capture a frame
            image = cvRetrieveFrame(capture); // retrieve the captured frame
*/           
//            cvShowImage( "camera", image );
            cvNamedWindow( "camera" );  cvShowImage( "camera", image );
   
            cout << endl << "finding chessboard corners..." << endl;
            CvPoint2D32f corners[60];
            int numCorners[60];
            //cvFindChessboardCorners(<#const void * image#>, <#CvSize pattern_size#>, <#CvPoint2D32f * corners#>, <#int * corner_count#>, <#int flags#>)
            int what = cvFindChessboardCorners( image, cvSize(10,6), corners, numCorners, CV_CALIB_CB_ADAPTIVE_THRESH );
            cout << "what = " << what << endl;
            cout << "chessboard corners: " << corners[0].x << ", " << corners[0].y << endl;            
       
    for( int n = 0; n < 60; n++ )
    {
        cout << "#" << n << "=(" << corners[n].x << ", " << corners[n].y << ")\t";
    }
    cout << endl;
       
            // cvDrawChessboardCorners(<#CvArr * image#>, <#CvSize pattern_size#>, <#CvPoint2D32f * corners#>, <#int count#>, <#int pattern_was_found#>)
    cvDrawChessboardCorners( image, cvSize(10,6), corners, 60, what );   
   
   
    cvNamedWindow( "chessboard" ); cvMoveWindow( "chessboard", 200, 200 ); cvShowImage( "chessboard", image );
    cvSaveImage( "chessboard.bmp", image );       
            cvWaitKey(0);
//        }
//    }
   
    cout << endl << "finished" << endl;
//   cvReleaseCapture( &capture ); // release the capture source
    cvDestroyAllWindows();
   
    return 0;
}





posted by maetel
2007. 11. 28. 16:46 Techne/Greenberg: Creative Code
Part One: Theory of Processing and Computational Art
Chapter 1: Code Art



algorithmic beauty
an apparant mathematical pattern
intuitive math
a common visual algorithmic literacy
randomization




Casey Reas
Ben Fry
John Maeda

computation; the procedure of calculating; determining something mathemetical or logical methods

The technical innocations of the day most often coincide with parallel developments in aesthetics. Early astrological and calendar systems, across many clultures, combined observed empirical data with richly expressive, mythological narratives as a way of interpreting and ultimately preserving and disseminating the data.

complex algorithmic patterns based upon mathemtatical principles

Qualitative notions of aesthetic beauty are combined with analytical systems for structuring visual data.

Giorgio Vasari
Filippo Brunelleschi
Piero della Francesca
Albert Du''rer
Leonardo da Vinci

Design by Numbers

The core expressive element of computing is at the lower level of computation, most accesible through direct programming.




Computer art history

Egyptian Ahmes Papyrus
Babylonian Salamis tablet (counting board)
Roman hand abacus
suan pan (Chinese abacus)
John Napier - logarithms
Edmund Gunter - pickett circular slide rule

Charles Babbage
Ada Lovelace
Analytical  Engine
 
Konrad Zuse
- Z1
John Atanasoff - Mark 1
ENIAC
UNIVAC
Grace M. Hopper


The higher-level symbolic abstraction, nearer to our natural language, allows the coder to think more naturally and thus gain programming literacy more easily.


Jasia Reichardt [The Computer in Art]

There were times in history when scientists, artists, philosophers, engineers, and so forth were all seen as integrated creative practitioners - not divided solely by their perceived utilitarian value in the marketplace.

Admiral Hopper

Mary Flanagan
    http://maryflanagan.com
RAPUNSEL project
    http://mrl.nyu.edu/rapunsel




Code artists

Ben Laposky
www.dam.org/laposky/index.htm
www.atariarchives.org/artist/sec6.php

    William Fetter coined first the term “computer graphics”.
    “oscillons” waveforms
    analog computer


John Whitney Sr.
www.siggraph.org/artdesign/profile/whitney/nowhitney.html
http://en.wikipedia.org/wiki/John_Whitney_(animator)

    the title sequence for Hitchcock's Vertigo
    <Catalog>
    “harmonic progression”
   

Herbert W. Franke
http://en.wikipedia.org/wiki/Herbert_W._Franke
www.dam.org/franke/index.htm
www.zi.biologie.uni-muenchen.de/~franke/

    speleology (the scientific study of caves)
    Ars Electronica Festival
    [Animation with Mathematica]


Lillian Schwartz
www.lillian.com

    Proxina Centauri, a kinetic sculpture
    1968 Machine Exhibition at the Museum of Modern Art (MOMA), New York
    Computerworld Smithsonian awards
    [The Computer Artist's Handbook]


Harold Cohen
www.kurzweilcyberart.com/aaron/hi_cohenbio.html
www.viewingspace.com/genetics_culture/pages_genetics_culture/gc_w05/cohen_h.htm
http://grandtextauto.gatech.edu/2003/06/17/harold-cohen-on-artist-programmers/

    artificial intelligence
    AARON
    Ray Kurzweil  www.kurzweilcyberart.com


Roman Verostko
www.verostko.com

    Gyorgy Kepes
    Hodos
    Jean-Pierre He'bert
    Ken Musgrave
    "Algorists"


George Legardy
www.georgelegrady.com

    Pockets Full of Memories


Mark Napier
http://potatoland.org

    Shredder
    Digital Landfall
    Feed
    riot


John F. Simon Jr.
http://numeral.com

    art appliances
    Plexiglas


John Maeda
www.maedastudio.com
www.media.mit.edu/people/bio_maeda.html
http://weblogs.media.mit.edu/SIMPLICITY/

    E. Rudge
    Nancy Allen
    Aesthetics + Computation Group at MIT
    Muriel Cooper
    Ron MacNeil
    Physical Language Workshop


Mary Flanagan
www.tiltfactor.org

    The Adventures of Josie True
    The RAPUNSEL project: a multiuser 3D game to teach middle school girls computer programming
    Art Journal
    Wide Angle
    Intelligent Agent
    Convergence
    Culture Machine


Casey Reas
http://reas.com

    the relationship between conceptual art and software art
    Jared Tarbell of Levitated
    Robert Hodgin of Flight 404
    William Ngan of Metaphorical.net
    {Software} Structures


Jared Tarbell
http://levitated.net
http://complexification.net


Ben Fry
http://benfry.com

    Altair 8800
    Computational Information Design
    Valence


Charles Csuri
http://old.siggraph.org/artdesign/profile/csuri/

Joshua Davis
www.joshuadavis.com

Andy Deck
http://artcontext.org

Amy Franceschini
www.futurefarmers.com

Ken Goldberg
http://ieor.berkeley.edu/~goldberg/index-flash.html

Jean-Pierre He'bert
http://hebert.kitp.ucsb.edu/
http://jeanpierrehebert.com/

John Klima
www.cityarts.com/

Mario Klingemann
http://www.quasimondo.com/

Ruth Leavitt
http://dam.org/leavitt/index.htm

Golan Levin
www.flong.com/

Manfred Mohr
www.emohr.com/

Colin Moock
www.moock.org/

Ken Musgrave
www.kenmusgrave.com/

Yugo Nakamura
http://yugop.com/

William Ngan
http://metaphorical.net/

Josh Nimoy
www.jtnimoy.net/

Josh On
www.futurefarmers.com/josh/

Robert Penner
www.robertpenner.com/


Ken Perlin
http://mrl.nyu.edu/~perlin/

Keith Peters
http://bit-101.com/

Amit Pitaru
http://pitaru.com/

Paul Prudence
www.transphormetic.com/

Daniel Rozin
http://smoothware.com/danny/

Karsten Schmidt
http://toxi.co.uk/

Manny Tan
www.uncontrol.com/

Martin Wattenberg
www.bewitched.com/

Marius Watz
http://unlekker.net/

Mark Wilson
http://mgwilson.com/


code-helper
zealots-JohnG
st33d
seltar
TomC
mflux
metaphorz
arielm
fjen
blprnt
flight404
shiffman
toxi
fry
REAS

posted by maetel
2007. 7. 18. 12:41 Code/NodeBox
The mission I chose:
사용자 삽입 이미지

David Hirmes - blobs01

from Flash Math Creativity


우선, blob 하나의 움직임을 코딩해 보자.
#hirmes_blobs01_0.0

size(400, 200)
speed(100)

def setup():
    global x
    global v
    global a
   
    global check
    global c

    x = 0
    v = 10
    a = -0.1*v
   
    check = 0
    c = 0

def draw():
    global x
    global v
    global a
   
    global check
    global c
     
    v += a
    x += v
   
    if x > WIDTH:
        x = 0
    if x < 0:
        x = WIDTH
   
    check += c
       
    if v < 0:
        v = 0
        a = 0
        c = 1
    if check == 40:
        v = 15
        a = -1
        check = 0
          
    oval(x, 50, 50, 50)
전에 배운 pattern에서 실마리를 얻어 새로운 pattern을 만들어 보았다.
내가 생각해도 good idea! 쿄쿄.


이것을 아래의 move 메쏘드에 적용하면 된다.  
원하는 결과를 위해서는 다른 색의 방울 두 개에 동시에 동일한 움직임을 주어야 했는데, 이를 위해 Blob 클래스에서 움직임을 주는 메쏘드(move)와 색을 넣어 그리는 메쏘드(ball)를 분리하는 것을 하나의 해결책으로 제시해 보았다.
# hirmes_blobs01_0.1

class Blob:
    def __init__(self):
        self.f = 0
        
        self.x0 = 20
        self.y0 = 100
        self.x1 = 100
        self.y1 = 120
        
        self.v = 10
        self.a = -0.1*self.v
        self.check = 0
        self.c = 0
        
    def move(self):
        self.v += self.a

        self.x0 += self.v
        self.x1 += self.v * 0.8

        ###borders     
        if self.x0 > WIDTH:
            self.x0 = 0
        if self.x1 > WIDTH:
            self.x1 = 0
        if self.x0 < 0:
            self.x0 = WIDTH
        if self.x1 < 0:
            self.x1 = WIDTH  
       
       ###pauses
        self.check += self.c
        
        if self.v < 0:
            self.v = 0
            self.a = 0
            self.c = 1

        if self.check == 40:
            self.v = 15
            self.a = -1
            self.check = 0
        
    def ball(self, d, r, g, b):                    
        fill(r, g, b)
        ovalc(self.x0, self.y0, d, d)
        ovalc(self.x1, self.y1, d, d)
        
       
size(400, 300)
speed(30)


def setup():
    global bb
    
    bb = Blob()

    
def draw():
    global bb
    
    bb.move()
    bb.ball(80, 1, 0, 0)
    bb.ball(70, 1, 1, 1)

def ovalc(cx, cy, w, h):
    x = cx-w/2
    y = cy-h/2
    oval(x, y, w, h)  


이제 방울 수를 늘려 보자.
# hirmes_blobs01_1.0

class Blob:
    def __init__(self):
        ###initial position
        self.x0 = random(-WIDTH,WIDTH)
        self.x1 = random(-WIDTH,WIDTH)
        self.x2 = random(-WIDTH,WIDTH)
        self.x3 = random(-WIDTH,WIDTH)
        self.x4 = random(-WIDTH,WIDTH)
        self.x5 = random(-WIDTH,WIDTH)
        self.x6 = random(-WIDTH,WIDTH)
        self.x7 = random(-WIDTH,WIDTH)
        self.x8 = random(-WIDTH,WIDTH)
        self.x9 = random(-WIDTH,WIDTH)

        tb = 50
        self.y0 = random(tb,HEIGHT-tb)
        self.y1 = random(tb,HEIGHT-tb)
        self.y2 = random(tb,HEIGHT-tb)
        self.y3 = random(tb,HEIGHT-tb)
        self.y4 = random(tb,HEIGHT-tb)
        self.y5 = random(tb,HEIGHT-tb)
        self.y6 = random(tb,HEIGHT-tb)
        self.y7 = random(tb,HEIGHT-tb)
        self.y8 = random(tb,HEIGHT-tb)      
        self.y9 = random(tb,HEIGHT-tb)
              
        self.x = range(10)
        self.x[0] = self.x0
        self.x[1] = self.x1
        self.x[2] = self.x2
        self.x[3] = self.x3
        self.x[4] = self.x4
        self.x[5] = self.x5
        self.x[6] = self.x6
        self.x[7] = self.x7
        self.x[8] = self.x8
        self.x[9] = self.x9
              
        ###factors to make a move
        self.v = 15
        self.a = -0.1*self.v
      
        self.check = 0
        self.c = 0
 
    def move(self):
        self.v += self.a
        self.check += self.c
                 
        ###stop and then move again
        if self.v < 0:
            self.v = 0
            self.a = 0
            self.c = 1
       
        if self.check == 30:
            self.v = 15
            self.a = -0.1*self.v
            self.check = 0
      
       ###to move the centers of blobs
        for i in range(10):
            self.x[i] += self.v * 0.5 * (i+1)
          
            ###borders              
            if self.x[i] > WIDTH:
                self.x[i] = 0
            if self.x[i] > WIDTH:
                self.x[i] = 0
  
    def ball(self, d, r, g, b):                               
        y = range(10)
        y[0] = self.y0
        y[1] = self.y1
        y[2] = self.y2
        y[3] = self.y3
        y[4] = self.y4
        y[5] = self.y5
        y[6] = self.y6
        y[7] = self.y7
        y[8] = self.y8
        y[9] = self.y9
      
        fill(r, g, b)     
        for i in range(10):      
            ovalc(self.x[i], y[i], d, d)

 
size(400, 300)
speed(30)

def setup():
    global bb
  
    bb = Blob()

  
def draw():
    global bb
  
    bb.move()
    bb.ball(110, 1, 1, 1)
    bb.ball(100, 0.6, 0.6, 1)
    background(0, 0, 1)

def ovalc(cx, cy, w, h):
    x = cx-w/2
    y = cy-h/2
    oval(x, y, w, h)

각 방울들이 range 변수(클래스 멤버 self.x)로 조정되고 있는 데 반해, 휴지기를 설정해 주는  self.check 값이 정수로 고정되어 있어 모든 방울들이 일시에 멈추고 일시에 움직인다. self.check를 리스트 x에 관해 정의해야겠다는 결론이다. (이 결정은 총 10시간이 넘는 시도 끝에 포기되었고...)

(다음 날...)
애초에 방울들의 집합을 클래스 안에 넣었던 이유는, 그렇게 하지 않으면 draw()에서 개체별로 방울들을 그리게 되어 원치않은 윤곽선(큰 원)이 남는다고 생각했기 때문이었다. 하지만 아래와 같이 별개의 for 구문을 써서 그리게 되면(ball()) 이 문제가 해결된다. 그러므로 굳이 클래스 안에서 클래스 멤버를 리스트로 만들 이유가 없다. (사실, 아니라면 클래스를 이용해서 얻는 효용이 무엇이란 말인가... 어제의 조악한 코드를 보라. 하나의 판단 착오가 엄청난 삽질을 가져왔음을 알 수 있다.)
v0.0의 코드를 그대로 적용하되, 클래스 외부에서 클래스 멤버에 접근하는 (친숙한) 방식으로 코딩한 다음, 클래스를 보다 깔끔하게 만들기 위해 메쏘드들을 단지 재정리하기만 했다.
 

# hirmes_blobs01_2.1

class Blob:
    def __init__(self,x):      
        self.x = x
        tb = HEIGHT/10
        self.y = random(tb, HEIGHT-tb)
       
        self.v = 20
        self.a = -0.1*self.v
       
        self.check = 0
        self.c = 0
       
    def move(self, m):
        self.v += self.a
        self.x += self.v * m

        ###borders    
        if self.x > WIDTH:
            self.x = 0
        if self.x < 0:
            self.x = WIDTH 
   
    def pause(self, p):
        self.check += self.c
       
        if self.v <= 0:
            self.v = 0
            self.a = 0
            self.c = 1

        if self.check == 20 * p:
            self.v = 20
            self.a = -0.1*self.v
            self.check = 0
            self.c = 0
       
    def ball(self, d, r, g, b):                   
        fill(r, g, b)
        ovalc(self.x, self.y, d, d)
       
def ovalc(cx, cy, w, h):
    x = cx-w/2
    y = cy-h/2
    oval(x, y, w, h)  
       
      
size(600, 300)
speed(60)


def setup():
    global bb
   
    bb = range(10)
    b = range(10)
   
    for i in range(10):
        b[i] = random(WIDTH)   
        bb[i] = Blob(b[i])
   
def draw():
    global bb

    m = range(10)
    p = range(10)
   
    for i in range(10):
        m[i] = (i+1)*0.5       
        p[i] = i+1
       
   
    background(0, 0, 1)
   
    for i in range(10):       
        bb[i].move(m[i])
        bb[i].pause(p[i])
        bb[i].ball(120, 1, 1, 1)

    for i in range(10):
        bb[i].ball(110, 0.6, 0.6, 1)

m과 p에 의해 방울들이 움직이는 속력(거리)과 멈추는 시간(차례)에 변화를 줄 수 있다. 비로소 뭔가 내어 놓을 수 있는 코드가 된 것 같다.
다시 한 번 짚어 보면, 윤곽선을 남기지 않는 문제는 class 내에서 그리는 메쏘드를 별도로 정의해 주는 것만으로 완전히 해결되었던 것이다.

사용자 삽입 이미지

'Code > NodeBox' 카테고리의 다른 글

David Hirmes - lines14  (0) 2007.07.31
David Hirmes - lines02  (0) 2007.07.25
splash_class_multi  (0) 2007.07.13
splash_class  (0) 2007.07.13
progress_class  (0) 2007.07.12
posted by maetel
2007. 7. 13. 16:40 Code/NodeBox
splash 예제를 두 개의 class를 써서 코딩하기

from math import sin, cos, radians

def ovalc(cx, cy, w, h):
    x = cx-w/2
    y = cy-h/2
    oval(x, y, w, h)

class Splash:
    def __init__(self):
        self.f = 0
        self.x = 0
        self.y = 0

        self.d = range(6)
        self.hit = 0
            
    def fall(self):
        self.x = WIDTH/2
        self.f += 1
        
        if self.y <= HEIGHT/2:
            self.y = self.f*10        
            ovalc(self.x, self.y, 20, 20)


        if (self.y > HEIGHT/2) & (self.hit==0):
            for i in range(6):
                self.d[i] = Drop(i*60)
                    
            self.hit = 1
        
        if self.hit==1:
            for i in range(6):
                ttt=self.d[i]
                ttt.scatter()
 
            
class Drop:       
    def __init__(self,a):
        self.f = 0
        self.a = a
        
    def scatter(self):
        r = 2*self.f
        self.f += 1
        a = self.a
        
        x = WIDTH/2 + r*cos(radians(a))
        y = HEIGHT/2 + r*sin(radians(a))             
 
        ovalc(x, y, 10, 10)


size(300,300)
speed(150)

def setup():
    global c    
    c = Splash()
    
def draw():
    global c
    c.fall()

lesson 1. class를 range 변수로 선언하는 것이 가능하다. (class member를 range의 순차번호를 매개로 했다.)
lesson 2. 어떠한 사건이 일어난 첫순간을 인식하여 사용할 때 쓰이는 pattern을 배웠다. (상기 코드의 self.hit 변수)

'Code > NodeBox' 카테고리의 다른 글

David Hirmes - blobs01  (0) 2007.07.18
splash_class_multi  (0) 2007.07.13
progress_class  (0) 2007.07.12
popping_1.1  (0) 2007.07.09
popping_1.0 (수정 중)  (0) 2007.07.06
posted by maetel
2006. 5. 19. 23:10 Footmarks
한국 HCI 연구회 5월 세미나
웹 어플리케이션 UI 패턴 모델

■ 발표자: LG CNS 김창겸
- S/W공학 및 HCI에서의 Design Pattern의 정의, 이해, 접근방식
- Web Application 개발을 위한 UI Pattern Model 소개
- UI Pattern Model의 특징, 구성요소
- 프로토타입 및 적용사례 소개


2006-05-19 쇠 7:30pm @SK 커뮤니케이션즈 4층 대접견실

LG CNS Software Engineering Center
UI Framework Div.
Kim Chang Gyum

"Web Application UI Design Pattern"


pattern:
해결책을 추상화 -> 폭넓게 적용 가능한 형태로 만든 것

1) 특정 상황에서 빈번하게 발생하는 문제에 대한 해결책
2) 검증된 해결책

posted by maetel