Skip to content
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

Improve support for shapes #10

Open
soegaard opened this issue Jun 9, 2021 · 5 comments
Open

Improve support for shapes #10

soegaard opened this issue Jun 9, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@soegaard
Copy link
Owner

soegaard commented Jun 9, 2021

Improve support for shapes.

createShape, loadShape, PShape, shape and shapeMode

@soegaard soegaard added the enhancement New feature or request label Jul 11, 2021
@Ecsodikas
Copy link
Contributor

I wanted to look into this, but I found out this functionality is already implemented.

Did I miss something, or should this be closed?

@soegaard
Copy link
Owner Author

Right now there is support for drawing a shape with begin-shape and end-shape. The command begin-shapestarts recording the shape andend-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]

; A shape is represented as a dc-path% and the number of points

@Ecsodikas
Copy link
Contributor

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)

@Ecsodikas
Copy link
Contributor

Ecsodikas commented Jan 24, 2022

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.

@soegaard
Copy link
Owner Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants