mirror of
https://github.com/processing/processing4.git
synced 2026-02-09 16:49:21 +01:00
Core files, plus some test files (note that test files may not compile due to recent changes to the core)
This commit is contained in:
628
core/processing/core/PCanvas.java
Executable file
628
core/processing/core/PCanvas.java
Executable file
@@ -0,0 +1,628 @@
|
||||
package processing.core;
|
||||
|
||||
import javax.microedition.lcdui.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class PCanvas extends Canvas {
|
||||
private PMIDlet midlet;
|
||||
|
||||
private Image buffer;
|
||||
private Graphics bufferg;
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
private boolean stroke;
|
||||
private int strokeWidth;
|
||||
private int strokeColor;
|
||||
|
||||
private boolean fill;
|
||||
private int fillColor;
|
||||
|
||||
private int rectMode;
|
||||
private int ellipseMode;
|
||||
|
||||
private int shapeMode;
|
||||
private int[] vertex;
|
||||
private int vertexIndex;
|
||||
private int[] curveVertex;
|
||||
private int curveVertexIndex;
|
||||
|
||||
private int textMode;
|
||||
|
||||
/** Creates a new instance of PCanvas */
|
||||
public PCanvas(PMIDlet midlet) {
|
||||
this.midlet = midlet;
|
||||
|
||||
width = getWidth();
|
||||
height = getHeight();
|
||||
|
||||
buffer = Image.createImage(width, height);
|
||||
bufferg = buffer.getGraphics();
|
||||
|
||||
stroke = true;
|
||||
strokeColor = 0;
|
||||
strokeWidth = 1;
|
||||
|
||||
fill = true;
|
||||
fillColor = 0xFFFFFF;
|
||||
|
||||
rectMode = PMIDlet.CORNER;
|
||||
ellipseMode = PMIDlet.CORNER;
|
||||
|
||||
shapeMode = -1;
|
||||
vertex = new int[16];
|
||||
vertexIndex = 0;
|
||||
|
||||
curveVertex = new int[8];
|
||||
curveVertexIndex = 0;
|
||||
|
||||
textMode = Graphics.TOP | Graphics.LEFT;
|
||||
|
||||
background(200);
|
||||
}
|
||||
|
||||
protected void paint(Graphics g) {
|
||||
g.drawImage(buffer, 0, 0, Graphics.LEFT | Graphics.TOP);
|
||||
}
|
||||
|
||||
protected void keyPressed(int keyCode) {
|
||||
midlet.keyPressed = true;
|
||||
|
||||
int action = getGameAction(keyCode);
|
||||
switch (action) {
|
||||
case Canvas.UP:
|
||||
midlet.key = PMIDlet.UP;
|
||||
break;
|
||||
case Canvas.DOWN:
|
||||
midlet.key = PMIDlet.DOWN;
|
||||
break;
|
||||
case Canvas.LEFT:
|
||||
midlet.key = PMIDlet.LEFT;
|
||||
break;
|
||||
case Canvas.RIGHT:
|
||||
midlet.key = PMIDlet.RIGHT;
|
||||
break;
|
||||
case Canvas.FIRE:
|
||||
midlet.key = PMIDlet.FIRE;
|
||||
break;
|
||||
default:
|
||||
//// MIDP 1.0 says the KEY_ values map to ASCII values, but I've seen it
|
||||
//// different on some foreign (i.e. Korean) handsets
|
||||
if ((keyCode >= Canvas.KEY_NUM0) && (keyCode <= Canvas.KEY_NUM9)) {
|
||||
midlet.key = (char) ('0' + (keyCode - Canvas.KEY_NUM0));
|
||||
} else {
|
||||
switch (keyCode) {
|
||||
case Canvas.KEY_POUND:
|
||||
midlet.key = '#';
|
||||
break;
|
||||
case Canvas.KEY_STAR:
|
||||
midlet.key = '*';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
midlet.keyPressed();
|
||||
}
|
||||
|
||||
protected void keyReleased(int keyCode) {
|
||||
midlet.keyPressed = false;
|
||||
midlet.keyReleased();
|
||||
}
|
||||
|
||||
public void point(int x1, int y1) {
|
||||
if (stroke) {
|
||||
bufferg.setColor(strokeColor);
|
||||
bufferg.drawLine(x1, y1, x1, y1);
|
||||
}
|
||||
}
|
||||
|
||||
public void line(int x1, int y1, int x2, int y2) {
|
||||
if (stroke) {
|
||||
bufferg.setColor(strokeColor);
|
||||
bufferg.drawLine(x1, y1, x2, y2);
|
||||
if (strokeWidth > 1) {
|
||||
//// to do
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void triangle(int x1, int y1, int x2, int y2, int x3, int y3) {
|
||||
shapeMode = PMIDlet.POLYGON;
|
||||
vertex[0] = x1;
|
||||
vertex[1] = y1;
|
||||
vertex[2] = x2;
|
||||
vertex[3] = y2;
|
||||
vertex[4] = x3;
|
||||
vertex[5] = y3;
|
||||
vertexIndex = 6;
|
||||
endShape();
|
||||
}
|
||||
|
||||
public void quad(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
|
||||
shapeMode = PMIDlet.POLYGON;
|
||||
vertex[0] = x1;
|
||||
vertex[1] = y1;
|
||||
vertex[2] = x2;
|
||||
vertex[3] = y2;
|
||||
vertex[4] = x3;
|
||||
vertex[5] = y3;
|
||||
vertex[6] = x4;
|
||||
vertex[7] = y4;
|
||||
vertexIndex = 8;
|
||||
endShape();
|
||||
}
|
||||
|
||||
public void rect(int x, int y, int width, int height) {
|
||||
int temp;
|
||||
switch (rectMode) {
|
||||
case PMIDlet.CORNERS:
|
||||
temp = x;
|
||||
x = Math.min(x, width);
|
||||
width = Math.abs(x - temp);
|
||||
temp = y;
|
||||
y = Math.min(y, height);
|
||||
height = Math.abs(y - temp);
|
||||
break;
|
||||
case PMIDlet.CENTER_DIAMETER:
|
||||
x -= width / 2;
|
||||
y -= height / 2;
|
||||
break;
|
||||
}
|
||||
if (fill) {
|
||||
bufferg.setColor(fillColor);
|
||||
bufferg.fillRect(x, y, width, height);
|
||||
}
|
||||
if (stroke) {
|
||||
bufferg.setColor(strokeColor);
|
||||
bufferg.drawRect(x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
public void rectMode(int MODE) {
|
||||
if ((MODE >= PMIDlet.CORNER) && (MODE <= PMIDlet.CENTER_DIAMETER)) {
|
||||
rectMode = MODE;
|
||||
}
|
||||
}
|
||||
|
||||
public void ellipse(int x, int y, int width, int height) {
|
||||
int temp;
|
||||
switch (ellipseMode) {
|
||||
case PMIDlet.CORNERS:
|
||||
temp = x;
|
||||
x = Math.min(x, width);
|
||||
width = Math.abs(x - temp);
|
||||
temp = y;
|
||||
y = Math.min(y, height);
|
||||
height = Math.abs(y - temp);
|
||||
break;
|
||||
case PMIDlet.CENTER_DIAMETER:
|
||||
x -= width / 2;
|
||||
y -= height / 2;
|
||||
break;
|
||||
case PMIDlet.CENTER_RADIUS:
|
||||
x -= width;
|
||||
y -= height;
|
||||
width *= 2;
|
||||
height *= 2;
|
||||
break;
|
||||
}
|
||||
if (fill) {
|
||||
bufferg.setColor(fillColor);
|
||||
bufferg.fillArc(x, y, width, height, 0, 360);
|
||||
}
|
||||
if (stroke) {
|
||||
bufferg.setColor(strokeColor);
|
||||
bufferg.drawArc(x, y, width, height, 0, 360);
|
||||
}
|
||||
}
|
||||
|
||||
public void ellipseMode(int MODE) {
|
||||
if ((MODE >= PMIDlet.CORNER) && (MODE <= PMIDlet.CENTER_RADIUS)) {
|
||||
ellipseMode = MODE;
|
||||
}
|
||||
}
|
||||
|
||||
public void curve(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
|
||||
beginShape(PMIDlet.LINE_STRIP);
|
||||
curveVertex(x1, y1);
|
||||
curveVertex(x1, y1);
|
||||
curveVertex(x2, y2);
|
||||
curveVertex(x3, y3);
|
||||
curveVertex(x4, y4);
|
||||
curveVertex(x4, y4);
|
||||
endShape();
|
||||
}
|
||||
|
||||
public void bezier(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
|
||||
beginShape(PMIDlet.LINE_STRIP);
|
||||
bezierVertex(x1, y1);
|
||||
bezierVertex(x2, y2);
|
||||
bezierVertex(x3, y3);
|
||||
bezierVertex(x4, y4);
|
||||
endShape();
|
||||
}
|
||||
|
||||
public void strokeWeight(int width) {
|
||||
strokeWidth = width;
|
||||
}
|
||||
|
||||
public void beginShape(int MODE) {
|
||||
if ((MODE >= PMIDlet.POINTS) && (MODE <= PMIDlet.POLYGON)) {
|
||||
shapeMode = MODE;
|
||||
} else {
|
||||
shapeMode = PMIDlet.POINTS;
|
||||
}
|
||||
vertexIndex = 0;
|
||||
curveVertexIndex = 0;
|
||||
}
|
||||
|
||||
public void endShape() {
|
||||
int i;
|
||||
int step;
|
||||
switch (shapeMode) {
|
||||
case PMIDlet.POINTS:
|
||||
i = 0;
|
||||
step = 2;
|
||||
break;
|
||||
case PMIDlet.LINES:
|
||||
i = 2;
|
||||
step = 4;
|
||||
break;
|
||||
case PMIDlet.LINE_STRIP:
|
||||
case PMIDlet.LINE_LOOP:
|
||||
i = 2;
|
||||
step = 2;
|
||||
break;
|
||||
case PMIDlet.TRIANGLES:
|
||||
i = 4;
|
||||
step = 6;
|
||||
break;
|
||||
case PMIDlet.TRIANGLE_STRIP:
|
||||
i = 4;
|
||||
step = 2;
|
||||
break;
|
||||
case PMIDlet.QUADS:
|
||||
i = 6;
|
||||
step = 8;
|
||||
break;
|
||||
case PMIDlet.QUAD_STRIP:
|
||||
i = 6;
|
||||
step = 4;
|
||||
break;
|
||||
case PMIDlet.POLYGON:
|
||||
polygon(0, vertexIndex - 2);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
for (; i < vertexIndex; i += step) {
|
||||
switch (shapeMode) {
|
||||
case PMIDlet.POINTS:
|
||||
point(vertex[i], vertex[i + 1]);
|
||||
break;
|
||||
case PMIDlet.LINES:
|
||||
case PMIDlet.LINE_STRIP:
|
||||
case PMIDlet.LINE_LOOP:
|
||||
line(vertex[i - 2], vertex[i - 1], vertex[i], vertex[i + 1]);
|
||||
break;
|
||||
case PMIDlet.TRIANGLES:
|
||||
case PMIDlet.TRIANGLE_STRIP:
|
||||
polygon(i - 4, i);
|
||||
break;
|
||||
case PMIDlet.QUADS:
|
||||
case PMIDlet.QUAD_STRIP:
|
||||
polygon(i - 6, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//// handle loop closing
|
||||
if (shapeMode == PMIDlet.LINE_LOOP) {
|
||||
if (vertexIndex >= 2) {
|
||||
line(vertex[vertexIndex - 2], vertex[vertexIndex - 1], vertex[0], vertex[1]);
|
||||
}
|
||||
}
|
||||
|
||||
vertexIndex = 0;
|
||||
}
|
||||
|
||||
private void polygon(int startIndex, int endIndex) {
|
||||
//// make sure at least 2 vertices
|
||||
if (endIndex >= (startIndex + 2)) {
|
||||
//// make sure at least 3 vertices for fill
|
||||
if (endIndex >= (startIndex + 4)) {
|
||||
if (fill) {
|
||||
bufferg.setColor(fillColor);
|
||||
|
||||
//// insertion sort of edges from top-left to bottom right
|
||||
Vector edges = new Vector();
|
||||
int edgeCount = 0;
|
||||
Edge e1, e2;
|
||||
int i, j;
|
||||
int yMin = Integer.MAX_VALUE;
|
||||
int yMax = Integer.MIN_VALUE;
|
||||
for (i = startIndex; i <= endIndex; i += 2) {
|
||||
e1 = new Edge();
|
||||
if (i == startIndex) {
|
||||
//// handle connecting line between start and endpoints
|
||||
if (vertex[startIndex + 1] < vertex[endIndex + 1]) {
|
||||
e1.x1 = vertex[startIndex];
|
||||
e1.y1 = vertex[startIndex + 1];
|
||||
e1.x2 = vertex[endIndex];
|
||||
e1.y2 = vertex[endIndex + 1];
|
||||
} else {
|
||||
e1.x1 = vertex[endIndex];
|
||||
e1.y1 = vertex[endIndex + 1];
|
||||
e1.x2 = vertex[startIndex];
|
||||
e1.y2 = vertex[startIndex + 1];
|
||||
}
|
||||
} else if (vertex[i - 1] < vertex[i + 1]) {
|
||||
e1.x1 = vertex[i - 2];
|
||||
e1.y1 = vertex[i - 1];
|
||||
e1.x2 = vertex[i];
|
||||
e1.y2 = vertex[i + 1];
|
||||
} else {
|
||||
e1.x1 = vertex[i];
|
||||
e1.y1 = vertex[i + 1];
|
||||
e1.x2 = vertex[i - 2];
|
||||
e1.y2 = vertex[i - 1];
|
||||
}
|
||||
e1.x = e1.x1;
|
||||
e1.dx = e1.x2 - e1.x1;
|
||||
e1.dy = e1.y2 - e1.y1;
|
||||
|
||||
yMin = Math.min(e1.y1, yMin);
|
||||
yMax = Math.max(e1.y2, yMax);
|
||||
|
||||
for (j = 0; j < edgeCount; j++) {
|
||||
e2 = (Edge) edges.elementAt(j);
|
||||
if (e1.y1 < e2.y1) {
|
||||
edges.insertElementAt(e1, j);
|
||||
e1 = null;
|
||||
break;
|
||||
} else if (e1.y1 == e2.y1) {
|
||||
if (e1.x1 < e2.x1) {
|
||||
edges.insertElementAt(e1, j);
|
||||
e1 = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e1 != null) {
|
||||
edges.addElement(e1);
|
||||
}
|
||||
edgeCount += 1;
|
||||
}
|
||||
|
||||
//// draw scanlines
|
||||
Vector active = new Vector();
|
||||
int activeCount = 0;
|
||||
for (int y = yMin; y <= yMax; y++) {
|
||||
//// update currently active edges
|
||||
for (i = activeCount - 1; i >= 0; i--) {
|
||||
e1 = (Edge) active.elementAt(i);
|
||||
if (e1.y2 <= y) {
|
||||
//// remove edges not intersecting current scan line
|
||||
active.removeElementAt(i);
|
||||
activeCount--;
|
||||
} else {
|
||||
//// update x coordinate
|
||||
e1.x = (y - e1.y1) * e1.dx / e1.dy + e1.x1;
|
||||
}
|
||||
}
|
||||
|
||||
//// re-sort active edge list
|
||||
Vector newActive = new Vector();
|
||||
for (i = 0; i < activeCount; i++) {
|
||||
e1 = (Edge) active.elementAt(i);
|
||||
|
||||
for (j = 0; j < i; j++) {
|
||||
e2 = (Edge) newActive.elementAt(j);
|
||||
if (e1.x < e2.x) {
|
||||
newActive.insertElementAt(e1, j);
|
||||
e1 = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (e1 != null) {
|
||||
newActive.addElement(e1);
|
||||
}
|
||||
}
|
||||
active = newActive;
|
||||
|
||||
//// insertion sort any new intersecting edges into active list
|
||||
for (i = 0; i < edgeCount; i++) {
|
||||
e1 = (Edge) edges.elementAt(i);
|
||||
if (e1.y1 == y) {
|
||||
for (j = 0; j < activeCount; j++) {
|
||||
e2 = (Edge) active.elementAt(j);
|
||||
if (e1.x < e2.x) {
|
||||
active.insertElementAt(e1, j);
|
||||
e1 = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (e1 != null) {
|
||||
active.addElement(e1);
|
||||
}
|
||||
activeCount++;
|
||||
|
||||
//// remove from edges list
|
||||
edges.removeElementAt(i);
|
||||
edgeCount--;
|
||||
//// indices are shifted down one
|
||||
i--;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//// draw line segments between pairs of edges
|
||||
for (i = 1; i < activeCount; i += 2) {
|
||||
e1 = (Edge) active.elementAt(i - 1);
|
||||
e2 = (Edge) active.elementAt(i);
|
||||
|
||||
bufferg.drawLine(e1.x, y, e2.x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (stroke) {
|
||||
for (int i = startIndex + 2; i <= endIndex; i += 2) {
|
||||
line(vertex[i - 2], vertex[i - 1], vertex[i], vertex[i + 1]);
|
||||
}
|
||||
line(vertex[endIndex], vertex[endIndex + 1], vertex[startIndex], vertex[startIndex + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void vertex(int x, int y) {
|
||||
vertex[vertexIndex] = x;
|
||||
vertexIndex++;
|
||||
vertex[vertexIndex] = y;
|
||||
vertexIndex++;
|
||||
|
||||
int length = vertex.length;
|
||||
if (vertexIndex == length) {
|
||||
int[] old = vertex;
|
||||
vertex = new int[length * 2];
|
||||
System.arraycopy(old, 0, vertex, 0, length);
|
||||
}
|
||||
}
|
||||
|
||||
public void curveVertex(int x, int y) {
|
||||
//// use fixed point, 8-bit precision
|
||||
curveVertex[curveVertexIndex] = x << 8;
|
||||
curveVertexIndex++;
|
||||
curveVertex[curveVertexIndex] = y << 8;
|
||||
curveVertexIndex++;
|
||||
|
||||
if (curveVertexIndex == 8) {
|
||||
int tension = 128 /* 0.5f */;
|
||||
|
||||
int dx0 = ((curveVertex[4] - curveVertex[0]) * tension) >> 8;
|
||||
int dx1 = ((curveVertex[6] - curveVertex[2]) * tension) >> 8;
|
||||
int dy0 = ((curveVertex[5] - curveVertex[1]) * tension) >> 8;
|
||||
int dy1 = ((curveVertex[7] - curveVertex[3]) * tension) >> 8;
|
||||
|
||||
plotCurveVertices(curveVertex[2], curveVertex[3],
|
||||
curveVertex[4], curveVertex[5],
|
||||
dx0, dx1, dy0, dy1);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
curveVertex[i] = curveVertex[i + 2];
|
||||
}
|
||||
curveVertexIndex = 6;
|
||||
}
|
||||
}
|
||||
|
||||
public void bezierVertex(int x, int y) {
|
||||
//// use fixed point, 8-bit precision
|
||||
curveVertex[curveVertexIndex] = x << 8;
|
||||
curveVertexIndex++;
|
||||
curveVertex[curveVertexIndex] = y << 8;
|
||||
curveVertexIndex++;
|
||||
|
||||
if (curveVertexIndex == 8) {
|
||||
//// use fixed point, 8-bit precision
|
||||
int tension = 768 /* 3.0f */;
|
||||
|
||||
int dx0 = ((curveVertex[2] - curveVertex[0]) * tension) >> 8;
|
||||
int dx1 = ((curveVertex[6] - curveVertex[4]) * tension) >> 8;
|
||||
int dy0 = ((curveVertex[3] - curveVertex[1]) * tension) >> 8;
|
||||
int dy1 = ((curveVertex[7] - curveVertex[5]) * tension) >> 8;
|
||||
|
||||
plotCurveVertices(curveVertex[0], curveVertex[1],
|
||||
curveVertex[6], curveVertex[7],
|
||||
dx0, dx1, dy0, dy1);
|
||||
|
||||
curveVertexIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void plotCurveVertices(int x0, int y0, int x1, int y1, int dx0, int dx1, int dy0, int dy1) {
|
||||
int x, y, t, t2, t3, h0, h1, h2, h3;
|
||||
vertex(x0 >> 8, y0 >> 8);
|
||||
for (t = 0; t < 256 /* 1.0f */; t += 26 /* 0.1f */) {
|
||||
t2 = (t * t) >> 8;
|
||||
t3 = (t * t2) >> 8;
|
||||
|
||||
h0 = ((512 /* 2.0f */ * t3) >> 8) - ((768 /* 3.0f */ * t2) >> 8) + 256 /* 1.0f */;
|
||||
h1 = ((-512 /* -2.0f */ * t3) >> 8) + ((768 /* 3.0f */ * t2) >> 8);
|
||||
h2 = t3 - ((512 /* 2.0f */ * t2) >> 8) + t;
|
||||
h3 = t3 - t2;
|
||||
|
||||
x = ((h0 * x0) >> 8) + ((h1 * x1) >> 8) + ((h2 * dx0) >> 8) + ((h3 * dx1) >> 8);
|
||||
y = ((h0 * y0) >> 8) + ((h1 * y1) >> 8) + ((h2 * dy0) >> 8) + ((h3 * dy1) >> 8);
|
||||
vertex(x >> 8, y >> 8);
|
||||
}
|
||||
vertex(x1 >> 8, y1 >> 8);
|
||||
}
|
||||
|
||||
public void translate(int x, int y) {
|
||||
bufferg.translate(x, y);
|
||||
}
|
||||
|
||||
public void background(int gray) {
|
||||
background(gray, gray, gray);
|
||||
}
|
||||
|
||||
public void background(int value1, int value2, int value3) {
|
||||
bufferg.setColor(value1, value2, value3);
|
||||
bufferg.fillRect(0, 0, width, height);
|
||||
}
|
||||
|
||||
public void stroke(int gray) {
|
||||
stroke(gray, gray, gray);
|
||||
}
|
||||
|
||||
public void stroke(int value1, int value2, int value3) {
|
||||
stroke = true;
|
||||
strokeColor = ((value1 & 0xFF) << 16) | ((value2 & 0xFF) << 8) | (value3 & 0xFF);
|
||||
}
|
||||
|
||||
public void noStroke() {
|
||||
stroke = false;
|
||||
}
|
||||
|
||||
public void fill(int gray) {
|
||||
fill(gray, gray, gray);
|
||||
}
|
||||
|
||||
public void fill(int value1, int value2, int value3) {
|
||||
fill = true;
|
||||
fillColor = ((value1 & 0xFF) << 16) | ((value2 & 0xFF) << 8) | (value3 & 0xFF);
|
||||
}
|
||||
|
||||
public void noFill() {
|
||||
fill = false;
|
||||
}
|
||||
|
||||
public void text(String data, int x, int y) {
|
||||
bufferg.drawString(data, x, y, textMode);
|
||||
}
|
||||
|
||||
public void textMode(int MODE) {
|
||||
switch (MODE) {
|
||||
case PMIDlet.ALIGN_LEFT:
|
||||
textMode = Graphics.TOP | Graphics.LEFT;
|
||||
break;
|
||||
case PMIDlet.ALIGN_RIGHT:
|
||||
textMode = Graphics.TOP | Graphics.RIGHT;
|
||||
break;
|
||||
case PMIDlet.ALIGN_CENTER:
|
||||
textMode = Graphics.TOP | Graphics.HCENTER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Edge {
|
||||
public int x1, y1, x2, y2;
|
||||
public int x, dx, dy;
|
||||
}
|
||||
}
|
||||
378
core/processing/core/PMIDlet.java
Executable file
378
core/processing/core/PMIDlet.java
Executable file
@@ -0,0 +1,378 @@
|
||||
package processing.core;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import javax.microedition.lcdui.*;
|
||||
import javax.microedition.midlet.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public abstract class PMIDlet extends MIDlet implements Runnable {
|
||||
private Display display;
|
||||
private PCanvas canvas;
|
||||
|
||||
private boolean running;
|
||||
private long startTime;
|
||||
|
||||
private Calendar calendar;
|
||||
private Random random;
|
||||
|
||||
/** Creates a new instance of PMIDlet */
|
||||
public PMIDlet() {
|
||||
display = Display.getDisplay(this);
|
||||
}
|
||||
|
||||
protected final void destroyApp(boolean unconditional) throws MIDletStateChangeException {
|
||||
running = false;
|
||||
}
|
||||
|
||||
protected final void pauseApp() {
|
||||
running = false;
|
||||
}
|
||||
|
||||
protected final void startApp() throws MIDletStateChangeException {
|
||||
running = true;
|
||||
if (canvas == null) {
|
||||
canvas = new PCanvas(this);
|
||||
width = canvas.getWidth();
|
||||
height = canvas.getHeight();
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
|
||||
setup();
|
||||
}
|
||||
display.setCurrent(canvas);
|
||||
display.callSerially(this);
|
||||
}
|
||||
|
||||
public final void run() {
|
||||
draw();
|
||||
canvas.repaint();
|
||||
|
||||
if (running) {
|
||||
display.callSerially(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static final int CORNER = 0;
|
||||
public static final int CORNERS = 1;
|
||||
public static final int CENTER_DIAMETER = 2;
|
||||
public static final int CENTER_RADIUS = 3;
|
||||
|
||||
public static final int POINTS = 0;
|
||||
public static final int LINES = 1;
|
||||
public static final int LINE_STRIP = 2;
|
||||
public static final int LINE_LOOP = 3;
|
||||
public static final int TRIANGLES = 4;
|
||||
public static final int TRIANGLE_STRIP = 5;
|
||||
public static final int QUADS = 6;
|
||||
public static final int QUAD_STRIP = 7;
|
||||
public static final int POLYGON = 8;
|
||||
|
||||
public static final int UP = 0;
|
||||
public static final int DOWN = 1;
|
||||
public static final int LEFT = 2;
|
||||
public static final int RIGHT = 3;
|
||||
public static final int FIRE = 4;
|
||||
|
||||
public static final int ALIGN_LEFT = 0;
|
||||
public static final int ALIGN_RIGHT = 1;
|
||||
public static final int ALIGN_CENTER = 2;
|
||||
|
||||
protected int width;
|
||||
protected int height;
|
||||
|
||||
protected char key;
|
||||
protected boolean keyPressed;
|
||||
|
||||
public void setup() {
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
}
|
||||
|
||||
public void keyPressed() {
|
||||
|
||||
}
|
||||
|
||||
public void keyReleased() {
|
||||
|
||||
}
|
||||
|
||||
public final void redraw() {
|
||||
draw();
|
||||
canvas.repaint();
|
||||
}
|
||||
|
||||
public final void loop() {
|
||||
running = true;
|
||||
display.callSerially(this);
|
||||
}
|
||||
|
||||
public final void noLoop() {
|
||||
running = false;
|
||||
}
|
||||
|
||||
public final void size(int width, int height) {
|
||||
}
|
||||
|
||||
public final void framerate(int fps) {
|
||||
}
|
||||
|
||||
public final void point(int x1, int y1) {
|
||||
canvas.point(x1, y1);
|
||||
}
|
||||
|
||||
public final void line(int x1, int y1, int x2, int y2) {
|
||||
canvas.line(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
public final void triangle(int x1, int y1, int x2, int y2, int x3, int y3) {
|
||||
canvas.triangle(x1, y1, x2, y2, x3, y3);
|
||||
}
|
||||
|
||||
public final void quad(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
|
||||
canvas.quad(x1, y1, x2, y2, x3, y3, x4, y4);
|
||||
}
|
||||
|
||||
public final void rect(int x, int y, int width, int height) {
|
||||
canvas.rect(x, y, width, height);
|
||||
}
|
||||
|
||||
public final void rectMode(int MODE) {
|
||||
canvas.rectMode(MODE);
|
||||
}
|
||||
|
||||
public final void ellipse(int x, int y, int width, int height) {
|
||||
canvas.ellipse(x, y, width, height);
|
||||
}
|
||||
|
||||
public final void ellipseMode(int MODE) {
|
||||
canvas.ellipseMode(MODE);
|
||||
}
|
||||
|
||||
public final void curve(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
|
||||
canvas.curve(x1, y1, x2, y2, x3, y3, x4, y4);
|
||||
}
|
||||
|
||||
public final void bezier(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
|
||||
canvas.bezier(x1, y1, x2, y2, x3, y3, x4, y4);
|
||||
}
|
||||
|
||||
public final void strokeWeight(int width) {
|
||||
canvas.strokeWeight(width);
|
||||
}
|
||||
|
||||
public final void beginShape(int MODE) {
|
||||
canvas.beginShape(MODE);
|
||||
}
|
||||
|
||||
public final void endShape() {
|
||||
canvas.endShape();
|
||||
}
|
||||
|
||||
public final void vertex(int x, int y) {
|
||||
canvas.vertex(x, y);
|
||||
}
|
||||
|
||||
public final void curveVertex(int x, int y) {
|
||||
canvas.curveVertex(x, y);
|
||||
}
|
||||
|
||||
public final void bezierVertex(int x, int y) {
|
||||
canvas.bezierVertex(x, y);
|
||||
}
|
||||
|
||||
public final void translate(int x, int y) {
|
||||
canvas.translate(x, y);
|
||||
}
|
||||
|
||||
public final void background(int gray) {
|
||||
canvas.background(gray);
|
||||
}
|
||||
|
||||
public final void background(int value1, int value2, int value3) {
|
||||
canvas.background(value1, value2, value3);
|
||||
}
|
||||
|
||||
public final void stroke(int gray) {
|
||||
canvas.stroke(gray);
|
||||
}
|
||||
|
||||
public final void stroke(int value1, int value2, int value3) {
|
||||
canvas.stroke(value1, value2, value3);
|
||||
}
|
||||
|
||||
public final void noStroke() {
|
||||
canvas.noStroke();
|
||||
}
|
||||
|
||||
public final void fill(int gray) {
|
||||
canvas.fill(gray);
|
||||
}
|
||||
|
||||
public final void fill(int value1, int value2, int value3) {
|
||||
canvas.fill(value1, value2, value3);
|
||||
}
|
||||
|
||||
public final void noFill() {
|
||||
canvas.noFill();
|
||||
}
|
||||
|
||||
public final void text(String data, int x, int y) {
|
||||
canvas.text(data, x, y);
|
||||
}
|
||||
|
||||
public final void textMode(int MODE) {
|
||||
canvas.textMode(MODE);
|
||||
}
|
||||
|
||||
public final int millis() {
|
||||
return (int) (System.currentTimeMillis() - startTime);
|
||||
}
|
||||
|
||||
private void checkCalendar() {
|
||||
if (calendar == null) {
|
||||
calendar = Calendar.getInstance();
|
||||
}
|
||||
calendar.setTime(new Date());
|
||||
}
|
||||
|
||||
public final int second() {
|
||||
checkCalendar();
|
||||
return calendar.get(Calendar.SECOND);
|
||||
}
|
||||
|
||||
public final int minute() {
|
||||
checkCalendar();
|
||||
return calendar.get(Calendar.MINUTE);
|
||||
}
|
||||
|
||||
public final int hour() {
|
||||
checkCalendar();
|
||||
return calendar.get(Calendar.HOUR_OF_DAY);
|
||||
}
|
||||
|
||||
public final int day() {
|
||||
checkCalendar();
|
||||
return calendar.get(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
|
||||
public final int month() {
|
||||
checkCalendar();
|
||||
return calendar.get(Calendar.MONTH);
|
||||
}
|
||||
|
||||
public final int year() {
|
||||
checkCalendar();
|
||||
return calendar.get(Calendar.YEAR);
|
||||
}
|
||||
|
||||
public final int abs(int value) {
|
||||
return Math.abs(value);
|
||||
}
|
||||
|
||||
public final int max(int value1, int value2) {
|
||||
return Math.max(value1, value2);
|
||||
}
|
||||
|
||||
public final int min(int value1, int value2) {
|
||||
return Math.min(value1, value2);
|
||||
}
|
||||
|
||||
public final int sq(int value) {
|
||||
return value * value;
|
||||
}
|
||||
|
||||
public final int pow(int base, int exponent) {
|
||||
int value = 1;
|
||||
for (int i = 0; i < exponent; i++) {
|
||||
value *= base;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public final int constrain(int value, int min, int max) {
|
||||
return Math.min(Math.max(value, min), max);
|
||||
}
|
||||
|
||||
public final int random(int value1) {
|
||||
return random(0, value1);
|
||||
}
|
||||
|
||||
public final int random(int value1, int value2) {
|
||||
if (random == null) {
|
||||
random = new Random();
|
||||
}
|
||||
int min = Math.min(value1, value2);
|
||||
int range = Math.abs(value2 - value1);
|
||||
|
||||
return min + Math.abs((random.nextInt() % range));
|
||||
}
|
||||
|
||||
public final String[] loadStrings(String filename) {
|
||||
String[] strings = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = getClass().getResourceAsStream(filename);
|
||||
Reader r = new InputStreamReader(is);
|
||||
|
||||
strings = new String[8];
|
||||
int numStrings = 0;
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int input = r.read();
|
||||
while (true) {
|
||||
if ((input < 0) || (input == '\n')) {
|
||||
String s = buffer.toString().trim();
|
||||
if (s.length() > 0) {
|
||||
numStrings++;
|
||||
|
||||
int length = strings.length;
|
||||
if (numStrings > length) {
|
||||
String[] old = strings;
|
||||
strings = new String[length * 2];
|
||||
System.arraycopy(old, 0, strings, 0, length);
|
||||
}
|
||||
strings[numStrings - 1] = s;
|
||||
}
|
||||
buffer.delete(0, Integer.MAX_VALUE);
|
||||
|
||||
if (input < 0) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
buffer.append((char) input);
|
||||
}
|
||||
|
||||
input = r.read();
|
||||
}
|
||||
//// shrink array
|
||||
if (numStrings < strings.length) {
|
||||
String[] old = strings;
|
||||
strings = new String[numStrings];
|
||||
if (numStrings > 0) {
|
||||
System.arraycopy(old, 0, strings, 0, numStrings);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException ioe) {
|
||||
|
||||
}
|
||||
}
|
||||
if (strings == null) {
|
||||
strings = new String[0];
|
||||
}
|
||||
}
|
||||
|
||||
return strings;
|
||||
}
|
||||
}
|
||||
18
core/test/BeginShapeTest1.java
Executable file
18
core/test/BeginShapeTest1.java
Executable file
@@ -0,0 +1,18 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class BeginShapeTest1 extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
beginShape(POINTS);
|
||||
vertex(30, 20);
|
||||
vertex(85, 20);
|
||||
vertex(85, 75);
|
||||
vertex(30, 75);
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
18
core/test/BeginShapeTest2.java
Executable file
18
core/test/BeginShapeTest2.java
Executable file
@@ -0,0 +1,18 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class BeginShapeTest2 extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
beginShape(LINES);
|
||||
vertex(30, 20);
|
||||
vertex(85, 20);
|
||||
vertex(85, 75);
|
||||
vertex(30, 75);
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
18
core/test/BeginShapeTest3.java
Executable file
18
core/test/BeginShapeTest3.java
Executable file
@@ -0,0 +1,18 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class BeginShapeTest3 extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
beginShape(LINE_STRIP);
|
||||
vertex(30, 20);
|
||||
vertex(85, 20);
|
||||
vertex(85, 75);
|
||||
vertex(30, 75);
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
18
core/test/BeginShapeTest4.java
Executable file
18
core/test/BeginShapeTest4.java
Executable file
@@ -0,0 +1,18 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class BeginShapeTest4 extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
beginShape(LINE_LOOP);
|
||||
vertex(30, 20);
|
||||
vertex(85, 20);
|
||||
vertex(85, 75);
|
||||
vertex(30, 75);
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
22
core/test/BeginShapeTest5.java
Executable file
22
core/test/BeginShapeTest5.java
Executable file
@@ -0,0 +1,22 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class BeginShapeTest5 extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
beginShape(TRIANGLES);
|
||||
vertex(30, 75);
|
||||
vertex(40, 20);
|
||||
vertex(50, 75);
|
||||
vertex(60, 20);
|
||||
vertex(70, 75);
|
||||
vertex(80, 20);
|
||||
vertex(90, 75);
|
||||
endShape();
|
||||
}
|
||||
|
||||
}
|
||||
22
core/test/BeginShapeTest6.java
Executable file
22
core/test/BeginShapeTest6.java
Executable file
@@ -0,0 +1,22 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class BeginShapeTest6 extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
beginShape(TRIANGLE_STRIP);
|
||||
vertex(30, 75);
|
||||
vertex(40, 20);
|
||||
vertex(50, 75);
|
||||
vertex(60, 20);
|
||||
vertex(70, 75);
|
||||
vertex(80, 20);
|
||||
vertex(90, 75);
|
||||
endShape();
|
||||
}
|
||||
|
||||
}
|
||||
22
core/test/BeginShapeTest7.java
Executable file
22
core/test/BeginShapeTest7.java
Executable file
@@ -0,0 +1,22 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class BeginShapeTest7 extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
beginShape(QUADS);
|
||||
vertex(30, 20);
|
||||
vertex(30, 75);
|
||||
vertex(50, 75);
|
||||
vertex(50, 20);
|
||||
vertex(65, 20);
|
||||
vertex(65, 75);
|
||||
vertex(85, 75);
|
||||
vertex(85, 20);
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
22
core/test/BeginShapeTest8.java
Executable file
22
core/test/BeginShapeTest8.java
Executable file
@@ -0,0 +1,22 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class BeginShapeTest8 extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
beginShape(QUAD_STRIP);
|
||||
vertex(30, 20);
|
||||
vertex(30, 75);
|
||||
vertex(50, 75);
|
||||
vertex(50, 20);
|
||||
vertex(65, 20);
|
||||
vertex(65, 75);
|
||||
vertex(85, 75);
|
||||
vertex(85, 20);
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
20
core/test/BeginShapeTest9.java
Executable file
20
core/test/BeginShapeTest9.java
Executable file
@@ -0,0 +1,20 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class BeginShapeTest9 extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
beginShape(POLYGON);
|
||||
vertex(20, 20);
|
||||
vertex(40, 20);
|
||||
vertex(40, 40);
|
||||
vertex(60, 40);
|
||||
vertex(60, 60);
|
||||
vertex(20, 60);
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
17
core/test/BezierTest1.java
Executable file
17
core/test/BezierTest1.java
Executable file
@@ -0,0 +1,17 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class BezierTest1 extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
stroke(255, 102, 0);
|
||||
line(85, 20, 10, 10);
|
||||
line(90, 90, 15, 80);
|
||||
stroke(0, 0, 0);
|
||||
bezier(85, 20, 10, 10, 90, 90, 15, 80);
|
||||
}
|
||||
}
|
||||
18
core/test/BezierTest2.java
Executable file
18
core/test/BezierTest2.java
Executable file
@@ -0,0 +1,18 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class BezierTest2 extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
stroke(255, 102, 0);
|
||||
line(30, 20, 80, 5);
|
||||
line(80, 75, 30, 75);
|
||||
stroke(0, 0, 0);
|
||||
bezier(30, 20, 80, 5, 80, 75, 30, 75);
|
||||
}
|
||||
|
||||
}
|
||||
18
core/test/BezierVertexTest.java
Executable file
18
core/test/BezierVertexTest.java
Executable file
@@ -0,0 +1,18 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class BezierVertexTest extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
beginShape(LINE_STRIP);
|
||||
bezierVertex(30, 20);
|
||||
bezierVertex(80, 0);
|
||||
bezierVertex(80, 75);
|
||||
bezierVertex(30, 75);
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
14
core/test/CurveTest.java
Executable file
14
core/test/CurveTest.java
Executable file
@@ -0,0 +1,14 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class CurveTest extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
curve(10, 26, 83, 24, 83, 61, 25, 65);
|
||||
}
|
||||
|
||||
}
|
||||
20
core/test/CurveVertexTest.java
Executable file
20
core/test/CurveVertexTest.java
Executable file
@@ -0,0 +1,20 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class CurveVertexTest extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
beginShape(LINE_STRIP);
|
||||
curveVertex(84, 91);
|
||||
curveVertex(84, 91);
|
||||
curveVertex(68, 19);
|
||||
curveVertex(21, 17);
|
||||
curveVertex(32, 100);
|
||||
curveVertex(32, 100);
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
16
core/test/EllipseModeTest.java
Executable file
16
core/test/EllipseModeTest.java
Executable file
@@ -0,0 +1,16 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class EllipseModeTest extends PMIDlet {
|
||||
void setup() {
|
||||
ellipseMode(CENTER_DIAMETER);
|
||||
ellipse(35, 35, 50, 50);
|
||||
ellipseMode(CORNER);
|
||||
fill(102);
|
||||
ellipse(35, 35, 50, 50);
|
||||
}
|
||||
}
|
||||
12
core/test/EllipseTest.java
Executable file
12
core/test/EllipseTest.java
Executable file
@@ -0,0 +1,12 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class EllipseTest extends PMIDlet {
|
||||
void setup() {
|
||||
ellipse(30, 20, 55, 55);
|
||||
}
|
||||
}
|
||||
12
core/test/LineTest1.java
Executable file
12
core/test/LineTest1.java
Executable file
@@ -0,0 +1,12 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class LineTest1 extends PMIDlet {
|
||||
void setup() {
|
||||
line(30, 20, 85, 75);
|
||||
}
|
||||
}
|
||||
16
core/test/LineTest2.java
Executable file
16
core/test/LineTest2.java
Executable file
@@ -0,0 +1,16 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class LineTest2 extends PMIDlet {
|
||||
void setup() {
|
||||
line(30, 20, 85, 20);
|
||||
stroke(126);
|
||||
line(85, 20, 85, 75);
|
||||
stroke(255);
|
||||
line(85, 75, 30, 75);
|
||||
}
|
||||
}
|
||||
30
core/test/Linear.java
Executable file
30
core/test/Linear.java
Executable file
@@ -0,0 +1,30 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class Linear extends PMIDlet {
|
||||
// Linear
|
||||
// by REAS <http://www.groupc.net>
|
||||
|
||||
int a = 100;
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
stroke(255);
|
||||
framerate(30);
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(51);
|
||||
a = a - 1;
|
||||
if (a < 0) {
|
||||
a = height;
|
||||
}
|
||||
line(0, a, width, a);
|
||||
}
|
||||
}
|
||||
15
core/test/PointTest.java
Executable file
15
core/test/PointTest.java
Executable file
@@ -0,0 +1,15 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class PointTest extends PMIDlet {
|
||||
void setup() {
|
||||
point(30, 20);
|
||||
point(85, 20);
|
||||
point(85, 75);
|
||||
point(30, 75);
|
||||
}
|
||||
}
|
||||
38
core/test/Points_Lines.java
Executable file
38
core/test/Points_Lines.java
Executable file
@@ -0,0 +1,38 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class Points_Lines extends PMIDlet {
|
||||
void setup() {
|
||||
// Points and Lines
|
||||
// by REAS <http://www.groupc.net>
|
||||
|
||||
int d = 40;
|
||||
int p1 = d;
|
||||
int p2 = p1+d;
|
||||
int p3 = p2+d;
|
||||
int p4 = p3+d;
|
||||
|
||||
size(200, 200);
|
||||
background(0);
|
||||
|
||||
// Draw gray box
|
||||
stroke(153);
|
||||
line(p3, p3, p2, p3);
|
||||
line(p2, p3, p2, p2);
|
||||
line(p2, p2, p3, p2);
|
||||
line(p3, p2, p3, p3);
|
||||
|
||||
// Draw white points
|
||||
stroke(255);
|
||||
point(p1, p1);
|
||||
point(p1, p3);
|
||||
point(p2, p4);
|
||||
point(p3, p1);
|
||||
point(p4, p2);
|
||||
point(p4, p4);
|
||||
}
|
||||
}
|
||||
13
core/test/QuadTest.java
Executable file
13
core/test/QuadTest.java
Executable file
@@ -0,0 +1,13 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class QuadTest extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
quad(38, 31, 86, 20, 69, 63, 30, 76);
|
||||
}
|
||||
}
|
||||
17
core/test/RandomTest1.java
Executable file
17
core/test/RandomTest1.java
Executable file
@@ -0,0 +1,17 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class RandomTest1 extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
for(int i=0; i<100; i++) {
|
||||
int r = random(50);
|
||||
stroke(r*5);
|
||||
line(50, i, 50+r, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
core/test/RandomTest2.java
Executable file
17
core/test/RandomTest2.java
Executable file
@@ -0,0 +1,17 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class RandomTest2 extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
for(int i=0; i<100; i++) {
|
||||
int r = random(-50, 50);
|
||||
stroke(abs(r*5));
|
||||
line(50, i, 50+r, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
core/test/RectModeTest.java
Executable file
17
core/test/RectModeTest.java
Executable file
@@ -0,0 +1,17 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class RectModeTest extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
rectMode(CENTER_DIAMETER);
|
||||
rect(35, 35, 50, 50);
|
||||
rectMode(CORNER);
|
||||
fill(102);
|
||||
rect(35, 35, 50, 50);
|
||||
}
|
||||
}
|
||||
13
core/test/RectTest.java
Executable file
13
core/test/RectTest.java
Executable file
@@ -0,0 +1,13 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class RectTest extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
rect(30, 20, 55, 55);
|
||||
}
|
||||
}
|
||||
19
core/test/SecondTest.java
Executable file
19
core/test/SecondTest.java
Executable file
@@ -0,0 +1,19 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class SecondTest extends PMIDlet {
|
||||
|
||||
public void draw() {
|
||||
background(204);
|
||||
int s = second(); // Values from 0 - 59
|
||||
int m = minute(); // Values from 0 - 59
|
||||
int h = hour(); // Values from 0 - 23
|
||||
line(s, 0, s, 33);
|
||||
line(m, 33, m, 66);
|
||||
line(h, 66, h, 100);
|
||||
}
|
||||
}
|
||||
23
core/test/Shape_Primitives.java
Executable file
23
core/test/Shape_Primitives.java
Executable file
@@ -0,0 +1,23 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class Shape_Primitives extends PMIDlet {
|
||||
void setup() {
|
||||
// Shape Primitives
|
||||
// by REAS <http://www.groupc.net>
|
||||
|
||||
size(200, 200);
|
||||
background(0);
|
||||
noStroke();
|
||||
fill(226);
|
||||
triangle(10, 10, 10, 200, 45, 200);
|
||||
rect(45, 45, 35, 35);
|
||||
quad(105, 10, 120, 10, 120, 200, 80, 200);
|
||||
ellipse(120, 60, 40, 40);
|
||||
triangle(160, 10, 195, 200, 160, 200);
|
||||
}
|
||||
}
|
||||
19
core/test/StrokeWeightTest.java
Executable file
19
core/test/StrokeWeightTest.java
Executable file
@@ -0,0 +1,19 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class StrokeWeightTest extends PMIDlet {
|
||||
void setup() {
|
||||
strokeWeight(1); // Default
|
||||
line(20, 20, 80, 20);
|
||||
|
||||
strokeWeight(4); // Thicker
|
||||
line(20, 40, 80, 40);
|
||||
|
||||
strokeWeight(10); // Beastly
|
||||
line(20, 70, 80, 70);
|
||||
}
|
||||
}
|
||||
13
core/test/TriangleTest.java
Executable file
13
core/test/TriangleTest.java
Executable file
@@ -0,0 +1,13 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class TriangleTest extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
triangle(30, 75, 58, 20, 86, 75);
|
||||
}
|
||||
}
|
||||
51
core/test/Vertices.java
Executable file
51
core/test/Vertices.java
Executable file
@@ -0,0 +1,51 @@
|
||||
package test;
|
||||
import processing.core.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Li
|
||||
*/
|
||||
public class Vertices extends PMIDlet {
|
||||
|
||||
void setup() {
|
||||
// Vertices
|
||||
// by REAS <http://www.groupc.net>
|
||||
|
||||
size(200, 200);
|
||||
background(0);
|
||||
|
||||
stroke(102);
|
||||
beginShape(LINE_STRIP);
|
||||
curveVertex(168, 182);
|
||||
curveVertex(168, 182);
|
||||
curveVertex(136, 38);
|
||||
curveVertex(42, 34);
|
||||
curveVertex(64, 200);
|
||||
curveVertex(64, 200);
|
||||
endShape();
|
||||
|
||||
stroke(51);
|
||||
beginShape(LINES);
|
||||
vertex(60, 40);
|
||||
vertex(160, 10);
|
||||
vertex(170, 150);
|
||||
vertex(60, 150);
|
||||
endShape();
|
||||
|
||||
stroke(126);
|
||||
beginShape(LINE_STRIP);
|
||||
bezierVertex(60, 40);
|
||||
bezierVertex(160, 10);
|
||||
bezierVertex(170, 150);
|
||||
bezierVertex(60, 150);
|
||||
endShape();
|
||||
|
||||
stroke(255);
|
||||
beginShape(POINTS);
|
||||
vertex(60, 40);
|
||||
vertex(160, 10);
|
||||
vertex(170, 150);
|
||||
vertex(60, 150);
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user