-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRuttEtra.pde
More file actions
83 lines (67 loc) · 1.73 KB
/
RuttEtra.pde
File metadata and controls
83 lines (67 loc) · 1.73 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
Emulation of the line scan effect popularised by the
Rutt-Etra video synthesizer.
Copyright (c) 2020 Robin Parmar. MIT License.
VERSION
1.01 adapt canvas size to image dimensions
improved mouse rotation
1.00 original
*/
PImage img;
int skipX = 1;
int skipY = 8;
float brightScale = 2.;
boolean mouser = false;
float mouse_x, mouse_y;
void setup() {
size(100, 100, P3D);
frame.setResizable(true);
noFill();
lights();
strokeWeight(4);
background(0);
img = loadImage("MonaLisa.jpg");
frame.setSize(img.width, img.height);
mouse_x = 0.5*float(width);
mouse_y = 0.5*float(height);
}
void draw() {
background(0);
pushMatrix();
mouseHandler();
// for each row, skipping some lines
for (int y=0; y<img.height; y+=skipY) {
// draw a shape using pixel information
beginShape();
for (int x=0; x<img.width; x+=skipX) {
int pix = img.pixels[x + y * width];
stroke(red(pix), green(pix), blue(pix), 255);
vertex(x, y, (brightness(pix)-100)/brightScale);
}
endShape();
}
popMatrix();
}
// mouse rotation
void mouseHandler() {
float factor = 10.;
if (mouser) {
mouse_x = float(mouseX);
mouse_y = float(mouseY);
}
translate(width, height, 0);
rotateY(radians( (mouse_x - 0.5*float(width)) / factor ));
rotateX(radians( (0.5*float(height) - mouse_y) / factor ));
translate(-width, -height, 0);
}
// spacebar toggles mouse rotation
void keyPressed() {
if (keyCode == 32) {
mouser = !mouser;
if (mouser) {
println("mouse rotation is ON");
} else {
println("mouse rotation is OFF");
}
}
}