Giter Site home page Giter Site logo

p5-examples's People

Contributors

abhikpal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

p5-examples's Issues

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.