Skip to content

Commit fa47811

Browse files
committed
Update for 1.1.9995b
It's... almost 1.2.0!
1 parent ecf23bf commit fa47811

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+5758
-1994
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# PixelTeleporter Change Log
22

3+
## Version 1.1.4 (7/03/2021) What's New
4+
Basic support for 3D printed and other geometric solids. Added ScreenShape and ScreenShapeFactory APIs so you can model objects with LEDs mounted behind translucent diffuser panels. For the moment, supports just one LED per face. See example code and javadocs for more details!
5+
36
## Version 1.1.3 (4/03/2021) What's New
47
Minor update - increased the maximum supported number of LEDs to 4096 per PixelTeleporter object, and
58
updated all the servers (except the ESP8266 version) to match. The ESP8266 version still supports up
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
3+
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
4+
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_DISABLED_BUILDER" value="org.eclipse.jdt.core.javabuilder"/>
5+
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS"/>
6+
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
7+
</launchConfiguration>

PixelTeleporter/.project

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
</projects>
77
<buildSpec>
88
<buildCommand>
9-
<name>org.eclipse.jdt.core.javabuilder</name>
9+
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
10+
<triggers>full,incremental,</triggers>
1011
<arguments>
12+
<dictionary>
13+
<key>LaunchConfigHandle</key>
14+
<value>&lt;project&gt;/.externalToolBuilders/org.eclipse.jdt.core.javabuilder.launch</value>
15+
</dictionary>
1116
</arguments>
1217
</buildCommand>
1318
<buildCommand>
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
PShape buildLightMap(int mapSize,float LEDSize) {
2+
PGraphics pg;
3+
int x,y;
4+
float dx,dy,center,dist,maxDist;
5+
float alpha;
6+
float LEDCore = LEDSize * 0.4;
7+
println("Building light map...");
8+
9+
center = mapSize / 2;
10+
maxDist = sqrt(center * center);
11+
12+
pg = createGraphics(mapSize,mapSize);
13+
14+
pg.beginDraw();
15+
pg.noStroke();
16+
pg.noFill();
17+
18+
for (y = 0; y < mapSize; y++) {
19+
for (x = 0; x < mapSize; x++) {
20+
21+
dx = (float) x - center;
22+
dy = (float) y - center;
23+
dist = sqrt(dx * dx + dy * dy);
24+
if (dist <= LEDCore) {
25+
dist = alpha = 255;
26+
}
27+
else {
28+
dist = 1-(dist / maxDist); // normalized distance
29+
alpha = 150; // 200 * pow(dist,2);
30+
dist = 255 * pow(dist, 3);
31+
}
32+
pg.set(x,y,color(dist,dist,dist,alpha));
33+
}
34+
35+
}
36+
pg.endDraw();
37+
38+
PImage tex = pg.get();
39+
PShape sh = texturedPlane(tex,mapSize,mapSize, 0);
40+
sh.disableStyle();
41+
42+
println("Light map ready.");
43+
return sh;
44+
}
45+
46+
PShape buildHighlightMap(int mapSize) {
47+
PGraphics pg;
48+
int x,y;
49+
float dx,dy,center,dist,maxDist;
50+
float alpha;
51+
println("Building highlight map...");
52+
53+
center = mapSize / 2;
54+
maxDist = sqrt(center * center);
55+
56+
pg = createGraphics(mapSize,mapSize);
57+
58+
pg.beginDraw();
59+
pg.noStroke();
60+
pg.noFill();
61+
62+
for (y = 0; y < mapSize; y++) {
63+
for (x = 0; x < mapSize; x++) {
64+
65+
dx = (float) x - center;
66+
dy = (float) y - center;
67+
dist = sqrt(dx * dx + dy * dy);
68+
dist = 1-(dist / maxDist); // normalized distance
69+
alpha = 255 * pow(dist,2);
70+
if (alpha < 10) {
71+
alpha = 0;
72+
dist = 0;
73+
} else {
74+
dist = 255 * pow(dist, 1.75);
75+
}
76+
pg.set(x,y,color(dist,dist,dist,alpha));
77+
}
78+
}
79+
pg.endDraw();
80+
81+
PImage tex = pg.get();
82+
PShape sh = texturedPlane(tex,mapSize,mapSize, 0);
83+
sh.disableStyle();
84+
sh.translate(-4,-4,0);
85+
86+
println("Highlight map ready.");
87+
return sh;
88+
}
89+
90+
91+
// set the coordinates of the individual LEDs in our data
92+
// transfer "texture"
93+
void initLEDCoords(float xSize,float ySize) {
94+
int tx = -width / 2;
95+
int ty = -height / 2;
96+
int n = 0;
97+
for (float y = 0; y < ySize; y++) {
98+
for (float x = 0; x < xSize; x++) {
99+
float x1 = (x + 1) / (xSize + 1);
100+
float y1 = (y + 1) / (xSize + 1);
101+
leds[n][0] = tx + (int) (x1 * width);
102+
leds[n][1] = ty + (int) (y1 * width);
103+
n++;
104+
}
105+
}
106+
}
107+
108+
// textured x/y background rect of specified size, centered at origin facing viewer
109+
PShape backgroundPlane(float x, float y, float z) {
110+
PImage tex = loadImage("plasticbg.png");
111+
return texturedPlane(tex,x,y,z);
112+
}
113+
114+
// textured x/y background rect of specified size, centered at origin facing viewer
115+
PShape texturedPlane(PImage tex,float x, float y, float z) {
116+
textureMode(NORMAL);
117+
x /= 2; y /=2; z /=2;
118+
PShape sh = createShape();
119+
sh.beginShape(QUADS);
120+
sh.noStroke();
121+
sh.shininess(100);
122+
sh.texture(tex);
123+
124+
sh.vertex(-x, -y, z, 0, 0);
125+
sh.vertex( x, -y, z, 1, 0);
126+
sh.vertex( x, y, z, 1, 1);
127+
sh.vertex(-x, y, z, 0, 1);
128+
129+
sh.endShape(CLOSE);
130+
return sh;
131+
}
132+
133+
134+
// Our model LED -- a thin rectangular box, but with no bottom face
135+
PShape LEDPad(float xs, float ys, float zs) {
136+
textureMode(NORMAL);
137+
PImage tex = loadImage("texLED.jpg");
138+
xs /= 2; ys /=2; zs /=2;
139+
PShape sh = createShape();
140+
sh.beginShape(QUADS);
141+
// sh.setStroke(true);
142+
sh.shininess(1000);
143+
sh.specular(255);
144+
sh.texture(tex);
145+
146+
// +Z "front" face
147+
sh.vertex(-xs, -ys, zs, 0, 0);
148+
sh.vertex( xs, -ys, zs, 1, 0);
149+
sh.vertex( xs, ys, zs, 1, 1);
150+
sh.vertex(-xs, ys, zs, 0, 1);
151+
152+
// +Y "bottom" face
153+
sh.vertex(-xs, ys, zs, 0, 0);
154+
sh.vertex( xs, ys, zs, 1, 0);
155+
sh.vertex( xs, ys, -zs, 1, 1);
156+
sh.vertex(-xs, ys, -zs, 0, 1);
157+
158+
// -Y "top" face
159+
sh.vertex(-xs, -ys, -zs, 0, 0);
160+
sh.vertex( xs, -ys, -zs, 1, 0);
161+
sh.vertex( xs, -ys, zs, 1, 1);
162+
sh.vertex(-xs, -ys, zs, 0, 1);
163+
164+
// +X "right" face
165+
sh.vertex( xs, -ys, zs, 0, 0);
166+
sh.vertex( xs, -ys, -zs, 1, 0);
167+
sh.vertex( xs, ys, -zs, 1, 1);
168+
sh.vertex( xs, ys, zs, 0, 1);
169+
170+
// -X "left" face
171+
sh.vertex(-xs, -ys, -zs, 0, 0);
172+
sh.vertex(-xs, -ys, zs, 1, 0);
173+
sh.vertex(-xs, ys, zs, 1, 1);
174+
sh.vertex(-xs, ys, -zs, 0, 1);
175+
176+
sh.endShape(CLOSE);
177+
sh.disableStyle();
178+
return sh;
179+
}
180+
181+
// Generic textured box of specified size, centered at the origin,
182+
// in case we need it later...
183+
PShape TexturedBox(PImage tex,float xs, float ys, float zs) {
184+
xs /= 2; ys /=2; zs /=2;
185+
textureMode(NORMAL);
186+
PShape sh = createShape();
187+
sh.beginShape(QUADS);
188+
sh.texture(tex);
189+
190+
// +Z "front" face
191+
sh.vertex(-xs, -ys, zs, 0, 0);
192+
sh.vertex( xs, -ys, zs, 1, 0);
193+
sh.vertex( xs, ys, zs, 1, 1);
194+
sh.vertex(-xs, ys, zs, 0, 1);
195+
196+
// -Z "back" face
197+
sh.vertex( xs, -ys, -zs, 0, 0);
198+
sh.vertex(-xs, -ys, -zs, 1, 0);
199+
sh.vertex(-xs, ys, -zs, 1, 1);
200+
sh.vertex( xs, ys, -zs, 0, 1);
201+
202+
// +Y "bottom" face
203+
sh.vertex(-xs, ys, zs, 0, 0);
204+
sh.vertex( xs, ys, zs, 1, 0);
205+
sh.vertex( xs, ys, -zs, 1, 1);
206+
sh.vertex(-xs, ys, -zs, 0, 1);
207+
208+
// -Y "top" face
209+
sh.vertex(-xs, -ys, -zs, 0, 0);
210+
sh.vertex( xs, -ys, -zs, 1, 0);
211+
sh.vertex( xs, -ys, zs, 1, 1);
212+
sh.vertex(-xs, -ys, zs, 0, 1);
213+
214+
// +X "right" face
215+
sh.vertex( xs, -ys, zs, 0, 0);
216+
sh.vertex( xs, -ys, -zs, 1, 0);
217+
sh.vertex( xs, ys, -zs, 1, 1);
218+
sh.vertex( xs, ys, zs, 0, 1);
219+
220+
// -X "left" face
221+
sh.vertex(-xs, -ys, -zs, 0, 0);
222+
sh.vertex(-xs, -ys, zs, 1, 0);
223+
sh.vertex(-xs, ys, zs, 1, 1);
224+
sh.vertex(-xs, ys, -zs, 0, 1);
225+
226+
sh.endShape(CLOSE);
227+
return sh;
228+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// Improved LED Simulation Renderer Testbed
2+
// 10/23/2021 ZRanger1
3+
//
4+
// Be sure to change PixelTeleporter's IP address in setup() to the
5+
// one you're using.
6+
7+
import pixelTeleporter.library.*;
8+
9+
PShape lightMap;
10+
PShape ledModel;
11+
PShape backgroundPlane;
12+
PShape highlight;
13+
PixelTeleporter pt;
14+
15+
float ledPadHeight = 0;
16+
float lightMapSize = 0;
17+
float backgroundSize = 0;
18+
int xSize = 16;
19+
int ySize = 16;
20+
21+
// camera sensor saturation level.
22+
// control with 0,1,2,3,4 keys.
23+
float lit = 64;
24+
25+
int pixelCount = xSize * ySize;
26+
int[][] leds = new int[pixelCount][2];
27+
int frameTimer = 0;
28+
29+
// works well at 16x16, should be OK with other dimensions as well,
30+
// but you may have to play with pixel size for best results.
31+
void setup() {
32+
size(768,768, P3D);
33+
imageMode(CENTER);
34+
rectMode(CENTER);
35+
noStroke();
36+
blendMode(ADD);
37+
38+
backgroundSize = width * 1.2;
39+
float ledSize = backgroundSize / (xSize * 1.9);
40+
lightMapSize = ledSize * 6;
41+
42+
lightMap = buildLightMap((int) lightMapSize,ledSize);
43+
highlight = buildHighlightMap(3 * (int) ledSize);
44+
ledPadHeight = ledSize / 5;
45+
ledModel = LEDPad(ledSize,ledSize,ledPadHeight);
46+
backgroundPlane = backgroundPlane(width * 1.2,height * 1.2,0);
47+
48+
initLEDCoords(xSize,ySize);
49+
50+
pt = new PixelTeleporter(this,"192.168.1.42");
51+
pt.start();
52+
}
53+
54+
void draw() {
55+
background(0);
56+
57+
// set material and lighting properties that will apply to
58+
// everything drawn in the frame
59+
shininess(1000);
60+
directionalLight(lit,lit,lit,0,0,-1);
61+
lightSpecular(255,255,255);
62+
63+
// draw the background
64+
shape(backgroundPlane);
65+
66+
for (int n = 0; n < pixelCount; n++) {
67+
pushMatrix();
68+
translate(leds[n][0],leds[n][1],ledPadHeight);
69+
70+
int col = pt.pixelBuffer[n];
71+
colorMode(HSB,255,255,255);
72+
float b = brightness(col);
73+
colorMode(RGB,255,255,255);
74+
75+
// make sure there's always a tiny amount of
76+
// ambient white light around.
77+
if (b < 10) {
78+
col = color(10);
79+
b = 10;
80+
}
81+
82+
// set up material properties and draw individual
83+
// LEDs, then lay the light map on top.
84+
emissive(col);
85+
specular(b);
86+
87+
tint(col);
88+
shape(ledModel);
89+
translate(0,0,4);
90+
shape(lightMap);
91+
92+
// draw (white) highlights proportional to brightness
93+
tint((int) b);
94+
emissive((int) b);
95+
shape(highlight);
96+
97+
popMatrix();
98+
}
99+
100+
if (millis() - frameTimer > 2000) {
101+
println(frameRate);
102+
frameTimer = millis();
103+
}
104+
}
105+
106+
// Keyboard UI for camera saturation
107+
void keyPressed() {
108+
switch (key) {
109+
case '0':
110+
lit = 0;
111+
break;
112+
case '1':
113+
lit = 32;
114+
break;
115+
case '2':
116+
lit = 64;
117+
break;
118+
case '3':
119+
lit = 128;
120+
break;
121+
case '4':
122+
lit = 256;
123+
break;
124+
}
125+
}
75.3 KB
Loading
6.15 KB
Loading
7.9 KB
Loading

0 commit comments

Comments
 (0)