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

Vector example — drawing arrows #1

Open
artyprog opened this issue Aug 14, 2017 · 3 comments
Open

Vector example — drawing arrows #1

artyprog opened this issue Aug 14, 2017 · 3 comments

Comments

@artyprog
Copy link

artyprog commented Aug 14, 2017

This is not an issue :-)

Perhaps could you put this snippet in examples directory ?
Feel free to modify it as you like

Regards

# Drawing Arrows

from p5 import *

ang = PI/60.0
v = Vector(0, 100)

def setup():
    size(800, 600)
    title("Rotating Arrow")

def line_vect(v1, v2):
    line((v1.x, v1.y), (v2.x , v2.y))

def drawArrow(v1, v2):
    vs = v2 - v1
    mag, angle  = vs.magnitude, vs.angle
    line_vect(v1, v2)
    with push_matrix():
        rotate(angle)
        line((mag, 0), (mag - 15, 6))
        line((mag, 0), (mag - 15, -6))

def drawAxes():
    drawArrow(Vector(0,0), Vector(0, -250))
    drawArrow(Vector(0,0), Vector(250, 0))

def draw():
    background(0, 0, 0, 5.0)
    stroke(0, 223, 0)
    translate(width/2, height/2)
    drawAxes()
    stroke(255, 0, 0)
    drawArrow(Vector(0, 0), v)
    v.rotate(ang)

if __name__ == '__main__':
    run()                                                                                                                                                                                                                                                                                                                                       
@abhikpal
Copy link
Member

abhikpal commented Aug 14, 2017

Hey,

This is great! I just have one small comment:

Did you know you can pass vectors directly to the line() function?
You don't have to write an extra line_vert() function! You can just
do line(v1, v2) and it will just work!

So, this is how the examples are structured:

  • basics contains ports of the basic examples from Processing
  • reference has all the sketches required for the p5 reference and documentation.
  • misc has everything else.

Maybe you could consider writing a whole set of examples inside misc
like these that show the functionality of the vector class. If
you're familiar with git, you could create a fork of this repository,
add your examples and then create a pull request! I would be more than
happy to review and merge new examples.

Would be happy to answer questions about sending in contributions if
you have any :)

@abhikpal abhikpal changed the title Drawing Arrows Vector example — drawing arrows Aug 14, 2017
@artyprog
Copy link
Author

Thank you Abhikpal,
I have some ideas, I must first get more familiarized with github

@abhikpal
Copy link
Member

Awesome!

Here are a couple of things you can take a look at:

Skim through these and decide which one you want to work through. You
obviously don't need to learn everything to start contributing code.
And let me know if you have any questions about the contributing
process and/or git.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants