diff --git a/demo/prototypes/beadstring/beadstring.pde b/demo/prototypes/beadstring/beadstring.pde new file mode 100644 index 00000000..6278f905 --- /dev/null +++ b/demo/prototypes/beadstring/beadstring.pde @@ -0,0 +1,38 @@ +final int refreshRate = 50; + +int colors[] = { color(255,192,0), color(0,192,255), color(255,0,192), color(192,0,255) }; + +void setup() { + size(640, 480, P3D); + frameRate(refreshRate); +} + +void draw() { + background(color(128)); + stroke(color(0)); + ortho(); + + for (int i = 0; i < 5; i++) { + float x = lerp(width * 0.1, width * 0.9, (float)i / 4.0); + float i_speed = i * refreshRate * 0.5; + + pushMatrix(); + translate(x, height/2, -50); + rotateY((frameCount + i_speed) / refreshRate); + fill(color(255)); + box(40, height, 40); + popMatrix(); + + for (int j = 0; j < 4; j++) { + float y = lerp(height * 0.15, height * 0.85, (float)j / 3.0); + float j_speed = j * refreshRate; + + pushMatrix(); + translate(x, y, -50); + rotateY((-frameCount + i_speed + j_speed) / refreshRate); + fill(colors[j]); + box(80, 80, 80); + popMatrix(); + } + } +} \ No newline at end of file diff --git a/demo/prototypes/cathedral/cathedral.pde b/demo/prototypes/cathedral/cathedral.pde new file mode 100644 index 00000000..1fa0201d --- /dev/null +++ b/demo/prototypes/cathedral/cathedral.pde @@ -0,0 +1,47 @@ +PImage imgLight; +PImage imgDark; +PImage mask; +PImage generatedMask; + +void updateMask() { + mask.loadPixels(); + generatedMask.loadPixels(); + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + int loc = x+ y * width; + int pixel = generatedMask.pixels[loc]; + float r = red(pixel); + float g = green(pixel); + float b = blue(pixel); + generatedMask.pixels[loc] = pixel != color(255) ? color(r+frameCount/50, g+frameCount/50, b+frameCount/50) : color(255); + } + } + generatedMask.updatePixels(); + imgLight.mask(generatedMask); +} + +void copyPixels() { + mask.loadPixels(); + generatedMask.loadPixels(); + for (int i = 0; i < generatedMask.pixels.length; i++) { + generatedMask.pixels[i] = mask.pixels[i]; + } + generatedMask.updatePixels(); +} + +void setup() { + size(320, 256); + imgLight = loadImage("light.png"); + imgDark = loadImage("dark.png"); + mask = loadImage("mask.png"); + generatedMask = createImage(320, 256, ALPHA); + copyPixels(); + imageMode(CENTER); +} + +void draw() { + background(0); + updateMask(); + image(imgDark, width/2, height/2); + image(imgLight, width/2, height/2); +} diff --git a/demo/prototypes/cathedral/data/dark.png b/demo/prototypes/cathedral/data/dark.png new file mode 100644 index 00000000..402e99a5 --- /dev/null +++ b/demo/prototypes/cathedral/data/dark.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f7124df355ac3f53cb89e88e44a0ad016294c59c14e5785e9f086864b8cda267 +size 26418 diff --git a/demo/prototypes/cathedral/data/light.png b/demo/prototypes/cathedral/data/light.png new file mode 100644 index 00000000..fabb3b65 --- /dev/null +++ b/demo/prototypes/cathedral/data/light.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:45c96c1da0d0ad9107c1c094eec363767755780d09204ca77a3b957edeca8537 +size 26482 diff --git a/demo/prototypes/cathedral/data/mask.png b/demo/prototypes/cathedral/data/mask.png new file mode 100644 index 00000000..ba0f1516 --- /dev/null +++ b/demo/prototypes/cathedral/data/mask.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ceeda9d262c5a4d506f21ec1b1576bd29ca73364b82bf34cf059000b6e62ec85 +size 25321 diff --git a/demo/prototypes/loading/data/background.png b/demo/prototypes/loading/data/background.png new file mode 100644 index 00000000..30a8004e --- /dev/null +++ b/demo/prototypes/loading/data/background.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee13625eb2ea22875f29dd038e9bd998835f74767b2d41875ce3be06d78898eb +size 6813 diff --git a/demo/prototypes/loading/data/pumpkin.png b/demo/prototypes/loading/data/pumpkin.png new file mode 100644 index 00000000..e1dc7bc8 --- /dev/null +++ b/demo/prototypes/loading/data/pumpkin.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2a2263024620a7c32f4e84b565ec42c23f875975730bdac62af4179052a9fd47 +size 597 diff --git a/demo/prototypes/loading/loading.pde b/demo/prototypes/loading/loading.pde new file mode 100644 index 00000000..47d9558c --- /dev/null +++ b/demo/prototypes/loading/loading.pde @@ -0,0 +1,30 @@ +PImage bg; +PImage pumpkin; + +final int pumpkin_x = 144; +final int pumpkin_low = 191; +final int pumpkin_high = 200; + +void setup() { + size(320, 256); + frameRate(50); + + bg = loadImage("background.png"); + pumpkin = loadImage("pumpkin.png"); +} + +void draw() { + int time = (frameCount / 2) % 25; + int pumpkin_y = (int)lerp(pumpkin_low, pumpkin_high + 2, 1.0 - sin(time / 25.0 * PI)); + int sy = 0; + + if (pumpkin_y >= pumpkin_high) + sy += 32; + if (pumpkin_y >= pumpkin_high + 1) + sy += 32; + + image(bg, 0, 0); + copy(pumpkin, 0, sy, 32, 32, + pumpkin_x, pumpkin_y, 32, 32); +} + diff --git a/demo/prototypes/multipipe/data/colors.png b/demo/prototypes/multipipe/data/colors.png new file mode 100644 index 00000000..e55bb4ab --- /dev/null +++ b/demo/prototypes/multipipe/data/colors.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4f31bd078f88002b01bebd2a6e8403fdde0def8488c89ed2128802b3107b0f0a +size 3399 diff --git a/demo/prototypes/multipipe/drawable.pde b/demo/prototypes/multipipe/drawable.pde new file mode 100644 index 00000000..3b7ba652 --- /dev/null +++ b/demo/prototypes/multipipe/drawable.pde @@ -0,0 +1,112 @@ +interface Drawable { + PVector intersection(Line other); +} + +class Line { + /* General equation: A * x + B * y + C = 0 */ + float a, b, c; + + float x0, y0; + float x1, y1; + + Line(float _x0, float _y0, float _x1, float _y1) { + x0 = _x0; y0 = _y0; x1 = _x1; y1 = _y1; + a = y0 - y1; + b = x1 - x0; + c = (x0 - x1) * y0 + (y1 - y0) * x0; + } + + float dx() { return x1 - x0; } + float dy() { return y1 - y0; } + + PVector intersection(Line other) { + float x = (b * other.c - other.b * c) / (other.b * a - b * other.a); + float y = - (a * x + c) / b; + return new PVector(x, y); + } + + public String toString() { + return "Line(" + str(a) + ", " + str(b) + ", " + str(c) + ")"; + } +} + +class Segment extends Line implements Drawable { + /* Parametric equation: p0 + (p1 - p0) * t = 0, t \in [0,1] */ + + Segment(float x0, float y0, float x1, float y1) { + super(x0, y0, x1, y1); + } + + PVector intersection(Line line) { + PVector pk = super.intersection(line); + + float tx = (pk.x - x0) / dx(); + float ty = (pk.y - y0) / dy(); + + if (tx < 0 || tx > 1) + throw new ArithmeticException(); + if (ty < 0 || ty > 1) + throw new ArithmeticException(); + + return pk; + } + + public String toString() { + return "Segment(" + str(x0) + ", " + str(y0) + " -> " + str(x1) + ", " + str(y1) + ")"; + } +} + +float sgn(float x) { + if (x < 0) + return -1; + return 1; +} + +enum Side { INNER, OUTER }; + +class Circle implements Drawable { + /* Equation: (x - a)^2 + (y - b)^2 = r^2 */ + float a, b; + float r; + Side side; + + Circle(float _x, float _y, float _r, Side _side) { + a = _x; b = _y; r = _r; side = _side; + } + + PVector intersection(Line line) { + /* http://mathworld.wolfram.com/Circle-LineIntersection.html */ + float x0 = line.x0 - a; + float y0 = line.y0 - b; + float x1 = line.x1 - a; + float y1 = line.y1 - b; + + float dx = x1 - x0; + float dy = y1 - y0; + float dr2 = sq(dx) + sq(dy); + float D = x0 * y1 - x1 * y0; + float Delta = sq(r) * dr2 - sq(D); + + if (Delta < 0) { + throw new ArithmeticException(); + } + + if (Delta == 0) { + return new PVector(D * dy / dr2 + a, -D * dx / dr2 + b); + } + + float xi = (D * dy + sgn(dy) * dx * sqrt(Delta)) / dr2; + float yi = (-D * dx + abs(dy) * sqrt(Delta)) / dr2; + + float xj = (D * dy - sgn(dy) * dx * sqrt(Delta)) / dr2; + float yj = (-D * dx - abs(dy) * sqrt(Delta)) / dr2; + + boolean which = (side == Side.OUTER) ? (yi < yj) : (yj < yi); + + if (which) { + return new PVector(xi + a, yi + b); + } else { + return new PVector(xj + a, yj + b); + } + } +} \ No newline at end of file diff --git a/demo/prototypes/multipipe/multipipe.pde b/demo/prototypes/multipipe/multipipe.pde new file mode 100644 index 00000000..e7381ccb --- /dev/null +++ b/demo/prototypes/multipipe/multipipe.pde @@ -0,0 +1,169 @@ +/* Tested on Processing 3.3.5 */ + +final int shift = 4; +final int WIDTH = 320; +final int HEIGHT = 256; + +final float near_z = 256; +final float far_z = near_z + 256; +final float focal_length = 256; +final float stripe = WIDTH / 7.0; + +PImage colors; +PImage flares; +PImage lines; + +void settings() { + size(WIDTH, HEIGHT); +} + +void rgb12(PImage img) { + for (int y = 0; y < img.height; y++) { + for (int x = 0; x < img.width; x++) { + int c = img.get(x, y); + c &= 0xf0f0f0f0; + c |= c >> 4; + img.set(x,y,c); + } + } +} + +final float minW = 21.0; +final float maxW = 37.0; +final int prec = 8; + +void calcLines() { + int linesW = width + int(maxW * 2); + int linesH = int((maxW - minW) * prec); + + lines = createImage(linesW, linesH + 1, RGB); + + for (int j = 0; j <= linesH; j++) { + float w = lerp(minW, maxW, float(j) / linesH); + + assert(w >= minW); + assert(w <= maxW); + + float x = 0.0; + int c = 0; + + for (int i = 0; i < linesW; i++) { + lines.set(i, j, color(c == 0 ? 0 : 255)); + x += 1.0; + if (x > w) { + x -= w; + c ^= 1; + } + } + } +} + +class Stripe { + int width; + int line; + int number; + + Stripe(int _w, int _y, int _n) { + width = _w; + line = _y; + number = _n; + } + + public String toString() { + return "{ .w = " + str(width) + ", .y = " + str(line) + ", .n = " + str(number) + " }"; + } +}; + +ArrayList stripes; +final int[] speed = {1, -2, -2}; + +void calcStripes() { + final int npipes = 3; + Drawable[] pipe; + + /* Drawables must be Z-sorted from farthest to nearest. */ + pipe = new Drawable[npipes]; + pipe[0] = new Circle(0, 384, 128 + 32 + 12, Side.INNER); + pipe[1] = new Circle(0, 384 + 32, 46, Side.INNER); + pipe[2] = new Circle(0, 384 + 32, 46, Side.OUTER); + + stripes = new ArrayList(); + + for (int y = 0; y < height; y++) { + Line camera = new Line(0, 0, y - height / 2, focal_length); + + for (int j = 0; j < npipes; j++) { + Drawable p = pipe[j]; + + try { + PVector meet = p.intersection(camera); + float z = meet.y; + float w = abs(stripe * focal_length / z); // 3d -> 2d + Stripe s = new Stripe(int(w * prec), y, j); + stripes.add(s); + // println(s); + } catch(ArithmeticException e) { + } + } + } +} + +void setup() { + frameRate(50); + + colors = loadImage("colors.png"); + rgb12(colors); + flares = loadImage("particles.png"); + + calcLines(); + calcStripes(); +} + +void drawLine(int y, int x, int w, boolean swap, boolean transparent) { + w -= int(minW * prec); + + int c0, c1; + + if (swap) { + c0 = colors.get(1, y); + c1 = colors.get(0, y); + } else { + c0 = colors.get(0, y); + c1 = colors.get(1, y); + } + + for (int i = 0; i < width; i++) { + boolean cs = lines.get(i + x, w) == color(0); + int c = cs ? c0 : c1; + if (transparent) { + int bg = get(i, y); + c = lerpColor(bg, c, 0.5); + } + set(i, y, c); + } +} + +void draw() { + final int center = - int(prec * (width / 2.0)); + + for (Stripe s : stripes) { + int w = s.width; + int y = s.line; + int n = s.number; + // calculate stripe offset + int x = w * speed[n] * frameCount / 64 + center; + + int _x = x % w; + int _s = x / w; + if (_x < 0) { + _x += w; + _s += 1; + } + + drawLine(y, _x / prec, w, _s % 2 == 0, n > 1); + } + + if (keyPressed) { + save("multipipe.png"); + } +} \ No newline at end of file diff --git a/demo/prototypes/multipipe/multipipe.png b/demo/prototypes/multipipe/multipipe.png new file mode 100644 index 00000000..2d837d85 --- /dev/null +++ b/demo/prototypes/multipipe/multipipe.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:522d64c2ea020a755ef5fa9bc7b1241d4d6252e207c1cd500729d72c7808af2c +size 4808 diff --git a/demo/prototypes/objects/dodecahedron_150edges.lwo b/demo/prototypes/objects/dodecahedron_150edges.lwo new file mode 100644 index 00000000..0dc45b22 --- /dev/null +++ b/demo/prototypes/objects/dodecahedron_150edges.lwo @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e0e4e23c5ae0c7de9fb2e29736941628998264617a0989459d12b6be976124d +size 2372 diff --git a/demo/prototypes/objects/dodecahedron_150edges.png b/demo/prototypes/objects/dodecahedron_150edges.png new file mode 100644 index 00000000..c4aef057 --- /dev/null +++ b/demo/prototypes/objects/dodecahedron_150edges.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a99b43aa2a568f1a14306bbc7aa5353bf6dd6e7247b45c3383cdcfa1ef3c01c5 +size 116076 diff --git a/demo/prototypes/objects/morph-torosphere.lwo b/demo/prototypes/objects/morph-torosphere.lwo new file mode 100644 index 00000000..9afff455 --- /dev/null +++ b/demo/prototypes/objects/morph-torosphere.lwo @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a8f315fb072db4bde255f21ea75cd5d02005067e085dfa66005445cc88b38939 +size 3948 diff --git a/demo/prototypes/objects/morph-torosphere.png b/demo/prototypes/objects/morph-torosphere.png new file mode 100644 index 00000000..70e88bd5 --- /dev/null +++ b/demo/prototypes/objects/morph-torosphere.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5779f5e232950d1e2fa56fb2f4f5a30c8ab3889935771d6ccc10e85b398a83be +size 96957 diff --git a/demo/prototypes/objects/morph-torus.lwo b/demo/prototypes/objects/morph-torus.lwo new file mode 100644 index 00000000..eeabd41e --- /dev/null +++ b/demo/prototypes/objects/morph-torus.lwo @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bbf3bc9346f3e66ef3b0e42bcd19fa2dcc8f93d5ddfe728214e99b4eeefdf7dc +size 3938 diff --git a/demo/prototypes/objects/morph-torus.png b/demo/prototypes/objects/morph-torus.png new file mode 100644 index 00000000..b7e7ee58 --- /dev/null +++ b/demo/prototypes/objects/morph-torus.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:67ecca124374f4e23b9d3b53ffdc063fa20a440060c8e6b0ec3ab4fa5fabbaee +size 91512 diff --git a/demo/prototypes/skulls/data/ball-poly.png b/demo/prototypes/skulls/data/ball-poly.png new file mode 100644 index 00000000..af61c921 --- /dev/null +++ b/demo/prototypes/skulls/data/ball-poly.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca4d89d42d44dea1204f760f5102e86f46fb709687c0556c07fa21e3c36bac5a +size 17171 diff --git a/demo/prototypes/skulls/data/skull-fade-128.png b/demo/prototypes/skulls/data/skull-fade-128.png new file mode 100644 index 00000000..4e394d5d --- /dev/null +++ b/demo/prototypes/skulls/data/skull-fade-128.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ce99518924742daf292a6b1cdb0d4d0c8ebe3841d6b95a36267842c4ebb04950 +size 138080 diff --git a/demo/prototypes/skulls/data/skull-rotate-128.png b/demo/prototypes/skulls/data/skull-rotate-128.png new file mode 100644 index 00000000..5d1877d1 --- /dev/null +++ b/demo/prototypes/skulls/data/skull-rotate-128.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:64af2823e6a146a3780173af0c732dcda97d7e54011ed73022c62ed633602756 +size 458763 diff --git a/demo/prototypes/skulls/data/skull_32x.png b/demo/prototypes/skulls/data/skull_32x.png new file mode 100644 index 00000000..0f59a4d7 --- /dev/null +++ b/demo/prototypes/skulls/data/skull_32x.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51dc892f81eeef8e9657d59821dd354fc33fa1d2a5c8404d43810dac8d42cf59 +size 13013 diff --git a/demo/prototypes/skulls/skulls.pde b/demo/prototypes/skulls/skulls.pde new file mode 100644 index 00000000..78795e30 --- /dev/null +++ b/demo/prototypes/skulls/skulls.pde @@ -0,0 +1,137 @@ +int GRID_SIZE = 32; +int SPEED = 2; +String SKULLS_IMAGE = "skull_32x.png"; +String BALL_IMAGE = "ball-poly.png"; + +// Features +float HIGHLIGHT_DISTANCE = 80.0; +boolean DISTANCE_SKULL_SIZE_FACTOR = true; +int HIGHLIGHT_FRAME_NUMBER = 7; +int MIN_BALL_SIZE = 10; +int MAX_BALL_SIZE = 40; +int BALL_SPRITE_FRAME_SIZE = 32; + +PImage skullImage; +PImage ballImage; +SkullSprite [][] skullsGrid; +BouncingBall bball; + +int gridCols; +int gridRows; + +class SkullSprite { + PVector position; + PImage image; + boolean highlighted; + + SkullSprite(PVector position_, PImage image_) { + position = position_; + image = image_; + highlighted = false; + } + + void show(int frame) { + int frameToDisplay = highlighted ? HIGHLIGHT_FRAME_NUMBER : frame; + copy(image, 0, 32 * frameToDisplay, 32, 32, Math.round(position.x), Math.round(position.y), 32, 32); + } +} + +class BouncingBall { + PImage image; + PVector position; + PVector direction; + float size; + int sizeDirection; + + BouncingBall(PImage image_) { + image = image_; + position = new PVector(10, 10); + direction = new PVector(1.5, 1); + size = MIN_BALL_SIZE; + sizeDirection = 1; + } + void draw() { + int frame = frameCount%12; + copy(image, BALL_SPRITE_FRAME_SIZE * frame, 0, BALL_SPRITE_FRAME_SIZE, BALL_SPRITE_FRAME_SIZE, round(position.x - size/2), round(position.y - size/2), round(size), round(size)); + } + + void setXdirection(float xDirection) { + direction = new PVector(xDirection, direction.y); + } + void setYdirection(float yDirection) { + direction = new PVector(direction.x, yDirection); + } +} + +// TODO Move it to the ball class +void updateBallPosition() { + double timeFactor = abs(sin(frameCount/20.0)) * MAX_BALL_SIZE - MIN_BALL_SIZE; + PVector position = bball.position; + PVector direction = bball.direction; + PVector nextPosition = new PVector(position.x + direction.x * SPEED, position.y + direction.y * SPEED); + + float nextSize = MIN_BALL_SIZE + (float)timeFactor; + + // Change direction is always for the smalles ball size, + // Dose not look super good when ball is close to max size. + if (nextPosition.x > width - MIN_BALL_SIZE || nextPosition.x < MIN_BALL_SIZE) { + bball.setXdirection(-direction.x); + } + if (nextPosition.y > height - MIN_BALL_SIZE || nextPosition.y < MIN_BALL_SIZE) { + bball.setYdirection(-direction.y); + } + bball.position = nextPosition; + + // + int nextDirection = bball.size - nextSize < 0 ? -1 : 1; + if ((nextDirection == -1) && (nextDirection != bball.sizeDirection)) { + int skullGridX = floor(position.x / GRID_SIZE); + int skullGridY = floor(position.y / GRID_SIZE); + skullsGrid[skullGridY][skullGridX].highlighted = true; + } + + bball.size = nextSize; + bball.sizeDirection = nextDirection; +} + +void skullsInit() { + skullImage = loadImage(SKULLS_IMAGE); + skullsGrid = new SkullSprite[gridCols][gridRows]; + for (int i = 0; i < gridCols; i++) { + for (int j = 0; j < gridRows; j++) { + skullsGrid[i][j] = new SkullSprite(new PVector(j * 32, i * 32), skullImage); + } + } +} + +void ballsInit() { + ballImage = loadImage(BALL_IMAGE); + bball = new BouncingBall(ballImage); +} + +void setup() +{ + size(320, 320); + frameRate(30); + gridCols = width / GRID_SIZE; + gridRows = height / GRID_SIZE; + skullsInit(); + ballsInit(); +} + + +void draw() { + background(0); + updateBallPosition(); + for (int i = 0; i < gridCols; i++) { + for (int j = 0; j < gridRows; j++) { + SkullSprite skull = skullsGrid[i][j]; + PVector skullPosition = skull.position; + float distance = dist(bball.position.x, bball.position.y, skullPosition.x, skullPosition.y); + float ballSizeFactor = DISTANCE_SKULL_SIZE_FACTOR ? bball.size * 1.5 : 0; + int frame = Math.round(map(distance + ballSizeFactor, 0, HIGHLIGHT_DISTANCE, 6, 1)); + skull.show(frame); + } + } + bball.draw(); +} diff --git a/demo/prototypes/texface/data/gull16.png b/demo/prototypes/texface/data/gull16.png new file mode 100644 index 00000000..f160f1ea --- /dev/null +++ b/demo/prototypes/texface/data/gull16.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a311bb9df9ea3d1cbd9d65e544bd059e1f05364a747699a1ce0dfd279a1c439a +size 844 diff --git a/demo/prototypes/texface/fp.pde b/demo/prototypes/texface/fp.pde new file mode 100644 index 00000000..51f067e3 --- /dev/null +++ b/demo/prototypes/texface/fp.pde @@ -0,0 +1,27 @@ +int fp16_round(int v) { + return (v + 32767) & 0xffff0000; +} + +int fp16_floor(int v) { + return v & 0xffff0000; +} + +int fp16_ceil(int v) { + return (v + 65535) & 0xffff0000; +} + +int fp16_div(int n, int d) { + return (int)((long)n * 65536 / d); +} + +int fp16_mul(int x, int y) { + return (int)((long)x * (long)y / 65536); +} + +int fp16_int(int v) { + return (v + 32767) / 65536; +} + +int fp16(float v) { + return (int)(v * 65536); +} \ No newline at end of file diff --git a/demo/prototypes/texface/texface.pde b/demo/prototypes/texface/texface.pde new file mode 100644 index 00000000..f62ab0e1 --- /dev/null +++ b/demo/prototypes/texface/texface.pde @@ -0,0 +1,184 @@ +PImage texture; + +/* + * if triangle rasterizer is not pixel perfect + * one should see white pixels on triangle edges + */ + +class Vertex { + int x, y, u, v; + + Vertex(float _x, float _y, float _u, float _v) { + x = fp16(_x); y = fp16(_y); u = fp16(_u); v = fp16(_v); + } +} + +class EdgeInfo { + int ys, ye; + int x, u, v; + int dx, du, dv; + boolean valid; + + EdgeInfo() { + valid = false; + } + + EdgeInfo(Vertex p0, Vertex p1) { + ys = fp16_int(p0.y); + ye = fp16_int(p1.y); + + assert(ys <= ye); + + if (ys == ye) { + valid = false; + dx = (p0.x < p1.x) ? MIN_INT : MAX_INT; + return; + } + + int ys_centered = p0.y + fp16(0.5); + int ys_prestep = fp16_ceil(ys_centered) - ys_centered; + + dx = fp16_div(p1.x - p0.x, p1.y - p0.y); + du = fp16_div(p1.u - p0.u, p1.y - p0.y); + dv = fp16_div(p1.v - p0.v, p1.y - p0.y); + + x = p0.x + fp16_mul(ys_prestep, dx); + u = p0.u + fp16_mul(ys_prestep, du); + v = p0.v + fp16_mul(ys_prestep, dv); + + valid = true; + } + + EdgeInfo copy() { + EdgeInfo n = new EdgeInfo(); + n.ys = ys; n.ye = ye; + n.x = x; n.u = u; n.v = v; + n.dx = dx; n.du = du; n.dv = dv; + n.valid = valid; + return n; + } + + void step() { + x += dx; u += du; v += dv; + } +} + +void span(int y, EdgeInfo left, EdgeInfo right) { + int xs = fp16_int(left.x); + int xe = fp16_int(right.x); + + if (xs == xe) + return; + + assert(xs < xe); + + int xs_centered = left.x + fp16(0.5); + int xs_prestep = fp16_ceil(xs_centered) - xs_centered; + + int du = fp16_div(right.u - left.u, right.x - left.x); + int dv = fp16_div(right.v - left.v, right.x - left.x); + + int u = left.u + fp16_mul(xs_prestep, du); + int v = left.v + fp16_mul(xs_prestep, dv); + + for (int x = xs; x < xe; x++) { + //int p = get(x, y) + color(127); + int p = texture.get(fp16_int(u) & 255, fp16_int(v) & 255); + set(x, y, p); + u += du; + v += dv; + } +} + +void rasterize(EdgeInfo e01, EdgeInfo e02, EdgeInfo e12) { + EdgeInfo left, right; + int y = e01.ys; + boolean shortOnLeft; + + if (e01.valid) { + shortOnLeft = e01.dx < e02.dx; + } else if (e12.valid) { + shortOnLeft = e02.dx < e12.dx; + } else { + return; + } + + left = shortOnLeft ? e01.copy() : e02.copy(); + right = shortOnLeft ? e02.copy() : e01.copy(); + + if (e01.valid) { + for (; y < e01.ye; y++) { + span(y, left, right); + left.step(); + right.step(); + } + } + + if (shortOnLeft) { + left = e12.copy(); + } else { + right = e12.copy(); + } + + if (e12.valid) { + for (; y < e12.ye; y++) { + span(y, left, right); + left.step(); + right.step(); + } + } +} + +void setup() { + texture = loadImage("gull16.png"); + + size(640, 480); + frameRate(50); + noSmooth(); + noStroke(); +} + +void draw() { + background(0); + clear(); + + float r = 200.0; + float cx = width / 2; + float cy = height / 2; + + for (int tri = 0; tri < 2; tri++) { + Vertex p[] = new Vertex[3]; + for (int i = 0; i < 3; i++) { + float a = 2 * (i + tri * 2) * PI / 4 + frameCount / 256.0; + p[i] = new Vertex(sin(a) * r + cx, cos(a) * r + cy, 0.0, 0.0); + } + + if (tri == 0) { + p[1].u = fp16(255); + p[2].u = fp16(255); p[2].v = fp16(255); + } else if (tri == 1) { + p[0].u = fp16(255); p[0].v = fp16(255); + p[1].v = fp16(255); + } + + if (p[0].y > p[1].y) { Vertex tmp = p[0]; p[0] = p[1]; p[1] = tmp; } + if (p[0].y > p[2].y) { Vertex tmp = p[0]; p[0] = p[2]; p[2] = tmp; } + if (p[1].y > p[2].y) { Vertex tmp = p[1]; p[1] = p[2]; p[2] = tmp; } + + assert(p[0].y < p[1].y); + assert(p[1].y < p[2].y); + + EdgeInfo e01 = new EdgeInfo(p[0], p[1]); + EdgeInfo e02 = new EdgeInfo(p[0], p[2]); + EdgeInfo e12 = new EdgeInfo(p[1], p[2]); + + rasterize(e01, e02, e12); + + set((int)p[0].x, (int)p[0].y, color(255, 255, 0)); + // println("P0", p[0].x, p[0].y); + set((int)p[1].x, (int)p[1].y, color(0, 255, 255)); + // println("P1", p[1].x, p[1].y); + set((int)p[2].x, (int)p[2].y, color(255, 0, 255)); + // println("P2", p[2].x, p[2].y); + } +} \ No newline at end of file diff --git a/demo/prototypes/textures/stripes-cylinder.png b/demo/prototypes/textures/stripes-cylinder.png new file mode 100644 index 00000000..e0788e3d --- /dev/null +++ b/demo/prototypes/textures/stripes-cylinder.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cf73ca6ca6327b41b49388a01bed722e4b52d32ba386da6c4bf81c30a621f2ea +size 49915 diff --git a/demo/prototypes/textures/stripes-shape.png b/demo/prototypes/textures/stripes-shape.png new file mode 100644 index 00000000..1c50b833 --- /dev/null +++ b/demo/prototypes/textures/stripes-shape.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d5ae3890f56d0f5156630f1339a9e4940904516ef8307c3042c31769fcb7ed45 +size 51095 diff --git a/demo/prototypes/tree/convert.py b/demo/prototypes/tree/convert.py new file mode 100755 index 00000000..5094fd74 --- /dev/null +++ b/demo/prototypes/tree/convert.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python2 + +from __future__ import print_function + +from PIL import Image +from collections import defaultdict + +# reduce colors to 4-bit components +def rgb12(pix, w, h): + for y in range(h): + for x in range(w): + r, g, b = pix[x, y] + pix[x, y] = (r & 0xf0, g & 0xf0, b & 0xf0) + + +img = Image.open("tree-24.png") +w, h = img.size +pix = img.load() + +for N in range(1, 8): + K = 32 + 13 * (N - 1) + + print("pass #%d: make each %d consecutive lines share no more than " + "%d colors." % (N, N, K)) + + rgb12(pix, w, h) + + for y in range(N, h): + line = img.crop((0, y - N, w, y + 1)) + line = line.convert("P", dither=Image.NONE, palette=Image.ADAPTIVE, colors=K) + line = line.convert("RGB") + line = line.load() + for k in range(N): + for x in range(w): + pix[x, y + (k - N)] = line[x, k] + + +rgb12(pix, w, h) +img.save("tree-12.png") diff --git a/demo/prototypes/tree/tree-12.png b/demo/prototypes/tree/tree-12.png new file mode 100644 index 00000000..22472321 --- /dev/null +++ b/demo/prototypes/tree/tree-12.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9db4a568b6197e4df0bf29bad3deb83c51165a2b21d18ec4d5520995672b4461 +size 119966 diff --git a/demo/prototypes/tree/tree-24.png b/demo/prototypes/tree/tree-24.png new file mode 100644 index 00000000..c79005ef --- /dev/null +++ b/demo/prototypes/tree/tree-24.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6d1f28eaaa49d5b4f11a3f42cb223c9ed9f5c52b97c5081a77085433c65cb600 +size 404282 diff --git a/demo/prototypes/tree/verify.py b/demo/prototypes/tree/verify.py new file mode 100755 index 00000000..6b79c0ab --- /dev/null +++ b/demo/prototypes/tree/verify.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +from __future__ import print_function + +from PIL import Image + +img = Image.open("tree-12.png") +w, h = img.size +pix = img.load() + +lines = [] +for y in range(h): + line = set(pix[x, y] for x in range(w)) + n = len(line) + if n > 32: + print("line %d has %d colors" % (y, n)) + lines.append(line) + +for y in range(h - 1): + l1 = lines[y] + l2 = lines[y + 1] + d = len(l1.difference(l2)) + if d > 13: + print("line %d..%d: change in %d colors" % (y, y + 1, d)) + +colors = set() +for line in lines: + colors.update(line) +print("image uses %d colors" % len(colors)) diff --git a/demo/prototypes/uv-map/pumpkin-uv.png b/demo/prototypes/uv-map/pumpkin-uv.png new file mode 100644 index 00000000..687815ad --- /dev/null +++ b/demo/prototypes/uv-map/pumpkin-uv.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:085fac123aa2c5fa5a1ce1117161dd0b91a677068e01b45e750260a7974ec152 +size 37096 diff --git a/demo/prototypes/uv-map/pumpkin_v1.png b/demo/prototypes/uv-map/pumpkin_v1.png new file mode 100644 index 00000000..e8d64940 --- /dev/null +++ b/demo/prototypes/uv-map/pumpkin_v1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dcdf3f81d1966f3ce476461f031fd201deff652a613dd0e37c860722b24b7662 +size 3111 diff --git a/demo/prototypes/uv_pumpkin/data/mapidx-0.png b/demo/prototypes/uv_pumpkin/data/mapidx-0.png new file mode 100644 index 00000000..1bd0b71b --- /dev/null +++ b/demo/prototypes/uv_pumpkin/data/mapidx-0.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a3599c80b571d55285ffb7df7e3e0b7187b11477b7e82efeb670ebbc03769810 +size 920 diff --git a/demo/prototypes/uv_pumpkin/data/pumpkin.png b/demo/prototypes/uv_pumpkin/data/pumpkin.png new file mode 100644 index 00000000..a2a28d3d --- /dev/null +++ b/demo/prototypes/uv_pumpkin/data/pumpkin.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:55307e9bd8031b1c34641662bbef263de77feb007f73298484042551e7d718ab +size 12951 diff --git a/demo/prototypes/uv_pumpkin/data/texture-0.png b/demo/prototypes/uv_pumpkin/data/texture-0.png new file mode 100644 index 00000000..e00624b8 --- /dev/null +++ b/demo/prototypes/uv_pumpkin/data/texture-0.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:745d35c124a63ed601505ff41371a663bcdd70d6008469ca70621e9ee3c555f6 +size 16531 diff --git a/demo/prototypes/uv_pumpkin/data/texture-1.png b/demo/prototypes/uv_pumpkin/data/texture-1.png new file mode 100644 index 00000000..33314e3d --- /dev/null +++ b/demo/prototypes/uv_pumpkin/data/texture-1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e4ec1fb100f91450ac3ee253be27b841798b941339f5699aa3b42f04fee26df7 +size 129845 diff --git a/demo/prototypes/uv_pumpkin/data/uvmap0-u.png b/demo/prototypes/uv_pumpkin/data/uvmap0-u.png new file mode 100644 index 00000000..bca2b4c8 --- /dev/null +++ b/demo/prototypes/uv_pumpkin/data/uvmap0-u.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b2408847216923a3c39251df8ee4f97d57a308660c004c129fb91c4445dd5d47 +size 18498 diff --git a/demo/prototypes/uv_pumpkin/data/uvmap0-v.png b/demo/prototypes/uv_pumpkin/data/uvmap0-v.png new file mode 100644 index 00000000..eb33468a --- /dev/null +++ b/demo/prototypes/uv_pumpkin/data/uvmap0-v.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:185ce0ca1fd9ae166d468e0678ad859466c237d6d7ebf84a75c841eaec6c1763 +size 16642 diff --git a/demo/prototypes/uv_pumpkin/data/uvmap1-u.png b/demo/prototypes/uv_pumpkin/data/uvmap1-u.png new file mode 100644 index 00000000..fef6e9d3 --- /dev/null +++ b/demo/prototypes/uv_pumpkin/data/uvmap1-u.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6a9392ade5ecd56620e3f549fda81a276ad40c35b87b143fbd9e2edfbd7065c1 +size 184714 diff --git a/demo/prototypes/uv_pumpkin/data/uvmap1-v.png b/demo/prototypes/uv_pumpkin/data/uvmap1-v.png new file mode 100644 index 00000000..0f4892f0 --- /dev/null +++ b/demo/prototypes/uv_pumpkin/data/uvmap1-v.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c4a7c016dd3abce8cf7ca1ddd99ab53d1d845e5d1e89c3d46fc8080217fc5c98 +size 63329 diff --git a/demo/prototypes/uv_pumpkin/uv_pumpkin.pde b/demo/prototypes/uv_pumpkin/uv_pumpkin.pde new file mode 100644 index 00000000..7f4f8ec6 --- /dev/null +++ b/demo/prototypes/uv_pumpkin/uv_pumpkin.pde @@ -0,0 +1,63 @@ +PImage[] umap; +PImage[] vmap; +PImage[] texture; + +/* Per pixel information on uvmap usage */ +PImage mapidx; +int[] mapidxcol = {color(255), color(0)}; + +/* Punpkin image overlay */ +PImage pumpkin; + +final int nmaps = 2; +final int ntextures = 2; + +void setup() { + size(320, 256); + frameRate(25); + + pumpkin = loadImage("pumpkin.png"); + + umap = new PImage[nmaps]; + vmap = new PImage[nmaps]; + + for (int i = 0; i < nmaps; i++) { + umap[i] = loadImage("uvmap" + str(i) + "-u.png"); + vmap[i] = loadImage("uvmap" + str(i) + "-v.png"); + } + + texture = new PImage[ntextures]; + + for (int i = 0; i < ntextures; i++) { + texture[i] = loadImage("texture-" + str(i) + ".png"); + } + + mapidx = loadImage("mapidx-0.png"); +} + +int get_mapidx(int x, int y) { + color c = mapidx.get(x, y); + for (int i = 0; i < nmaps; i++) + if (c == mapidxcol[i]) + return i; + return -1; +} + +void draw() { + int t = frameCount; + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + int i = get_mapidx(x, y); + + if (i == -1) + continue; + + int u = (umap[i].get(x, y) + t) & 255; + int v = (vmap[i].get(x, y) + t) & 255; + + set(x, y, texture[i].get(u, v)); + } + } + image(pumpkin, 0, 0); +} \ No newline at end of file diff --git a/demo/prototypes/uv_torus/data/.gitattributes b/demo/prototypes/uv_torus/data/.gitattributes new file mode 100644 index 00000000..24a8e879 --- /dev/null +++ b/demo/prototypes/uv_torus/data/.gitattributes @@ -0,0 +1 @@ +*.png filter=lfs diff=lfs merge=lfs -text diff --git a/demo/prototypes/uv_torus/data/Makefile b/demo/prototypes/uv_torus/data/Makefile new file mode 100644 index 00000000..c04cda3b --- /dev/null +++ b/demo/prototypes/uv_torus/data/Makefile @@ -0,0 +1,13 @@ +all: torus-u.png torus-v.png torus-light.png + +torus-u.png: torus.pov + povray -D Width=640 Height=480 +O$@ Declare=UMAP=1 $^ + +torus-v.png: torus.pov + povray -D Width=640 Height=480 +O$@ Declare=VMAP=1 $^ + +torus-light.png: light.pov + povray -D Width=640 Height=480 +O$@ $^ + +clean: + rm -f *~ torus-*.png diff --git a/demo/prototypes/uv_torus/data/bake.png b/demo/prototypes/uv_torus/data/bake.png new file mode 100644 index 00000000..e6783f80 --- /dev/null +++ b/demo/prototypes/uv_torus/data/bake.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6f07d3356aadf67f6b35fabd1e39e8a94b56a47521bd627ab76375e0c68a04cb +size 339458 diff --git a/demo/prototypes/uv_torus/data/bake2.png b/demo/prototypes/uv_torus/data/bake2.png new file mode 100644 index 00000000..d548f23f --- /dev/null +++ b/demo/prototypes/uv_torus/data/bake2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6b73d491af965c03ecfbdcb0f5980eedc20811e9027cdcbe958108fb848e4a82 +size 322957 diff --git a/demo/prototypes/uv_torus/data/light.png b/demo/prototypes/uv_torus/data/light.png new file mode 100644 index 00000000..0ca5f4de --- /dev/null +++ b/demo/prototypes/uv_torus/data/light.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:32a4dcdf0f4a23059fe29e1397875dc0ac640cd3d590b755011733d40526a3cf +size 263249 diff --git a/demo/prototypes/uv_torus/data/light.pov b/demo/prototypes/uv_torus/data/light.pov new file mode 100644 index 00000000..0bb03d5c --- /dev/null +++ b/demo/prototypes/uv_torus/data/light.pov @@ -0,0 +1,34 @@ +#include "colors.inc" +#include "shapes.inc" +#include "textures.inc" + +#declare R = 4; +#declare r = 2; + +camera { + location <0,0,10> + look_at <0,0,0> +} + +light_source { + <0,0,20> + color White +} + +torus { + R r + rotate 45*x + rotate -22.5*y + translate <-0.4, 1.25, 0> + uv_mapping + pigment{ + image_map {png "bake2.png"} + } + finish { + ambient .45 + } +} + +background { + Green +} diff --git a/demo/prototypes/uv_torus/data/small-torus-u.png b/demo/prototypes/uv_torus/data/small-torus-u.png new file mode 100644 index 00000000..6bca0894 --- /dev/null +++ b/demo/prototypes/uv_torus/data/small-torus-u.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7d1d6d88ff10fa43cd63afd17b9039b3f312ad9ff0af6bcb745d353887264dc6 +size 2259 diff --git a/demo/prototypes/uv_torus/data/small-torus-v.png b/demo/prototypes/uv_torus/data/small-torus-v.png new file mode 100644 index 00000000..7b79e5b5 --- /dev/null +++ b/demo/prototypes/uv_torus/data/small-torus-v.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f563b6479f2d96110d54423f59c9d48384d5ceff3127bf8a904be00441d5037e +size 2626 diff --git a/demo/prototypes/uv_torus/data/texture.png b/demo/prototypes/uv_torus/data/texture.png new file mode 100644 index 00000000..09580819 --- /dev/null +++ b/demo/prototypes/uv_torus/data/texture.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b6caa90e9c30e1e2cc91b68b4b73f61a1194a6485da4c6523f375c3576ad38cd +size 75372 diff --git a/demo/prototypes/uv_torus/data/torus-bake.png b/demo/prototypes/uv_torus/data/torus-bake.png new file mode 100644 index 00000000..0fbd5d39 --- /dev/null +++ b/demo/prototypes/uv_torus/data/torus-bake.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b2eb2d47251f5888831695c5ac19681d5eab9cd53ed6110f29a0a699d631d9ec +size 22640 diff --git a/demo/prototypes/uv_torus/data/torus-light.png b/demo/prototypes/uv_torus/data/torus-light.png new file mode 100644 index 00000000..10d182bb --- /dev/null +++ b/demo/prototypes/uv_torus/data/torus-light.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d1dff27d602f282b4dba36c2eda537f6972f888b74e6f0e0fff92e28961bdde +size 7893 diff --git a/demo/prototypes/uv_torus/data/torus-u.png b/demo/prototypes/uv_torus/data/torus-u.png new file mode 100644 index 00000000..43532ed5 --- /dev/null +++ b/demo/prototypes/uv_torus/data/torus-u.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:07c178f5ca7938ddc4806aeea151ff9b58faab0fea842d3db4ecc2bcd81e91d0 +size 27766 diff --git a/demo/prototypes/uv_torus/data/torus-v.png b/demo/prototypes/uv_torus/data/torus-v.png new file mode 100644 index 00000000..ba9309db --- /dev/null +++ b/demo/prototypes/uv_torus/data/torus-v.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:408e5f6b2c05d04427db165ee8cbae7104423c53662d4cf77857de57b0b55d70 +size 37720 diff --git a/demo/prototypes/uv_torus/data/torus.pov b/demo/prototypes/uv_torus/data/torus.pov new file mode 100644 index 00000000..697a3ffa --- /dev/null +++ b/demo/prototypes/uv_torus/data/torus.pov @@ -0,0 +1,42 @@ +#include "colors.inc" +#include "shapes.inc" +#include "textures.inc" + +#declare R = 4; +#declare r = 2; + +#declare rad = function(x,y) { atan2(x, y) / (2 * pi) } +#declare dist = function(x,y) { sqrt(x * x + y * y) } + +#declare torus_u = function(x,y,z) { rad(z, x) } +#declare torus_v = function(x,y,z) { rad(y, dist(x, z) - R) } + +camera { + location <0,0,10> + look_at <0,0,0> +} + +torus { + R r + uv_mapping + pigment { +#ifdef (VMAP) + // torus_v(x,y,z) + gradient -v +#end +#ifdef (UMAP) + // torus_u(x,y,z) + gradient u +#end + } + rotate 45*x + rotate -22.5*y + translate <-0.4, 1.25, 0> + finish { + ambient 1.0 + } +} + +background { + Green +} \ No newline at end of file diff --git a/demo/prototypes/uv_torus/uv_torus.pde b/demo/prototypes/uv_torus/uv_torus.pde new file mode 100644 index 00000000..9dfb4312 --- /dev/null +++ b/demo/prototypes/uv_torus/uv_torus.pde @@ -0,0 +1,61 @@ +PImage umap; +PImage vmap; +PImage texture; +PImage bake; + +final int green = color(0, 255, 0); + +/* Per pixel information on uvmap usage */ +PImage mapidx; + +void setup() { + size(640, 480); + frameRate(50); + + umap = loadImage("torus-u.png"); + vmap = loadImage("torus-v.png"); + bake = loadImage("torus-bake.png"); + texture = loadImage("texture.png"); + + mapidx = createImage(width, height, RGB); + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + int i = (umap.get(x, y) == green) ? 0 : 255; + mapidx.set(x, y, color(i)); + } + } +} + +void draw() { + background(0); + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + int i = mapidx.get(x, y); + + if (i == color(0)) + continue; + + int ub = (umap.get(x, y) - frameCount) & 255; + int vb = (vmap.get(x, y)) & 255; + + int uc = (umap.get(x, y) + frameCount) & 255; + int vc = (vmap.get(x, y) + frameCount) & 255; + + float l = brightness(bake.get(ub, vb)); + int c = texture.get(uc, vc); + + if (l < 128.0) + c = lerpColor(color(0), c, l / 128.0); + else + c = lerpColor(c, color(255), (l - 128.0) / 128.0); + + set(x, y, c); + } + } + + if (keyPressed) { + save("uv_torus.png"); + } +} \ No newline at end of file diff --git a/demo/prototypes/vector_zoom/data/bat.obj b/demo/prototypes/vector_zoom/data/bat.obj new file mode 100644 index 00000000..76ac3556 --- /dev/null +++ b/demo/prototypes/vector_zoom/data/bat.obj @@ -0,0 +1,60 @@ +g Mesh +v 0.00852159 0.010048 0 +v 0.0138989 0.0194753 0 +v 0.0195281 -0.00175789 0 +v 0.0259165 -0.00961505 0 +v 0.037928 -0.0109157 0 +v 0.0597184 0.00756429 0 +v 0.0846263 0.0320342 0 +v 0.112918 0.0514211 0 +v 0.151825 0.0648489 0 +v 0.192107 0.0661723 0 +v 0.175286 0.0611851 0 +v 0.161327 0.0508585 0 +v 0.153707 0.0379067 0 +v 0.151641 0.0234291 0 +v 0.156323 0.00218261 0 +v 0.140672 0.006675 0 +v 0.126671 0.00332011 0 +v 0.117571 -0.0107391 0 +v 0.116959 -0.0243721 0 +v 0.11995 -0.0337693 0 +v 0.102289 -0.0287783 0 +v 0.0867595 -0.0311162 0 +v 0.0737074 -0.044762 0 +v 0.0663942 -0.0643281 0 +v 0.0517464 -0.0500396 0 +v 0.0329813 -0.0438529 0 +v 0.0128686 -0.0541646 0 +v -0.00852159 0.010048 0 +v -0.0138989 0.0194753 0 +v -0.0195281 -0.00175789 0 +v -0.0259165 -0.00961505 0 +v -0.037928 -0.0109157 0 +v -0.0597184 0.00756429 0 +v -0.0846263 0.0320342 0 +v -0.112918 0.0514211 0 +v -0.151825 0.0648489 0 +v -0.192107 0.0661723 0 +v -0.175286 0.0611851 0 +v -0.161327 0.0508585 0 +v -0.153707 0.0379067 0 +v -0.151641 0.0234291 0 +v -0.156323 0.00218261 0 +v -0.140672 0.006675 0 +v -0.126671 0.00332011 0 +v -0.117571 -0.0107391 0 +v -0.116959 -0.0243721 0 +v -0.11995 -0.0337693 0 +v -0.102289 -0.0287783 0 +v -0.0867595 -0.0311162 0 +v -0.0737074 -0.044762 0 +v -0.0663942 -0.0643281 0 +v -0.0517464 -0.0500396 0 +v -0.0329813 -0.0438529 0 +v -0.0128686 -0.0541646 0 +v 0 -0.0813561 0 +v 0 0.00709105 0 +usemtl Default +g Default +f 55 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 56 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 diff --git a/demo/prototypes/vector_zoom/data/ghost.obj b/demo/prototypes/vector_zoom/data/ghost.obj new file mode 100644 index 00000000..81345d34 --- /dev/null +++ b/demo/prototypes/vector_zoom/data/ghost.obj @@ -0,0 +1,80 @@ +g Mesh +v 0.0101173 0.0465417 -0.00075 +v 0.01109 0.0415502 -0.00075 +v 0.0137475 0.0378962 -0.00075 +v 0.0173777 0.0365588 -0.00075 +v 0.0210079 0.0378962 -0.00075 +v 0.0236654 0.0415502 -0.00075 +v 0.0246381 0.0465417 -0.00075 +v 0.0236654 0.0515331 -0.00075 +v 0.0210079 0.0551871 -0.00075 +v 0.0173777 0.0565246 -0.00075 +v 0.0137475 0.0551871 -0.00075 +v 0.01109 0.0515331 -0.00075 +v 0.0557036 0.0465417 -0.00075 +v 0.0547309 0.0415502 -0.00075 +v 0.0520734 0.0378962 -0.00075 +v 0.0484432 0.0365588 -0.00075 +v 0.044813 0.0378962 -0.00075 +v 0.0421555 0.0415502 -0.00075 +v 0.0411828 0.0465417 -0.00075 +v 0.0421555 0.0515331 -0.00075 +v 0.044813 0.0551871 -0.00075 +v 0.0484432 0.0565246 -0.00075 +v 0.0520734 0.0551871 -0.00075 +v 0.0547309 0.0515331 -0.00075 +v -0.00029096 0.045933 -0.00075 +v 0.00171462 0.0334543 -0.00075 +v 0.00719398 0.0243193 -0.00075 +v 0.0146789 0.0209757 -0.00075 +v 0.0221639 0.0243193 -0.00075 +v 0.0276432 0.0334543 -0.00075 +v 0.0296488 0.045933 -0.00075 +v 0.0276432 0.0584116 -0.00075 +v 0.0221639 0.0675466 -0.00075 +v 0.0146789 0.0708903 -0.00075 +v 0.00719398 0.0675466 -0.00075 +v 0.00171462 0.0584116 -0.00075 +v 0.0659044 0.045933 -0.00075 +v 0.0638988 0.0334543 -0.00075 +v 0.0584194 0.0243193 -0.00075 +v 0.0509345 0.0209757 -0.00075 +v 0.0434496 0.0243193 -0.00075 +v 0.0379702 0.0334543 -0.00075 +v 0.0359646 0.045933 -0.00075 +v 0.0379702 0.0584116 -0.00075 +v 0.0434496 0.0675466 -0.00075 +v 0.0509345 0.0708903 -0.00075 +v 0.0584194 0.0675466 -0.00075 +v 0.0638988 0.0584116 -0.00075 +v -0.0438958 0.0315583 0.00075 +v -0.0432538 0.0121292 0.00075 +v -0.0742131 -0.0853871 0.00075 +v -0.0807092 -0.0933884 0.00075 +v -0.0799448 -0.10031 0.00075 +v -0.073615 -0.103153 0.00075 +v -0.0624835 -0.101576 0.00075 +v 0.0701734 -0.0190356 0.00075 +v 0.0769519 0.00669363 0.00075 +v 0.0807092 0.0315583 0.00075 +v 0.0769519 0.0564231 0.00075 +v 0.0661332 0.0782887 0.00075 +v 0.049558 0.094518 0.00075 +v 0.0292254 0.103153 0.00075 +v 0.007588 0.103153 0.00075 +v -0.0127445 0.094518 0.00075 +v -0.0293198 0.0782887 0.00075 +v -0.0401385 0.0564231 0.00075 +v -0.0650372 -0.0691589 0.00075 +v -0.0301548 -0.0967146 0.00075 +v 0.0138176 -0.081171 0.00075 +v -0.0507313 -0.0389721 0.00075 +v 0.0546195 -0.0461078 0.00075 +v -0.0441562 -0.00941055 0.00075 +usemtl Default +g Default +f 1 2 3 4 5 6 7 8 9 10 11 12 +f 13 24 23 22 21 20 19 18 17 16 15 14 +f 25 26 27 28 29 30 31 32 33 34 35 36 +f 37 48 47 46 45 44 43 42 41 40 39 38 +f 69 71 56 57 58 59 60 61 62 63 64 65 66 49 50 72 70 67 51 52 53 54 55 68 diff --git a/demo/prototypes/vector_zoom/data/pumpkin.obj b/demo/prototypes/vector_zoom/data/pumpkin.obj new file mode 100644 index 00000000..a8ffa797 --- /dev/null +++ b/demo/prototypes/vector_zoom/data/pumpkin.obj @@ -0,0 +1,55 @@ +g Mesh +v -0.0225687 0.0877723 0 +v -0.00821535 0.0982596 0 +v 0.00769405 0.0827943 0 +v 0.0143015 0.0600925 0 +v 0.0319248 0.0509648 0 +v 0.057054 0.0621068 0 +v 0.0753644 0.056879 0 +v 0.0924576 0.041182 0 +v 0.104812 0.0183908 0 +v 0.108931 -0.00812352 0 +v 0.0971853 -0.0531232 0 +v 0.0792419 -0.0776829 0 +v 0.0599869 -0.0931392 0 +v 0.0411856 -0.0982596 0 +v -0.000557259 -0.0918028 0 +v -0.0422911 -0.0982596 0 +v -0.0611575 -0.0931392 0 +v -0.0806568 -0.0776829 0 +v -0.0987661 -0.0531232 0 +v -0.108931 -0.0197307 0 +v -0.10521 0.017628 0 +v -0.0927258 0.041182 0 +v -0.0764136 0.056879 0 +v -0.0555404 0.062943 0 +v -0.0330404 0.050943 0 +v -0.00754039 0.061443 0 +v -0.0105404 0.076443 0 +v -0.0682585 0.0138215 0 +v -0.0215913 -0.00273263 0 +v -0.0298329 -0.0151328 0 +v -0.0428044 -0.0192662 0 +v -0.0594771 -0.0124553 0 +v -0.0666968 -0.0025157 0 +v 0.0699777 0.0138215 0 +v 0.0233105 -0.00273263 0 +v 0.0315521 -0.0151328 0 +v 0.0445236 -0.0192662 0 +v 0.0611963 -0.0124553 0 +v 0.068416 -0.0025157 0 +v -0.0623795 -0.0354679 0 +v -0.0545533 -0.0581056 0 +v 0.0528104 -0.0581056 0 +v 0.0626048 -0.0368363 0 +v 0.0407367 -0.0510186 0 +v 0.0221394 -0.0344726 0 +v -0.00167863 -0.052018 0 +v -0.0245324 -0.0354679 0 +v -0.0414946 -0.0500067 0 +usemtl Default +g Default +f 2 1 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 +f 29 28 33 32 31 30 +f 35 36 37 38 39 34 +f 41 42 43 44 45 46 47 48 40 diff --git a/demo/prototypes/vector_zoom/vector_zoom.pde b/demo/prototypes/vector_zoom/vector_zoom.pde new file mode 100644 index 00000000..435e102f --- /dev/null +++ b/demo/prototypes/vector_zoom/vector_zoom.pde @@ -0,0 +1,34 @@ +ArrayList shapes; +int[] colors = {color(64,64,64), color(0x40,0xE0,0x80), color(255,192,0)}; +int nshapes; + +void setup() { + size(640, 480, P3D); + frameRate(50); + + shapes = new ArrayList(); + shapes.add(loadShape("bat.obj")); + shapes.add(loadShape("ghost.obj")); + shapes.add(loadShape("pumpkin.obj")); + + nshapes = shapes.size(); +} + +final int phase = 200; + +void draw() { + int time = frameCount % phase; + int num = (frameCount / phase) % nshapes; + PShape s = shapes.get(num); + + int bg = colors[(num + nshapes - 1) % nshapes]; + int fg = colors[num]; + + s.setFill(lerpColor(bg, fg, time / 25.0)); + background(bg); + + translate(width/2, height/2); + scale(8000.0 * (float)time / phase); + rotateZ(PI + sin(time / 32.0) * 0.05 * PI); + shape(s); +} \ No newline at end of file