├── README.md └── extras ├── Triangle_Strips ├── Icon ├── Triangle_Strips.pde └── data │ └── cat.jpg ├── alignment ├── Icon ├── index.html ├── sketch.js └── vehicle.js ├── millis_timer ├── Icon └── millis_timer.pde └── textured_flag ├── Particle.pde ├── Spring.pde ├── data └── cat.jpg └── textured_flag.pde /README.md: -------------------------------------------------------------------------------- 1 | The Nature of Code Part 1 (Spring 2017) 2 | ====================================== 3 | 4 | Syllabus for Part 1 of Nature of Code: "Physics and Animation" at ITP Spring 2017 5 | 6 | Class Info 7 | ---------- 8 | * Daniel Shiffman: daniel.shiffman@nyu.edu 9 | * Section 1: Tuesdays, 9:00-11:30am 10 | * Section 2: Wednesdays, 9:00-11:30am 11 | * [Office Hours](https://itp.nyu.edu/inwiki/Signup/Shiffman) 12 | * [Sign up for Mailing List](https://groups.google.com/a/itp.nyu.edu/forum/#!forum/natureofcode) 13 | 14 | Resources 15 | --------- 16 | * [All course videos](https://www.youtube.com/user/shiffman/playlists?view=50&sort=dd&shelf_id=6) -- If you would like offline access to the videos and/or just prefer to watch them somewhere other than YouTube, let me know. 17 | * [Nature of Code Kadenze Course](https://www.kadenze.com/courses/the-nature-of-code/info) 18 | * [Online textbook](http://natureofcode.com/book/) 19 | * [p5.js code examples](https://github.com/shiffman/The-Nature-of-Code-Examples-p5.js) 20 | * [Processing (Java) code examples](https://github.com/shiffman/The-Nature-of-Code-Examples) 21 | * [Other ports](https://github.com/shiffman/The-Nature-of-Code-Examples/blob/master/README.md) 22 | * [Further Reading](http://natureofcode.com/book/further-reading/) 23 | * Some assignments and materials based on Mimi Yin's [Nature of Code course](https://github.com/mimiyin/Nature-of-Code-S-16/). 24 | 25 | Related Reading and Watching 26 | ---------------------------- 27 | * [Coding Math Video Series](http://www.youtube.com/user/codingmath) 28 | * [Generative Design with Processing](http://www.amazon.com/gp/product/1616890770/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1616890770&linkCode=as2&tag=natureofcode-20) 29 | * [Mathematics and Physics for Programmers](http://www.amazon.com/gp/product/1435457331/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1435457331&linkCode=as2&tag=learniproces-20) 30 | * [Computational Beauty of Nature](http://www.amazon.com/gp/product/0262561271/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=0262561271&linkCode=as2&tag=natureofcode-20) 31 | * [Form and Code](http://formandcode.com/) 32 | 33 | Week 1 - Introduction (Jan 24/25) 34 | ------------------------------- 35 | * Class Intro / Overview 36 | * [Related and Past Projects](https://github.com/shiffman/The-Nature-of-Code-S14/wiki/Nature-of-Code-Related-and-Past-Projects) 37 | * [Processing](http://www.processing.org), [p5.js](http://p5js.org), or ______________. 38 | * Randomness, Probability, and Perlin Noise 39 | * [Nature of Code Introduction](http://natureofcode.com/book/introduction/) 40 | * [Videos I.1 - I.5](https://www.youtube.com/playlist?list=PLRqwX-V7Uu6YVljJvFRCyRM6mmF5wMPeE) 41 | * [Perlin Noise playlist](https://www.youtube.com/playlist?list=PLRqwX-V7Uu6bgPNQAdxQZpJuJCjeOr7VD) 42 | * [p5.js examples](https://github.com/shiffman/The-Nature-of-Code-Examples-p5.js/tree/master/introduction) 43 | * Object Oriented Programming Review & Vectors 44 | * [Nature of Code Chapter 1](http://natureofcode.com/book/chapter-1-vectors/) 45 | * [Videos 1.1 - 1.6](https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZwSmtE13iJBcoI-r4y7iEc) 46 | * [Processing examples](https://github.com/shiffman/The-Nature-of-Code-Examples/tree/master/chp1_vectors) 47 | * [p5.js examples](https://github.com/shiffman/The-Nature-of-Code-Examples-p5.js/tree/master/chp01_vectors) 48 | * Assignment 49 | * [Sign up for class mailing list](https://groups.google.com/a/itp.nyu.edu/forum/#!forum/natureofcode) 50 | * [Assignment](https://github.com/shiffman/NOC-S17-1-Physics-Animation/wiki/Homework-1). 51 | * Supplemental Reading 52 | * [Mathematics and Physics for Programmers](http://www.amazon.com/gp/product/1584503300/) Chapter 5 53 | * [Computational Beauty of Nature](http://www.amazon.com/gp/product/0262561271/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=0262561271&linkCode=as2&tag=natureofcode-20), Introduction 54 | * [Probability Theory](http://www.probabilitytheory.info/) 55 | 56 | Week 2 - Build a Physics Engine (Jan 31 / Feb 1) 57 | ------------------------ 58 | * [Nature of Code Chapter 2](http://natureofcode.com/book/chapter-2-forces/) 59 | * [Videos 2.1 - 2.6](https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZRrqLcQ5BkBKmBLiGD8n4O) 60 | * [Processing examples](https://github.com/shiffman/The-Nature-of-Code-Examples/tree/master/chp02_forces) 61 | * [p5.js examples](https://github.com/shiffman/The-Nature-of-Code-Examples-p5.js/tree/master/chp02_forces) 62 | * [Assignment](https://github.com/shiffman/NOC-S17-1-Physics-Animation/wiki/Homework-2). 63 | * Supplemental Reading 64 | * [Newtonian Physics, An Online Textbook](http://www.lightandmatter.com/area1book1.html) (This is long, you may find Chapter 4 to be particularly relevant to this week's discussion.) 65 | * [The Physics Classroom -- Newton's Laws](http://www.physicsclassroom.com/Class/newtlaws/newtltoc.html) 66 | * [Mathematics and Physics for Programmers](http://www.amazon.com/gp/product/1584503300/), Chapters 12 and 14 67 | 68 | Week 3 - Oscillation and Particle Systems (Feb 7/8) 69 | ------------------------------- 70 | * [Nature of Code Chapter 3: Oscillation](http://natureofcode.com/book/chapter-3-oscillation/) 71 | * [Nature of Code Chapter 4: Particle Systems](http://natureofcode.com/book/chapter-4-particle-systems/) 72 | * Videos 3.1 - 3.5, Videos 4.1 - 4.9 73 | * [p5.js chapter 3 examples](https://github.com/shiffman/The-Nature-of-Code-Examples-p5.js/tree/master/chp03_oscillation) 74 | * [p5.js chapter 4 examples](https://github.com/shiffman/The-Nature-of-Code-Examples-p5.js/tree/master/chp04_systems) 75 | * [Simple Harmonic Motion by Memo Akten](http://www.memo.tv/simple-harmonic-motion/) 76 | * [Demo of Oscillating Movement and Sine Wave](https://www.youtube.com/watch?v=PhvJcVDuJsY#t=55) 77 | * Supplemental reading 78 | * [Trigonometry, What is it good for?](http://www.phy6.org/stargaze/Strig1.htm) 79 | * [Mathematics and Physics for Programmers](http://www.amazon.com/gp/product/1584503300/), Chapter 4 80 | * ["Particle animation and rendering using data parallel computation", Karl Sims](http://doi.acm.org/10.1145/97879.97923) (available via NYU network/proxy) 81 | * ["Particle Systems, a Technique for Modeling a Class of Fuzzy Objects", Reeves](http://doi.acm.org/10.1145/357318.357320) (available via NYU network/proxy) 82 | * [How my Dog learned Polymorphism](http://www.javaranch.com/campfire/StoryPoly.jsp) 83 | * [Particle System API, by David K. McAllister](http://www.siggraph.org/education/materials/HyperGraph/animation/particle.htm) 84 | * [Particle Systems by Allen Martin](http://web.cs.wpi.edu/~matt/courses/cs563/talks/psys.html) 85 | ms) 86 | * [Assignment](https://github.com/shiffman/NOC-S17-1-Physics-Animation/wiki/Homework-3) 87 | 88 | Week 4 - Autonomous Agents (Feb 14/15) 89 | ----------------------------------- 90 | * [Nature of Code Chapter 6: Autonomous Agents](http://natureofcode.com/book/chapter-6-autonomous-agents/) 91 | * [Videos 6.1 - 6.8](https://www.youtube.com/playlist?list=PLRqwX-V7Uu6YHt0dtyf4uiw8tKOxQLvlW) 92 | * [Processing examples](https://github.com/shiffman/The-Nature-of-Code-Examples/tree/master/chp06_agents) 93 | * [p5.js examples](https://github.com/shiffman/The-Nature-of-Code-Examples-p5.js/tree/master/chp06_agents) 94 | * Supplemental 95 | * [Reas Process Compendium](https://vimeo.com/22955812) 96 | * [Braitenberg Vehicles](http://books.google.com/books/?id=7KkUAT_q_sQC) 97 | * [Craig Reynolds' Steering Behaviors for Autonomous Characters](http://www.red3d.com/cwr/steer/) 98 | * [BetterExplained/ Dot Product + Finding The "Normal"](http://betterexplained.com/articles/vector-calculus-understanding-the-dot-product/) 99 | * [Finding the closest point on a curve.](http://www.mesacc.edu/~marfv02121/readings/nearest_point/index.html) 100 | * [Homework-4: Final Project Start](https://github.com/shiffman/NOC-S17-1-Physics-Animation/wiki/Project-Step-1) 101 | 102 | Week 5 - Physics Libraries (Friday Feb 24!) 103 | --------------------------- 104 | * '''Please note the makeup time for this week on Friday, Feb 24''' 105 | * '''Both classes will meet in room 50 from 12pm-3pm''' 106 | * [Add your questions here](https://github.com/shiffman/NOC-S17-1-Physics-Animation/wiki/Questions:-Steering-and-Physics-Engine) 107 | * [Nature of Code Chapter 5: Physics Libraries](http://natureofcode.com/book/chapter-5-physics-libraries/) 108 | * Box2D 109 | * [Box2D web site](http://box2d.org/) 110 | * [Videos 5.1 - 5.12](https://www.youtube.com/playlist?list=PLRqwX-V7Uu6akvoNKE4GAxf6ZeBYoJ4uh) 111 | * [Processing examples](https://github.com/shiffman/The-Nature-of-Code-Examples/tree/master/chp05_libraries/box2d) 112 | * [p5.js examples](https://github.com/shiffman/The-Nature-of-Code-Examples-p5.js/tree/master/chp05_libraries/box2d-html5) 113 | * Toxiclibs 114 | * [Videos 5.13 - 5.16](https://www.youtube.com/playlist?list=PLRqwX-V7Uu6akvoNKE4GAxf6ZeBYoJ4uh) 115 | * [Processing examples](https://github.com/shiffman/The-Nature-of-Code-Examples/tree/master/chp05_libraries/toxiclibs) 116 | * [p5.js examples](https://github.com/shiffman/The-Nature-of-Code-Examples-p5.js/tree/master/chp05_libraries/toxiclibs) 117 | * [ToxicLibs](http://toxiclibs.org/) 118 | * [ToxicLibs.js](http://haptic-data.com/toxiclibsjs/) 119 | * [The Making of Nokia Friends](https://vimeo.com/1472427) 120 | * [Advanced Character Physics](http://www.gamasutra.com/resource_guide/20030121/jacobson_pfv.htm) 121 | * Bullet 122 | * [bRigid Processing Library](http://www.lab-eds.org/bRigid) 123 | * [ammo.js Javascript port](https://github.com/kripken/ammo.js/) 124 | * [simple 3d box demo](https://github.com/shiffman/The-Nature-of-Code-Examples/tree/master/chp5_physicslibraries/bRigid_jBullet) 125 | * Other libraries? 126 | 127 | Week 6 - Catch-up and Project Workshop (Feb 28 / Mar 1 ) 128 | ------------------------------------ 129 | * More on inheritance/polymorphism 130 | * Geometry and Texturing 131 | * Matter.js 132 | * Closer look at flocking and complex systems 133 | * Preview of NOC: Intelligence and Learning 134 | 135 | Week 7 - Project Presentations (Mar 7/8) 136 | ------------------------------ 137 | * [Project Presentations and Documentation](https://github.com/shiffman/NOC-S17-1-Physics-Animation/wiki/Project) 138 | 139 | Policies 140 | ----------------------------------------------- 141 | * Submit assignments by the evening before class to the extent possible. 142 | * Come prepared with questions. 143 | * Put away screens during others' presentations. 144 | * Participate! 145 | * Document! 146 | * Grading: 147 | * 40% Class Participation 148 | * 40% Quality of assignments 149 | * 20% Final project 150 | * For a 2-point class, 2 or more unexcused absences is grounds for failure. 151 | -------------------------------------------------------------------------------- /extras/Triangle_Strips/Icon : -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nature-of-code/NOC-S17-1-Physics-Animation/7740d290402e10dbcd203de14f043c4498402206/extras/Triangle_Strips/Icon -------------------------------------------------------------------------------- /extras/Triangle_Strips/Triangle_Strips.pde: -------------------------------------------------------------------------------- 1 | PImage img; 2 | void setup() { 3 | size(600, 600, P2D); 4 | img = loadImage("cat.jpg"); 5 | background(0); 6 | strokeWeight(3); 7 | stroke(255); 8 | noFill(); 9 | 10 | beginShape(TRIANGLE_STRIP); 11 | texture(img); 12 | for (float x = 0; x < width; x+= 50) { 13 | float u = map(x, 0, width, 0, img.width); 14 | vertex(x, 300, u, 10); 15 | vertex(x, 350, u, 60); 16 | } 17 | endShape(); 18 | } -------------------------------------------------------------------------------- /extras/Triangle_Strips/data/cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nature-of-code/NOC-S17-1-Physics-Animation/7740d290402e10dbcd203de14f043c4498402206/extras/Triangle_Strips/data/cat.jpg -------------------------------------------------------------------------------- /extras/alignment/Icon : -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nature-of-code/NOC-S17-1-Physics-Animation/7740d290402e10dbcd203de14f043c4498402206/extras/alignment/Icon -------------------------------------------------------------------------------- /extras/alignment/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Nature of Code Example 6.1 Seek 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /extras/alignment/sketch.js: -------------------------------------------------------------------------------- 1 | // The Nature of Code 2 | // Daniel Shiffman 3 | // http://natureofcode.com 4 | 5 | // Seeking "vehicle" follows the mouse position 6 | 7 | // Implements Craig Reynold's autonomous steering behaviors 8 | // One vehicle "seeks" 9 | // See: http://www.red3d.com/cwr/ 10 | 11 | var vehicles = []; 12 | 13 | function setup() { 14 | createCanvas(800, 600); 15 | for (var i = 0; i < 50; i++) { 16 | vehicles[i] = new Vehicle(random(width), random(height)); 17 | } 18 | } 19 | 20 | function draw() { 21 | background(51); 22 | 23 | var mouse = createVector(mouseX, mouseY); 24 | 25 | // Call the appropriate steering behaviors for our agents 26 | for (var i = 0; i < vehicles.length; i++) { 27 | var v = vehicles[i]; 28 | //v.seek(mouse); 29 | v.alignment(); 30 | v.update(); 31 | v.display(); 32 | v.borders(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /extras/alignment/vehicle.js: -------------------------------------------------------------------------------- 1 | // The Nature of Code 2 | // Daniel Shiffman 3 | // http://natureofcode.com 4 | 5 | // The "Vehicle" class 6 | 7 | function Vehicle(x, y) { 8 | this.maxspeed = 4; 9 | this.maxforce = 0.1; 10 | this.acceleration = createVector(0, 0); 11 | this.velocity = p5.Vector.random2D(); 12 | this.velocity.setMag(this.maxspeed); 13 | this.position = createVector(x, y); 14 | this.r = 4; 15 | 16 | // Method to update location 17 | this.update = function() { 18 | // Update velocity 19 | this.velocity.add(this.acceleration); 20 | // Limit speed 21 | this.velocity.limit(this.maxspeed); 22 | this.position.add(this.velocity); 23 | // Reset accelerationelertion to 0 each cycle 24 | this.acceleration.mult(0); 25 | }; 26 | 27 | this.applyForce = function(force) { 28 | // We could add mass here if we want A = F / M 29 | this.acceleration.add(force); 30 | }; 31 | 32 | this.alignment = function() { 33 | var threshold = 100; 34 | var count = 0; 35 | 36 | var desired = createVector(0, 0); 37 | for (var i = 0; i < vehicles.length; i++) { 38 | var v = vehicles[i]; 39 | var d = dist(v.position.x, v.position.y, this.position.x, this.position.y); 40 | if (v != this && d < threshold) { 41 | desired.add(v.velocity); 42 | count++; 43 | } 44 | } 45 | 46 | if (count > 0) { 47 | desired.div(count); 48 | desired.setMag(this.maxspeed); 49 | // Reynolds Steering Rule 50 | var steer = p5.Vector.sub(desired, this.velocity); 51 | steer.limit(this.maxforce); // Limit to maximum steering force 52 | this.applyForce(steer); 53 | } 54 | 55 | 56 | 57 | } 58 | 59 | // Wraparound 60 | this.borders = function() { 61 | if (this.position.x < -this.r) this.position.x = width + this.r; 62 | if (this.position.y < -this.r) this.position.y = height + this.r; 63 | if (this.position.x > width + this.r) this.position.x = -this.r; 64 | if (this.position.y > height + this.r) this.position.y = -this.r; 65 | }; 66 | 67 | 68 | 69 | // A method that calculates a steering force towards a target 70 | // STEER = DESIRED MINUS VELOCITY 71 | this.seek = function(target) { 72 | 73 | var desired = p5.Vector.sub(target, this.position); // A vector pointing from the location to the target 74 | 75 | // Scale to maximum speed 76 | desired.setMag(this.maxspeed); 77 | 78 | // Steering = Desired minus velocity 79 | var steer = p5.Vector.sub(desired, this.velocity); 80 | steer.limit(this.maxforce); // Limit to maximum steering force 81 | 82 | this.applyForce(steer); 83 | }; 84 | 85 | this.display = function() { 86 | // Draw a triangle rotated in the direction of velocity 87 | var theta = this.velocity.heading() + PI / 2; 88 | fill(127); 89 | stroke(200); 90 | strokeWeight(1); 91 | push(); 92 | translate(this.position.x, this.position.y); 93 | rotate(theta); 94 | beginShape(); 95 | vertex(0, -this.r * 2); 96 | vertex(-this.r, this.r * 2); 97 | vertex(this.r, this.r * 2); 98 | endShape(CLOSE); 99 | pop(); 100 | }; 101 | } 102 | -------------------------------------------------------------------------------- /extras/millis_timer/Icon : -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nature-of-code/NOC-S17-1-Physics-Animation/7740d290402e10dbcd203de14f043c4498402206/extras/millis_timer/Icon -------------------------------------------------------------------------------- /extras/millis_timer/millis_timer.pde: -------------------------------------------------------------------------------- 1 | int startTime = 0; 2 | void setup() { 3 | size(400,400); 4 | startTime = millis(); 5 | } 6 | 7 | void draw() { 8 | background(0); 9 | fill(255); 10 | textSize(24); 11 | int now = millis() - startTime; 12 | int minutes = (now/1000) % 60; 13 | text(now / 1000, 10, 200); 14 | } -------------------------------------------------------------------------------- /extras/textured_flag/Particle.pde: -------------------------------------------------------------------------------- 1 | // Daniel Shiffman 2 | // http://codingtra.in 3 | // http://patreon.com/codingtrain 4 | // Code for: https://youtu.be/jrk_lOg_pVA 5 | 6 | class Particle extends VerletParticle3D { 7 | 8 | Particle(float x, float y, float z) { 9 | super(x, y, z); 10 | } 11 | 12 | void display() { 13 | pushMatrix(); 14 | translate(x,y,z); 15 | //fill(255); 16 | //ellipse(x, y, 10, 10); 17 | popMatrix(); 18 | } 19 | } -------------------------------------------------------------------------------- /extras/textured_flag/Spring.pde: -------------------------------------------------------------------------------- 1 | // Daniel Shiffman 2 | // http://codingtra.in 3 | // http://patreon.com/codingtrain 4 | // Code for: https://youtu.be/jrk_lOg_pVA 5 | 6 | class Spring extends VerletSpring3D { 7 | 8 | Spring(Particle a, Particle b) { 9 | super(a, b, w, 0.98); 10 | } 11 | 12 | void display() { 13 | stroke(255); 14 | strokeWeight(2); 15 | line(a.x, a.y, a.z, b.x, b.y, b.z); 16 | } 17 | } -------------------------------------------------------------------------------- /extras/textured_flag/data/cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nature-of-code/NOC-S17-1-Physics-Animation/7740d290402e10dbcd203de14f043c4498402206/extras/textured_flag/data/cat.jpg -------------------------------------------------------------------------------- /extras/textured_flag/textured_flag.pde: -------------------------------------------------------------------------------- 1 | // Daniel Shiffman 2 | // http://codingtra.in 3 | // http://patreon.com/codingtrain 4 | // Code for: https://youtu.be/jrk_lOg_pVA 5 | 6 | import toxi.physics3d.*; 7 | import toxi.physics3d.behaviors.*; 8 | import toxi.physics3d.constraints.*; 9 | import toxi.geom.*; 10 | 11 | float zoff = 0.0; 12 | 13 | int cols = 80; 14 | int rows = 40; 15 | 16 | Particle[][] particles = new Particle[cols][rows]; 17 | ArrayList springs; 18 | 19 | float w = 8; 20 | 21 | PImage flag; 22 | 23 | VerletPhysics3D physics; 24 | 25 | void setup() { 26 | size(800, 600, P3D); 27 | springs = new ArrayList(); 28 | flag = loadImage("cat.jpg"); 29 | 30 | physics = new VerletPhysics3D(); 31 | Vec3D gravity = new Vec3D(0, 0.05, 0); 32 | GravityBehavior3D gb = new GravityBehavior3D(gravity); 33 | physics.addBehavior(gb); 34 | 35 | float x = -cols*w/2; 36 | for (int i = 0; i < cols; i++) { 37 | float y = -rows*w/2; 38 | for (int j = 0; j < rows; j++) { 39 | Particle p = new Particle(x, y, 0); 40 | particles[i][j] = p; 41 | physics.addParticle(p); 42 | y = y + w; 43 | } 44 | x = x + w; 45 | } 46 | 47 | for (int i = 0; i < cols; i++) { 48 | for (int j = 0; j < rows; j++) { 49 | Particle a = particles[i][j]; 50 | if (i != cols-1) { 51 | Particle b1 = particles[i+1][j]; 52 | Spring s1 = new Spring(a, b1); 53 | springs.add(s1); 54 | physics.addSpring(s1); 55 | } 56 | if (j != rows-1) { 57 | Particle b2 = particles[i][j+1]; 58 | Spring s2 = new Spring(a, b2); 59 | springs.add(s2); 60 | physics.addSpring(s2); 61 | } 62 | } 63 | } 64 | 65 | particles[0][0].lock(); 66 | particles[0][rows-1].lock(); 67 | } 68 | float a = 0; 69 | 70 | void draw() { 71 | background(51); 72 | translate(width/2, height/2); 73 | //rotateY(a); 74 | //a += 0.01; 75 | physics.update(); 76 | 77 | strokeWeight(4); 78 | stroke(255); 79 | line(-cols*w/2, -rows*w/2, -cols*w/2, rows*w); 80 | 81 | stroke(255); 82 | noStroke(); 83 | noFill(); 84 | float yoff = 0; 85 | for (int j = 0; j < rows-1; j++) { 86 | beginShape(TRIANGLE_STRIP); 87 | texture(flag); 88 | float xoff = 0; 89 | for (int i = 0; i < cols; i++) { 90 | float u = map(i, 0, cols, 0, flag.width); 91 | float v = map(j, 0, rows, 0, flag.height); 92 | Particle p1= particles[i][j]; 93 | vertex(p1.x, p1.y, p1.z, u, v); 94 | Particle p2= particles[i][j+1]; 95 | v = map(j+1, 0, rows, 0, flag.height); 96 | vertex(p2.x, p2.y, p2.z, u, v); 97 | //particles[i][j].display(); 98 | 99 | float wx = map(noise(xoff, yoff, zoff), 0, 1, -0.1, 1); 100 | float wy = map(noise(xoff+5000, yoff+5000, zoff), 0, 1, -0.1, 0.1); 101 | float wz = map(noise(xoff+10000, yoff+10000, zoff), 0, 1, -0.1, 0.1); 102 | Vec3D wind = new Vec3D(wx,wy,wz); 103 | p1.addForce(wind); 104 | xoff += 0.1; 105 | } 106 | yoff += 0.1; 107 | endShape(); 108 | } 109 | 110 | //for (Spring s : springs) { 111 | // s.display(); 112 | //} 113 | zoff += 0.1; 114 | } --------------------------------------------------------------------------------