-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmySketch.js
102 lines (93 loc) · 2.73 KB
/
mySketch.js
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
let pg;
let TILES_X = 100;
let TILES_Y = 100;
let TILE_W, TILE_H;
let myModel;
let asciiChars = "�*%1+";
let font;
let angle = 0;
let targetAngleY = 0;
let currentAngleX = 0;
let currentAngleY = 0;
let currentAngleZ = 0;
function preload() {
myModel = loadModel('butterfly (1).obj', true);
font = loadFont('Geist-Light.ttf');
}
function setup() {
createCanvas(1000, 1000, WEBGL);
pg = createGraphics(2 * TILES_X, 2 * TILES_Y, WEBGL);
pg.smooth();
pg.directionalLight(200, 200, 200, -1, 0, -1);
pg.directionalLight(255, 255, 255, 1, 0, -1);
pointLight(255, 255, 255, 500, 500, 500);
specularColor(255, 255, 255);
TILE_W = width / TILES_X;
TILE_H = height / TILES_Y;
textFont(font);
textSize(TILE_W);
textAlign(CENTER, CENTER);
}
function draw() {
background("#ffffff");
noStroke();
pg.push();
pg.clear();
pg.noStroke();
pg.background(0);
pg.fill(255);
pg.rotateX(PI);
pg.rotateX(radians(-30));
if (mouseX < 0 || mouseX > width || mouseY < 0 || mouseY > height) {
currentAngleY += 0.04; //тут меняется скорость, на демо была 0.1
currentAngleX = lerp(currentAngleX, 0, 0.1);
currentAngleZ = lerp(currentAngleZ, 0, 0.1);
} else {
targetAngleX = -radians(mouseY) / 4;
targetAngleY = radians(mouseX) / 4;
targetAngleZ = 0;
currentAngleX = lerp(currentAngleX, targetAngleX, 0.1);
currentAngleY = lerp(currentAngleY, targetAngleY, 0.1);
currentAngleZ = lerp(currentAngleZ, targetAngleZ, 0.1);
}
pg.rotateX(currentAngleX);
pg.rotateY(currentAngleY);
pg.rotateZ(currentAngleZ);
pg.rotateY(PI / 2);
pg.scale(0.7);
pg.model(myModel);
pg.pop();
let buffer = pg.get();
for (let x = 0; x < TILES_X; x++) {
for (let y = 0; y < TILES_Y; y++) {
let c = buffer.get(x * 2, y * 2);
let b = brightness(c);
let asciiChar;
if (b > 1 & b <= 15) {
asciiChar = asciiChars.charAt(0);
} else if (b > 15 & b <= 30) {
asciiChar = asciiChars.charAt(1);
} else if (b > 30 & b <= 45) {
asciiChar = asciiChars.charAt(2);
} else if (b > 45 & b <= 60) {
asciiChar = asciiChars.charAt(3);
} else if (b > 60 & b <= 75) {
asciiChar = asciiChars.charAt(4);
} else if (b > 75 & b <= 90) {
asciiChar = asciiChars.charAt(5);
} else if (b > 90 & b <= 100) {
asciiChar = asciiChars.charAt(6);
} else {
asciiChar = ' ';
}
push();
let posX = x * TILE_W + TILE_W / 2 - width / 2;
let posY = y * TILE_H + TILE_H / 2 - height / 2;
translate(posX, posY);
fill(0, 0, 255); //тут менять цвет
text(asciiChar, 0, 0);
pop();
}
}
//image(pg, -width / 2, -height / 2, width / 8, height / 8);
}