Created
March 14, 2018 21:12
-
-
Save mikkoelo/a9d4c95ca59737e2cd9f31e6d80ea844 to your computer and use it in GitHub Desktop.
Serialpointillism_Processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// importataan serial-kirjasto | |
import processing.serial.*; | |
import processing.video.*; | |
Capture video; | |
// luodaan serial-muuttuja ja num, johon tallennetaan luettu arvo | |
Serial myPort; | |
int num; | |
int num2; | |
void setup() { | |
size(640, 480); | |
noStroke(); | |
video = new Capture(this, width, height); | |
video.start(); | |
// valitaan käytössä oleva portti ja alustetaan myPort | |
String portName = Serial.list()[0]; | |
myPort = new Serial(this, portName, 9600); | |
num = 0; | |
num2 = 0; | |
} | |
void draw() { | |
// tarkistetaan onko serial portissa tavaraa ja luetaan sieltä rivi | |
if (myPort.available() > 0) { | |
String val = myPort.readStringUntil('\n'); //Luetaan serial-portista ensimmäisellä rivillä oleva arvo | |
String val2 = myPort.readStringUntil('\n'); //Luetaan serial-portista toisella rivillä oleva arvo | |
// jos luetut arvot eivät ole null, parsitaan arvo muuttujaan num | |
if (val != null) { | |
val = trim(val); | |
num = Integer.parseInt(val); | |
} | |
if (val2 != null) { | |
val2 = trim(val2); | |
num2 = Integer.parseInt(val2); | |
} | |
} | |
if (video.available()) { | |
video.read(); | |
video.loadPixels(); | |
for (int i = 0; i < 1000; i++) { | |
int x = int(random(video.width)); | |
int y = int(random(video.height)); | |
int index = x+(y*video.width); | |
float red = red(video.pixels[index]); | |
float green = green(video.pixels[index]); | |
float blue = blue(video.pixels[index]); | |
float size = random(num/10); //Luodaan muuttuja size, johon vaikuttaa serial portin ensimmäisen rivin arvo | |
float distance = num2/100; //Luodaan muuttuja distance, jossa serial portin toisen rivin arvo | |
float red2 = red/distance; // Luodaan muuttuja red2, johon vaikuttaa muuttuja distance | |
fill(red2, green, blue, 100); // Muutetaan punaisuuden arvoa muuttujan distance avulla | |
ellipse(x, y, size, size); // käytetään num-muuttujaa ellipsin koon arvonnassa | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment