Coder Social home page Coder Social logo

shiffman / learningprocessing-p5.js Goto Github PK

View Code? Open in Web Editor NEW
263.0 31.0 87.0 4.89 MB

Port all of Learning Processing examples to JavaScript using p5.js

Home Page: http://learningprocessing.com

JavaScript 98.87% Processing 0.01% HTML 1.13%

learningprocessing-p5.js's Issues

console.log instead of println

On line 22 here should read console.log() not println()

EDIT: Ahh, I guess println() and print() are still a thing in p5. Is this something we want though? Shouldn't we be teaching console.log() only?

Change to using ES6 classes!

Here's a basic model of how I'm doing this simply:

// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Exercise 8-5: Rewrite the gravity example from Chapter 5 using objects with a Ball class. 
// Include two instances of a Ball object.

// Ball constuctor
class Ball {
  constructor(x, y, w) {
    this.x = x; // x location of square 
    this.y = y; // y location of square 
    this.w = w; // speed of square 
    this.speed = 0; // size
  }

  display() {
    // Display the square 
    fill(175);
    stroke(0);
    ellipse(this.x, this.y, this.w, this.w);
  }

  update() {
    // Add speed to location
    this.y = this.y + this.speed;

    // Add gravity to speed
    this.speed = this.speed + gravity;

    // If square reaches the bottom 
    // Reverse speed 
    if (this.y > height) {
      this.speed = this.speed * -0.95;
    }
  }
}

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.