diff --git a/README.md b/README.md
index 1410c30..8765c0f 100644
--- a/README.md
+++ b/README.md
@@ -1,82 +1,16 @@
-# [Project2: Toolbox Functions](https://github.com/CIS700-Procedural-Graphics/Project2-Toolbox-Functions)
+# [Bird Wing]
+
-## Overview
+## Objective
-The objective of this assignment is to procedurally model and animate a bird wing. Let's get creative!
+Learn how to use different functions to make a bird wing.
-Start by forking and then cloning [this repository](https://github.com/CIS700-Procedural-Graphics/Project2-Toolbox-Functions)
+## Process
-## Modeling
-
-##### Reference images
-
-Search for three or more images of a bird wing (or any flying creature, really) in order to provide yourself reference material, as you're going to base your modeling and animation from these images. For the more artistic minds, feel free to sketch your own concept.
-
-##### Make wing curve
-
-Begin with a 3D curve for your basic wing shape. Three.js provides classes to create many different types of curves, so you may use whatever type of curve you prefer.
-
-##### Distribute feathers
-
-We have provided a simple feather model from which to begin. You are not required to use this model if you have others that you prefer. From this base, you must duplicate the feather to model a complete wing, and your wing should consist of at least thirty feathers. Distribute points along the curve you created previously; you will append the feather primitives to the curve at these points. Make sure that you modify the size, orientation, and color of your feathers depending on their location on the wing.
-
-Feel free to diversify your wings by using multiple base feather models.
-
-## Animation
-
-Add a wind force to your scene, and parameterize its direction and speed. You will use this wind force to animate the feathers of your wing by vibrating them slightly. Using Dat.GUI, allow the user to modify these wind parameters. Please note that we don't care about your feather motion being physically accurate, as long as it looks nice.
-
-Additionally, animate the control points of your wing curve to make the wing flap, and allow the user to control the speed of the wing flapping.
+I started off deciding which of the functions taught I would like to use to make my bird wing. I saved the bird feather geometry read by the OBJLoader and used it to make my wing. I created several layers for my wing and each layer is aligned differently based on a number of parameters. Then, I finally added the time component by adding some wing and flapping.
## Interactivity
-Using Dat.GUI and the examples provided in the reference code, allow the user to adjust the following controls:
-
-1. The curvature of the wing's basic shape
-2. Feather distribution
-3. Feather size
-4. Feather color
-5. Feather orientation
-6. Flapping speed
-7. Flapping motion
-
-## For the Overachievers
-
-Suggestions:
-- Make a pretty iridescent or otherwise feather appropriate shader.
-- Otherwise, going the extra mile for this assignment is really in the polish!
-
-## Submission
-
-- Create a folder called `references` to include your reference images.
-
-- Update `README.md` to contain a solid description of your project
-
-- Publish your project to gh-pages. `npm run deploy`. It should now be visible at http://username.github.io/repo-name
-
-- Create a [pull request](https://help.github.com/articles/creating-a-pull-request/) to this repository, and in the comment, include a link to your published project.
-
-- Submit the link to your pull request on Canvas.
-
-## Getting Started
-
-1. [Install Node.js](https://nodejs.org/en/download/). Node.js is a JavaScript runtime. It basically allows you to run JavaScript when not in a browser. For our purposes, this is not necessary. The important part is that with it comes `npm`, the Node Package Manager. This allows us to easily declare and install external dependencies such as [three.js](https://threejs.org/), [dat.GUI](https://workshop.chromeexperiments.com/examples/gui/#1--Basic-Usage), and [glMatrix](http://glmatrix.net/). Some other packages we'll be using make it significantly easier to develop your code and create modules for better code reuse and clarity. These tools make it _signficantly_ easier to write code in multiple `.js` files without globally defining everything.
-
-2. Fork and clone your repository.
-
-3. In the root directory of your project, run `npm install`. This will download all of those dependencies.
-
-4. Do either of the following (but I highly recommend the first one for reasons I will explain later).
-
- a. Run `npm start` and then go to `localhost:7000` in your web browser
-
- b. Run `npm run build` and then go open `index.html` in your web browser
-
- You should hopefully see the framework code with a 3D cube at the center of the screen!
-
-
-## Developing Your Code
-All of the JavaScript code is living inside the `src` directory. The main file that gets executed when you load the page as you may have guessed is `main.js`. Here, you can make any changes you want, import functions from other files, etc. The reason that I highly suggest you build your project with `npm start` is that doing so will start a process that watches for any changes you make to your code. If it detects anything, it'll automagically rebuild your project and then refresh your browser window for you. Wow. That's cool. If you do it the other way, you'll need to run `npm build` and then refresh your page every time you want to test something.
+Using dat.GUI, I added sliders to affect the curvature, distribution, size, orientation, and color of the feathers and speed of motion of wind and flapping. Feather fluttering is dependent on the wind speed. I selectively make my feathers on the lower side of the wind flutter to give a more realistic look.
-## Publishing Your Code
-We highly suggest that you put your code on GitHub. One of the reasons we chose to make this course using JavaScript is that the Web is highly accessible and making your awesome work public and visible can be a huge benefit when you're looking to score a job or internship. To aid you in this process, running `npm run deploy` will automatically build your project and push it to `gh-pages` where it will be visible at `username.github.io/repo-name`.
\ No newline at end of file
+
diff --git a/demo.gif b/demo.gif
new file mode 100644
index 0000000..4bf3d79
Binary files /dev/null and b/demo.gif differ
diff --git a/npm-debug.log b/npm-debug.log
new file mode 100644
index 0000000..f707ff1
--- /dev/null
+++ b/npm-debug.log
@@ -0,0 +1,46 @@
+0 info it worked if it ends with ok
+1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'deploy' ]
+2 info using npm@3.10.10
+3 info using node@v6.9.4
+4 verbose run-script [ 'predeploy', 'deploy', 'postdeploy' ]
+5 info lifecycle @~predeploy: @
+6 silly lifecycle @~predeploy: no script for predeploy, continuing
+7 info lifecycle @~deploy: @
+8 verbose lifecycle @~deploy: unsafe-perm in lifecycle true
+9 verbose lifecycle @~deploy: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/Anvi/Desktop/CIS700/Project2-Toolbox-Functions/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin
+10 verbose lifecycle @~deploy: CWD: /Users/Anvi/Desktop/CIS700/Project2-Toolbox-Functions
+11 silly lifecycle @~deploy: Args: [ '-c',
+11 silly lifecycle 'rm -rf npm-debug.log && git checkout master && git commit -am \'update\' && gh-pages-deploy' ]
+12 silly lifecycle @~deploy: Returned: code: 1 signal: null
+13 info lifecycle @~deploy: Failed to exec deploy script
+14 verbose stack Error: @ deploy: `rm -rf npm-debug.log && git checkout master && git commit -am 'update' && gh-pages-deploy`
+14 verbose stack Exit status 1
+14 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:255:16)
+14 verbose stack at emitTwo (events.js:106:13)
+14 verbose stack at EventEmitter.emit (events.js:191:7)
+14 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
+14 verbose stack at emitTwo (events.js:106:13)
+14 verbose stack at ChildProcess.emit (events.js:191:7)
+14 verbose stack at maybeClose (internal/child_process.js:877:16)
+14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
+15 verbose pkgid @
+16 verbose cwd /Users/Anvi/Desktop/CIS700/Project2-Toolbox-Functions
+17 error Darwin 16.1.0
+18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "deploy"
+19 error node v6.9.4
+20 error npm v3.10.10
+21 error code ELIFECYCLE
+22 error @ deploy: `rm -rf npm-debug.log && git checkout master && git commit -am 'update' && gh-pages-deploy`
+22 error Exit status 1
+23 error Failed at the @ deploy script 'rm -rf npm-debug.log && git checkout master && git commit -am 'update' && gh-pages-deploy'.
+23 error Make sure you have the latest version of node.js and npm installed.
+23 error If you do, this is most likely a problem with the package,
+23 error not with npm itself.
+23 error Tell the author that this fails on your system:
+23 error rm -rf npm-debug.log && git checkout master && git commit -am 'update' && gh-pages-deploy
+23 error You can get information on how to open an issue for this project with:
+23 error npm bugs
+23 error Or if that isn't available, you can get their info via:
+23 error npm owner ls
+23 error There is likely additional logging output above.
+24 verbose exit [ 1, true ]
diff --git a/references/condora_nphll6.jpg b/references/condora_nphll6.jpg
new file mode 100644
index 0000000..658e053
Binary files /dev/null and b/references/condora_nphll6.jpg differ
diff --git a/references/pelicano_j3r1qt.jpg b/references/pelicano_j3r1qt.jpg
new file mode 100644
index 0000000..f01df27
Binary files /dev/null and b/references/pelicano_j3r1qt.jpg differ
diff --git a/src/helpers.js b/src/helpers.js
new file mode 100644
index 0000000..758c938
--- /dev/null
+++ b/src/helpers.js
@@ -0,0 +1,99 @@
+//helper functions
+export function ease_in_quadratic(t)
+{
+ return t * t;
+}
+
+export function ease_out_quadratic(t)
+{
+ return 1 - ease_in_quadratic(1 - t);
+}
+
+export function ease_in_out_quadratic(t)
+{
+ if (t < 0.5)
+ {
+ return ease_in_quadratic(t * 2) / 2;
+ }
+ else
+ {
+ return 1 - ease_in_quadratic((1 - t) * 2) / 2;
+ }
+}
+
+export function smoothstep(edge0, edge1, x)
+{
+ x = Math.ceil((x - edge0) / (edge1 - edge0), 0.0, 1.0);
+ return x * x * (3 - 2 * x);
+}
+
+export function smootherstep(edge0, edge1, x)
+{
+ x = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
+ return x * x * x * (x * (x * 6 - 15) + 10);
+}
+
+export function lerp(a, b, t)
+{
+ return a * (1 - t) + b * t;
+}
+
+export function square_wave(x, fq, amp)
+{
+ return Math.abs(Math.floor(x * fq) * amp);
+}
+
+export function sawtooth_wave(x, fq, amp)
+{
+ return (x * fq - Math.floor(x * fq)) * amp;
+}
+
+export function triangle_wave(x, fq, amp)
+{
+ return Math.abs((x * fq) % amp - (0.5 * amp));
+}
+
+export function bias(time, bias)
+{
+ return Math.pow(t, Math.log(bias) / Math.log(0.5));
+}
+
+export function gain(time, gain)
+{
+ if (t < 0.5)
+ {
+ return bias(1 - gain, 2 * t) / 2;
+ }
+ else
+ {
+ return 1 - bias(1 - gain, 2 * t) / 2;
+ }
+}
+
+export function pulse(c, w, x)
+{
+ x = Math.abs(x - c);
+ if (x > w)
+ {
+ return 0;
+ }
+ x /= w;
+ return 1 - x * x * (2 - 2 * x);
+}
+
+export function parabola(x, k)
+{
+ return Math.pow(4 * x * (1 - x), k);
+}
+
+export function impulse(k, x)
+{
+ var h = k * x;
+ return h * Math.exp(1 - h);
+}
+
+export function pcurve(a, b, x)
+{
+ var k = Math.pow(a + b, a + b) / (Math.pow(a, a) * Math.pow(b, b));
+ return k * Math.pow(x, a) * Math.pow(1 - x, b);
+}
\ No newline at end of file
diff --git a/src/main.js b/src/main.js
index fd8fbd4..602ab0b 100755
--- a/src/main.js
+++ b/src/main.js
@@ -3,17 +3,74 @@
const THREE = require('three'); // older modules are imported like this. You shouldn't have to worry about this much
import Framework from './framework'
+import {pcurve, ease_in_out_quadratic, impulse} from './helpers'
+
+var user_input =
+{
+ feather_curvature : 0.5,
+ feather_distribution : 0.1,
+ feather_count : 100,
+ feather_size : 1,
+ feather_color : 0xaaaaaa,
+ feather_orientation : -1,
+ flapping_speed : 1,
+ flapping_motion : 1,
+ wind_speed : 1
+};
+var time = 0;
+var featherGeo;
+var feather_meshes = [];
+var wing = new THREE.Object3D();
+wing.name = "wing";
+
+function alignFeathers(scale, feather_distribution, feather_count, z_offset, color)
+{
+ var length = feather_distribution * feather_count;
+ for (var x = feather_distribution; x < length; x += feather_distribution)
+ {
+ var material = new THREE.MeshPhongMaterial({ color, shininess : 0.5 });
+ var mesh = new THREE.Mesh(featherGeo, material);
+ var y = impulse(x, user_input.feather_curvature);
+ var z = ease_in_out_quadratic(x / length) - z_offset / 4;
+ mesh.position.set(x, y, z);
+ mesh.scale.set(scale, scale, scale);
+ var rot = Math.abs(0.5 * Math.sin(2 * x) * Math.cos(2 * x));
+ mesh.rotation.set(Math.PI / 2,
+ Math.PI / 2 * rot + user_input.feather_orientation + 1,
+ Math.PI);
+ mesh.name = "feather";
+ mesh.receiveShadow = true;
+ wing.add(mesh);
+ }
+}
-// called after the scene loads
-function onLoad(framework) {
- var scene = framework.scene;
- var camera = framework.camera;
- var renderer = framework.renderer;
- var gui = framework.gui;
- var stats = framework.stats;
+function makeWing()
+{
+ for (var i = 1; i <= 6 * (user_input.feather_distribution + 0.1)/ 0.1; i++)
+ {
+ var color = new THREE.Color(user_input.feather_color);
+ color.lerp(new THREE.Color(1, 1, 1), 0.1 * i);
+ var scale = i * 0.5 * user_input.feather_size;
+ var feather_distribution = 0.1 * i;
+ var feather_count = user_input.feather_count / i;
+ alignFeathers(scale, feather_distribution, feather_count, (i - 1) / 4, color);
+ }
+
+ wing.rotation.x = - Math.PI / 4;
+}
- // Basic Lambert white
- var lambertWhite = new THREE.MeshLambertMaterial({ color: 0xaaaaaa, side: THREE.DoubleSide });
+function removeFeathers()
+{
+ for(var i = 0; i < wing.children.length; i++)
+ {
+ wing.remove(wing.children[i]);
+ }
+}
+
+// called after the scene loads
+function onLoad(framework)
+{
+ var {scene, camera, renderer, gui, stats} = framework;
// Set light
var directionalLight = new THREE.DirectionalLight( 0xffffff, 1 );
@@ -36,17 +93,14 @@ function onLoad(framework) {
// load a simple obj mesh
var objLoader = new THREE.OBJLoader();
objLoader.load('/geo/feather.obj', function(obj) {
-
- // LOOK: This function runs after the obj has finished loading
- var featherGeo = obj.children[0].geometry;
-
- var featherMesh = new THREE.Mesh(featherGeo, lambertWhite);
- featherMesh.name = "feather";
- scene.add(featherMesh);
+ featherGeo = obj.children[0].geometry;
+ makeWing();
});
+
+ scene.add(wing);
// set camera position
- camera.position.set(0, 1, 5);
+ camera.position.set(-2, 10, 15);
camera.lookAt(new THREE.Vector3(0,0,0));
// scene.add(lambertCube);
@@ -57,15 +111,66 @@ function onLoad(framework) {
gui.add(camera, 'fov', 0, 180).onChange(function(newVal) {
camera.updateProjectionMatrix();
});
+ gui.add(user_input, 'feather_curvature', 0, 1).onChange(function(newVal) {
+ removeFeathers();
+ makeWing();
+ });
+ gui.add(user_input, 'feather_distribution', 0, 0.2).onChange(function(newVal) {
+ removeFeathers();
+ makeWing();
+ });
+ gui.add(user_input, 'feather_size', 0.5, 1.5).onChange(function(newVal) {
+ removeFeathers();
+ makeWing();
+ });
+ gui.add(user_input, 'feather_orientation', -1, 1).onChange(function(newVal) {
+ removeFeathers();
+ makeWing();
+ });
+ gui.addColor(user_input, 'feather_color', 0, 2).onChange(function(newVal) {
+ removeFeathers();
+ makeWing();
+ });
+ gui.add(user_input, 'wind_speed', 1, 10);
+ gui.add(user_input, 'flapping_speed', 1, 2);
+ gui.add(user_input, 'flapping_motion', 1, 2);
+}
+
+function flap(wing)
+{
+ var sin = Math.cos(time * user_input.flapping_motion / 500);
+ sin *= user_input.flapping_speed;
+ wing.rotation.x += 0.02 * sin;
+}
+
+
+function wind(wing)
+{
+ for (var i = 0; i < wing.children.length; i++)
+ {
+ var rand = Math.random() * 10;
+ var sin = Math.sin(time / 500);
+ sin *= user_input.flapping_speed;
+ if (rand < 5)
+ {
+ wing.children[i].rotation.z += 0.0005 * sin;
+ }
+ else
+ {
+ wing.children[i].rotation.y -= 0.0002 * sin;
+ }
+ }
}
// called on frame updates
-function onUpdate(framework) {
- var feather = framework.scene.getObjectByName("feather");
- if (feather !== undefined) {
- // Simply flap wing
+function onUpdate(framework)
+{
+ var wing = framework.scene.getObjectByName("wing");
+ if (wing !== undefined) {
var date = new Date();
- feather.rotateZ(Math.sin(date.getTime() / 100) * 2 * Math.PI / 180);
+ time = date.getTime();
+ flap(wing);
+ wind(wing);
}
}
diff --git a/wind.gif b/wind.gif
new file mode 100644
index 0000000..9a3f7e3
Binary files /dev/null and b/wind.gif differ