p5-examples
p5-examples copied to clipboard
Vector example — drawing arrows
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()
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 :)
Thank you Abhikpal, I have some ideas, I must first get more familiarized with github
Awesome!
Here are a couple of things you can take a look at:
-
Daniel Shiffman's "Git and Github for Poets" on YouTube: https://youtu.be/BCQHnlnPusY?list=PLRqwX-V7Uu6ZF9C0YMKuns9sLDzK6zoiV
-
Michael Hartl's "Learn Enough Git to be Dangerous": https://www.learnenough.com/git-tutorial
-
Scott Chacon and Ben Straub's "Pro Git": https://git-scm.com/book/en/v2
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.