Skip to content

Commit aa0e428

Browse files
committed
Add contribution.txt
0 parents  commit aa0e428

148 files changed

Lines changed: 28139 additions & 0 deletions

File tree

Some content is hidden

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

contribution.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name=C++ Mode
2+
category=Other
3+
authors=[Jose Llamas](https://github.com/pepc84)
4+
url=https://github.com/processing-cpp/processing.cpp
5+
sentence=Write Processing sketches in C++, compiled to a native binary.
6+
paragraph=C++ Mode lets you write sketches using the familiar Processing API — size(), ellipse(), mouseX, draw() — but compiled to a native binary via g++. Runs on Linux, macOS, and Windows (via MSYS2). Requires g++ and OpenGL (GLFW + GLEW).
7+
version=1
8+
prettyVersion=0.1.0
9+
minRevision=1275
10+
maxRevision=0
11+
type=Mode
12+
download=https://github.com/processing-cpp/processing.cpp/releases/download/v0.1.0/cppMode.zip

examples/Basics/arrays/Array.pde

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Array.
3+
*
4+
* An array is a list of data. Each piece of data in an array
5+
* is identified by an index number representing its position in
6+
* the array. Arrays are zero based, which means that the first
7+
* element in the array is [0], the second element is [1], and so on.
8+
* In this example, an array named "coswave" is created and
9+
* filled with the cosine values. This data is displayed three
10+
* separate ways on the screen.
11+
*/
12+
13+
float* coswave;
14+
15+
void setup() {
16+
size(640, 360);
17+
coswave = new float[width];
18+
for (int i = 0; i < width; i++) {
19+
float amount = map(i, 0, width, 0, PI);
20+
coswave[i] = abs(cos(amount));
21+
}
22+
background(255);
23+
noLoop();
24+
}
25+
26+
void draw() {
27+
int y1 = 0;
28+
int y2 = height / 3;
29+
for (int i = 0; i < width; i++) {
30+
stroke(coswave[i] * 255);
31+
line(i, y1, i, y2);
32+
}
33+
y1 = y2;
34+
y2 = y1 + y1;
35+
for (int i = 0; i < width; i++) {
36+
stroke(coswave[i] * 255 / 4);
37+
line(i, y1, i, y2);
38+
}
39+
y1 = y2;
40+
y2 = height;
41+
for (int i = 0; i < width; i++) {
42+
stroke(255 - coswave[i] * 255);
43+
line(i, y1, i, y2);
44+
}
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Array.
3+
*
4+
* An array is a list of data. Each piece of data in an array
5+
* is identified by an index number representing its position in
6+
* the array. Arrays are zero based, which means that the first
7+
* element in the array is [0], the second element is [1], and so on.
8+
* In this example, an array named "coswave" is created and
9+
* filled with the cosine values. This data is displayed three
10+
* separate ways on the screen.
11+
*/
12+
13+
float* coswave;
14+
15+
void setup() {
16+
size(640, 360);
17+
coswave = new float[width];
18+
for (int i = 0; i < width; i++) {
19+
float amount = map(i, 0, width, 0, PI);
20+
coswave[i] = abs(cos(amount));
21+
}
22+
background(255);
23+
noLoop();
24+
}
25+
26+
void draw() {
27+
int y1 = 0;
28+
int y2 = height / 3;
29+
for (int i = 0; i < width; i++) {
30+
stroke(coswave[i] * 255);
31+
line(i, y1, i, y2);
32+
}
33+
y1 = y2;
34+
y2 = y1 + y1;
35+
for (int i = 0; i < width; i++) {
36+
stroke(coswave[i] * 255 / 4);
37+
line(i, y1, i, y2);
38+
}
39+
y1 = y2;
40+
y2 = height;
41+
for (int i = 0; i < width; i++) {
42+
stroke(255 - coswave[i] * 255);
43+
line(i, y1, i, y2);
44+
}
45+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Array 2D.
3+
*
4+
* Demonstrates the syntax for creating a two-dimensional (2D) array.
5+
* Values in a 2D array are accessed through two index values.
6+
* 2D arrays are useful for storing images. In this example, each dot
7+
* is colored in relation to its distance from the center of the image.
8+
*/
9+
10+
float* distances;
11+
float maxDistance;
12+
int spacer;
13+
14+
void setup() {
15+
size(640, 360);
16+
maxDistance = dist(width/2, height/2, width, height);
17+
distances = new float[width * height];
18+
for (int y = 0; y < height; y++) {
19+
for (int x = 0; x < width; x++) {
20+
float distance = dist(width/2, height/2, x, y);
21+
distances[x + y * width] = distance / maxDistance * 255;
22+
}
23+
}
24+
spacer = 10;
25+
strokeWeight(6);
26+
noLoop();
27+
}
28+
29+
void draw() {
30+
background(0);
31+
for (int y = 0; y < height; y += spacer) {
32+
for (int x = 0; x < width; x += spacer) {
33+
stroke(distances[x + y * width]);
34+
point(x + spacer/2, y + spacer/2);
35+
}
36+
}
37+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Array Objects.
3+
*
4+
* Demonstrates the syntax for creating an array of custom objects.
5+
*/
6+
7+
struct Module {
8+
int xOffset, yOffset;
9+
float x, y;
10+
int unit;
11+
int xDirection, yDirection;
12+
float speed;
13+
14+
Module() : xOffset(0),yOffset(0),x(0),y(0),unit(0),xDirection(1),yDirection(1),speed(0) {}
15+
Module(int xOffsetTemp, int yOffsetTemp, int xTemp, int yTemp, float speedTemp, int tempUnit)
16+
: xOffset(xOffsetTemp), yOffset(yOffsetTemp), x(xTemp), y(yTemp),
17+
unit(tempUnit), xDirection(1), yDirection(1), speed(speedTemp) {}
18+
19+
void update() {
20+
x += speed * xDirection;
21+
if (x >= unit || x <= 0) {
22+
xDirection *= -1;
23+
x += 1 * xDirection;
24+
y += 1 * yDirection;
25+
}
26+
if (y >= unit || y <= 0) {
27+
yDirection *= -1;
28+
y += 1 * yDirection;
29+
}
30+
}
31+
32+
void display() {
33+
fill(255);
34+
ellipse(xOffset + x, yOffset + y, 6, 6);
35+
}
36+
};
37+
38+
int unit = 40;
39+
int count;
40+
Module* mods;
41+
42+
void setup() {
43+
size(640, 360);
44+
noStroke();
45+
int wideCount = width / unit;
46+
int highCount = height / unit;
47+
count = wideCount * highCount;
48+
mods = new Module[count];
49+
50+
int index = 0;
51+
for (int y = 0; y < highCount; y++) {
52+
for (int x = 0; x < wideCount; x++) {
53+
mods[index++] = Module(x*unit, y*unit, unit/2, unit/2, random(0.05f, 0.8f), unit);
54+
}
55+
}
56+
}
57+
58+
void draw() {
59+
background(0);
60+
for (int i = 0; i < count; i++) {
61+
mods[i].update();
62+
mods[i].display();
63+
}
64+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
main=Array.pde
2+
mode=C++
3+
mode.id=processing.mode.cpp.CppMode
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
/**
3+
* Move Eye.
4+
* by Simon Greenwold.
5+
*
6+
* The camera lifts up (controlled by mouseY) while looking at the same point.
7+
*/
8+
9+
void setup() {
10+
size(640, 360, P3D);
11+
fill(204);
12+
}
13+
14+
void draw() {
15+
lights();
16+
background(0);
17+
18+
// Change height of the camera with mouseY
19+
camera(30.0, mouseY, 220.0, // eyeX, eyeY, eyeZ
20+
0.0, 0.0, 0.0, // centerX, centerY, centerZ
21+
0.0, 1.0, 0.0); // upX, upY, upZ
22+
23+
noStroke();
24+
box(90);
25+
stroke(255);
26+
line(-100, 0, 0, 100, 0, 0);
27+
line(0, -100, 0, 0, 100, 0);
28+
line(0, 0, -100, 0, 0, 100);
29+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Perspective.
3+
*
4+
* Move the mouse left and right to change the field of view (fov).
5+
* Click to modify the aspect ratio. The perspective() function
6+
* sets a perspective projection applying foreshortening, making
7+
* distant objects appear smaller than closer ones. The parameters
8+
* define a viewing volume with the shape of truncated pyramid.
9+
* Objects near to the front of the volume appear their actual size,
10+
* while farther objects appear smaller. This projection simulates
11+
* the perspective of the world more accurately than orthographic projection.
12+
* The version of perspective without parameters sets the default
13+
* perspective and the version with four parameters allows the programmer
14+
* to set the area precisely.
15+
*/
16+
17+
void setup() {
18+
size(640, 360, P3D);
19+
noStroke();
20+
}
21+
22+
void draw() {
23+
lights();
24+
background(0);
25+
float cameraY = height/2.0;
26+
float fov = mouseX/float(width) * PI/2;
27+
float cameraZ = cameraY / tan(fov / 2.0);
28+
float aspect = float(width)/float(height);
29+
if (_mousePressed) {
30+
aspect = aspect / 2.0;
31+
}
32+
perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0);
33+
34+
translate(width/2+30, height/2, 0);
35+
rotateX(-PI/6);
36+
rotateY(PI/3 + mouseY/float(height) * PI);
37+
box(45);
38+
translate(0, 0, -50);
39+
box(30);
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Perspective vs. Ortho
3+
*
4+
* Move the mouse left to right to change the "far"
5+
* parameter for the perspective() and ortho() functions.
6+
* This parameter sets the maximum distance from the
7+
* origin away from the viewer and will clip the geometry.
8+
* Click a mouse button to switch between the perspective and
9+
* orthographic projections.
10+
*/
11+
12+
13+
bool showPerspective = false;
14+
15+
void setup() {
16+
size(600, 360, P3D);
17+
noFill();
18+
fill(255);
19+
noStroke();
20+
}
21+
22+
void draw() {
23+
lights();
24+
background(0);
25+
float far = map(mouseX, 0, width, 120, 400);
26+
if (showPerspective == true) {
27+
perspective(PI/3.0, float(width)/float(height), 10, far);
28+
} else {
29+
ortho(-width/2.0, width/2.0, -height/2.0, height/2.0, 10, far);
30+
}
31+
translate(width/2, height/2, 0);
32+
rotateX(-PI/6);
33+
rotateY(PI/3);
34+
box(180);
35+
}
36+
37+
void mousePressed() {
38+
showPerspective = !showPerspective;
39+
}
40+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
int barWidth = 20;
2+
int lastBar = -1;
3+
4+
void setup() {
5+
size(640, 360);
6+
colorMode(HSB, width, 100, height);
7+
noStroke();
8+
background(0);
9+
}
10+
11+
void draw() {
12+
int whichBar = mouseX / barWidth;
13+
14+
if (whichBar != lastBar) {
15+
int barX = whichBar * barWidth;
16+
17+
fill(barX, 100, mouseY);
18+
rect(barX, 0, barWidth, height);
19+
20+
lastBar = whichBar;
21+
}
22+
}

0 commit comments

Comments
 (0)