sketching
sketching copied to clipboard
Improve support for shapes
Improve support for shapes.
createShape, loadShape, PShape, shape and shapeMode
I wanted to look into this, but I found out this functionality is already implemented.
Did I miss something, or should this be closed?
Right now there is support for drawing a shape with begin-shape
and end-shape. The command
begin-shapestarts recording the shape and
end-shape` finally draws it.
What's missing somewhat of making an explicit shape object that represent a shape. This can for example be used to draw the same shape multiple times. Or you could an array with shapes, each shape representing an animation frame.
In Processing they create a PShape object (P for Processing - it took me a while to figure out what the P stood for) with createShape
. The object has methods to affect the shape. Instead of calling vertex
one know calls ashape.vertex
. When the shape is done, one can draw it using shape()
.
The overview of how it works is here: https://processing.org/reference/createShape_.html
The list of methods is here: https://processing.org/reference/PShape.html
Take a look and see if you are interested in adding a Shape class to Sketching. It would be a great addition.
FWIW the code that handles the current shape operations are here:
[1] https://github.com/soegaard/sketching/blob/9dac18590261d9df86c6d010f07c400bcf0f201a/sketching-lib/sketching/graphics.rkt#L746
I am currently looking into it and I have not done much OOP in Racket. But I'll give it a shot and try to figure it out. (Don't get your hopes too high that I can solve this quickly. :P)
I have a very basic and feature-missing, but running, version now. I found some problems with the Processing API VS. Sketching.
In Processing for example the shape constructor is overloaded with a parameter for the default shapes like RECT and ELLIPSE, plus some extra arguments for the position, based on the basic shape that's provided. I'd like to split this up into different functions, like create-shape
, create-shape-rect
, create-shape-ellipse
and so on, to not get lost in arity mismatch land.
Also I put a draw method inside the shape class, because draw-shape
and shape-draw
are both already taken.
Are those changes okay, or should I stay as close to Processing as possible?
Edit:
I also have no idea where to export those new functions, currently i'm loading them via (require sketching/graphics)
because I can't find out where I am missing a provide
.
I have a very basic and feature-missing, but running, version now. I Great news.
Are those changes okay, or should I stay as close to Processing as possible? The idea is that Sketching is what Processing would have looked like if it were written in Racket. So we are free to make the API more "Rackety" if we like.
On the other hand staying close to P. means that it is easier to port examples to Sketching.
In this case I think we can do both :-)
If you have functions create-shape-rect
, create-shape-ellipse
etc, then the function create-shape
could look at its input and then call one of the other functions. I'll gladly volunteer to write create-shape
if you write the other functions ;-)
Giving Shape
a draw
method is a good idea.
Wrt to getting the Shape class seen inside a #lang sketching
program:
Let's say you have a file "shape.rkt" which contains the Shape
class.
First of all use (provide Shape)
in "shape.rkt".
Second in "sketching-lib/sketching/exports-no-gui.rkt" you will need to add an (require "shape.rkt")
and then add Shape
to the long list of names that are in the language (see lines 200-300 ish).