Skip to content

Commit

Permalink
Add examples for create_graphics (#393)
Browse files Browse the repository at this point in the history
* Add examples for create_graphics

* typo fix
  • Loading branch information
tushar5526 authored Sep 18, 2022
1 parent 7a8cb92 commit 285e8ad
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Structure
structure/redraw
structure/function
structure/recursion
structure/create graphics

Transform
#########
Expand Down
66 changes: 66 additions & 0 deletions docs/examples/structure/create graphics.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
***************
Create Graphics
***************

.. raw:: html

<script>
let pg;
function setup() {
var canvas = createCanvas(710, 400);
canvas.parent('sketch-holder');
pg = createGraphics(400, 250);
}
function draw() {
fill(0, 12);
rect(0, 0, width, height);
fill(255);
noStroke();
ellipse(mouseX, mouseY, 60, 60);
pg.background(51);
pg.noFill();
pg.stroke(255);
pg.ellipse(mouseX - 150, mouseY - 75, 60, 60);
//Draw the offscreen buffer to the screen with image()
image(pg, 150, 75);
}
</script>
<div id="sketch-holder"></div>


The ``draw_target()`` function makes it easy to draw many distinct targets. Each call to ``draw_target()`` specifies the position, size, and number of rings for each target.

.. code:: python
from p5 import *
pg = None
def setup():
global pg
size(710, 400)
pg = create_graphics(400,250)
def draw():
fill(0, 12)
rect(0, 0, width, height)
fill(255)
no_stroke()
ellipse(mouse_x, mouse_y, 60, 60)
pg.background(51)
pg.no_fill()
pg.stroke(255)
pg.ellipse(mouse_x - 150, mouse_y - 75, 60, 60)
# Draw the offscreen buffer to the screen with image()
image(pg, 150, 75)
if __name__ == '__main__':
# Create Graphics is only available in skia
run(renderer='skia')

0 comments on commit 285e8ad

Please sign in to comment.