Skip to content

Commit e2b5426

Browse files
committed
Added README.md file
1 parent ca96c65 commit e2b5426

250 files changed

Lines changed: 8951 additions & 134 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.

CppMode.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors=[Jose Gonzalez Llamas](https://github.com/pepc84)
44
url=https://github.com/processing-cpp/processing.cpp
55
sentence=Write and run Processing sketches in C++.
66
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 and Windows (via MSYS2). Requires g++ and OpenGL (GLFW + GLEW).
7-
version=7
8-
prettyVersion=0.2.2
7+
version=8
8+
prettyVersion=0.2.3
99
minRevision=1280
1010
maxRevision=0

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# processing.cpp
2+
3+
C++ Mode for Processing. Write sketches with `setup()` and `draw()` inside the Processing IDE, or drop the engine into your own C++ project and use the same API from your own editor and build system.
4+
5+
---
6+
7+
## Two ways to use it
8+
9+
### 1. Inside the Processing IDE
10+
11+
If you know Processing, this is the fastest way in. Install C++ Mode through the Contribution Manager, select it from the mode dropdown, and write sketches exactly like you normally would. They compile to native C++ instead of Java, but the workflow is identical.
12+
13+
**Install:**
14+
1. Open Processing
15+
2. Click the mode dropdown (top right, says **Java** by default) → **Add Mode...**
16+
3. Search for **C++ Mode** and click Install
17+
4. Restart Processing, select **C++** from the mode dropdown
18+
19+
```cpp
20+
void setup() {
21+
size(640, 360);
22+
}
23+
24+
void draw() {
25+
background(20);
26+
fill(255, 140, 0);
27+
circle(mouseX, mouseY, 40);
28+
}
29+
```
30+
31+
### 2. As a standalone header library
32+
33+
Use the Processing-style API in any C++ project without opening the Processing IDE. Two packaging options:
34+
35+
**Drag-and-drop** — unzip, drop two files next to your source, compile:
36+
37+
```cpp
38+
#include "Processing.h"
39+
40+
struct Sketch : public Processing::PApplet {
41+
void settings() override { size(640, 360); }
42+
void setup() override { background(0); }
43+
void draw() override {
44+
background(0);
45+
fill(255, 140, 0);
46+
circle(mouseX, mouseY, 40);
47+
}
48+
};
49+
50+
int main() {
51+
Sketch sketch;
52+
sketch.run();
53+
}
54+
```
55+
56+
```bash
57+
g++ -std=c++17 main.cpp Processing.cpp -o sketch && ./sketch
58+
```
59+
60+
**CMake** — add as a subdirectory and link:
61+
62+
```cmake
63+
add_subdirectory(processing-cpp)
64+
target_link_libraries(your_target PRIVATE processing_cpp)
65+
```
66+
67+
---
68+
69+
## Downloads
70+
71+
Get the latest release from the [releases page](https://github.com/processing-cpp/processing.cpp/releases/latest):
72+
73+
- `processing-cpp-dragdrop.zip` — drag-and-drop version
74+
- `processing-cpp-cmake.zip` — CMake version
75+
76+
---
77+
78+
## Requirements
79+
80+
### Windows
81+
MSYS2 with MinGW 64-bit. Install once:
82+
83+
```bash
84+
pacman -S --needed mingw-w64-x86_64-gcc mingw-w64-x86_64-glfw mingw-w64-x86_64-glew
85+
```
86+
87+
Always build from the **MSYS2 MinGW 64-bit** terminal, not PowerShell or Command Prompt.
88+
89+
### macOS
90+
Xcode command line tools and Homebrew:
91+
92+
```bash
93+
xcode-select --install
94+
brew install glfw glew
95+
```
96+
97+
### Linux
98+
```bash
99+
# Ubuntu / Debian
100+
sudo apt install g++ libglfw3-dev libglew-dev
101+
102+
# Arch
103+
sudo pacman -S gcc glfw glew
104+
```
105+
106+
---
107+
108+
## Documentation
109+
110+
Full reference and tutorials at [processing-cpp.github.io](https://processing-cpp.github.io)
111+
112+
- [Getting Started](https://processing-cpp.github.io/gettingstarted) — first sketch in the IDE
113+
- [Drag-and-Drop Setup](https://processing-cpp.github.io/downloads/dragdrop-setup.html) — full Windows/macOS/Linux walkthrough
114+
- [CMake Setup](https://processing-cpp.github.io/downloads/cmake-setup.html) — full Windows/macOS/Linux walkthrough
115+
- [Reference](https://processing-cpp.github.io/reference) — full API reference
116+
- [Examples](https://processing-cpp.github.io/examples) — 100+ example sketches
117+
118+
---
119+
120+
## License
121+
122+
[LGPL-2.1](LICENSE)

deploy_processing_h.py

Lines changed: 36 additions & 0 deletions
Large diffs are not rendered by default.

dist/processing-cpp-cmake.zip

7.2 KB
Binary file not shown.

dist/processing-cpp-dragdrop.zip

7.87 KB
Binary file not shown.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Blur.
3+
*
4+
* This program analyzes every pixel in an image and blends it with the
5+
* neighboring pixels to blur the image.
6+
*
7+
* This is an example of an "image convolution" using a kernel (small matrix)
8+
* to analyze and transform a pixel based on the values of its neighbors.
9+
*
10+
* Image blur is also called a "low-pass filter". Pixels of low frequency
11+
* change (similar brightness as neighbors) are left mostly unchanged, while
12+
* those with high frequency change (sharply different values) are smoothed
13+
* out.
14+
*
15+
* The kernel here is a Box Blur, in which all components are equally valued.
16+
* Another common blur is "Gaussian Blur", in which pixels nearer the center
17+
* of the kernel have more weight than those further away.
18+
*/
19+
20+
float v = 1.0 / 9.0;
21+
float kernel[3][3] = {{ v, v, v },
22+
{ v, v, v },
23+
{ v, v, v }};
24+
25+
PImage* img;
26+
27+
void setup() {
28+
size(640, 360);
29+
img = loadImage("moon.jpg"); // Load the original image
30+
noLoop();
31+
}
32+
33+
void draw() {
34+
image(img, 0, 0); // Displays the image from point (0,0)
35+
img->loadPixels();
36+
37+
// Create an opaque image of the same size as the original
38+
PImage* blurImg = createImage(img->width, img->height, RGB);
39+
40+
// Loop through every pixel in the image
41+
for (int y = 1; y < img->height - 1; y++) { // Skip top and bottom edges
42+
for (int x = 1; x < img->width - 1; x++) { // Skip left and right edges
43+
float sumRed = 0; // Kernel sums for this pixel
44+
float sumGreen = 0;
45+
float sumBlue = 0;
46+
for (int ky = -1; ky <= 1; ky++) {
47+
for (int kx = -1; kx <= 1; kx++) {
48+
// Calculate the adjacent pixel for this kernel point
49+
int pos = (y + ky) * img->width + (x + kx);
50+
51+
// Process each channel separately, Red first.
52+
float valRed = red(img->pixels[pos]);
53+
// Multiply adjacent pixels based on the kernel values
54+
sumRed += kernel[ky + 1][kx + 1] * valRed;
55+
56+
// Green
57+
float valGreen = green(img->pixels[pos]);
58+
sumGreen += kernel[ky + 1][kx + 1] * valGreen;
59+
60+
// Blue
61+
float valBlue = blue(img->pixels[pos]);
62+
sumBlue += kernel[ky + 1][kx + 1] * valBlue;
63+
}
64+
}
65+
// For this pixel in the new image, set the output value
66+
// based on the sum from the kernel
67+
blurImg->pixels[y * blurImg->width + x] = color(sumRed, sumGreen, sumBlue);
68+
}
69+
}
70+
// State that there are changes to blurImg->pixels[]
71+
blurImg->updatePixels();
72+
73+
image(blurImg, width / 2, 0); // Draw the new image
74+
}
59.1 KB
Loading
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Brightness Pixels
3+
* by Daniel Shiffman.
4+
*
5+
* This program adjusts the brightness of a part of the image by
6+
* calculating the distance of each pixel to the mouse.
7+
*/
8+
9+
PImage* img;
10+
11+
void setup() {
12+
size(640, 360);
13+
frameRate(30);
14+
img = loadImage("moon-wide.jpg");
15+
img->loadPixels();
16+
// Only need to load the pixels[] array once, because we're only
17+
// manipulating pixels[] inside draw(), not drawing shapes.
18+
loadPixels();
19+
}
20+
21+
void draw() {
22+
for (int x = 0; x < img->width; x++) {
23+
for (int y = 0; y < img->height; y++) {
24+
// Calculate the 1D location from a 2D grid
25+
int loc = x + y * img->width;
26+
// Get the R,G,B values from image
27+
float r, g, b;
28+
r = red(img->pixels[loc]);
29+
//g = green(img->pixels[loc]);
30+
//b = blue(img->pixels[loc]);
31+
// Calculate an amount to change brightness based on proximity to the mouse
32+
float maxdist = 50; //dist(0,0,width,height);
33+
float d = dist(x, y, mouseX, mouseY);
34+
float adjustbrightness = 255 * (maxdist - d) / maxdist;
35+
r += adjustbrightness;
36+
//g += adjustbrightness;
37+
//b += adjustbrightness;
38+
// Constrain RGB to make sure they are within 0-255 color range
39+
r = constrain(r, 0, 255);
40+
//g = constrain(g, 0, 255);
41+
//b = constrain(b, 0, 255);
42+
// Make a new color and set pixel in the window
43+
//color c = color(r, g, b);
44+
color c = color(r);
45+
pixels[y * width + x] = c;
46+
}
47+
}
48+
updatePixels();
49+
}
168 KB
Loading

0 commit comments

Comments
 (0)