Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Processing 2. Креативное программирование

.pdf
Скачиваний:
144
Добавлен:
06.03.2016
Размер:
16.65 Mб
Скачать

size( 1024, 480 ); smooth();

strokeWeight( 2 );

minim = new Minim( this );

out = minim.getLineOut( Minim.STEREO );

sine = new SineWave( 130.816, 0.5, out.sampleRate() ); out.addSignal( sine );

saw = new SawWave( 65.4064, 1.0, out.sampleRate() ); out.addSignal( saw );

}

, draw(). ,.

void draw()

{

background( 255 );

translate( 0, height/2 );

for ( int i = 0; i < out.bufferSize(); i++ ) { float y1 = out.left.get( i ) * 100;

float y2 = out.right.get( i ) * 100; stroke( 0 );

point( i, y1 ); stroke( 255, 0, 0 ); point( i, y2 );

}

}

mouseMoved() . mouseX0, , - . , .

void mouseMoved()

{

float pan = map( mouseX, 0, width, -1, 1 ); sine.setPan( pan );

saw.setPan( -pan );

}

160

7

keyPressed() .AZERTY, , .

void keyPressed()

{

if ( key == 'q' ) { sine.setFreq( 130.813 ); // C3 saw.setFreq( 65.4064 ); // C2

}

if ( key == 's' ) { sine.setFreq( 146.832 ); // D3 saw.setFreq( 73.4162 ); // D2

}

if ( key == 'd' ) { sine.setFreq( 164.814 ); // E3 saw.setFreq( 82.4069 ); // E2

}

if ( key == 'f' ) { sine.setFreq( 174.614 ); // F3 saw.setFreq( 87.3071 ); // F2

}

if ( key == 'g' ) { sine.setFreq( 195.998 ); // G3 saw.setFreq( 97.9989 ); // G2

}

if ( key == 'h' ) { sine.setFreq( 220 ); // A3 saw.setFreq( 110 ); // A2

}

if ( key == 'j' ) { sine.setFreq( 246.942 ); // B3 saw.setFreq( 123.471 ); // B2

}

}

void stop()

{

out.close();

minim.stop();

super.stop();

}

161

, , .

, - AudioOutput.:

out = minim.getLineOut( Minim.STEREO );

Minim .. .- , - , - ., AudioOutput., .

sine = new SineWave( 130.816, 0.5, out.sampleRate() ); out.addSignal( sine );

saw = new SawWave( 65.4064, 1.0, out.sampleRate() ); out.addSignal( saw );

keyPressed() . -wave.setFreq(). ., 130.813 . (C3)( 2) ., , C3 C2 x 2. C4 C3.. : http://en.wikipedia.org/wiki/Piano_key_frequencies.

162

7

..

.. - AudioPlayer.

import ddf.minim.*;

import ddf.minim.signals.*; import ddf.minim.analysis.*; import ddf.minim.effects.*;

Minim minim;

AudioPlayer player;

LowPassSP lowpass;

HighPassSP highpass;

void setup()

{

size( 640, 480 );

minim = new Minim( this );

player = minim.loadFile("song.mp3"); player.play();

lowpass = new LowPassSP( 440, 44100 ); player.addEffect( lowpass );

highpass = new HighPassSP( 440, 44100 ); player.addEffect( highpass );

}

void draw()

{

background( 255 );

}

163

void stop()

{

player.close();

minim.stop();

super.stop();

}

, .player. addEffect() ,.

setup(). lowpass ( ) highpass ( ). Minim, bandpass (-) notch (- - ) . : http:// code.compartmental.net/minim/javadoc/. ., ,. , player. addEffect().

164

8

ၞၢၠၣၰၲၦၙၤၡၢၙ

:

fOpenCV

fOpenCV

fOpenCV

fOpenCV

fOpenCV

- ... , , . .

, - . Processing . .

. video, Processing. Sketch | Import Library | video.Capture..

import processing.video.*;

Capture webcam;

setup() Capture . draw() .

void setup()

{

size( 640, 480 ); smooth();

println( Capture.list() );

webcam = new Capture( this, width, height, 30 ); webcam.start();

}

void draw()

{

background( 255 ); image( webcam, 0, 0 );

}

, captureEvent()., .

void captureEvent( Capture webcam )

{

webcam.read();

}

166

8

, :

, - Capture.:

webcam = new Capture( this, width, height, 30 );

Capture() .this. . , , .- .

, ,. Capture.list(). :

webcam = new Capture( this, width, height, "Logitech Camera", 30 );

, - start()., . draw()image().

captureEvent() ,. webcam.read() -.

167

ၞၢၠၣၰၲၦၙၤၡၯၠ. ... ,- . ,.

video.. CapturenumPixels threshold.

import processing.video.*;

Capture webcam;

int numPixels; int threshold;

setup(). numPixels. ,draw(). threshold 127.

void setup()

{

size( 640, 480 ); smooth();

webcam = new Capture( this, width, height, 30); webcam.start();

numPixels = webcam.width * webcam.height; threshold = 127;

}

168

8

draw() webcam.available(). loadPixels() updatePixels() ., .

void draw()

{

if ( webcam.available() ) { webcam.read();

image( webcam, 0, 0 );

loadPixels();

for ( int i = 0; i < numPixels; i++ ) { float b = brightness( webcam.pixels[i] ); if ( b > threshold ) {

pixels[i] = color( 255 ); } else {

pixels[i] = color( 0 );

}

}

updatePixels();

}

fill( 255, 0, 0 ); noStroke();

rect( 10, 10, 110, 20 ); fill( 255 );

text( "Threshold: " + threshold, 14, 24 );

}

keyPressed(). - , - .

void keyPressed()

{

if ( key == CODED ) {

if ( keyCode == UP ) { threshold++;

}

if ( keyCode == DOWN ) { threshold--;

}

}

}

169

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]