forked from SAIC-ATS/ARTTECH-3135
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ofApp.cpp
69 lines (55 loc) · 1.87 KB
/
ofApp.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "ofApp.h"
void ofApp::setup()
{
grabber.setup(640, 480);
pixels.allocate(640, 480, OF_PIXELS_RGB);
pixels.set(255);
}
void ofApp::update()
{
grabber.update();
if (grabber.isFrameNew())
{
for (int x = 0; x < grabber.getWidth(); x++)
{
for (int y = 0; y < grabber.getHeight(); y++)
{
// Here we use perlin noise to figure out how to offset our pixels.
// This is 1-D noise.
float theNoise = ofNoise((x + mouseX) * scale);
int xDisplace = x + grabber.getWidth() * theNoise;
int yDisplace = y; // None.
// We "wrap" the values to make sure they are accessing
// legitimate pixel x / y values. This is kind of like doing a
// modulo, but takes care of negative numbersÊand floating
// point as well.
xDisplace = ofWrap(xDisplace, 0, grabber.getWidth());
yDisplace = ofWrap(yDisplace, 0, grabber.getHeight());
// So when we set our color, we don't get the color from
// the x, y position in the grabber, we get it from somewhere
// a position determined by the perlin noise field.
ofColor theDisplacedColorFromTheGrabber = grabber.getPixels().getColor(xDisplace, yDisplace);
// Save that color to our pixels!
pixels.setColor(x, y, theDisplacedColorFromTheGrabber);
}
}
}
texture.loadData(pixels);
}
void ofApp::draw()
{
grabber.draw(0, 0);
texture.draw(grabber.getWidth(), 0);
ofDrawBitmapStringHighlight("- / = to scale\n(scale = " + ofToString(scale) + ")", 14, 14);
}
void ofApp::keyPressed(int key)
{
if (key == '-')
{
scale += 0.001;
}
else if (key == '=')
{
scale -= 0.001;
}
}