From 0c2ba31b1ada7d62b81bbce909b48bc09da4f8e8 Mon Sep 17 00:00:00 2001 From: Eric Carlson Date: Tue, 8 Dec 2015 14:11:20 -0500 Subject: [PATCH 1/5] draw 3D ball bouncing around --- ...unctions_making_a_sphere_bounce_around.pde | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 sketch_3D_void_functions_making_a_sphere_bounce_around/sketch_3D_void_functions_making_a_sphere_bounce_around.pde diff --git a/sketch_3D_void_functions_making_a_sphere_bounce_around/sketch_3D_void_functions_making_a_sphere_bounce_around.pde b/sketch_3D_void_functions_making_a_sphere_bounce_around/sketch_3D_void_functions_making_a_sphere_bounce_around.pde new file mode 100644 index 0000000..1cdaedf --- /dev/null +++ b/sketch_3D_void_functions_making_a_sphere_bounce_around/sketch_3D_void_functions_making_a_sphere_bounce_around.pde @@ -0,0 +1,89 @@ +int xPos=400; +int yPos=300; //necessary floats for all functions to work for postion of the ball so it knows where to translate the ball +int zPos=500; + +int xSpeed=1; +int ySpeed=1; //necessary floats for functions to work for speed in the 3 directions +int zSpeed=1; + +int xDirection=17; +int yDirection=10; // the speed floats could work on their own but i added another set of floats so i can add more direction of movements +int zDirection=15; +int radius=100; //unnecessary floats but its easier to change the size of the ball and depth of the box without having to change all the numbers in the code +int depth=1000; + +// end of variables + +void setup() { + size (800,600, P3D); //makes drawing in 3D + +} + +void draw() { + background(0); + backgroundsquare(); //use created functions + drawball(); + makeballmove(); +} + + + +void backgroundsquare() { + + stroke(255); + + // these lines draw the back of the so called box that the ball is in + line(0, 0, -depth, width, 0, -depth); + line(0, 0, -depth, 0, height, -depth); //depth variable is used so i dont have to change each number if i wanna make the "box go back further + line(0, height, -depth, width, height, -depth); + line(width, height, -depth, width, 0, -depth); + + // perspective lines that are the sides of the box the ball is in + + line(0, 0, -depth, 0, 0, 0); + line(width, 0, -depth, width, 0, 0); + line(0, height, -depth, 0, height, 0); + line(width, height, -depth, width, height, 0); +} + + + +void drawball() { + //makes ball move follwing the x,y,and z postion of the sphere + translate (xPos, yPos, -zPos); + //draws sphere + sphere(radius); + //adds no fill to make ball look more 3D, just a personal preference + noFill(); +} + + +void makeballmove() { + xPos = xPos + (xSpeed * xDirection); //gives the sphere its x velocity + yPos = yPos + (ySpeed * yDirection); //gives the sphere its y velocity + zPos = zPos + (zSpeed * zDirection); // gives the sphere its z velocity + + if (xPos>width-radius) { //makes ball bounce back if hits the right side of screen + xDirection*=-1; + } + + if (yPos>height-radius) { //makes ball bounce back if it hits bottom of screen + yDirection*=-1; + } + + if (zPos>depth) { //makes ball bounce back if it hits "back" of screen + zDirection*=-1; + } + + if (xPos Date: Tue, 8 Dec 2015 14:51:39 -0500 Subject: [PATCH 2/5] physics function --- physics_function/physics_function.pde | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 physics_function/physics_function.pde diff --git a/physics_function/physics_function.pde b/physics_function/physics_function.pde new file mode 100644 index 0000000..4925536 --- /dev/null +++ b/physics_function/physics_function.pde @@ -0,0 +1,20 @@ +void setup() { +} + + + +void draw() { + + + + +} + float findAccelceration(float velocityI,float velocityF,float time) { + float accelceration = (velocityF-velocityF)/time; + return accelceration; + +} + + + +x=v*t -1/2at^2 \ No newline at end of file From 4e20603426d081695c858bbf34abe61294ce02e5 Mon Sep 17 00:00:00 2001 From: Eric Carlson Date: Wed, 9 Dec 2015 13:37:14 -0500 Subject: [PATCH 3/5] changed physics --- physics_function/physics_function.pde | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/physics_function/physics_function.pde b/physics_function/physics_function.pde index 4925536..f2deedd 100644 --- a/physics_function/physics_function.pde +++ b/physics_function/physics_function.pde @@ -1,20 +1,16 @@ + + void setup() { + } void draw() { - - - - -} - float findAccelceration(float velocityI,float velocityF,float time) { - float accelceration = (velocityF-velocityF)/time; - return accelceration; - + println(findAccelceration(0, 500, 60)); + } - - - -x=v*t -1/2at^2 \ No newline at end of file +float findAccelceration ( float vi, float vf, float time){ + float accelceration = (vf-vi)/time; + return accelceration; +} \ No newline at end of file From f559b141ab63fa8a770af1a2835c3e6db7fec92f Mon Sep 17 00:00:00 2001 From: Eric Carlson Date: Wed, 9 Dec 2015 13:53:24 -0500 Subject: [PATCH 4/5] Update Documentation1.md --- Documentation1.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Documentation1.md b/Documentation1.md index 28f94fa..d3d0bd5 100644 --- a/Documentation1.md +++ b/Documentation1.md @@ -1,19 +1,24 @@ # Name: +sphere() ## Examples: -Insert examples here. +noStroke(); +lights(); +translate(58, 48, 0); +sphere(28); ## Description: -Insert description here - + A sphere is a hollow ball made from tessellated triangles + ## Syntax: -Demonstrate syntax here + sphere(r) ##Parameters: -Name and describe parameters here +r float: the radius of the sphere + ##Returns: -What type of data does it return? +void ##Other notes: Anything else? From 87a450a75526d0efe43f7a85aaa8ac2048a79523 Mon Sep 17 00:00:00 2001 From: Eric Carlson Date: Mon, 14 Dec 2015 19:23:46 -0500 Subject: [PATCH 5/5] made math function --- math_function/math_function.pde | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 math_function/math_function.pde diff --git a/math_function/math_function.pde b/math_function/math_function.pde new file mode 100644 index 0000000..a530c63 --- /dev/null +++ b/math_function/math_function.pde @@ -0,0 +1,20 @@ +int x1=0; +int x2=300; +int y1=7; +int y2=-200; +void setup() { + size(800,600); +} + + +void draw() { + scale(1,-1); + translate(width/2,-height/2); + println(findSlopeOfLine(x1,y1,x2,y2)); + line(x1,y1,x2,y2); +} + +float findSlopeOfLine(float y2,float y1, float x2,float x1){ + float slope = (y2 - y1)/(x2-x1); + return slope; +} \ No newline at end of file