-
-
Notifications
You must be signed in to change notification settings - Fork 108
Add SVG export examples for various scenarios #1291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hxrshxz
wants to merge
2
commits into
processing:main
Choose a base branch
from
hxrshxz:svg-examples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
java/libraries/svg/examples/NoScreenDisplay/NoScreenDisplay.pde
This file contains hidden or 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,23 @@ | ||
| /** | ||
| * SVG Export (No Screen Display) | ||
| * | ||
| * This example draws a single frame to a SVG file and quits. | ||
| * (Note that no display window will open; this helps when you're | ||
| * trying to create massive SVG images that are far larger than | ||
| * the screen size.) | ||
| */ | ||
|
|
||
| import processing.svg.*; | ||
|
|
||
| void setup() { | ||
| size(400, 400, SVG, "filename.svg"); | ||
| } | ||
|
|
||
| void draw() { | ||
| // Draw something good here | ||
| line(0, 0, width/2, height); | ||
|
|
||
| // Exit the program | ||
| println("Finished."); | ||
| exit(); | ||
| } |
36 changes: 36 additions & 0 deletions
36
java/libraries/svg/examples/SingleFrameFromAnimation/SingleFrameFromAnimation.pde
This file contains hidden or 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,36 @@ | ||
| /** | ||
| * Single Frame from an Animation (With Screen Display) | ||
| * | ||
| * It's also possible to save one frame from a program with | ||
| * moving elements. Create a boolean variable to turn the SVG | ||
| * recording process on and off. | ||
| */ | ||
|
|
||
| import processing.svg.*; | ||
|
|
||
| boolean record; | ||
|
|
||
| void setup() { | ||
| size(400, 400); | ||
| } | ||
|
|
||
| void draw() { | ||
| if (record) { | ||
| // Note that #### will be replaced with the frame number. Fancy! | ||
| beginRecord(SVG, "frame-####.svg"); | ||
| } | ||
|
|
||
| // Draw something good here | ||
| background(255); | ||
| line(mouseX, mouseY, width/2, height/2); | ||
|
|
||
| if (record) { | ||
| endRecord(); | ||
| record = false; | ||
| } | ||
| } | ||
|
|
||
| // Use a mouse press so thousands of files aren't created | ||
| void mousePressed() { | ||
| record = true; | ||
| } |
49 changes: 49 additions & 0 deletions
49
java/libraries/svg/examples/ThreeDGeometry/ThreeDGeometry.pde
This file contains hidden or 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,49 @@ | ||
| /** | ||
| * SVG Files from 3D Geometry (With Screen Display) | ||
| * | ||
| * To create vectors from 3D data, use the beginRaw() and | ||
| * endRaw() commands. These commands will grab the shape data | ||
| * just before it is rendered to the screen. At this stage, | ||
| * your entire scene is nothing but a long list of lines and | ||
| * triangles. This means that a shape created with sphere() | ||
| * method will be made up of hundreds of triangles, rather | ||
| * than a single object. | ||
| * | ||
| * When using beginRaw() and endRaw(), it's possible to write | ||
| * to either a 2D or 3D renderer. For instance, beginRaw() | ||
| * with the SVG library will write the geometry as flattened | ||
| * triangles and lines. | ||
| */ | ||
|
|
||
| import processing.svg.*; | ||
|
|
||
| boolean record; | ||
|
|
||
| void setup() { | ||
| size(500, 500, P3D); | ||
| } | ||
|
|
||
| void draw() { | ||
| if (record) { | ||
| beginRaw(SVG, "output.svg"); | ||
| } | ||
|
|
||
| // Do all your drawing here | ||
| background(204); | ||
| translate(width/2, height/2, -200); | ||
| rotateZ(0.2); | ||
| rotateY(mouseX/500.0); | ||
| box(200); | ||
|
|
||
| if (record) { | ||
| endRaw(); | ||
| record = false; | ||
| } | ||
| } | ||
|
|
||
| // Hit 'r' to record a single frame | ||
| void keyPressed() { | ||
| if (key == 'r') { | ||
| record = true; | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
java/libraries/svg/examples/UsingCreateGraphics/UsingCreateGraphics.pde
This file contains hidden or 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,17 @@ | ||
| /** | ||
| * Using createGraphics() to Create an SVG File | ||
| * | ||
| * To write a SVG file using only the createGraphics() command, | ||
| * rather than as part of a sketch, it's necessary to call | ||
| * dispose() on the PGraphicsSVG object. This is the same as | ||
| * calling exit(), but it won't quit the sketch. | ||
| */ | ||
|
|
||
| import processing.svg.*; | ||
|
|
||
| PGraphics svg = createGraphics(300, 300, SVG, "output.svg"); | ||
| svg.beginDraw(); | ||
| svg.background(128, 0, 0); | ||
| svg.line(50, 50, 250, 250); | ||
| svg.dispose(); | ||
| svg.endDraw(); | ||
24 changes: 24 additions & 0 deletions
24
java/libraries/svg/examples/WithScreenDisplay/WithScreenDisplay.pde
This file contains hidden or 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,24 @@ | ||
| /** | ||
| * SVG Export (With Screen Display) | ||
| * | ||
| * To draw to the screen while also saving an SVG, use the | ||
| * beginRecord() and endRecord() functions. Unlike the PDF | ||
| * renderer, the SVG renderer will only save the final frame | ||
| * of a sequence. This is slower, but is useful when you need | ||
| * to see what you're working on as it saves. | ||
| */ | ||
|
|
||
| import processing.svg.*; | ||
|
|
||
| void setup() { | ||
| size(400, 400); | ||
| noLoop(); | ||
| beginRecord(SVG, "filename.svg"); | ||
| } | ||
|
|
||
| void draw() { | ||
| // Draw something good here | ||
| line(0, 0, width/2, height); | ||
|
|
||
| endRecord(); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.