-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import all files from bitbucket repo.
- Loading branch information
Showing
62 changed files
with
1,381 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
Oops, something went wrong.