From 9b4891e419dc123e8be89fd5a013ffe3cd7a89fe Mon Sep 17 00:00:00 2001 From: shiffman Date: Tue, 11 Dec 2012 20:01:56 +0000 Subject: [PATCH] removing old nature of code examples before adding new ones --- java/examples/Books/Nature of Code/README.md | 15 - .../Connection.pde | 63 - .../Exercise_10_5_LayeredNetworkAnimation.pde | 49 - .../Network.pde | 66 - .../Neuron.pde | 62 - .../chp10_nn/LayeredNetworkViz/Connection.pde | 20 - .../LayeredNetworkViz/LayeredNetworkViz.pde | 14 - .../chp10_nn/LayeredNetworkViz/Network.pde | 45 - .../chp10_nn/LayeredNetworkViz/Neuron.pde | 29 - .../LayeredNetworkViz/sketch.properties | 1 - .../NOC_10_01_SimplePerceptron.pde | 89 - .../NOC_10_01_SimplePerceptron/Perceptron.pde | 59 - .../NOC_10_01_SimplePerceptron/Trainer.pde | 23 - .../NOC_10_02_SeekingNeural.pde | 62 - .../NOC_10_02_SeekingNeural/Perceptron.pde | 44 - .../NOC_10_02_SeekingNeural/Vehicle.pde | 102 - .../NOC_10_03_NetworkViz/Connection.pde | 29 - .../NOC_10_03_NetworkViz.pde | 39 - .../chp10_nn/NOC_10_03_NetworkViz/Network.pde | 37 - .../chp10_nn/NOC_10_03_NetworkViz/Neuron.pde | 36 - .../NOC_10_03_NetworkViz/sketch.properties | 1 - .../NOC_10_04_NetworkAnimation/Connection.pde | 63 - .../NOC_10_04_NetworkAnimation.pde | 50 - .../NOC_10_04_NetworkAnimation/Network.pde | 62 - .../NOC_10_04_NetworkAnimation/Neuron.pde | 62 - .../sketch.properties | 1 - .../Nature of Code/chp10_nn/xor/Landscape.pde | 73 - .../chp10_nn/xor/code/src/Connection.java | 47 - .../chp10_nn/xor/code/src/HiddenNeuron.java | 20 - .../chp10_nn/xor/code/src/InputNeuron.java | 23 - .../chp10_nn/xor/code/src/Network.java | 143 - .../chp10_nn/xor/code/src/Neuron.java | 81 - .../chp10_nn/xor/code/src/OutputNeuron.java | 7 - .../chp10_nn/xor/data/GillSans-16.vlw | Bin 28543 -> 0 bytes .../Books/Nature of Code/chp10_nn/xor/xor.pde | 114 - .../NOC_1_10_motion101_acceleration/Mover.pde | 55 - .../NOC_1_10_motion101_acceleration.pde | 27 - .../Mover.pde | 55 - .../NOC_1_11_motion101_acceleration_array.pde | 21 - .../NOC_1_1_bouncingball_novectors.pde | 38 - .../NOC_1_2_bouncingball_vectors.pde | 38 - .../NOC_1_3_vector_subtraction.pde | 26 - .../NOC_1_4_vector_multiplication.pde | 28 - .../NOC_1_5_vector_magnitude.pde | 31 - .../NOC_1_6_vector_normalize.pde | 38 - .../chp1_vectors/NOC_1_7_motion101/Mover.pde | 39 - .../NOC_1_7_motion101/NOC_1_7_motion101.pde | 16 - .../NOC_1_8_motion101_acceleration/Mover.pde | 45 - .../NOC_1_8_motion101_acceleration.pde | 17 - .../NOC_1_9_motion101_acceleration/Mover.pde | 49 - .../NOC_1_9_motion101_acceleration.pde | 15 - .../NOC_02forces_attractrepel/Attractor.pde | 74 - .../NOC_02forces_attractrepel/Mover.pde | 69 - .../NOC_02forces_attractrepel.pde | 52 - .../Attractor.pde | 39 - .../NOC_02forces_many_attraction_3D/Mover.pde | 51 - .../NOC_02forces_many_attraction_3D.pde | 50 - .../sketch.properties | 1 - .../Mover.pde | 70 - .../NOC_02forces_many_mutual_boundaries.pde | 44 - .../sketch.properties | 1 - .../chp2_forces/NOC_2_1_forces/Mover.pde | 53 - .../NOC_2_1_forces/NOC_2_1_forces.pde | 27 - .../chp2_forces/NOC_2_2_forces_many/Mover.pde | 53 - .../NOC_2_2_forces_many.pde | 36 - .../NOC_2_3_forces_many_realgravity/Mover.pde | 53 - .../NOC_2_3_forces_many_realgravity.pde | 34 - .../NOC_2_4_forces_friction/Mover.pde | 53 - .../NOC_2_4_forces_friction.pde | 42 - .../NOC_2_4_forces_nofriction/Mover.pde | 53 - .../NOC_2_4_forces_nofriction.pde | 42 - .../NOC_2_5_fluidresistance/Liquid.pde | 62 - .../NOC_2_5_fluidresistance/Mover.pde | 64 - .../NOC_2_5_fluidresistance.pde | 72 - .../NOC_2_5_fluidresistance/sketch.properties | 1 - .../Liquid.pde | 62 - .../Mover.pde | 64 - .../NOC_2_5_fluidresistance_sequence.pde | 74 - .../sketch.properties | 1 - .../NOC_2_6_attraction/Attractor.pde | 77 - .../chp2_forces/NOC_2_6_attraction/Mover.pde | 51 - .../NOC_2_6_attraction/NOC_2_6_attraction.pde | 36 - .../NOC_2_6_attraction/sketch.properties | 1 - .../NOC_2_7_attraction_many/Attractor.pde | 77 - .../NOC_2_7_attraction_many/Mover.pde | 33 - .../NOC_2_7_attraction_many.pde | 46 - .../NOC_2_8_mutual_attraction/Mover.pde | 48 - .../NOC_2_8_mutual_attraction.pde | 42 - .../sketch.properties | 1 - .../AdditiveWave/AdditiveWave.pde | 70 - .../AttractionArrayWithOscillation.pde | 46 - .../Attractor.pde | 81 - .../Crawler.pde | 56 - .../Oscillator.pde | 35 - .../Exercise_3_01_exercise_baton.pde | 24 - .../Exercise_3_04_spiral.pde | 30 - .../Exercise_3_05_asteroids.pde | 41 - .../Exercise_3_05_asteroids/Spaceship.pde | 97 - .../Exercise_3_10_OOPWave.pde | 31 - .../Exercise_3_10_OOPWave/Wave.pde | 45 - .../Exercise_3_11_AdditiveWave.pde | 69 - .../NOC_03spring_exercise_sine.pde | 21 - .../NOC_3_01_angular_motion.pde | 30 - .../NOC_3_01_angular_motion_trail.pde | 35 - .../Attractor.pde | 36 - .../Mover.pde | 49 - .../NOC_3_02_forces_angular_mot_trails.pde | 44 - .../Attractor.pde | 36 - .../NOC_3_02_forces_angular_motion/Mover.pde | 49 - .../NOC_3_02_forces_angular_motion.pde | 39 - .../NOC_3_03_pointing_velocity/Mover.pde | 65 - .../NOC_3_03_pointing_velocity.pde | 17 - .../Mover.pde | 65 - .../NOC_3_03_pointing_velocity_trail.pde | 25 - .../NOC_3_04_PolarToCartesian.pde | 50 - .../NOC_3_04_PolarToCartesian_trail.pde | 54 - .../NOC_3_05_simple_harmonic_mot_trail.pde | 20 - .../NOC_3_05_simple_harmonic_motion.pde | 18 - .../NOC_3_06_simple_harmonic_motion.pde | 23 - .../NOC_3_07_oscillating_objects.pde | 33 - .../Oscillator.pde | 33 - .../NOC_3_07_oscillating_objects_trail.pde | 36 - .../Oscillator.pde | 33 - .../NOC_3_08_static_wave_lines.pde | 19 - .../NOC_3_09_exercise_additive_wave.pde | 70 - .../NOC_3_09_wave/NOC_3_09_wave.pde | 28 - .../NOC_3_09_wave_a/NOC_3_09_wave_a.pde | 28 - .../NOC_3_09_wave_b/NOC_3_09_wave_b.pde | 28 - .../NOC_3_09_wave_c/NOC_3_09_wave_c.pde | 28 - .../NOC_3_10_PendulumExample.pde | 43 - .../NOC_3_10_PendulumExample/Pendulum.pde | 95 - .../NOC_3_10_PendulumExampleSimplified.pde | 34 - .../Pendulum.pde | 61 - .../NOC_3_11_spring/Mover.pde | 78 - .../NOC_3_11_spring/NOC_3_11_spring.pde | 61 - .../NOC_3_11_spring/Spring.pde | 75 - .../NOC_3_11_spring/sketch.properties | 2 - .../OOPWaveParticles/OOPWaveParticles.pde | 31 - .../OOPWaveParticles/Particle.pde | 20 - .../OOPWaveParticles/Wave.pde | 52 - .../CircleVsBlob/CircleVsBlob.pde | 28 - .../chp4_systems/CircleVsBlob/blob.tif | Bin 120768 -> 0 bytes .../chp4_systems/CircleVsBlob/circle.tif | Bin 120768 -> 0 bytes .../CircleVsBlob/data/texture.gif | Bin 1829 -> 0 bytes .../CircleVsBlob/data/texture.psd | Bin 26456 -> 0 bytes .../NOC_4_01_SingleParticle.pde | 21 - .../NOC_4_01_SingleParticle/Particle.pde | 49 - .../NOC_4_01_SingleParticle_trail.pde | 23 - .../Particle.pde | 49 - .../NOC_4_02_ArrayListParticles.pde | 27 - .../NOC_4_02_ArrayListParticles/Particle.pde | 49 - .../NOC_4_03_ParticleSystemClass.pde | 13 - .../NOC_4_03_ParticleSystemClass/Particle.pde | 49 - .../ParticleSystem.pde | 31 - .../NOC_4_04_SystemofSystems.pde | 30 - .../NOC_4_04_SystemofSystems/Particle.pde | 49 - .../ParticleSystem.pde | 52 - .../NOC_4_04_SystemofSystems_b.pde | 32 - .../NOC_4_04_SystemofSystems_b/Particle.pde | 49 - .../ParticleSystem.pde | 52 - .../NOC_4_04_SystemofSystems_c.pde | 35 - .../NOC_4_04_SystemofSystems_c/Particle.pde | 49 - .../ParticleSystem.pde | 52 - .../Confetti.pde | 25 - ..._ParticleSystemInheritancePolymorphism.pde | 13 - .../Particle.pde | 50 - .../ParticleSystem.pde | 34 - .../NOC_4_06_ParticleSystemForces.pde | 18 - .../Particle.pde | 57 - .../ParticleSystem.pde | 34 - .../NOC_4_07_ParticleSystemForcesRepeller.pde | 23 - .../Particle.pde | 57 - .../ParticleSystem.pde | 43 - .../Repeller.pde | 36 - .../NOC_4_08_ParticleSystemSmoke.pde | 54 - .../NOC_4_08_ParticleSystemSmoke/Particle.pde | 64 - .../ParticleSystem.pde | 62 - .../data/texture.psd | Bin 26456 -> 0 bytes .../sketch.properties | 1 - .../NOC_4_08_ParticleSystemSmoke_b.pde | 54 - .../Particle.pde | 64 - .../ParticleSystem.pde | 62 - .../data/texture.psd | Bin 26456 -> 0 bytes .../sketch.properties | 2 - .../NOC_4_09_AdditiveBlending.pde | 34 - .../NOC_4_09_AdditiveBlending/Particle.pde | 51 - .../ParticleSystem.pde | 53 - .../data/texture.psd | Bin 26028 -> 0 bytes ..._04_6ParticleSystemInheritance_pushpop.pde | 13 - .../Particle.pde | 61 - .../ParticleChild.pde | 20 - .../ParticleSystem.pde | 34 - .../flight404_particles_1_simple/NOC_gl.pde | 11 - .../flight404_particles_1_simple/emitter.pde | 89 - .../flight404_particles_1_simple.pde | 160 - .../flight404_particles_1_simple/particle.pde | 208 - .../NOC_gl.pde | 49 - .../cursor.pde | 25 - .../emitter.pde | 182 - .../flight404_particles_2_GLtexture.pde | 210 - .../images.pde | 13 - .../nebula.pde | 56 - .../particle.pde | 171 - .../flight404_particles_2_GLtexture/pov.pde | 62 - .../sketch.properties | 1 - .../flight404_particles_2_simple/NOC_gl.pde | 31 - .../flight404_particles_2_simple/cursor.pde | 25 - .../flight404_particles_2_simple/emitter.pde | 149 - .../flight404_particles_2_simple.pde | 184 - .../flight404_particles_2_simple/images.pde | 13 - .../flight404_particles_2_simple/nebula.pde | 56 - .../flight404_particles_2_simple/particle.pde | 172 - .../flight404_particles_2_simple/pov.pde | 64 - .../chp4_systems/simpleInheritance/Circle.pde | 36 - .../chp4_systems/simpleInheritance/Shape.pde | 28 - .../chp4_systems/simpleInheritance/Square.pde | 25 - .../simpleInheritance/simpleInheritance.pde | 27 - .../simplePolymorphism/Circle.pde | 36 - .../chp4_systems/simplePolymorphism/Shape.pde | 28 - .../simplePolymorphism/Square.pde | 25 - .../simplePolymorphism/simplePolymorphism.pde | 32 - .../CollisionsEqualMass.pde | 33 - .../CollisionsEqualMass/Mover.pde | 99 - .../CollisionsEqualMass/drawVector.pde | 21 - .../box2d/BlobSkeleton/Blob.pde | 196 - .../box2d/BlobSkeleton/BlobSkeleton.pde | 112 - .../box2d/BlobSkeleton/Boundary.pde | 54 - .../box2d/BlobSkeleton/Box.pde | 86 - .../box2d/BlobSkeleton/Spring.pde | 76 - .../box2d/Blobby/Blob.pde | 117 - .../box2d/Blobby/Blobby.pde | 66 - .../box2d/Blobby/Boundary.pde | 54 - .../Boundary.pde | 56 - .../CollisionListeningDeletionExercise.pde | 121 - .../Particle.pde | 96 - .../box2d/CollisionsAndControl/Box.pde | 86 - .../CollisionsAndControl.pde | 153 - .../box2d/CollisionsAndControl/Particle.pde | 92 - .../box2d/CollisionsAndControl/Spring.pde | 82 - .../CollisionsAndControlInterface/Box.pde | 86 - .../CollisionsAndControlInterface.pde | 114 - .../ContactListener.pde | 57 - .../Particle.pde | 92 - .../CollisionsAndControlInterface/Spring.pde | 82 - .../Boundary.pde | 54 - .../Box.pde | 97 - .../Exercise_5_10_ApplyForceAttractMouse.pde | 85 - .../Boundary.pde | 54 - .../Box.pde | 88 - .../Exercise_5_10_ApplyForceSimpleWind.pde | 86 - .../Attractor.pde | 70 - .../Exercise_5_10_AttractionApplyForce.pde | 60 - .../Mover.pde | 64 - .../Exercise_5_3_NoiseChain.pde | 72 - .../Exercise_5_3_NoiseChain/Particle.pde | 90 - .../box2d/Exercise_5_3_NoiseChain/Surface.pde | 79 - .../Exercise_5_3_SineChain.pde | 72 - .../box2d/Exercise_5_3_SineChain/Particle.pde | 90 - .../box2d/Exercise_5_3_SineChain/Surface.pde | 70 - .../box2d/Exercise_5_6_Bridge/Box.pde | 89 - .../box2d/Exercise_5_6_Bridge/Bridge.pde | 67 - .../Exercise_5_6_Bridge.pde | 85 - .../box2d/Exercise_5_6_Bridge/Particle.pde | 79 - .../box2d/KinematicTest/Box.pde | 103 - .../box2d/KinematicTest/KinematicTest.pde | 144 - .../box2d/KinematicTest/Particle.pde | 93 - .../box2d/Liquidy/Boundary.pde | 62 - .../box2d/Liquidy/Liquidy.pde | 74 - .../box2d/Liquidy/Particle.pde | 99 - .../box2d/Liquidy/ParticleSystem.pde | 59 - .../box2d/MouseKinematic/Boundary.pde | 62 - .../box2d/MouseKinematic/Box.pde | 106 - .../box2d/MouseKinematic/MouseKinematic.pde | 78 - .../box2d/NOC_5_1_box2d_exercise/Box.pde | 23 - .../NOC_5_1_box2d_exercise.pde | 24 - .../NOC_5_1_box2d_exercise_solved/Box.pde | 55 - .../NOC_5_1_box2d_exercise_solved.pde | 37 - .../box2d/NOC_5_2_Boxes/Boundary.pde | 54 - .../box2d/NOC_5_2_Boxes/Box.pde | 88 - .../box2d/NOC_5_2_Boxes/NOC_5_2_Boxes.pde | 74 - .../NOC_5_3_ChainShape_Simple.pde | 72 - .../NOC_5_3_ChainShape_Simple/Particle.pde | 90 - .../NOC_5_3_ChainShape_Simple/Surface.pde | 53 - .../box2d/NOC_5_4_Polygons/Boundary.pde | 60 - .../box2d/NOC_5_4_Polygons/CustomShape.pde | 91 - .../NOC_5_4_Polygons/NOC_5_4_Polygons.pde | 74 - .../box2d/NOC_5_5_MultiShapes/Boundary.pde | 62 - .../box2d/NOC_5_5_MultiShapes/Lollipop.pde | 89 - .../NOC_5_5_MultiShapes.pde | 74 - .../box2d/NOC_5_6_DistanceJoint/Boundary.pde | 54 - .../NOC_5_6_DistanceJoint.pde | 81 - .../box2d/NOC_5_6_DistanceJoint/Pair.pde | 48 - .../box2d/NOC_5_6_DistanceJoint/Particle.pde | 77 - .../box2d/NOC_5_7_RevoluteJoint/Box.pde | 73 - .../NOC_5_7_RevoluteJoint.pde | 90 - .../box2d/NOC_5_7_RevoluteJoint/Particle.pde | 85 - .../box2d/NOC_5_7_RevoluteJoint/Windmill.pde | 62 - .../box2d/NOC_5_8_MouseJoint/Boundary.pde | 63 - .../box2d/NOC_5_8_MouseJoint/Box.pde | 89 - .../NOC_5_8_MouseJoint/NOC_5_8_MouseJoint.pde | 86 - .../box2d/NOC_5_8_MouseJoint/Spring.pde | 78 - .../NOC_5_9_CollisionListening/Boundary.pde | 56 - .../NOC_5_9_CollisionListening.pde | 111 - .../NOC_5_9_CollisionListening/Particle.pde | 91 - .../box2d/VectorStuff/VectorStuff.pde | 57 - .../chp5_physicslibraries/readme.txt | 3 - .../Blanket.pde | 51 - .../Connection.pde | 11 - .../Exercise_5_13_SoftBodySquareAdapted.pde | 63 - .../Particle.pde | 17 - .../Cluster.pde | 99 - .../Exercise_5_15_ForceDirectedGraph.pde | 134 - .../Exercise_5_15_ForceDirectedGraph/Node.pde | 27 - .../NOC_5_10_SimpleSpring.pde | 70 - .../NOC_5_10_SimpleSpring/Particle.pde | 18 - .../NOC_5_11_SoftStringPendulum/Chain.pde | 104 - .../NOC_5_11_SoftStringPendulum.pde | 70 - .../NOC_5_11_SoftStringPendulum/Particle.pde | 20 - .../NOC_5_12_SimpleCluster/Cluster.pde | 64 - .../NOC_5_12_SimpleCluster.pde | 76 - .../toxiclibs/NOC_5_12_SimpleCluster/Node.pde | 27 - .../NOC_5_13_AttractRepel/Attractor.pde | 17 - .../NOC_5_13_AttractRepel.pde | 41 - .../NOC_5_13_AttractRepel/Particle.pde | 20 - .../chp6_agents/Cohesion/Cohesion.pde | 49 - .../chp6_agents/Cohesion/Vehicle.pde | 99 - .../CrowdPathFollowing/CrowdPathFollowing.pde | 76 - .../chp6_agents/CrowdPathFollowing/Path.pde | 50 - .../CrowdPathFollowing/Vehicle.pde | 239 - .../CrowdPathFollowing/sketch.properties | 1 - .../Exercise_6_04_Wander.pde | 30 - .../Exercise_6_04_Wander/Vehicle.pde | 123 - .../Exercise_6_09_AngleBetween.pde | 54 - .../Exercise_6_13_CrowdPathFollowing.pde | 77 - .../Exercise_6_13_CrowdPathFollowing/Path.pde | 50 - .../Vehicle.pde | 239 - .../NOC_6_01_Seek/NOC_6_01_Seek.pde | 36 - .../chp6_agents/NOC_6_01_Seek/Vehicle.pde | 74 - .../NOC_6_01_Seek_trail.pde | 39 - .../NOC_6_01_Seek_trail/Vehicle.pde | 90 - .../NOC_6_02_Arrive/NOC_6_02_Arrive.pde | 35 - .../chp6_agents/NOC_6_02_Arrive/Vehicle.pde | 80 - .../NOC_6_02_Arrive_trail.pde | 38 - .../NOC_6_02_Arrive_trail/Vehicle.pde | 96 - .../NOC_6_03_StayWithinWalls.pde | 37 - .../NOC_6_03_StayWithinWalls/Vehicle.pde | 92 - .../NOC_6_03_StayWithinWalls_trail.pde | 37 - .../Vehicle.pde | 108 - .../NOC_6_04_Flow_Figures/FlowField.pde | 92 - .../NOC_6_04_Flow_Figures.pde | 34 - .../NOC_6_04_Flow_Figures/Vehicle.pde | 85 - .../NOC_6_04_Flow_Figures/data/arrow.svg | 5149 ----------------- .../NOC_6_04_Flowfield/FlowField.pde | 77 - .../NOC_6_04_Flowfield/NOC_6_04_Flowfield.pde | 55 - .../NOC_6_04_Flowfield/Vehicle.pde | 85 - .../NOC_6_04_Flowfield/sketch.properties | 0 .../NOC_6_05_PathFollowingSimple.pde | 52 - .../NOC_6_05_PathFollowingSimple/Path.pde | 46 - .../NOC_6_05_PathFollowingSimple/Vehicle.pde | 161 - .../sketch.properties | 1 - .../NOC_6_06_PathFollowing.pde | 65 - .../NOC_6_06_PathFollowing/Path.pde | 48 - .../NOC_6_06_PathFollowing/Vehicle.pde | 190 - .../NOC_6_07_Separation.pde | 45 - .../NOC_6_07_Separation/Vehicle.pde | 99 - .../NOC_6_08_SeparationAndSeek.pde | 43 - .../NOC_6_08_SeparationAndSeek/Vehicle.pde | 115 - .../sketch.properties | 1 - .../chp6_agents/NOC_6_09_Flocking/Boid.pde | 182 - .../chp6_agents/NOC_6_09_Flocking/Flock.pde | 25 - .../NOC_6_09_Flocking/NOC_6_09_Flocking.pde | 38 - .../StayWithinCircle/StayWithinCircle.pde | 43 - .../chp6_agents/StayWithinCircle/Vehicle.pde | 95 - .../intersection/intersection/Thing.pde | 32 - .../intersection/intersection.pde | 106 - .../intersection/intersection_slow/Thing.pde | 32 - .../intersection_slow/intersection_slow.pde | 59 - .../chp6_agents/box2d/Flocking_box2d/Boid.pde | 255 - .../box2d/Flocking_box2d/Flock.pde | 25 - .../box2d/Flocking_box2d/Flocking_box2d.pde | 56 - .../chp6_agents/flocking_sliders/Boid.pde | 181 - .../chp6_agents/flocking_sliders/Flock.pde | 25 - .../flocking_sliders/flocking_sliders.pde | 60 - .../flocking_sliders/keyPressed.pde | 3 - .../flocking_sliders/scrollbar.pde | 133 - .../chp7_CA/Ex7_09_HexagonCells/Cell.pde | 38 - .../Ex7_09_HexagonCells.pde | 24 - .../chp7_CA/Ex7_09_HexagonCells/GOL.pde | 40 - .../CA.pde | 95 - ...xercise_7_01_WolframCA_randomizedrules.pde | 42 - .../Exercise_7_04_WolframCA_scrolling/CA.pde | 92 - .../Exercise_7_04_WolframCA_scrolling.pde | 34 - .../CA.pde | 104 - .../Exercise_7_04_WolframCA_scrolling_110.pde | 26 - .../CA.pde | 104 - .../Exercise_7_04_WolframCA_scrolling_190.pde | 27 - .../CA.pde | 104 - .../Exercise_7_04_WolframCA_scrolling_222.pde | 27 - .../CA.pde | 103 - .../Exercise_7_04_WolframCA_scrolling_30.pde | 27 - .../Figure_7_17_cells/Figure_7_17_cells.pde | 28 - .../chp7_CA/Figure_7_17_cells/cells.tif | Bin 486768 -> 0 bytes .../chp7_CA/GameOfLifeWrapAround/GOL.pde | 73 - .../GameOfLifeWrapAround.pde | 31 - .../chp7_CA/HexagonCells/Cell.pde | 38 - .../chp7_CA/HexagonCells/GOL.pde | 40 - .../chp7_CA/HexagonCells/HexagonCells.pde | 24 - .../chp7_CA/NOC_7_01_WolframCA_figures/CA.pde | 92 - .../NOC_7_01_WolframCA_figures.pde | 35 - .../chp7_CA/NOC_7_01_WolframCA_simple/CA.pde | 65 - .../NOC_7_01_WolframCA_simple.pde | 21 - .../chp7_CA/NOC_7_02_GameOfLifeOOP/Cell.pde | 36 - .../chp7_CA/NOC_7_02_GameOfLifeOOP/GOL.pde | 69 - .../NOC_7_02_GameOfLifeOOP.pde | 27 - .../chp7_CA/NOC_7_03_GameOfLifeSimple/GOL.pde | 73 - .../NOC_7_03_GameOfLifeSimple.pde | 29 - .../CantorSetArrayList/CantorSetArrayList.pde | 47 - .../chp8_fractals/CantorSetArrayList/Line.pde | 23 - .../Exercise_8_01_RecursionLines.pde | 35 - .../Exercise_8_02_KochSnowFlake.pde | 54 - .../Exercise_8_02_KochSnowFlake/KochLine.pde | 71 - .../Exercise_8_06_Tree/Exercise_8_06_Tree.pde | 56 - .../Exercise_8_07_Tree/Exercise_8_07_Tree.pde | 51 - .../Figure_8_02_Mandelbrot.pde | 79 - .../Figure_8_14_Koch/Figure_8_14_Koch.pde | 65 - .../Figure_8_14_Koch/KochLine.pde | 71 - .../Figure_8_20_Tree/Figure_8_20_Tree.pde | 53 - .../Figure_8_CantorLine.pde | 20 - .../NOC_8_01_Recursion/NOC_8_01_Recursion.pde | 26 - .../NOC_8_02_Recursion/NOC_8_02_Recursion.pde | 27 - .../NOC_8_03_KochSimple/KochLine.pde | 71 - .../NOC_8_03_KochSimple.pde | 50 - .../NOC_8_03_Recursion/NOC_8_03_Recursion.pde | 28 - .../NOC_8_04_CantorSet/NOC_8_04_CantorSet.pde | 38 - .../NOC_8_04_Tree/NOC_8_04_Tree.pde | 52 - .../NOC_8_05_Koch/KochFractal.pde | 70 - .../chp8_fractals/NOC_8_05_Koch/KochLine.pde | 73 - .../NOC_8_05_Koch/NOC_8_05_Koch.pde | 29 - .../NOC_8_05_Koch/sketch.properties | 2 - .../NOC_8_05_KochSimple/KochLine.pde | 71 - .../NOC_8_05_KochSimple.pde | 50 - .../NOC_8_05_TreeStochastic.pde | 63 - .../NOC_8_06_SimpleLSystem.pde | 47 - .../NOC_8_06_Tree/NOC_8_06_Tree.pde | 53 - .../NOC_8_06_Tree_static.pde | 45 - .../NOC_8_07_TreeStochastic.pde | 66 - .../NOC_8_07_TreeStochastic_angleonly.pde | 59 - .../NOC_8_08_SimpleLSystem.pde | 47 - .../NOC_8_09_LSystem/LSystem.pde | 67 - .../NOC_8_09_LSystem/NOC_8_09_LSystem.pde | 63 - .../chp8_fractals/NOC_8_09_LSystem/Rule.pde | 26 - .../chp8_fractals/NOC_8_09_LSystem/Turtle.pde | 53 - .../NOC_8_09_LSystem/sketch.properties | 2 - .../chp8_fractals/Tree2/Branch.pde | 59 - .../chp8_fractals/Tree2/Tree2.pde | 47 - .../chp8_fractals/Tree3/Branch.pde | 66 - .../chp8_fractals/Tree3/Leaf.pde | 21 - .../chp8_fractals/Tree3/Tree3.pde | 58 - .../TreeStochasticNoise.pde | 71 - .../TreeStochasticNoise/sketch.properties | 1 - .../chp8_fractals/lsys/LSystem.pde | 67 - .../chp8_fractals/lsys/Rule.pde | 26 - .../chp8_fractals/lsys/Turtle.pde | 53 - .../chp8_fractals/lsys/lsys.pde | 56 - .../chp9_ga/EvolveFlowField/DNA.pde | 51 - .../EvolveFlowField/EvolveFlowField.pde | 100 - .../chp9_ga/EvolveFlowField/Obstacle.pde | 34 - .../chp9_ga/EvolveFlowField/Population.pde | 115 - .../chp9_ga/EvolveFlowField/Rocket.pde | 149 - .../GA_Shakespeare_fancyfitness/DNA.pde | 67 - .../GA_Shakespeare_fancyfitness.pde | 86 - .../Population.pde | 127 - .../chp9_ga/NOC_9_01_GA_Shakespeare/DNA.pde | 67 - .../NOC_9_01_GA_Shakespeare.pde | 87 - .../NOC_9_01_GA_Shakespeare/Population.pde | 127 - .../NOC_9_01_GA_Shakespeare/sketch.properties | 2 - .../DNA.pde | 67 - .../NOC_9_01_GA_Shakespeare_simplified.pde | 86 - .../sketch.properties | 2 - .../NOC_9_02_SmartRockets_superbasic/DNA.pde | 57 - .../NOC_9_02_SmartRockets_superbasic.pde | 73 - .../Population.pde | 100 - .../Rocket.pde | 105 - .../chp9_ga/NOC_9_03_SmartRockets/DNA.pde | 65 - .../NOC_9_03_SmartRockets.pde | 93 - .../NOC_9_03_SmartRockets/Obstacle.pde | 37 - .../NOC_9_03_SmartRockets/Population.pde | 110 - .../chp9_ga/NOC_9_03_SmartRockets/Rocket.pde | 147 - .../NOC_9_03_SmartRockets/sketch.properties | 1 - .../Button.pde | 53 - .../DNA.pde | 46 - .../Face.pde | 101 - .../NOC_9_04_Faces_interactiveselection.pde | 46 - .../Population.pde | 99 - .../Rectangle.pde | 21 - .../NOC_9_05_EvolutionEcosystem/Bloop.pde | 105 - .../NOC_9_05_EvolutionEcosystem/DNA.pde | 44 - .../NOC_9_05_EvolutionEcosystem/Food.pde | 41 - .../NOC_9_05_EvolutionEcosystem.pde | 33 - .../NOC_9_05_EvolutionEcosystem/World.pde | 56 - .../sketch.properties | 1 - .../chp9_ga/bruteforce/bruteforce.pde | 16 - .../Exc_I_10_NoiseLandscape.pde | 32 - .../Exc_I_10_NoiseLandscape/Landscape.pde | 65 - .../Exc_I_9_Noise3D/Exc_I_9_Noise3D.pde | 47 - .../Figure_I_2_BellCurve.pde | 38 - .../Figure_I_5_Noise1DGraph.pde | 27 - .../Figure_I_6_RandomGraph.pde | 22 - .../introduction/Gaussian2/Gaussian2.pde | 49 - .../MonteCarloDistribution/MonteCarlo.pde | 66 - .../MultipleProbability.pde | 39 - .../NOC_I_1_RandomWalkTraditional.pde | 20 - .../NOC_I_1_RandomWalkTraditional/Walker.pde | 38 - .../NOC_I_2_RandomDistribution.pde | 26 - .../NOC_I_3_RandomWalkTendsToRight.pde | 20 - .../NOC_I_3_RandomWalkTendsToRight/Walker.pde | 39 - .../NOC_I_4_Gaussian/NOC_I_4_Gaussian.pde | 32 - .../NOC_I_5_NoiseWalk/NOC_I_5_NoiseWalk.pde | 23 - .../introduction/NOC_I_5_NoiseWalk/Walker.pde | 33 - .../introduction/Noise1D/Noise1D.pde | 31 - .../introduction/Noise2D/Noise2D.pde | 41 - .../NoiseDistribution/NoiseDistribution.pde | 33 - .../NoiseWalkAcceleration.pde | 24 - .../NoiseWalkAcceleration/Walker.pde | 65 - .../NoiseWalkVelocity/NoiseWalkVelocity.pde | 25 - .../introduction/NoiseWalkVelocity/Walker.pde | 60 - .../introduction/RandomWalk/RandomWalk.pde | 24 - .../introduction/RandomWalk/Walker.pde | 34 - .../RandomWalkLevy/RandomWalkLevy.pde | 20 - .../introduction/RandomWalkLevy/Walker.pde | 54 - .../RandomWalkNoise/RandomWalkNoise.pde | 20 - .../introduction/RandomWalkNoise/Walker.pde | 39 - .../RandomWalkPVector/RandomWalkPVector.pde | 24 - .../introduction/RandomWalkPVector/Walker.pde | 30 - .../RandomWalkTraditional2.pde | 20 - .../RandomWalkTraditional2/Walker.pde | 29 - .../RandomWalkTraditional3.pde | 20 - .../RandomWalkTraditional3/Walker.pde | 30 - .../RandomWalkTrail/RandomWalkTrail.pde | 24 - .../introduction/RandomWalkTrail/Walker.pde | 49 - .../SimpleProbablility/SimpleProbablility.pde | 34 - 541 files changed, 35009 deletions(-) delete mode 100644 java/examples/Books/Nature of Code/README.md delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Connection.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Exercise_10_5_LayeredNetworkAnimation.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Network.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Neuron.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Connection.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/LayeredNetworkViz.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Network.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Neuron.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/NOC_10_01_SimplePerceptron.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/Perceptron.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/Trainer.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/NOC_10_02_SeekingNeural.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Perceptron.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Connection.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/NOC_10_03_NetworkViz.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Network.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Neuron.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Connection.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/NOC_10_04_NetworkAnimation.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Network.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Neuron.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/sketch.properties delete mode 100755 java/examples/Books/Nature of Code/chp10_nn/xor/Landscape.pde delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Connection.java delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/xor/code/src/HiddenNeuron.java delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/xor/code/src/InputNeuron.java delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Network.java delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Neuron.java delete mode 100644 java/examples/Books/Nature of Code/chp10_nn/xor/code/src/OutputNeuron.java delete mode 100755 java/examples/Books/Nature of Code/chp10_nn/xor/data/GillSans-16.vlw delete mode 100755 java/examples/Books/Nature of Code/chp10_nn/xor/xor.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_10_motion101_acceleration/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_10_motion101_acceleration/NOC_1_10_motion101_acceleration.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_11_motion101_acceleration_array/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_11_motion101_acceleration_array/NOC_1_11_motion101_acceleration_array.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_1_bouncingball_novectors/NOC_1_1_bouncingball_novectors.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_2_bouncingball_vectors/NOC_1_2_bouncingball_vectors.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_3_vector_subtraction/NOC_1_3_vector_subtraction.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_4_vector_multiplication/NOC_1_4_vector_multiplication.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_5_vector_magnitude/NOC_1_5_vector_magnitude.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_6_vector_normalize/NOC_1_6_vector_normalize.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_7_motion101/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_7_motion101/NOC_1_7_motion101.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_8_motion101_acceleration/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_8_motion101_acceleration/NOC_1_8_motion101_acceleration.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_9_motion101_acceleration/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp1_vectors/NOC_1_9_motion101_acceleration/NOC_1_9_motion101_acceleration.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_attractrepel/Attractor.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_attractrepel/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_attractrepel/NOC_02forces_attractrepel.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/Attractor.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/NOC_02forces_many_attraction_3D.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/NOC_02forces_many_mutual_boundaries.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_1_forces/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_1_forces/NOC_2_1_forces.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_2_forces_many/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_2_forces_many/NOC_2_2_forces_many.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_3_forces_many_realgravity/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_3_forces_many_realgravity/NOC_2_3_forces_many_realgravity.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_friction/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_friction/NOC_2_4_forces_friction.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_nofriction/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_nofriction/NOC_2_4_forces_nofriction.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/Liquid.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/NOC_2_5_fluidresistance.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/Liquid.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/NOC_2_5_fluidresistance_sequence.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/Attractor.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/NOC_2_6_attraction.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/Attractor.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/NOC_2_7_attraction_many.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/NOC_2_8_mutual_attraction.pde delete mode 100644 java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/AdditiveWave/AdditiveWave.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/AttractionArrayWithOscillation.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Attractor.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Crawler.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Oscillator.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_01_exercise_baton/Exercise_3_01_exercise_baton.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_04_spiral/Exercise_3_04_spiral.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_05_asteroids/Exercise_3_05_asteroids.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_05_asteroids/Spaceship.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_10_OOPWave/Exercise_3_10_OOPWave.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_10_OOPWave/Wave.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_11_AdditiveWave/Exercise_3_11_AdditiveWave.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_03spring_exercise_sine/NOC_03spring_exercise_sine.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_01_angular_motion/NOC_3_01_angular_motion.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_01_angular_motion_trail/NOC_3_01_angular_motion_trail.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_mot_trails/Attractor.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_mot_trails/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_mot_trails/NOC_3_02_forces_angular_mot_trails.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/Attractor.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/NOC_3_02_forces_angular_motion.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/NOC_3_03_pointing_velocity.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity_trail/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity_trail/NOC_3_03_pointing_velocity_trail.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_04_PolarToCartesian/NOC_3_04_PolarToCartesian.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_04_PolarToCartesian_trail/NOC_3_04_PolarToCartesian_trail.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_05_simple_harmonic_mot_trail/NOC_3_05_simple_harmonic_mot_trail.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_05_simple_harmonic_motion/NOC_3_05_simple_harmonic_motion.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_06_simple_harmonic_motion/NOC_3_06_simple_harmonic_motion.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects/NOC_3_07_oscillating_objects.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects/Oscillator.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects_trail/NOC_3_07_oscillating_objects_trail.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects_trail/Oscillator.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_08_static_wave_lines/NOC_3_08_static_wave_lines.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_exercise_additive_wave/NOC_3_09_exercise_additive_wave.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave/NOC_3_09_wave.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_a/NOC_3_09_wave_a.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_b/NOC_3_09_wave_b.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_c/NOC_3_09_wave_c.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExample/NOC_3_10_PendulumExample.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExample/Pendulum.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExampleSimplified/NOC_3_10_PendulumExampleSimplified.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExampleSimplified/Pendulum.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/NOC_3_11_spring.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/Spring.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/OOPWaveParticles.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/Wave.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/CircleVsBlob.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/blob.tif delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/circle.tif delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/data/texture.gif delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/data/texture.psd delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle/NOC_4_01_SingleParticle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle_trail/NOC_4_01_SingleParticle_trail.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle_trail/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_02_ArrayListParticles/NOC_4_02_ArrayListParticles.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_02_ArrayListParticles/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/NOC_4_03_ParticleSystemClass.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/ParticleSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/NOC_4_04_SystemofSystems.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/ParticleSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_b/NOC_4_04_SystemofSystems_b.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_b/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_b/ParticleSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_c/NOC_4_04_SystemofSystems_c.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_c/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_c/ParticleSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/Confetti.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/NOC_4_05_ParticleSystemInheritancePolymorphism.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/ParticleSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/NOC_4_06_ParticleSystemForces.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/ParticleSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/NOC_4_07_ParticleSystemForcesRepeller.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/ParticleSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/Repeller.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/NOC_4_08_ParticleSystemSmoke.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/ParticleSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/data/texture.psd delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/NOC_4_08_ParticleSystemSmoke_b.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/ParticleSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/data/texture.psd delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/NOC_4_09_AdditiveBlending.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/ParticleSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/data/texture.psd delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/NOC_04_6ParticleSystemInheritance_pushpop.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleChild.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/NOC_gl.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/emitter.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/flight404_particles_1_simple.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/NOC_gl.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/cursor.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/emitter.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/flight404_particles_2_GLtexture.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/images.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/nebula.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/pov.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/NOC_gl.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/cursor.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/emitter.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/flight404_particles_2_simple.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/images.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/nebula.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/pov.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Circle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Shape.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Square.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/simpleInheritance.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Circle.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Shape.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Square.pde delete mode 100644 java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/simplePolymorphism.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/CollisionsEqualMass.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/drawVector.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Blob.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/BlobSkeleton.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Boundary.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Box.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Spring.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Blob.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Blobby.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Boundary.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/Boundary.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/CollisionListeningDeletionExercise.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Box.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/CollisionsAndControl.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Spring.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Box.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/CollisionsAndControlInterface.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/ContactListener.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Spring.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Boundary.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Box.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Exercise_5_10_ApplyForceAttractMouse.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Boundary.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Box.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Exercise_5_10_ApplyForceSimpleWind.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Attractor.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Exercise_5_10_AttractionApplyForce.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Mover.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Exercise_5_3_NoiseChain.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Surface.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Exercise_5_3_SineChain.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Surface.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Box.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Bridge.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Exercise_5_6_Bridge.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/Box.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/KinematicTest.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Boundary.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Liquidy.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/ParticleSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/Boundary.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/Box.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/MouseKinematic.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise/Box.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise/NOC_5_1_box2d_exercise.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise_solved/Box.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise_solved/NOC_5_1_box2d_exercise_solved.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/Boundary.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/Box.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/NOC_5_2_Boxes.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/NOC_5_3_ChainShape_Simple.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/Surface.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/Boundary.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/CustomShape.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/NOC_5_4_Polygons.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/Boundary.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/Lollipop.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/NOC_5_5_MultiShapes.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Boundary.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/NOC_5_6_DistanceJoint.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Pair.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Box.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/NOC_5_7_RevoluteJoint.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Windmill.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Boundary.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Box.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/NOC_5_8_MouseJoint.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Spring.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/Boundary.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/NOC_5_9_CollisionListening.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/VectorStuff/VectorStuff.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/readme.txt delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Blanket.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Connection.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Exercise_5_13_SoftBodySquareAdapted.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Cluster.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Exercise_5_15_ForceDirectedGraph.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Node.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_10_SimpleSpring/NOC_5_10_SimpleSpring.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_10_SimpleSpring/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/Chain.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/NOC_5_11_SoftStringPendulum.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/Cluster.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/NOC_5_12_SimpleCluster.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/Node.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/Attractor.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/NOC_5_13_AttractRepel.pde delete mode 100644 java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/Particle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/Cohesion/Cohesion.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/Cohesion/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/CrowdPathFollowing.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/Path.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Exercise_6_04_Wander.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/Exercise_6_09_AngleBetween/Exercise_6_09_AngleBetween.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Exercise_6_13_CrowdPathFollowing.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Path.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/NOC_6_01_Seek.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/NOC_6_01_Seek_trail.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/NOC_6_02_Arrive.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive_trail/NOC_6_02_Arrive_trail.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive_trail/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/NOC_6_03_StayWithinWalls.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/NOC_6_03_StayWithinWalls_trail.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/FlowField.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/NOC_6_04_Flow_Figures.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/data/arrow.svg delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/FlowField.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/NOC_6_04_Flowfield.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/NOC_6_05_PathFollowingSimple.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Path.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/NOC_6_06_PathFollowing.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Path.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_07_Separation/NOC_6_07_Separation.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_07_Separation/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/NOC_6_08_SeparationAndSeek.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Boid.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Flock.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/NOC_6_09_Flocking.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/StayWithinCircle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/Vehicle.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection/Thing.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection/intersection.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection_slow/Thing.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection_slow/intersection_slow.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Boid.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Flock.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Flocking_box2d.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Boid.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Flock.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/flocking_sliders.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/keyPressed.pde delete mode 100644 java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/scrollbar.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Ex7_09_HexagonCells/Cell.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Ex7_09_HexagonCells/Ex7_09_HexagonCells.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Ex7_09_HexagonCells/GOL.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Exercise_7_01_WolframCA_randomizedrules/CA.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Exercise_7_01_WolframCA_randomizedrules/Exercise_7_01_WolframCA_randomizedrules.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling/CA.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling/Exercise_7_04_WolframCA_scrolling.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_110/CA.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_110/Exercise_7_04_WolframCA_scrolling_110.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_190/CA.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_190/Exercise_7_04_WolframCA_scrolling_190.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_222/CA.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_222/Exercise_7_04_WolframCA_scrolling_222.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_30/CA.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_30/Exercise_7_04_WolframCA_scrolling_30.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Figure_7_17_cells/Figure_7_17_cells.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/Figure_7_17_cells/cells.tif delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/GameOfLifeWrapAround/GOL.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/GameOfLifeWrapAround/GameOfLifeWrapAround.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/HexagonCells/Cell.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/HexagonCells/GOL.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/HexagonCells/HexagonCells.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_figures/CA.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_figures/NOC_7_01_WolframCA_figures.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_simple/CA.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_simple/NOC_7_01_WolframCA_simple.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeOOP/Cell.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeOOP/GOL.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeOOP/NOC_7_02_GameOfLifeOOP.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeSimple/GOL.pde delete mode 100644 java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeSimple/NOC_7_03_GameOfLifeSimple.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/CantorSetArrayList/CantorSetArrayList.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/CantorSetArrayList/Line.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_01_RecursionLines/Exercise_8_01_RecursionLines.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_02_KochSnowFlake/Exercise_8_02_KochSnowFlake.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_02_KochSnowFlake/KochLine.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_06_Tree/Exercise_8_06_Tree.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_07_Tree/Exercise_8_07_Tree.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/Figure_8_02_Mandelbrot/Figure_8_02_Mandelbrot.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/Figure_8_14_Koch/Figure_8_14_Koch.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/Figure_8_14_Koch/KochLine.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/Figure_8_20_Tree/Figure_8_20_Tree.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/Figure_8_CantorLine/Figure_8_CantorLine.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_01_Recursion/NOC_8_01_Recursion.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_02_Recursion/NOC_8_02_Recursion.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_03_KochSimple/KochLine.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_03_KochSimple/NOC_8_03_KochSimple.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_03_Recursion/NOC_8_03_Recursion.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_04_CantorSet/NOC_8_04_CantorSet.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_04_Tree/NOC_8_04_Tree.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/KochFractal.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/KochLine.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/NOC_8_05_Koch.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_KochSimple/KochLine.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_KochSimple/NOC_8_05_KochSimple.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_TreeStochastic/NOC_8_05_TreeStochastic.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_SimpleLSystem/NOC_8_06_SimpleLSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_Tree/NOC_8_06_Tree.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_Tree_static/NOC_8_06_Tree_static.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_07_TreeStochastic/NOC_8_07_TreeStochastic.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_07_TreeStochastic_angleonly/NOC_8_07_TreeStochastic_angleonly.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_08_SimpleLSystem/NOC_8_08_SimpleLSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/LSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/NOC_8_09_LSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/Rule.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/Turtle.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/Tree2/Branch.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/Tree2/Tree2.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/Tree3/Branch.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/Tree3/Leaf.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/Tree3/Tree3.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/TreeStochasticNoise/TreeStochasticNoise.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/TreeStochasticNoise/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/lsys/LSystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/lsys/Rule.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/lsys/Turtle.pde delete mode 100644 java/examples/Books/Nature of Code/chp8_fractals/lsys/lsys.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/DNA.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/EvolveFlowField.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Obstacle.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Population.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Rocket.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/DNA.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/GA_Shakespeare_fancyfitness.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/Population.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/DNA.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/NOC_9_01_GA_Shakespeare.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/Population.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare_simplified/DNA.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare_simplified/NOC_9_01_GA_Shakespeare_simplified.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare_simplified/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/DNA.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/NOC_9_02_SmartRockets_superbasic.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/Population.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/Rocket.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/DNA.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/NOC_9_03_SmartRockets.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Obstacle.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Population.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Rocket.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Button.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/DNA.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Face.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/NOC_9_04_Faces_interactiveselection.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Population.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Rectangle.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/Bloop.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/DNA.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/Food.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/NOC_9_05_EvolutionEcosystem.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/World.pde delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/sketch.properties delete mode 100644 java/examples/Books/Nature of Code/chp9_ga/bruteforce/bruteforce.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/Exc_I_10_NoiseLandscape/Exc_I_10_NoiseLandscape.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/Exc_I_10_NoiseLandscape/Landscape.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/Exc_I_9_Noise3D/Exc_I_9_Noise3D.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/Figure_I_2_BellCurve/Figure_I_2_BellCurve.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/Figure_I_5_Noise1DGraph/Figure_I_5_Noise1DGraph.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/Figure_I_6_RandomGraph/Figure_I_6_RandomGraph.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/Gaussian2/Gaussian2.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/MonteCarloDistribution/MonteCarlo.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/MultipleProbability/MultipleProbability.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/NOC_I_1_RandomWalkTraditional/NOC_I_1_RandomWalkTraditional.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/NOC_I_1_RandomWalkTraditional/Walker.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/NOC_I_2_RandomDistribution/NOC_I_2_RandomDistribution.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/NOC_I_3_RandomWalkTendsToRight/NOC_I_3_RandomWalkTendsToRight.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/NOC_I_3_RandomWalkTendsToRight/Walker.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/NOC_I_4_Gaussian/NOC_I_4_Gaussian.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/NOC_I_5_NoiseWalk/NOC_I_5_NoiseWalk.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/NOC_I_5_NoiseWalk/Walker.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/Noise1D/Noise1D.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/Noise2D/Noise2D.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/NoiseDistribution/NoiseDistribution.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/NoiseWalkAcceleration/NoiseWalkAcceleration.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/NoiseWalkAcceleration/Walker.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/NoiseWalkVelocity/NoiseWalkVelocity.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/NoiseWalkVelocity/Walker.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/RandomWalk/RandomWalk.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/RandomWalk/Walker.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/RandomWalkLevy/RandomWalkLevy.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/RandomWalkLevy/Walker.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/RandomWalkNoise/RandomWalkNoise.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/RandomWalkNoise/Walker.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/RandomWalkPVector/RandomWalkPVector.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/RandomWalkPVector/Walker.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/RandomWalkTraditional2/RandomWalkTraditional2.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/RandomWalkTraditional2/Walker.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/RandomWalkTraditional3/RandomWalkTraditional3.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/RandomWalkTraditional3/Walker.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/RandomWalkTrail/RandomWalkTrail.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/RandomWalkTrail/Walker.pde delete mode 100644 java/examples/Books/Nature of Code/introduction/SimpleProbablility/SimpleProbablility.pde diff --git a/java/examples/Books/Nature of Code/README.md b/java/examples/Books/Nature of Code/README.md deleted file mode 100644 index d008e776b..000000000 --- a/java/examples/Books/Nature of Code/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# The Nature of Code - -![Screenshot](http://www.shiffman.net/images/noc/1.jpg) ![Screenshot](http://www.shiffman.net/images/noc/2.jpg) ![Screenshot](http://www.shiffman.net/images/noc/3.jpg) ![Screenshot](http://www.shiffman.net/images/noc/4.jpg) ![Screenshot](http://www.shiffman.net/images/noc/5.jpg) ![Screenshot](http://www.shiffman.net/images/noc/6.jpg) ![Screenshot](http://www.shiffman.net/images/noc/7.jpg) ![Screenshot](http://www.shiffman.net/images/noc/8.jpg) - -# What is this? - -This repository contains all of the examples for my ITP course and upcoming book "The Nature of Code." It is currently in progress and as I write the book, I will continue to add and update the examples here. - -Relevant links: - -[Site](http://www.natureofcode.com) - -[Online tutorials](http://www.shiffman.net/teaching/nature/) - -[2011 Syllabus](http://itp.nyu.edu/varwiki/Syllabus/Nature-of-Code-S11) diff --git a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Connection.pde b/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Connection.pde deleted file mode 100644 index 8d6ec8907..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Connection.pde +++ /dev/null @@ -1,63 +0,0 @@ -// An animated drawing of a Neural Network -// Daniel Shiffman -// Nature of Code - -class Connection { - // Connection is from Neuron A to B - Neuron a; - Neuron b; - - // Connection has a weight - float weight; - - // Variables to track the animation - boolean sending = false; - PVector sender; - - // Need to store the output for when its time to pass along - float output = 0; - - Connection(Neuron from, Neuron to, float w) { - weight = w; - a = from; - b = to; - } - - - // The Connection is active - void feedforward(float val) { - output = val*weight; // Compute output - sender = a.location.get(); // Start animation at Neuron A - sending = true; // Turn on sending - } - - // Update traveling sender - void update() { - if (sending) { - // Use a simple interpolation - sender.x = lerp(sender.x, b.location.x, 0.1); - sender.y = lerp(sender.y, b.location.y, 0.1); - float d = PVector.dist(sender, b.location); - // If we've reached the end - if (d < 1) { - // Pass along the output! - b.feedforward(output); - sending = false; - } - } - } - - // Draw line and traveling circle - void display() { - stroke(0); - strokeWeight(1+weight*4); - line(a.location.x, a.location.y, b.location.x, b.location.y); - - if (sending) { - fill(0); - strokeWeight(1); - ellipse(sender.x, sender.y, 16, 16); - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Exercise_10_5_LayeredNetworkAnimation.pde b/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Exercise_10_5_LayeredNetworkAnimation.pde deleted file mode 100644 index 951bf44c0..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Exercise_10_5_LayeredNetworkAnimation.pde +++ /dev/null @@ -1,49 +0,0 @@ -// An animated drawing of a Neural Network -// Daniel Shiffman -// Nature of Code - -Network network; - -void setup() { - size(750,200); - smooth(); - - // Create the Network object - network = new Network(width/2, height/2); - - int layers = 3; - int inputs = 2; - - Neuron output = new Neuron(250, 0); - for (int i = 0; i < layers; i++) { - for (int j = 0; j < inputs; j++) { - float x = map(i, 0, layers, -300, 300); - float y = map(j, 0, inputs-1, -75, 75); - Neuron n = new Neuron(x, y); - if (i > 0) { - for (int k = 0; k < inputs; k++) { - Neuron prev = network.neurons.get(network.neurons.size()-inputs+k-j); - network.connect(prev, n, random(1)); - } - } - if (i == layers-1) { - network.connect(n, output, random(1)); - } - network.addNeuron(n); - } - } - network.addNeuron(output); -} - -void draw() { - background(255); - // Update and display the Network - network.update(); - network.display(); - - // Every 30 frames feed in an input - if (frameCount % 30 == 0) { - network.feedforward(random(1),random(1)); - } -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Network.pde b/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Network.pde deleted file mode 100644 index 045808741..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Network.pde +++ /dev/null @@ -1,66 +0,0 @@ -// An animated drawing of a Neural Network -// Daniel Shiffman -// Nature of Code - -class Network { - - // The Network has a list of neurons - ArrayList neurons; - - // The Network now keeps a duplicate list of all Connection objects. - // This makes it easier to draw everything in this class - ArrayList connections; - PVector location; - - Network(float x, float y) { - location = new PVector(x, y); - neurons = new ArrayList(); - connections = new ArrayList(); - } - - // We can add a Neuron - void addNeuron(Neuron n) { - neurons.add(n); - } - - // We can connection two Neurons - void connect(Neuron a, Neuron b, float weight) { - Connection c = new Connection(a, b, weight); - a.addConnection(c); - // Also add the Connection here - connections.add(c); - } - - // Sending an input to the first Neuron - // We should do something better to track multiple inputs - void feedforward(float input1, float input2) { - Neuron n1 = neurons.get(0); - n1.feedforward(input1); - - Neuron n2 = neurons.get(1); - n2.feedforward(input2); - - } - - // Update the animation - void update() { - for (Connection c : connections) { - c.update(); - } - } - - // Draw everything - void display() { - pushMatrix(); - translate(location.x, location.y); - for (Neuron n : neurons) { - n.display(); - } - - for (Connection c : connections) { - c.display(); - } - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Neuron.pde b/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Neuron.pde deleted file mode 100644 index 372ba3fa7..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Neuron.pde +++ /dev/null @@ -1,62 +0,0 @@ -// An animated drawing of a Neural Network -// Daniel Shiffman -// Nature of Code - -class Neuron { - // Neuron has a location - PVector location; - - // Neuron has a list of connections - ArrayList connections; - - // We now track the inputs and sum them - float sum = 0; - - // The Neuron's size can be animated - float r = 32; - - Neuron(float x, float y) { - location = new PVector(x, y); - connections = new ArrayList(); - } - - // Add a Connection - void addConnection(Connection c) { - connections.add(c); - } - - // Receive an input - void feedforward(float input) { - // Accumulate it - sum += input; - // Activate it? - if (sum > 1) { - fire(); - sum = 0; // Reset the sum to 0 if it fires - } - } - - // The Neuron fires - void fire() { - r = 64; // It suddenly is bigger - - // We send the output through all connections - for (Connection c : connections) { - c.feedforward(sum); - } - } - - // Draw it as a circle - void display() { - stroke(0); - strokeWeight(1); - // Brightness is mapped to sum - float b = map(sum,0,1,255,0); - fill(b); - ellipse(location.x, location.y, r, r); - - // Size shrinks down back to original dimensions - r = lerp(r,32,0.1); - } -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Connection.pde b/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Connection.pde deleted file mode 100644 index e0a563df8..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Connection.pde +++ /dev/null @@ -1,20 +0,0 @@ -class Connection { - float weight; - Neuron a; - Neuron b; - - Connection(Neuron from, Neuron to,float w) { - weight = w; - a = from; - b = to; - } - - void display() { - stroke(0); - strokeWeight(weight*4); - line(a.location.x, a.location.y, b.location.x, b.location.y); - } -} - - - diff --git a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/LayeredNetworkViz.pde b/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/LayeredNetworkViz.pde deleted file mode 100644 index 0e5597662..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/LayeredNetworkViz.pde +++ /dev/null @@ -1,14 +0,0 @@ - -Network network; - -void setup() { - size(640, 360); - smooth(); - network = new Network(4,3,1); -} - -void draw() { - background(255); - network.display(); -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Network.pde b/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Network.pde deleted file mode 100644 index 2a5515ea2..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Network.pde +++ /dev/null @@ -1,45 +0,0 @@ - - -class Network { - ArrayList neurons; - PVector location; - Network(int layers, int inputs, int outputs) { - location = new PVector(width/2, height/2); - - neurons = new ArrayList(); - - Neuron output = new Neuron(250, 0); - for (int i = 0; i < layers; i++) { - for (int j = 0; j < inputs; j++) { - float x = map(i, 0, layers, -200, 200); - float y = map(j, 0, inputs-1, -100, 100); - println(j + " " + y); - Neuron n = new Neuron(x, y); - - if (i > 0) { - for (int k = 0; k < inputs; k++) { - Neuron prev = neurons.get(neurons.size()-inputs+k-j); - prev.connect(n); - } - } - - if (i == layers-1) { - n.connect(output); - } - neurons.add(n); - } - } - neurons.add(output); - } - - - void display() { - pushMatrix(); - translate(location.x, location.y); - for (Neuron n : neurons) { - n.display(); - } - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Neuron.pde b/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Neuron.pde deleted file mode 100644 index b99256c82..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Neuron.pde +++ /dev/null @@ -1,29 +0,0 @@ - - -class Neuron { - PVector location; - - ArrayList connections; - - Neuron(float x, float y) { - location = new PVector(x, y); - connections = new ArrayList(); - } - - void connect(Neuron n) { - Connection c = new Connection(this, n, random(1)); - connections.add(c); - } - - void display() { - stroke(0); - strokeWeight(1); - fill(0); - ellipse(location.x, location.y, 16, 16); - - for (Connection c : connections) { - c.display(); - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/sketch.properties b/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/sketch.properties deleted file mode 100644 index 28faa5897..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=Standard diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/NOC_10_01_SimplePerceptron.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/NOC_10_01_SimplePerceptron.pde deleted file mode 100644 index 67658e853..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/NOC_10_01_SimplePerceptron.pde +++ /dev/null @@ -1,89 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/teaching/nature -// Simple Perceptron Example -// See: http://en.wikipedia.org/wiki/Perceptron - -// Code based on text "Artificial Intelligence", George Luger - -// A list of points we will use to "train" the perceptron -Trainer[] training = new Trainer[2000]; -// A Perceptron object -Perceptron ptron; - -// We will train the perceptron with one "Point" object at a time -int count = 0; - -// Coordinate space -float xmin = -400; -float ymin = -100; -float xmax = 400; -float ymax = 100; - -// The function to describe a line -float f(float x) { - return 0.4*x+1; -} - -void setup() { - size(800, 200); - - // The perceptron has 3 inputs -- x, y, and bias - // Second value is "Learning Constant" - ptron = new Perceptron(3, 0.00001); // Learning Constant is low just b/c it's fun to watch, this is not necessarily optimal - - // Create a random set of training points and calculate the "known" answer - for (int i = 0; i < training.length; i++) { - float x = random(xmin, xmax); - float y = random(ymin, ymax); - int answer = 1; - if (y < f(x)) answer = -1; - training[i] = new Trainer(x, y, answer); - } - smooth(); -} - - -void draw() { - background(255); - translate(width/2,height/2); - - // Draw the line - strokeWeight(4); - stroke(127); - float x1 = xmin; - float y1 = f(x1); - float x2 = xmax; - float y2 = f(x2); - line(x1,y1,x2,y2); - - // Draw the line based on the current weights - // Formula is weights[0]*x + weights[1]*y + weights[2] = 0 - stroke(0); - strokeWeight(1); - float[] weights = ptron.getWeights(); - x1 = xmin; - y1 = (-weights[2] - weights[0]*x1)/weights[1]; - x2 = xmax; - y2 = (-weights[2] - weights[0]*x2)/weights[1]; - line(x1,y1,x2,y2); - - - - // Train the Perceptron with one "training" point at a time - ptron.train(training[count].inputs, training[count].answer); - count = (count + 1) % training.length; - - // Draw all the points based on what the Perceptron would "guess" - // Does not use the "known" correct answer - for (int i = 0; i < count; i++) { - stroke(0); - strokeWeight(1); - fill(0); - int guess = ptron.feedforward(training[i].inputs); - if (guess > 0) noFill(); - - ellipse(training[i].inputs[0], training[i].inputs[1], 8, 8); - } -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/Perceptron.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/Perceptron.pde deleted file mode 100644 index f49e0343b..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/Perceptron.pde +++ /dev/null @@ -1,59 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/teaching/nature -// Simple Perceptron Example -// See: http://en.wikipedia.org/wiki/Perceptron - -// Perceptron Class - -class Perceptron { - float[] weights; // Array of weights for inputs - float c; // learning constant - - // Perceptron is created with n weights and learning constant - Perceptron(int n, float c_) { - weights = new float[n]; - // Start with random weights - for (int i = 0; i < weights.length; i++) { - weights[i] = random(-1,1); - } - c = c_; - } - - // Function to train the Perceptron - // Weights are adjusted based on "desired" answer - void train(float[] inputs, int desired) { - // Guess the result - int guess = feedforward(inputs); - // Compute the factor for changing the weight based on the error - // Error = desired output - guessed output - // Note this can only be 0, -2, or 2 - // Multiply by learning constant - float error = desired - guess; - // Adjust weights based on weightChange * input - for (int i = 0; i < weights.length; i++) { - weights[i] += c * error * inputs[i]; - } - } - - // Guess -1 or 1 based on input values - int feedforward(float[] inputs) { - // Sum all values - float sum = 0; - for (int i = 0; i < weights.length; i++) { - sum += inputs[i]*weights[i]; - } - // Result is sign of the sum, -1 or 1 - return activate(sum); - } - - int activate(float sum) { - if (sum > 0) return 1; - else return -1; - } - - // Return weights - float[] getWeights() { - return weights; - } -} diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/Trainer.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/Trainer.pde deleted file mode 100644 index f7ee88d68..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/Trainer.pde +++ /dev/null @@ -1,23 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/teaching/nature -// Simple Perceptron Example -// See: http://en.wikipedia.org/wiki/Perceptron - -// A class to describe a training point -// Has an x and y, a "bias" (1) and known output -// Could also add a variable for "guess" but not required here - -class Trainer { - - float[] inputs; - int answer; - - Trainer(float x, float y, int a) { - inputs = new float[3]; - inputs[0] = x; - inputs[1] = y; - inputs[2] = 1; - answer = a; - } -} diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/NOC_10_02_SeekingNeural.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/NOC_10_02_SeekingNeural.pde deleted file mode 100644 index 66fe6590a..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/NOC_10_02_SeekingNeural.pde +++ /dev/null @@ -1,62 +0,0 @@ -// A Vehicle controlled by a Perceptron -// Daniel Shiffman -// Nature of Code, Spring 2011 - -Vehicle v; - -PVector desired; - -ArrayList targets; - -void setup() { - size(800, 200); - smooth(); - - // The Vehicle's desired location - desired = new PVector(width/2,height/2); - - - // Create a list of targets - makeTargets(); - - // Create the Vehicle (it has to know about the number of targets - // in order to configure its brain) - v = new Vehicle(targets.size(), random(width), random(height)); -} - -// Make a random ArrayList of targets to steer towards -void makeTargets() { - targets = new ArrayList(); - for (int i = 0; i < 8; i++) { - targets.add(new PVector(random(width), random(height))); - } -} - -void draw() { - background(255); - - // Draw a rectangle to show the Vehicle's goal - rectMode(CENTER); - stroke(0); - strokeWeight(2); - fill(0, 100); - rect(desired.x, desired.y, 36, 36); - - // Draw the targets - for (PVector target : targets) { - fill(0, 100); - stroke(0); - strokeWeight(2); - ellipse(target.x, target.y, 30, 30); - } - - // Update the Vehicle - v.steer(targets); - v.update(); - v.display(); -} - -void mousePressed() { - makeTargets(); -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Perceptron.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Perceptron.pde deleted file mode 100644 index 8936904f8..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Perceptron.pde +++ /dev/null @@ -1,44 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/teaching/nature -// Simple Perceptron Example -// See: http://en.wikipedia.org/wiki/Perceptron - -// Perceptron Class - -class Perceptron { - float[] weights; // Array of weights for inputs - float c; // learning constant - - // Perceptron is created with n weights and learning constant - Perceptron(int n, float c_) { - weights = new float[n]; - c = c_; - // Start with random weights - for (int i = 0; i < weights.length; i++) { - weights[i] = random(0, 1); - } - } - - // Function to train the Perceptron - // Weights are adjusted based on vehicle's error - void train(PVector[] forces, PVector error) { - for (int i = 0; i < weights.length; i++) { - weights[i] += c*error.x*forces[i].x; - weights[i] += c*error.y*forces[i].y; - weights[i] = constrain(weights[i], 0, 1); - } - } - - // Give me a steering result - PVector feedforward(PVector[] forces) { - // Sum all values - PVector sum = new PVector(); - for (int i = 0; i < weights.length; i++) { - forces[i].mult(weights[i]); - sum.add(forces[i]); - } - return sum; - } -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Vehicle.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Vehicle.pde deleted file mode 100644 index efd9bf287..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Vehicle.pde +++ /dev/null @@ -1,102 +0,0 @@ -// Seek -// Daniel Shiffman - -// The "Vehicle" class - -class Vehicle { - - // Vehicle now has a brain! - Perceptron brain; - - PVector location; - PVector velocity; - PVector acceleration; - float r; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - Vehicle(int n, float x, float y) { - brain = new Perceptron(n,0.001); - acceleration = new PVector(0,0); - velocity = new PVector(0,0); - location = new PVector(x,y); - r = 3.0; - maxspeed = 4; - maxforce = 0.1; - } - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelerationelertion to 0 each cycle - acceleration.mult(0); - - location.x = constrain(location.x,0,width); - location.y = constrain(location.y,0,height); - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - // Here is where the brain processes everything - void steer(ArrayList targets) { - // Make an array of forces - PVector[] forces = new PVector[targets.size()]; - - // Steer towards all targets - for (int i = 0; i < forces.length; i++) { - forces[i] = seek(targets.get(i)); - } - - // That array of forces is the input to the brain - PVector result = brain.feedforward(forces); - - // Use the result to steer the vehicle - applyForce(result); - - // Train the brain according to the error - PVector error = PVector.sub(desired, location); - brain.train(forces,error); - - } - - // A method that calculates a steering force towards a target - // STEER = DESIRED MINUS VELOCITY - PVector seek(PVector target) { - PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target - - // Normalize desired and scale to maximum speed - desired.normalize(); - desired.mult(maxspeed); - // Steering = Desired minus velocity - PVector steer = PVector.sub(desired,velocity); - steer.limit(maxforce); // Limit to maximum steering force - - return steer; - } - - void display() { - - // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + PI/2; - fill(175); - stroke(0); - strokeWeight(1); - pushMatrix(); - translate(location.x,location.y); - rotate(theta); - beginShape(); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(CLOSE); - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Connection.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Connection.pde deleted file mode 100644 index a8e75c1ca..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Connection.pde +++ /dev/null @@ -1,29 +0,0 @@ -// A static drawing of a Neural Network -// Daniel Shiffman -// Nature of Code - -class Connection { - - // Connection is from Neuron A to B - Neuron a; - Neuron b; - - // Connection has a weight - float weight; - - Connection(Neuron from, Neuron to,float w) { - weight = w; - a = from; - b = to; - } - - // Drawn as a line - void display() { - stroke(0); - strokeWeight(weight*4); - line(a.location.x, a.location.y, b.location.x, b.location.y); - } -} - - - diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/NOC_10_03_NetworkViz.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/NOC_10_03_NetworkViz.pde deleted file mode 100644 index 5aa884c9b..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/NOC_10_03_NetworkViz.pde +++ /dev/null @@ -1,39 +0,0 @@ -// A static drawing of a Neural Network -// Daniel Shiffman -// Nature of Code, Spring 2011 - -Network network; - -void setup() { - size(800, 200); - smooth(); - - // Create the Network object - network = new Network(width/2,height/2); - - // Create a bunch of Neurons - Neuron a = new Neuron(-300,0); - Neuron b = new Neuron(0,75); - Neuron c = new Neuron(0,-75); - Neuron d = new Neuron(300,0); - - // Connect them - network.connect(a,b); - network.connect(a,c); - network.connect(b,d); - network.connect(c,d); - - // Add them to the Network - network.addNeuron(a); - network.addNeuron(b); - network.addNeuron(c); - network.addNeuron(d); -} - -void draw() { - background(255); - // Draw the Network - network.display(); - noLoop(); -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Network.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Network.pde deleted file mode 100644 index 52ad9a9bf..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Network.pde +++ /dev/null @@ -1,37 +0,0 @@ -// A static drawing of a Neural Network -// Daniel Shiffman -// Nature of Code - -class Network { - - // The Network has a list of neurons - ArrayList neurons; - PVector location; - - Network(float x, float y) { - location = new PVector(x,y); - neurons = new ArrayList(); - } - - // We can add a Neuron - void addNeuron(Neuron n) { - neurons.add(n); - } - - // We can connection two Neurons - void connect(Neuron a, Neuron b) { - Connection c = new Connection(a, b, random(1)); - a.addConnection(c); - } - - // We can draw the network - void display() { - pushMatrix(); - translate(location.x, location.y); - for (Neuron n : neurons) { - n.display(); - } - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Neuron.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Neuron.pde deleted file mode 100644 index a6a14be07..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Neuron.pde +++ /dev/null @@ -1,36 +0,0 @@ -// A static drawing of a Neural Network -// Daniel Shiffman -// Nature of Code - -class Neuron { - - // Neuron has a location - PVector location; - - // Neuron has a list of connections - ArrayList connections; - - Neuron(float x, float y) { - location = new PVector(x, y); - connections = new ArrayList(); - } - - // Add a Connection - void addConnection(Connection c) { - connections.add(c); - } - - // Draw Neuron as a circle - void display() { - stroke(0); - strokeWeight(1); - fill(0); - ellipse(location.x, location.y, 16, 16); - - // Draw all its connections - for (Connection c : connections) { - c.display(); - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/sketch.properties b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/sketch.properties deleted file mode 100644 index 28faa5897..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=Standard diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Connection.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Connection.pde deleted file mode 100644 index 8d6ec8907..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Connection.pde +++ /dev/null @@ -1,63 +0,0 @@ -// An animated drawing of a Neural Network -// Daniel Shiffman -// Nature of Code - -class Connection { - // Connection is from Neuron A to B - Neuron a; - Neuron b; - - // Connection has a weight - float weight; - - // Variables to track the animation - boolean sending = false; - PVector sender; - - // Need to store the output for when its time to pass along - float output = 0; - - Connection(Neuron from, Neuron to, float w) { - weight = w; - a = from; - b = to; - } - - - // The Connection is active - void feedforward(float val) { - output = val*weight; // Compute output - sender = a.location.get(); // Start animation at Neuron A - sending = true; // Turn on sending - } - - // Update traveling sender - void update() { - if (sending) { - // Use a simple interpolation - sender.x = lerp(sender.x, b.location.x, 0.1); - sender.y = lerp(sender.y, b.location.y, 0.1); - float d = PVector.dist(sender, b.location); - // If we've reached the end - if (d < 1) { - // Pass along the output! - b.feedforward(output); - sending = false; - } - } - } - - // Draw line and traveling circle - void display() { - stroke(0); - strokeWeight(1+weight*4); - line(a.location.x, a.location.y, b.location.x, b.location.y); - - if (sending) { - fill(0); - strokeWeight(1); - ellipse(sender.x, sender.y, 16, 16); - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/NOC_10_04_NetworkAnimation.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/NOC_10_04_NetworkAnimation.pde deleted file mode 100644 index 07596246b..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/NOC_10_04_NetworkAnimation.pde +++ /dev/null @@ -1,50 +0,0 @@ -// An animated drawing of a Neural Network -// Daniel Shiffman -// Nature of Code - -Network network; - -void setup() { - size(800, 200); - smooth(); - - // Create the Network object - network = new Network(width/2, height/2); - - // Create a bunch of Neurons - Neuron a = new Neuron(-350, 0); - Neuron b = new Neuron(-200, 0); - Neuron c = new Neuron(0, 75); - Neuron d = new Neuron(0, -75); - Neuron e = new Neuron(200, 0); - Neuron f = new Neuron(350, 0); - - // Connect them - network.connect(a, b,1); - network.connect(b, c,random(1)); - network.connect(b, d,random(1)); - network.connect(c, e,random(1)); - network.connect(d, e,random(1)); - network.connect(e, f,1); - - // Add them to the Network - network.addNeuron(a); - network.addNeuron(b); - network.addNeuron(c); - network.addNeuron(d); - network.addNeuron(e); - network.addNeuron(f); -} - -void draw() { - background(255); - // Update and display the Network - network.update(); - network.display(); - - // Every 30 frames feed in an input - if (frameCount % 30 == 0) { - network.feedforward(random(1)); - } -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Network.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Network.pde deleted file mode 100644 index 2a2d2e5b5..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Network.pde +++ /dev/null @@ -1,62 +0,0 @@ -// An animated drawing of a Neural Network -// Daniel Shiffman -// Nature of Code - -class Network { - - // The Network has a list of neurons - ArrayList neurons; - - // The Network now keeps a duplicate list of all Connection objects. - // This makes it easier to draw everything in this class - ArrayList connections; - PVector location; - - Network(float x, float y) { - location = new PVector(x, y); - neurons = new ArrayList(); - connections = new ArrayList(); - } - - // We can add a Neuron - void addNeuron(Neuron n) { - neurons.add(n); - } - - // We can connection two Neurons - void connect(Neuron a, Neuron b, float weight) { - Connection c = new Connection(a, b, weight); - a.addConnection(c); - // Also add the Connection here - connections.add(c); - } - - // Sending an input to the first Neuron - // We should do something better to track multiple inputs - void feedforward(float input) { - Neuron start = neurons.get(0); - start.feedforward(input); - } - - // Update the animation - void update() { - for (Connection c : connections) { - c.update(); - } - } - - // Draw everything - void display() { - pushMatrix(); - translate(location.x, location.y); - for (Neuron n : neurons) { - n.display(); - } - - for (Connection c : connections) { - c.display(); - } - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Neuron.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Neuron.pde deleted file mode 100644 index 372ba3fa7..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Neuron.pde +++ /dev/null @@ -1,62 +0,0 @@ -// An animated drawing of a Neural Network -// Daniel Shiffman -// Nature of Code - -class Neuron { - // Neuron has a location - PVector location; - - // Neuron has a list of connections - ArrayList connections; - - // We now track the inputs and sum them - float sum = 0; - - // The Neuron's size can be animated - float r = 32; - - Neuron(float x, float y) { - location = new PVector(x, y); - connections = new ArrayList(); - } - - // Add a Connection - void addConnection(Connection c) { - connections.add(c); - } - - // Receive an input - void feedforward(float input) { - // Accumulate it - sum += input; - // Activate it? - if (sum > 1) { - fire(); - sum = 0; // Reset the sum to 0 if it fires - } - } - - // The Neuron fires - void fire() { - r = 64; // It suddenly is bigger - - // We send the output through all connections - for (Connection c : connections) { - c.feedforward(sum); - } - } - - // Draw it as a circle - void display() { - stroke(0); - strokeWeight(1); - // Brightness is mapped to sum - float b = map(sum,0,1,255,0); - fill(b); - ellipse(location.x, location.y, r, r); - - // Size shrinks down back to original dimensions - r = lerp(r,32,0.1); - } -} - diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/sketch.properties b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/sketch.properties deleted file mode 100644 index 28faa5897..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=Standard diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/Landscape.pde b/java/examples/Books/Nature of Code/chp10_nn/xor/Landscape.pde deleted file mode 100755 index 40ef0a733..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/xor/Landscape.pde +++ /dev/null @@ -1,73 +0,0 @@ -// Daniel Shiffman -// -// "Landscape" example - -class Landscape { - - int scl; // size of each cell - int w,h; // width and height of thingie - int rows, cols; // number of rows and columns - float zoff = 0.0; // perlin noise argument - float[][] z; // using an array to store all the height values - - Landscape(int scl_, int w_, int h_) { - scl = scl_; - w = w_; - h = h_; - cols = w/scl; - rows = h/scl; - z = new float[cols][rows]; - } - - - // Calculate height values (based off a neural netork) - void calculate(Network nn) { - float x = 0; - float dx = (float) 1.0 / cols; - for (int i = 0; i < cols; i++) - { - float y = 0; - float dy = (float) 1.0 / rows; - for (int j = 0; j < rows; j++) - { - float[] input = new float[2]; - input[0] = x; - input[1] = y; - float result = nn.feedForward(input); - z[i][j] = z[i][j]*0.95 + 0.05*(float)(result*280.0f-140.0); - y += dy; - } - x += dx; - } - - } - - // Render landscape as grid of quads - void render() { - // Every cell is an individual quad - // (could use quad_strip here, but produces funny results, investigate this) - for (int x = 0; x < z.length-1; x++) - { - for (int y = 0; y < z[x].length-1; y++) - { - // one quad at a time - // each quad's color is determined by the height value at each vertex - // (clean this part up) - noStroke(); - pushMatrix(); - beginShape(QUADS); - translate(x*scl-w/2,y*scl-h/2,0); - fill(z[x][y]+127,220); - vertex(0,0,z[x][y]); - fill(z[x+1][y]+127,220); - vertex(scl,0,z[x+1][y]); - fill(z[x+1][y+1]+127,220); - vertex(scl,scl,z[x+1][y+1]); - fill(z[x][y+1]+127,220); - vertex(0,scl,z[x][y+1]); - endShape(); - popMatrix(); - } - } - } -} diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Connection.java b/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Connection.java deleted file mode 100644 index d8415d2a6..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Connection.java +++ /dev/null @@ -1,47 +0,0 @@ -// Daniel Shiffman -// The Nature of Code, Fall 2006 -// Neural Network - -// Class to describe a connection between two neurons - -package nn; - -public class Connection { - - private Neuron from; // Connection goes from. . . - private Neuron to; // To. . . - private float weight; // Weight of the connection. . . - - // Constructor builds a connection with a random weight - public Connection(Neuron a_, Neuron b_) { - from = a_; - to = b_; - weight = (float) Math.random()*2-1; - } - - // In case I want to set the weights manually, using this for testing - public Connection(Neuron a_, Neuron b_, float w) { - from = a_; - to = b_; - weight = w; - } - - public Neuron getFrom() { - return from; - } - - public Neuron getTo() { - return to; - } - - public float getWeight() { - return weight; - } - - // Changing the weight of the connection - public void adjustWeight(float deltaWeight) { - weight += deltaWeight; - } - - -} diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/HiddenNeuron.java b/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/HiddenNeuron.java deleted file mode 100644 index 3c8d7945d..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/HiddenNeuron.java +++ /dev/null @@ -1,20 +0,0 @@ -//Daniel Shiffman -//The Nature of Code, Fall 2006 -//Neural Network - -// Hidden Neuron Class -// So far not necessary to differentiate these - -package nn; - -public class HiddenNeuron extends Neuron { - - public HiddenNeuron() { - super(); - } - - public HiddenNeuron(int i) { - super(i); - } - -} diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/InputNeuron.java b/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/InputNeuron.java deleted file mode 100644 index a2191632f..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/InputNeuron.java +++ /dev/null @@ -1,23 +0,0 @@ -//Daniel Shiffman -//The Nature of Code, Fall 2006 -//Neural Network - -// Input Neuron Class -// Has additional functionality to receive beginning input - -package nn; - -public class InputNeuron extends Neuron { - public InputNeuron() { - super(); - } - - public InputNeuron(int i) { - super(i); - } - - public void input(float d) { - output = d; - } - -} diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Network.java b/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Network.java deleted file mode 100644 index c0854712d..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Network.java +++ /dev/null @@ -1,143 +0,0 @@ -// Daniel Shiffman -// The Nature of Code, Fall 2006 -// Neural Network - -// Class to describe the entire network -// Arrays for input neurons, hidden neurons, and output neuron - -// Need to update this so that it would work with an array out outputs -// Rather silly that I didn't do this initially - -// Also need to build in a "Layer" class so that there can easily -// be more than one hidden layer - -package nn; - -import java.util.ArrayList; - -public class Network { - - // Layers - InputNeuron[] input; - HiddenNeuron[] hidden; - OutputNeuron output; - - public static final float LEARNING_CONSTANT = 0.5f; - - // Only One output now to start!!! (i can do better, really. . .) - // Constructor makes the entire network based on number of inputs & number of neurons in hidden layer - // Only One hidden layer!!! (fix this dood) - - public Network(int inputs, int hiddentotal) { - - input = new InputNeuron[inputs+1]; // Got to add a bias input - hidden = new HiddenNeuron[hiddentotal+1]; - - // Make input neurons - for (int i = 0; i < input.length-1; i++) { - input[i] = new InputNeuron(); - } - - // Make hidden neurons - for (int i = 0; i < hidden.length-1; i++) { - hidden[i] = new HiddenNeuron(); - } - - // Make bias neurons - input[input.length-1] = new InputNeuron(1); - hidden[hidden.length-1] = new HiddenNeuron(1); - - // Make output neuron - output = new OutputNeuron(); - - // Connect input layer to hidden layer - for (int i = 0; i < input.length; i++) { - for (int j = 0; j < hidden.length-1; j++) { - // Create the connection object and put it in both neurons - Connection c = new Connection(input[i],hidden[j]); - input[i].addConnection(c); - hidden[j].addConnection(c); - } - } - - // Connect the hidden layer to the output neuron - for (int i = 0; i < hidden.length; i++) { - Connection c = new Connection(hidden[i],output); - hidden[i].addConnection(c); - output.addConnection(c); - } - - } - - - public float feedForward(float[] inputVals) { - - // Feed the input with an array of inputs - for (int i = 0; i < inputVals.length; i++) { - input[i].input(inputVals[i]); - } - - // Have the hidden layer calculate its output - for (int i = 0; i < hidden.length-1; i++) { - hidden[i].calcOutput(); - } - - // Calculate the output of the output neuron - output.calcOutput(); - - // Return output - return output.getOutput(); - } - - public float train(float[] inputs, float answer) { - float result = feedForward(inputs); - - - // This is where the error correction all starts - // Derivative of sigmoid output function * diff between known and guess - float deltaOutput = result*(1-result) * (answer-result); - - - // BACKPROPOGATION - // This is easier b/c we just have one output - // Apply Delta to connections between hidden and output - ArrayList connections = output.getConnections(); - for (int i = 0; i < connections.size(); i++) { - Connection c = (Connection) connections.get(i); - Neuron neuron = c.getFrom(); - float output = neuron.getOutput(); - float deltaWeight = output*deltaOutput; - c.adjustWeight(LEARNING_CONSTANT*deltaWeight); - } - - // ADJUST HIDDEN WEIGHTS - for (int i = 0; i < hidden.length; i++) { - connections = hidden[i].getConnections(); - float sum = 0; - // Sum output delta * hidden layer connections (just one output) - for (int j = 0; j < connections.size(); j++) { - Connection c = (Connection) connections.get(j); - // Is this a connection from hidden layer to next layer (output)? - if (c.getFrom() == hidden[i]) { - sum += c.getWeight()*deltaOutput; - } - } - // Then adjust the weights coming in based: - // Above sum * derivative of sigmoid output function for hidden neurons - for (int j = 0; j < connections.size(); j++) { - Connection c = (Connection) connections.get(j); - // Is this a connection from previous layer (input) to hidden layer? - if (c.getTo() == hidden[i]) { - float output = hidden[i].getOutput(); - float deltaHidden = output * (1 - output); // Derivative of sigmoid(x) - deltaHidden *= sum; // Would sum for all outputs if more than one output - Neuron neuron = c.getFrom(); - float deltaWeight = neuron.getOutput()*deltaHidden; - c.adjustWeight(LEARNING_CONSTANT*deltaWeight); - } - } - } - - return result; - } -} diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Neuron.java b/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Neuron.java deleted file mode 100644 index 234780016..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Neuron.java +++ /dev/null @@ -1,81 +0,0 @@ -//Daniel Shiffman -//The Nature of Code, Fall 2006 -//Neural Network - -//Generic Neuron Class -//Can be a bias neuron (true or false) - -package nn; - -import java.util.ArrayList; - -public class Neuron { - - protected float output; - protected ArrayList connections; - protected boolean bias = false; - - // A regular Neuron - public Neuron() { - output = 0; - // Using an arraylist to store list of connections to other neurons - connections = new ArrayList(); - bias = false; - } - - // Constructor for a bias neuron - public Neuron(int i) { - output = i; - connections = new ArrayList(); - bias = true; - } - - // Function to calculate output of this neuron - // Output is sum of all inputs*weight of connections - public void calcOutput() { - if (bias) { - // do nothing - } else { - float sum = 0; - float bias = 0; - //System.out.println("Looking through " + connections.size() + " connections"); - for (int i = 0; i < connections.size(); i++) { - Connection c = (Connection) connections.get(i); - Neuron from = c.getFrom(); - Neuron to = c.getTo(); - // Is this connection moving forward to us - // Ignore connections that we send our output to - if (to == this) { - // This isn't really necessary - // But I am treating the bias individually in case I need to at some point - if (from.bias) { - bias = from.getOutput()*c.getWeight(); - } else { - sum += from.getOutput()*c.getWeight(); - } - } - } - // Output is result of sigmoid function - output = f(bias+sum); - } - } - - void addConnection(Connection c) { - connections.add(c); - } - - float getOutput() { - return output; - } - - // Sigmoid function - public static float f(float x) { - return 1.0f / (1.0f + (float) Math.exp(-x)); - } - - public ArrayList getConnections() { - return connections; - } - - -} diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/OutputNeuron.java b/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/OutputNeuron.java deleted file mode 100644 index abe8daee4..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/OutputNeuron.java +++ /dev/null @@ -1,7 +0,0 @@ -package nn; - -public class OutputNeuron extends Neuron { - public OutputNeuron() { - super(); - } -} diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/data/GillSans-16.vlw b/java/examples/Books/Nature of Code/chp10_nn/xor/data/GillSans-16.vlw deleted file mode 100755 index 380eee76c34bd39bdd163b4b9c0bda5407db9a69..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 28543 zcmd6vXRz#AcGvZ0WRSr!2v8NM0Nr`QMqmVX6B-+u&=}k%G{H@3k_K!V!_Wjn6Pu6y zwX68n-+(3=2SgRAph}ozgGnWFEHap!!7xyp-+%4B&(%9V_sn~5?##RE9JRJ~TzjRx zc94=J`IaO}z9ZLn=6b>PSzIaCN4RpX4~J*Pzr`hZo9o-nE~Q0i2&mk5;QCCidD{2k z`Ljd(hwt}98c_z{pI_nk z?ZYL!B77bJrNvA5MEC&&)RyR{OZY_S24Ef+*5V_uxHYip-#~=wnxz5hx033 zo~rW;iC2H0O8X+>RbQm3@wY!jC1Oyt*Fi!#c#rHs^KzIMP(lQ{}$+QT)8zj}K{2@%<+} zllCQ~#r9O6t_T|fdKNumTI~CmhB(Qjc%k%|_7e$5y|pw45GVLaT(QnrZ!GtdL)u&> zV%kp$X_1!m_O{QY{Z!J_zj&!!gr7!0&rh}Y(~191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*6ohi$Mib z9?rsFwrj9sVsO#D=VKhvhJSN54Q0(dP3X|%xD69~>pIwtS${QeX@A51`Q;vpUsZ&V*o z`u-HnO%v40qF8M;bPD_%F0zdeGO6gb7c@SOHR*{8j=Vd-4Kpjt;F+l{gaLmD$n}NF zTQD;Cf$4U)+if>{KI!BEQ{^Gg;+L0XVSI^FekL>pDuUrNSQ>AMDfB@qK5>aC-}y!% z1Dd_P$-6N-&iU{X;nWQOHHC%hWR^G(nYvY9PjY#jo61t zUL2-XTOdVpmB5bY#wtS0y_QC2MwKSrgVP|nj{0ItM?n^uaPXZ)dnXr%G5`aUOlttW zDH%cEoQS{+4p|IKRbHmZ3hKamfZA_W`X|`=kfgDn@4F!c^0EYJM|x$HL0)%u?$Xdo z>GHMEOWg-de#+wWUhnSdyc*1J5IGJbXcgVOO)cZg7C(3A?Tu~C!i)NFVH`cUOU*lb p<`Agd5!!RtR6_MLWPPIgHPXLqH~W&W{Mg67?4!r8N*+RQ{eM>Vwm|>@ diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/xor.pde b/java/examples/Books/Nature of Code/chp10_nn/xor/xor.pde deleted file mode 100755 index eab37c5c7..000000000 --- a/java/examples/Books/Nature of Code/chp10_nn/xor/xor.pde +++ /dev/null @@ -1,114 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/teaching/nature - -// XOR Multi-Layered Neural Network Example -// Neural network code is all in the "code" folder - -import processing.opengl.*; -import nn.*; - -ArrayList inputs; // List of training input values -Network nn; // Neural Network Object -int count; // Total training interations -Landscape land; // Solution space -float theta = 0.0; // Angle of rotation -PFont f; // Font - - -void setup() { - - size(400,400,OPENGL); - - // Create a landscape object - land = new Landscape(20,300,300); - - f = createFont("Courier",12,true); - - nn = new Network(2,4); - - // Create a list of 4 training inputs - inputs = new ArrayList(); - float[] input = new float[2]; - input[0] = 1; - input[1] = 0; - inputs.add((float []) input.clone()); - input[0] = 0; - input[1] = 1; - inputs.add((float []) input.clone()); - input[0] = 1; - input[1] = 1; - inputs.add((float []) input.clone()); - input[0] = 0; - input[1] = 0; - inputs.add((float []) input.clone()); -} - -void draw() { - - int trainingIterationsPerFrame = 5; - - for (int i = 0; i < trainingIterationsPerFrame; i++) { - // Pick a random training input - int pick = int(random(inputs.size())); - // Grab that input - float[] inp = (float[]) inputs.get(pick); - // Compute XOR - float known = 1; - if ((inp[0] == 1.0 && inp[1] == 1.0) || (inp[0] == 0 && inp[1] == 0)) known = 0; - // Train that sucker! - float result = nn.train(inp,known); - count++; - } - - // Ok, visualize the solution space - background(175); - pushMatrix(); - translate(width/2,height/2+20,-160); - rotateX(PI/3); - rotateZ(theta); - - // Put a little BOX on screen - pushMatrix(); - stroke(50); - noFill(); - translate(-10,-10,0); - box(280); - - // Draw the landscape - popMatrix(); - land.calculate(nn); - land.render(); - theta += 0.0025; - popMatrix(); - - // Display overal neural net stats - networkStatus(); - -} - - -void networkStatus() { - float mse = 0.0; - - textFont(f); - fill(0); - text("Your friendly neighborhood neural network solving XOR.",10,20); - text("Total iterations: " + count,10,40); - - for (int i = 0; i < inputs.size(); i++) { - float[] inp = (float[]) inputs.get(i); - float known = 1; - if ((inp[0] == 1.0 && inp[1] == 1.0) || (inp[0] == 0 && inp[1] == 0)) known = 0; - float result = nn.feedForward(inp); - //System.out.println("For: " + inp[0] + " " + inp[1] + ": " + result); - mse += (result - known)*(result - known); - } - - float rmse = sqrt(mse/4.0); - DecimalFormat df = new DecimalFormat("0.000"); - text("Root mean squared error: " + df.format(rmse), 10,60); - -} - - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_10_motion101_acceleration/Mover.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_10_motion101_acceleration/Mover.pde deleted file mode 100644 index e7fc0c200..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_10_motion101_acceleration/Mover.pde +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Acceleration with Vectors - * by Daniel Shiffman. - * - * Demonstration of the basics of motion with vector. - * A "Mover" object stores location, velocity, and acceleration as vectors - * The motion is controlled by affecting the acceleration (in this case towards the mouse) - */ - - -class Mover { - - // The Mover tracks location, velocity, and acceleration - PVector location; - PVector velocity; - PVector acceleration; - // The Mover's maximum speed - float topspeed; - - Mover() { - // Start in the center - location = new PVector(width/2,height/2); - velocity = new PVector(0,0); - topspeed = 5; - } - - void update() { - - // Compute a vector that points from location to mouse - PVector mouse = new PVector(mouseX,mouseY); - PVector acceleration = PVector.sub(mouse,location); - // Set magnitude of acceleration - //acceleration.setMag(0.2); - acceleration.normalize(); - acceleration.mult(0.2); - - // Velocity changes according to acceleration - velocity.add(acceleration); - // Limit the velocity by topspeed - velocity.limit(topspeed); - // Location changes by velocity - location.add(velocity); - } - - void display() { - stroke(0); - strokeWeight(2); - fill(127); - ellipse(location.x,location.y,48,48); - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_10_motion101_acceleration/NOC_1_10_motion101_acceleration.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_10_motion101_acceleration/NOC_1_10_motion101_acceleration.pde deleted file mode 100644 index 6822430f0..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_10_motion101_acceleration/NOC_1_10_motion101_acceleration.pde +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Acceleration with Vectors - * by Daniel Shiffman. - * - * Demonstration of the basics of motion with vector. - * A "Mover" object stores location, velocity, and acceleration as vectors - * The motion is controlled by affecting the acceleration (in this case towards the mouse) - */ - -// A Mover object -Mover mover; - -void setup() { - size(800,200); - smooth(); - mover = new Mover(); -} - -void draw() { - background(255); - - // Update the location - mover.update(); - // Display the Mover - mover.display(); -} - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_11_motion101_acceleration_array/Mover.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_11_motion101_acceleration_array/Mover.pde deleted file mode 100644 index 19114ebf6..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_11_motion101_acceleration_array/Mover.pde +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Acceleration with Vectors - * by Daniel Shiffman. - * - * Demonstration of the basics of motion with vector. - * A "Mover" object stores location, velocity, and acceleration as vectors - * The motion is controlled by affecting the acceleration (in this case towards the mouse) - */ - - -class Mover { - - // The Mover tracks location, velocity, and acceleration - PVector location; - PVector velocity; - PVector acceleration; - // The Mover's maximum speed - float topspeed; - - Mover() { - // Start in the center - location = new PVector(random(width),random(height)); - velocity = new PVector(0,0); - topspeed = 5; - } - - void update() { - - // Compute a vector that points from location to mouse - PVector mouse = new PVector(mouseX,mouseY); - PVector acceleration = PVector.sub(mouse,location); - // Set magnitude of acceleration - //acceleration.setMag(0.2); - acceleration.normalize(); - acceleration.mult(0.2); - - // Velocity changes according to acceleration - velocity.add(acceleration); - // Limit the velocity by topspeed - velocity.limit(topspeed); - // Location changes by velocity - location.add(velocity); - } - - void display() { - stroke(0); - strokeWeight(2); - fill(127,200); - ellipse(location.x,location.y,48,48); - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_11_motion101_acceleration_array/NOC_1_11_motion101_acceleration_array.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_11_motion101_acceleration_array/NOC_1_11_motion101_acceleration_array.pde deleted file mode 100644 index b1cafa931..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_11_motion101_acceleration_array/NOC_1_11_motion101_acceleration_array.pde +++ /dev/null @@ -1,21 +0,0 @@ -Mover[] movers = new Mover[20]; - -void setup() { - size(800,200); - smooth(); - for (int i = 0; i < movers.length; i++) { - movers[i] = new Mover(); - } -} - -void draw() { - - background(255); - - for (int i = 0; i < movers.length; i++) { - movers[i].update(); - movers[i].display(); - } -} - - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_1_bouncingball_novectors/NOC_1_1_bouncingball_novectors.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_1_bouncingball_novectors/NOC_1_1_bouncingball_novectors.pde deleted file mode 100644 index 6dfb4b6a1..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_1_bouncingball_novectors/NOC_1_1_bouncingball_novectors.pde +++ /dev/null @@ -1,38 +0,0 @@ -// The Nature of Code -// Daniel Shiffman -// Draft book - -// Example 1-1: Bouncing Ball, no vectors -float x = 100; -float y = 100; -float xspeed = 2.5; -float yspeed = 2; - -void setup() { - size(800, 200); - smooth(); -} - -void draw() { - background(255); - - - // Add the current speed to the location. - x = x + xspeed; - y = y + yspeed; - - if ((x > width) || (x < 0)) { - xspeed = xspeed * -1; - } - if ((y > height) || (y < 0)) { - yspeed = yspeed * -1; - } - - - // Display circle at x location - stroke(0); - strokeWeight(2); - fill(127); - ellipse(x, y, 48, 48); -} - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_2_bouncingball_vectors/NOC_1_2_bouncingball_vectors.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_2_bouncingball_vectors/NOC_1_2_bouncingball_vectors.pde deleted file mode 100644 index 49d7912c2..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_2_bouncingball_vectors/NOC_1_2_bouncingball_vectors.pde +++ /dev/null @@ -1,38 +0,0 @@ -// The Nature of Code -// Daniel Shiffman -// Draft book - -// Example 1-2: Bouncing Ball, with PVector! -PVector location; -PVector velocity; - -void setup() { - size(200,200); - smooth(); - background(255); - location = new PVector(100,100); - velocity = new PVector(2.5,5); -} - -void draw() { - noStroke(); - fill(255,10); - rect(0,0,width,height); - - // Add the current speed to the location. - location.add(velocity); - - if ((location.x > width) || (location.x < 0)) { - velocity.x = velocity.x * -1; - } - if ((location.y > height) || (location.y < 0)) { - velocity.y = velocity.y * -1; - } - - // Display circle at x location - stroke(0); - fill(175); - ellipse(location.x,location.y,16,16); -} - - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_3_vector_subtraction/NOC_1_3_vector_subtraction.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_3_vector_subtraction/NOC_1_3_vector_subtraction.pde deleted file mode 100644 index b0f89414e..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_3_vector_subtraction/NOC_1_3_vector_subtraction.pde +++ /dev/null @@ -1,26 +0,0 @@ -// The Nature of Code -// Daniel Shiffman -// Draft book - -// Example 1-3: Vector subtraction - -void setup() { - size(800,200); - smooth(); -} - -void draw() { - background(255); - - PVector mouse = new PVector(mouseX,mouseY); - PVector center = new PVector(width/2,height/2); - mouse.sub(center); - - translate(width/2,height/2); - strokeWeight(2); - stroke(0); - line(0,0,mouse.x,mouse.y); - -} - - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_4_vector_multiplication/NOC_1_4_vector_multiplication.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_4_vector_multiplication/NOC_1_4_vector_multiplication.pde deleted file mode 100644 index fb71aa400..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_4_vector_multiplication/NOC_1_4_vector_multiplication.pde +++ /dev/null @@ -1,28 +0,0 @@ -// The Nature of Code -// Daniel Shiffman -// Draft book - -// Example 1-4: Vector multiplication - -void setup() { - size(800,200); - smooth(); -} - -void draw() { - background(255); - - PVector mouse = new PVector(mouseX,mouseY); - PVector center = new PVector(width/2,height/2); - mouse.sub(center); - - // Multiplying a vector! The vector is now half its original size (multiplied by 0.5). - mouse.mult(0.5); - - translate(width/2,height/2); - strokeWeight(2); - stroke(0); - line(0,0,mouse.x,mouse.y); -} - - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_5_vector_magnitude/NOC_1_5_vector_magnitude.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_5_vector_magnitude/NOC_1_5_vector_magnitude.pde deleted file mode 100644 index 45a576288..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_5_vector_magnitude/NOC_1_5_vector_magnitude.pde +++ /dev/null @@ -1,31 +0,0 @@ -// The Nature of Code -// Daniel Shiffman -// Draft book - -// Example 1-5: Vector magnitude - -void setup() { - size(800,200); - smooth(); -} - -void draw() { - background(255); - - PVector mouse = new PVector(mouseX,mouseY); - PVector center = new PVector(width/2,height/2); - mouse.sub(center); - - float m = mouse.mag(); - fill(0); - noStroke(); - rect(0,0,m,10); - - translate(width/2,height/2); - stroke(0); - strokeWeight(2); - line(0,0,mouse.x,mouse.y); - -} - - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_6_vector_normalize/NOC_1_6_vector_normalize.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_6_vector_normalize/NOC_1_6_vector_normalize.pde deleted file mode 100644 index 63ee12326..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_6_vector_normalize/NOC_1_6_vector_normalize.pde +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Normalize - * by Daniel Shiffman. - * - * Demonstration of normalizing a vector. - * Normalizing a vector sets its length to 1. - */ - -void setup() { - size(800,200); - smooth(); -} - -void draw() { - background(255); - - // A vector that points to the mouse location - PVector mouse = new PVector(mouseX,mouseY); - // A vector that points to the center of the window - PVector center = new PVector(width/2,height/2); - // Subtract center from mouse which results in a vector that points from center to mouse - mouse.sub(center); - - // Normalize the vector - mouse.normalize(); - - // Multiply its length by 50 - mouse.mult(150); - - translate(width/2,height/2); - // Draw the resulting vector - stroke(0); - strokeWeight(2); - line(0,0,mouse.x,mouse.y); - -} - - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_7_motion101/Mover.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_7_motion101/Mover.pde deleted file mode 100644 index 70357ce71..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_7_motion101/Mover.pde +++ /dev/null @@ -1,39 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - - Mover() { - location = new PVector(random(width), random(height)); - velocity = new PVector(random(-2, 2), random(-2, 2)); - } - - void update() { - location.add(velocity); - } - - void display() { - stroke(0); - strokeWeight(2); - fill(127); - ellipse(location.x, location.y, 48, 48); - } - - void checkEdges() { - - if (location.x > width) { - location.x = 0; - } - else if (location.x < 0) { - location.x = width; - } - - if (location.y > height) { - location.y = 0; - } - else if (location.y < 0) { - location.y = height; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_7_motion101/NOC_1_7_motion101.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_7_motion101/NOC_1_7_motion101.pde deleted file mode 100644 index 987429706..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_7_motion101/NOC_1_7_motion101.pde +++ /dev/null @@ -1,16 +0,0 @@ -Mover mover; - -void setup() { - size(800,200); - smooth(); - mover = new Mover(); -} - -void draw() { - background(255); - - mover.update(); - mover.checkEdges(); - mover.display(); -} - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_8_motion101_acceleration/Mover.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_8_motion101_acceleration/Mover.pde deleted file mode 100644 index 0f815f24a..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_8_motion101_acceleration/Mover.pde +++ /dev/null @@ -1,45 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float topspeed; - - Mover() { - location = new PVector(width/2, height/2); - velocity = new PVector(0, 0); - acceleration = new PVector(-0.001, 0.01); - topspeed = 10; - } - - void update() { - velocity.add(acceleration); - velocity.limit(topspeed); - location.add(velocity); - } - - void display() { - stroke(0); - strokeWeight(2); - fill(127); - ellipse(location.x, location.y, 48, 48); - } - - void checkEdges() { - - if (location.x > width) { - location.x = 0; - } - else if (location.x < 0) { - location.x = width; - } - - if (location.y > height) { - location.y = 0; - } - else if (location.y < 0) { - location.y = height; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_8_motion101_acceleration/NOC_1_8_motion101_acceleration.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_8_motion101_acceleration/NOC_1_8_motion101_acceleration.pde deleted file mode 100644 index 34b8281b0..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_8_motion101_acceleration/NOC_1_8_motion101_acceleration.pde +++ /dev/null @@ -1,17 +0,0 @@ -Mover mover; - -void setup() { - size(800,200); - smooth(); - mover = new Mover(); -} - -void draw() { - background(255); - - mover.update(); - mover.checkEdges(); - mover.display(); -} - - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_9_motion101_acceleration/Mover.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_9_motion101_acceleration/Mover.pde deleted file mode 100644 index 4be6262ee..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_9_motion101_acceleration/Mover.pde +++ /dev/null @@ -1,49 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float topspeed; - - Mover() { - location = new PVector(width/2, height/2); - velocity = new PVector(0, 0); - topspeed = 6; - } - - void update() { - - acceleration = new PVector(random(-1, 1), random(-1, 1)); - acceleration.normalize(); - acceleration.mult(random(2)); - - velocity.add(acceleration); - velocity.limit(topspeed); - location.add(velocity); - } - - void display() { - stroke(0); - strokeWeight(2); - fill(127); - ellipse(location.x, location.y, 48, 48); - } - - void checkEdges() { - - if (location.x > width) { - location.x = 0; - } - else if (location.x < 0) { - location.x = width; - } - - if (location.y > height) { - location.y = 0; - } - else if (location.y < 0) { - location.y = height; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_9_motion101_acceleration/NOC_1_9_motion101_acceleration.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_9_motion101_acceleration/NOC_1_9_motion101_acceleration.pde deleted file mode 100644 index e505f1d66..000000000 --- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_9_motion101_acceleration/NOC_1_9_motion101_acceleration.pde +++ /dev/null @@ -1,15 +0,0 @@ -Mover mover; - -void setup() { - size(800,200); - smooth(); - mover = new Mover(); -} - -void draw() { - background(255); - mover.update(); - mover.checkEdges(); - mover.display(); -} - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_attractrepel/Attractor.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_attractrepel/Attractor.pde deleted file mode 100644 index d0ce84406..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_attractrepel/Attractor.pde +++ /dev/null @@ -1,74 +0,0 @@ -// Attraction -// Daniel Shiffman - -// A class for a draggable attractive body in our world - -class Attractor { - float mass; // Mass, tied to size - PVector location; // Location - boolean dragging = false; // Is the object being dragged? - boolean rollover = false; // Is the mouse over the ellipse? - PVector drag; // holds the offset for when object is clicked on - - Attractor() { - location = new PVector(width/2,height/2); - mass = 10; - drag = new PVector(0.0,0.0); - } - - PVector attract(Mover m) { - PVector force = PVector.sub(location,m.location); // Calculate direction of force - float d = force.mag(); // Distance between objects - d = constrain(d,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects - force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction) - float strength = (g * mass * m.mass) / (d * d); // Calculate gravitional force magnitude - force.mult(strength); // Get force vector --> magnitude * direction - return force; - } - - // Method to display - void display() { - ellipseMode(CENTER); - stroke(0); - if (dragging) fill (50); - else if (rollover) fill(100); - else fill(0); - ellipse(location.x,location.y,mass*6,mass*6); - } - - // The methods below are for mouse interaction - void clicked(int mx, int my) { - float d = dist(mx,my,location.x,location.y); - if (d < mass) { - dragging = true; - drag.x = location.x-mx; - drag.y = location.y-my; - } - } - - void rollover(int mx, int my) { - float d = dist(mx,my,location.x,location.y); - if (d < mass) { - rollover = true; - } - else { - rollover = false; - } - } - - void stopDragging() { - dragging = false; - } - - - - void drag() { - if (dragging) { - location.x = mouseX + drag.x; - location.y = mouseY + drag.y; - } - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_attractrepel/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_attractrepel/Mover.pde deleted file mode 100644 index 8b2214570..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_attractrepel/Mover.pde +++ /dev/null @@ -1,69 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float mass; - - Mover(float m, float x , float y) { - mass = m; - location = new PVector(x,y); - velocity = new PVector(0,0); - acceleration = new PVector(0,0); - } - - void applyForce(PVector force) { - PVector f = PVector.div(force,mass); - acceleration.add(f); - } - - void update() { - velocity.add(acceleration); - location.add(velocity); - acceleration.mult(0); - } - - void display() { - stroke(0); - fill(175,200); - ellipse(location.x,location.y,mass*2,mass*2); - } - - PVector repel(Mover m) { - PVector force = PVector.sub(location,m.location); // Calculate direction of force - float distance = force.mag(); // Distance between objects - distance = constrain(distance,1.0,10000.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects - force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction - - float strength = (g * mass * m.mass) / (distance * distance); // Calculate gravitional force magnitude - force.mult(-1*strength); // Get force vector --> magnitude * direction - return force; - } - - void checkEdges() { - - if (location.x > width) { - location.x = width; - velocity.x *= -1; - } - else if (location.x < 0) { - location.x = 0; - velocity.x *= -1; - } - - if (location.y > height) { - location.y = height; - velocity.y *= -1; - } - else if (location.y < 0) { - location.y = 0; - velocity.y *= -1; - } - - } - -} - - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_attractrepel/NOC_02forces_attractrepel.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_attractrepel/NOC_02forces_attractrepel.pde deleted file mode 100644 index 1a4c37a61..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_attractrepel/NOC_02forces_attractrepel.pde +++ /dev/null @@ -1,52 +0,0 @@ -Mover[] movers = new Mover[20]; - -Attractor a; - -float g = 1; - -void setup() { - size(800,200); - smooth(); - a = new Attractor(); - for (int i = 0; i < movers.length; i++) { - movers[i] = new Mover(random(4,12),random(width),random(height)); - } -} - -void draw() { - background(255); - - a.display(); - - - for (int i = 0; i < movers.length; i++) { - for (int j = 0; j < movers.length; j++) { - if (i != j) { - PVector force = movers[j].repel(movers[i]); - movers[i].applyForce(force); - } - } - - PVector force = a.attract(movers[i]); - movers[i].applyForce(force); - movers[i].update(); - movers[i].display(); - } - - - -} - - - - - - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/Attractor.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/Attractor.pde deleted file mode 100644 index 36b144ae3..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/Attractor.pde +++ /dev/null @@ -1,39 +0,0 @@ -// Attraction -// Daniel Shiffman - -// A class for a draggable attractive body in our world - -class Attractor { - float mass; // Mass, tied to size - PVector location; // Location - float g; - - Attractor() { - location = new PVector(0,0); - mass = 20; - g = 0.4; - } - - - PVector attract(Mover m) { - PVector force = PVector.sub(location,m.location); // Calculate direction of force - float distance = force.mag(); // Distance between objects - distance = constrain(distance,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects - force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction) - float strength = (g * mass * m.mass) / (distance * distance); // Calculate gravitional force magnitude - force.mult(strength); // Get force vector --> magnitude * direction - return force; - } - - // Method to display - void display() { - stroke(255); - noFill(); - pushMatrix(); - translate(location.x,location.y,location.z); - sphere(mass*2); - popMatrix(); - } -} - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/Mover.pde deleted file mode 100644 index 5c9c79ea3..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/Mover.pde +++ /dev/null @@ -1,51 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float mass; - - Mover(float m, float x, float y, float z) { - mass = m; - location = new PVector(x,y,z); - velocity = new PVector(1,0); - acceleration = new PVector(0,0); - } - - void applyForce(PVector force) { - PVector f = PVector.div(force,mass); - acceleration.add(f); - } - - void update() { - velocity.add(acceleration); - location.add(velocity); - acceleration.mult(0); - } - - void display() { - noStroke(); - fill(255); - pushMatrix(); - translate(location.x,location.y,location.z); - sphere(mass*8); - popMatrix(); - } - - void checkEdges() { - - if (location.x > width) { - location.x = 0; - } - else if (location.x < 0) { - location.x = width; - } - - if (location.y > height) { - velocity.y *= -1; - location.y = height; - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/NOC_02forces_many_attraction_3D.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/NOC_02forces_many_attraction_3D.pde deleted file mode 100644 index e88b686c2..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/NOC_02forces_many_attraction_3D.pde +++ /dev/null @@ -1,50 +0,0 @@ -import processing.opengl.*; - -Mover[] movers = new Mover[10]; - -Attractor a; - -float angle = 0; - -void setup() { - size(800,200,OPENGL); - smooth(); - background(255); - for (int i = 0; i < movers.length; i++) { - movers[i] = new Mover(random(0.1,2),random(-width/2,width/2),random(-height/2,height/2),random(-100,100)); - } - a = new Attractor(); -} - -void draw() { - background(0); - sphereDetail(8); - lights(); - translate(width/2,height/2); - rotateY(angle); - - - a.display(); - - for (int i = 0; i < movers.length; i++) { - PVector force = a.attract(movers[i]); - movers[i].applyForce(force); - - movers[i].update(); - movers[i].display(); - } - - angle += 0.003; - -} - - - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/sketch.properties b/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/sketch.properties deleted file mode 100644 index 28faa5897..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=Standard diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/Mover.pde deleted file mode 100644 index b092ef546..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/Mover.pde +++ /dev/null @@ -1,70 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float mass; - - Mover(float m, float x, float y) { - mass = m; - location = new PVector(x, y); - velocity = new PVector(0, 0); - acceleration = new PVector(0, 0); - } - - void applyForce(PVector force) { - PVector f = PVector.div(force, mass); - acceleration.add(f); - } - - void update() { - velocity.add(acceleration); - location.add(velocity); - acceleration.mult(0); - } - - void display() { - stroke(0); - fill(175, 200); - ellipse(location.x, location.y, mass*16, mass*16); - } - - PVector attract(Mover m) { - PVector force = PVector.sub(location, m.location); // Calculate direction of force - float distance = force.mag(); // Distance between objects - distance = constrain(distance, 5.0, 25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects - force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction - - float strength = (g * mass * m.mass) / (distance * distance); // Calculate gravitional force magnitude - force.mult(strength); // Get force vector --> magnitude * direction - return force; - } - - void boundaries() { - - float d = 50; - - PVector force = new PVector(0, 0); - - if (location.x < d) { - force.x = 1; - } - else if (location.x > width -d) { - force.x = -1; - } - - if (location.y < d) { - force.y = 1; - } - else if (location.y > height-d) { - force.y = -1; - } - - force.normalize(); - force.mult(0.1); - - applyForce(force); - } -} - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/NOC_02forces_many_mutual_boundaries.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/NOC_02forces_many_mutual_boundaries.pde deleted file mode 100644 index 3ccfbe320..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/NOC_02forces_many_mutual_boundaries.pde +++ /dev/null @@ -1,44 +0,0 @@ -Mover[] movers = new Mover[20]; - -float g = 0.4; - -void setup() { - size(800,200); - smooth(); - for (int i = 0; i < movers.length; i++) { - movers[i] = new Mover(random(1,2),random(width),random(height)); - } -} - -void draw() { - background(255); - - - for (int i = 0; i < movers.length; i++) { - for (int j = 0; j < movers.length; j++) { - if (i != j) { - PVector force = movers[j].attract(movers[i]); - movers[i].applyForce(force); - } - } - - movers[i].boundaries(); - - movers[i].update(); - movers[i].display(); - } - -} - - - - - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/sketch.properties b/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/sketch.properties deleted file mode 100644 index 6d28cd598..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=JavaScript diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_1_forces/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_1_forces/Mover.pde deleted file mode 100644 index 2e13412b5..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_1_forces/Mover.pde +++ /dev/null @@ -1,53 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float mass; - - Mover() { - location = new PVector(30,30); - velocity = new PVector(0,0); - acceleration = new PVector(0,0); - mass = 1; - } - - void applyForce(PVector force) { - PVector f = PVector.div(force,mass); - acceleration.add(f); - } - - void update() { - velocity.add(acceleration); - location.add(velocity); - acceleration.mult(0); - } - - void display() { - stroke(0); - strokeWeight(2); - fill(127); - ellipse(location.x,location.y,48,48); - } - - void checkEdges() { - - if (location.x > width) { - location.x = width; - velocity.x *= -1; - } else if (location.x < 0) { - velocity.x *= -1; - location.x = 0; - } - - if (location.y > height) { - velocity.y *= -1; - location.y = height; - } - - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_1_forces/NOC_2_1_forces.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_1_forces/NOC_2_1_forces.pde deleted file mode 100644 index c87fd78e7..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_1_forces/NOC_2_1_forces.pde +++ /dev/null @@ -1,27 +0,0 @@ -Mover m; - -void setup() { - size(800,200); - smooth(); - m = new Mover(); -} - -void draw() { - background(255); - - PVector wind = new PVector(0.01,0); - PVector gravity = new PVector(0,0.1); - m.applyForce(wind); - m.applyForce(gravity); - - - m.update(); - m.display(); - m.checkEdges(); - -} - - - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_2_forces_many/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_2_forces_many/Mover.pde deleted file mode 100644 index 02f1804bb..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_2_forces_many/Mover.pde +++ /dev/null @@ -1,53 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float mass; - - Mover(float m, float x , float y) { - mass = m; - location = new PVector(x,y); - velocity = new PVector(0,0); - acceleration = new PVector(0,0); - } - - void applyForce(PVector force) { - PVector f = PVector.div(force,mass); - acceleration.add(f); - } - - void update() { - velocity.add(acceleration); - location.add(velocity); - acceleration.mult(0); - } - - void display() { - stroke(0); - strokeWeight(2); - fill(0,127); - ellipse(location.x,location.y,mass*16,mass*16); - } - - void checkEdges() { - - if (location.x > width) { - location.x = width; - velocity.x *= -1; - } else if (location.x < 0) { - velocity.x *= -1; - location.x = 0; - } - - if (location.y > height) { - velocity.y *= -1; - location.y = height; - } - - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_2_forces_many/NOC_2_2_forces_many.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_2_forces_many/NOC_2_2_forces_many.pde deleted file mode 100644 index bf22b65af..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_2_forces_many/NOC_2_2_forces_many.pde +++ /dev/null @@ -1,36 +0,0 @@ -Mover[] movers = new Mover[20]; - -void setup() { - size(800,200); - smooth(); - for (int i = 0; i < movers.length; i++) { - movers[i] = new Mover(random(0.1,4),0,0); - } -} - -void draw() { - background(255); - - for (int i = 0; i < movers.length; i++) { - - PVector wind = new PVector(0.01,0); - PVector gravity = new PVector(0,0.1); - - movers[i].applyForce(wind); - movers[i].applyForce(gravity); - - movers[i].update(); - movers[i].display(); - movers[i].checkEdges(); - } - -} - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_3_forces_many_realgravity/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_3_forces_many_realgravity/Mover.pde deleted file mode 100644 index 02f1804bb..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_3_forces_many_realgravity/Mover.pde +++ /dev/null @@ -1,53 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float mass; - - Mover(float m, float x , float y) { - mass = m; - location = new PVector(x,y); - velocity = new PVector(0,0); - acceleration = new PVector(0,0); - } - - void applyForce(PVector force) { - PVector f = PVector.div(force,mass); - acceleration.add(f); - } - - void update() { - velocity.add(acceleration); - location.add(velocity); - acceleration.mult(0); - } - - void display() { - stroke(0); - strokeWeight(2); - fill(0,127); - ellipse(location.x,location.y,mass*16,mass*16); - } - - void checkEdges() { - - if (location.x > width) { - location.x = width; - velocity.x *= -1; - } else if (location.x < 0) { - velocity.x *= -1; - location.x = 0; - } - - if (location.y > height) { - velocity.y *= -1; - location.y = height; - } - - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_3_forces_many_realgravity/NOC_2_3_forces_many_realgravity.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_3_forces_many_realgravity/NOC_2_3_forces_many_realgravity.pde deleted file mode 100644 index 377b98f02..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_3_forces_many_realgravity/NOC_2_3_forces_many_realgravity.pde +++ /dev/null @@ -1,34 +0,0 @@ -Mover[] movers = new Mover[20]; - -void setup() { - size(800, 200); - smooth(); - for (int i = 0; i < movers.length; i++) { - movers[i] = new Mover(random(1, 4), 0, 0); - } -} - -void draw() { - background(255); - - for (int i = 0; i < movers.length; i++) { - - PVector wind = new PVector(0.01, 0); - PVector gravity = new PVector(0, 0.1*movers[i].mass); - - movers[i].applyForce(wind); - movers[i].applyForce(gravity); - - movers[i].update(); - movers[i].display(); - movers[i].checkEdges(); - } -} - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_friction/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_friction/Mover.pde deleted file mode 100644 index 7fb1353b5..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_friction/Mover.pde +++ /dev/null @@ -1,53 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float mass; - - Mover(float m, float x , float y) { - mass = m; - location = new PVector(x,y); - velocity = new PVector(0,0); - acceleration = new PVector(0,0); - } - - void applyForce(PVector force) { - PVector f = PVector.div(force,mass); - acceleration.add(f); - } - - void update() { - velocity.add(acceleration); - location.add(velocity); - acceleration.mult(0); - } - - void display() { - stroke(0); - strokeWeight(2); - fill(0,127); - ellipse(location.x,location.y,mass*16,mass*16); - } - - void checkEdges() { - - if (location.x > width) { - location.x = width; - velocity.x *= -1; - } else if (location.x < 0) { - location.x = 0; - velocity.x *= -1; - } - - if (location.y > height) { - velocity.y *= -1; - location.y = height; - } - - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_friction/NOC_2_4_forces_friction.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_friction/NOC_2_4_forces_friction.pde deleted file mode 100644 index fccf7341c..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_friction/NOC_2_4_forces_friction.pde +++ /dev/null @@ -1,42 +0,0 @@ -Mover[] movers = new Mover[5]; - -void setup() { - size(383, 200); - randomSeed(1); - smooth(); - for (int i = 0; i < movers.length; i++) { - movers[i] = new Mover(random(1, 4), random(width), 0); - } -} - -void draw() { - background(255); - - for (int i = 0; i < movers.length; i++) { - - PVector wind = new PVector(0.01, 0); - PVector gravity = new PVector(0, 0.1*movers[i].mass); - - float c = 0.05; - PVector friction = movers[i].velocity.get(); - friction.mult(-1); - friction.normalize(); - friction.mult(c); - - movers[i].applyForce(friction); - movers[i].applyForce(wind); - movers[i].applyForce(gravity); - - movers[i].update(); - movers[i].display(); - movers[i].checkEdges(); - } -} - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_nofriction/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_nofriction/Mover.pde deleted file mode 100644 index 7fb1353b5..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_nofriction/Mover.pde +++ /dev/null @@ -1,53 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float mass; - - Mover(float m, float x , float y) { - mass = m; - location = new PVector(x,y); - velocity = new PVector(0,0); - acceleration = new PVector(0,0); - } - - void applyForce(PVector force) { - PVector f = PVector.div(force,mass); - acceleration.add(f); - } - - void update() { - velocity.add(acceleration); - location.add(velocity); - acceleration.mult(0); - } - - void display() { - stroke(0); - strokeWeight(2); - fill(0,127); - ellipse(location.x,location.y,mass*16,mass*16); - } - - void checkEdges() { - - if (location.x > width) { - location.x = width; - velocity.x *= -1; - } else if (location.x < 0) { - location.x = 0; - velocity.x *= -1; - } - - if (location.y > height) { - velocity.y *= -1; - location.y = height; - } - - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_nofriction/NOC_2_4_forces_nofriction.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_nofriction/NOC_2_4_forces_nofriction.pde deleted file mode 100644 index 23f0304e2..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_nofriction/NOC_2_4_forces_nofriction.pde +++ /dev/null @@ -1,42 +0,0 @@ -Mover[] movers = new Mover[5]; - -void setup() { - size(383, 200); - randomSeed(1); - smooth(); - for (int i = 0; i < movers.length; i++) { - movers[i] = new Mover(random(1, 4), random(width), 0); - } -} - -void draw() { - background(255); - - for (int i = 0; i < movers.length; i++) { - - PVector wind = new PVector(0.01, 0); - PVector gravity = new PVector(0, 0.1*movers[i].mass); - - float c = 0.05; - PVector friction = movers[i].velocity.get(); - friction.mult(-1); - friction.normalize(); - friction.mult(c); - - //movers[i].applyForce(friction); - movers[i].applyForce(wind); - movers[i].applyForce(gravity); - - movers[i].update(); - movers[i].display(); - movers[i].checkEdges(); - } -} - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/Liquid.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/Liquid.pde deleted file mode 100644 index ab0e3ee2d..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/Liquid.pde +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Forces (Gravity and Fluid Resistence) with Vectors - * by Daniel Shiffman. - * - * Demonstration of multiple force acting on bodies (Mover class) - * Bodies experience gravity continuously - * Bodies experience fluid resistance when in "water" - */ - - // Liquid class - class Liquid { - - - // Liquid is a rectangle - float x,y,w,h; - // Coefficient of drag - float c; - - Liquid(float x_, float y_, float w_, float h_, float c_) { - x = x_; - y = y_; - w = w_; - h = h_; - c = c_; - } - - // Is the Mover in the Liquid? - boolean contains(Mover m) { - PVector l = m.location; - if (l.x > x && l.x < x + w && l.y > y && l.y < y + h) { - return true; - } - else { - return false; - } - } - - // Calculate drag force - PVector drag(Mover m) { - // Magnitude is coefficient * speed squared - float speed = m.velocity.mag(); - float dragMagnitude = c * speed * speed; - - // Direction is inverse of velocity - PVector dragForce = m.velocity.get(); - dragForce.mult(-1); - - // Scale according to magnitude - // dragForce.setMag(dragMagnitude); - dragForce.normalize(); - dragForce.mult(dragMagnitude); - return dragForce; - } - - void display() { - noStroke(); - fill(50); - rect(x,y,w,h); - } - -} - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/Mover.pde deleted file mode 100644 index eaad60a81..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/Mover.pde +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Forces (Gravity and Fluid Resistence) with Vectors - * by Daniel Shiffman. - * - * Demonstration of multiple force acting on bodies (Mover class) - * Bodies experience gravity continuously - * Bodies experience fluid resistance when in "water" - */ - - -class Mover { - - // location, velocity, and acceleration - PVector location; - PVector velocity; - PVector acceleration; - - // Mass is tied to size - float mass; - - Mover(float m, float x, float y) { - mass = m; - location = new PVector(x, y); - velocity = new PVector(0, 0); - acceleration = new PVector(0, 0); - } - - // Newton's 2nd law: F = M * A - // or A = F / M - void applyForce(PVector force) { - // Divide by mass - PVector f = PVector.div(force, mass); - // Accumulate all forces in acceleration - acceleration.add(f); - } - - void update() { - - // Velocity changes according to acceleration - velocity.add(acceleration); - // Location changes by velocity - location.add(velocity); - // We must clear acceleration each frame - acceleration.mult(0); - } - - // Draw Mover - void display() { - stroke(0); - strokeWeight(2); - fill(127, 200); - ellipse(location.x, location.y, mass*16, mass*16); - } - - // Bounce off bottom of window - void checkEdges() { - if (location.y > height) { - velocity.y *= -0.9; // A little dampening when hitting the bottom - location.y = height; - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/NOC_2_5_fluidresistance.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/NOC_2_5_fluidresistance.pde deleted file mode 100644 index d1a2201c4..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/NOC_2_5_fluidresistance.pde +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Forces (Gravity and Fluid Resistence) with Vectors - * by Daniel Shiffman. - * - * Demonstration of multiple force acting on bodies (Mover class) - * Bodies experience gravity continuously - * Bodies experience fluid resistance when in "water" - */ - -// Five moving bodies -Mover[] movers = new Mover[11]; - -// Liquid -Liquid liquid; - -void setup() { - size(800, 200); - smooth(); - reset(); - // Create liquid object - liquid = new Liquid(0, height/2, width, height/2, 0.1); -} - -void draw() { - background(255); - - // Draw water - liquid.display(); - - for (int i = 0; i < movers.length; i++) { - - // Is the Mover in the liquid? - if (liquid.contains(movers[i])) { - // Calculate drag force - PVector dragForce = liquid.drag(movers[i]); - // Apply drag force to Mover - movers[i].applyForce(dragForce); - } - - // Gravity is scaled by mass here! - PVector gravity = new PVector(0, 0.1*movers[i].mass); - // Apply gravity - movers[i].applyForce(gravity); - - // Update and display - movers[i].update(); - movers[i].display(); - movers[i].checkEdges(); - } - - fill(0); - text("click mouse to reset",10,30); - -} - -void mousePressed() { - reset(); -} - -// Restart all the Mover objects randomly -void reset() { - for (int i = 0; i < movers.length; i++) { - movers[i] = new Mover(random(0.5, 3), 40+i*70, 0); - } -} - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/sketch.properties b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/sketch.properties deleted file mode 100644 index 28faa5897..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=Standard diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/Liquid.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/Liquid.pde deleted file mode 100644 index ab0e3ee2d..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/Liquid.pde +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Forces (Gravity and Fluid Resistence) with Vectors - * by Daniel Shiffman. - * - * Demonstration of multiple force acting on bodies (Mover class) - * Bodies experience gravity continuously - * Bodies experience fluid resistance when in "water" - */ - - // Liquid class - class Liquid { - - - // Liquid is a rectangle - float x,y,w,h; - // Coefficient of drag - float c; - - Liquid(float x_, float y_, float w_, float h_, float c_) { - x = x_; - y = y_; - w = w_; - h = h_; - c = c_; - } - - // Is the Mover in the Liquid? - boolean contains(Mover m) { - PVector l = m.location; - if (l.x > x && l.x < x + w && l.y > y && l.y < y + h) { - return true; - } - else { - return false; - } - } - - // Calculate drag force - PVector drag(Mover m) { - // Magnitude is coefficient * speed squared - float speed = m.velocity.mag(); - float dragMagnitude = c * speed * speed; - - // Direction is inverse of velocity - PVector dragForce = m.velocity.get(); - dragForce.mult(-1); - - // Scale according to magnitude - // dragForce.setMag(dragMagnitude); - dragForce.normalize(); - dragForce.mult(dragMagnitude); - return dragForce; - } - - void display() { - noStroke(); - fill(50); - rect(x,y,w,h); - } - -} - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/Mover.pde deleted file mode 100644 index 5500dc39d..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/Mover.pde +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Forces (Gravity and Fluid Resistence) with Vectors - * by Daniel Shiffman. - * - * Demonstration of multiple force acting on bodies (Mover class) - * Bodies experience gravity continuously - * Bodies experience fluid resistance when in "water" - */ - - -class Mover { - - // location, velocity, and acceleration - PVector location; - PVector velocity; - PVector acceleration; - - // Mass is tied to size - float mass; - - Mover(float m, float x, float y) { - mass = m; - location = new PVector(x, y); - velocity = new PVector(0, 0); - acceleration = new PVector(0, 0); - } - - // Newton's 2nd law: F = M * A - // or A = F / M - void applyForce(PVector force) { - // Divide by mass - PVector f = PVector.div(force, mass); - // Accumulate all forces in acceleration - acceleration.add(f); - } - - void update() { - - // Velocity changes according to acceleration - velocity.add(acceleration); - // Location changes by velocity - location.add(velocity); - // We must clear acceleration each frame - acceleration.mult(0); - } - - // Draw Mover - void display() { - stroke(0); - strokeWeight(2*2.25); - fill(127,200); - ellipse(location.x, location.y, mass*16, mass*16); - } - - // Bounce off bottom of window - void checkEdges() { - if (location.y > height) { - velocity.y *= -0.9; // A little dampening when hitting the bottom - location.y = height; - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/NOC_2_5_fluidresistance_sequence.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/NOC_2_5_fluidresistance_sequence.pde deleted file mode 100644 index aa712c059..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/NOC_2_5_fluidresistance_sequence.pde +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Forces (Gravity and Fluid Resistence) with Vectors - * by Daniel Shiffman. - * - * Demonstration of multiple force acting on bodies (Mover class) - * Bodies experience gravity continuously - * Bodies experience fluid resistance when in "water" - */ - -// Five moving bodies -Mover[] movers = new Mover[5]; - -// Liquid -Liquid liquid; - -void setup() { - size(450, 450); - smooth(); - randomSeed(1); - reset(); - // Create liquid object - liquid = new Liquid(0, height/2, width, height/2, 0.1); -} - -void draw() { - background(255); - - // Draw water - liquid.display(); - - for (int i = 0; i < movers.length; i++) { - - // Is the Mover in the liquid? - if (liquid.contains(movers[i])) { - // Calculate drag force - PVector dragForce = liquid.drag(movers[i]); - // Apply drag force to Mover - movers[i].applyForce(dragForce); - } - - // Gravity is scaled by mass here! - PVector gravity = new PVector(0, 0.1*movers[i].mass); - // Apply gravity - movers[i].applyForce(gravity); - - // Update and display - movers[i].update(); - movers[i].display(); - movers[i].checkEdges(); - } - - fill(255); - //text("click mouse to reset",10,30); - - if (frameCount % 20 == 0) saveFrame("ch2_05_####.png"); -} - -void mousePressed() { - reset(); -} - -// Restart all the Mover objects randomly -void reset() { - for (int i = 0; i < movers.length; i++) { - movers[i] = new Mover(random(0.5*2.25,3*2.25), 20*2.25+i*40*2.25, 0); - } -} - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/sketch.properties b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/sketch.properties deleted file mode 100644 index 28faa5897..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=Standard diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/Attractor.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/Attractor.pde deleted file mode 100644 index 62115f590..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/Attractor.pde +++ /dev/null @@ -1,77 +0,0 @@ -// Attraction -// Daniel Shiffman - -// A class for a draggable attractive body in our world - -class Attractor { - float mass; // Mass, tied to size - float G; // Gravitational Constant - PVector location; // Location - boolean dragging = false; // Is the object being dragged? - boolean rollover = false; // Is the mouse over the ellipse? - PVector dragOffset; // holds the offset for when object is clicked on - - Attractor() { - location = new PVector(width/2,height/2); - mass = 20; - G = 1; - dragOffset = new PVector(0.0,0.0); - } - - PVector attract(Mover m) { - PVector force = PVector.sub(location,m.location); // Calculate direction of force - float d = force.mag(); // Distance between objects - d = constrain(d,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects - force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction) - float strength = (G * mass * m.mass) / (d * d); // Calculate gravitional force magnitude - force.mult(strength); // Get force vector --> magnitude * direction - return force; - } - - // Method to display - void display() { - ellipseMode(CENTER); - strokeWeight(4); - stroke(0); - if (dragging) fill (50); - else if (rollover) fill(100); - else fill(175,200); - ellipse(location.x,location.y,mass*2,mass*2); - } - - // The methods below are for mouse interaction - void clicked(int mx, int my) { - float d = dist(mx,my,location.x,location.y); - if (d < mass) { - dragging = true; - dragOffset.x = location.x-mx; - dragOffset.y = location.y-my; - } - } - - void hover(int mx, int my) { - float d = dist(mx,my,location.x,location.y); - if (d < mass) { - rollover = true; - } - else { - rollover = false; - } - } - - void stopDragging() { - dragging = false; - } - - - - void drag() { - if (dragging) { - location.x = mouseX + dragOffset.x; - location.y = mouseY + dragOffset.y; - } - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/Mover.pde deleted file mode 100644 index ec2069b99..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/Mover.pde +++ /dev/null @@ -1,51 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float mass; - - Mover() { - location = new PVector(400,50); - velocity = new PVector(1,0); - acceleration = new PVector(0,0); - mass = 1; - } - - void applyForce(PVector force) { - PVector f = PVector.div(force,mass); - acceleration.add(f); - } - - void update() { - velocity.add(acceleration); - location.add(velocity); - acceleration.mult(0); - } - - void display() { - stroke(0); - strokeWeight(2); - fill(127); - ellipse(location.x,location.y,16,16); - } - - void checkEdges() { - - if (location.x > width) { - location.x = 0; - } else if (location.x < 0) { - location.x = width; - } - - if (location.y > height) { - velocity.y *= -1; - location.y = height; - } - - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/NOC_2_6_attraction.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/NOC_2_6_attraction.pde deleted file mode 100644 index 320ddc5ba..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/NOC_2_6_attraction.pde +++ /dev/null @@ -1,36 +0,0 @@ -Mover m; -Attractor a; - -void setup() { - size(800,200); - smooth(); - m = new Mover(); - a = new Attractor(); -} - -void draw() { - background(255); - - PVector force = a.attract(m); - m.applyForce(force); - m.update(); - - a.drag(); - a.hover(mouseX,mouseY); - - a.display(); - m.display(); -} - -void mousePressed() { - a.clicked(mouseX,mouseY); -} - -void mouseReleased() { - a.stopDragging(); -} - - - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/sketch.properties b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/sketch.properties deleted file mode 100644 index 6d28cd598..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=JavaScript diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/Attractor.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/Attractor.pde deleted file mode 100644 index 62115f590..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/Attractor.pde +++ /dev/null @@ -1,77 +0,0 @@ -// Attraction -// Daniel Shiffman - -// A class for a draggable attractive body in our world - -class Attractor { - float mass; // Mass, tied to size - float G; // Gravitational Constant - PVector location; // Location - boolean dragging = false; // Is the object being dragged? - boolean rollover = false; // Is the mouse over the ellipse? - PVector dragOffset; // holds the offset for when object is clicked on - - Attractor() { - location = new PVector(width/2,height/2); - mass = 20; - G = 1; - dragOffset = new PVector(0.0,0.0); - } - - PVector attract(Mover m) { - PVector force = PVector.sub(location,m.location); // Calculate direction of force - float d = force.mag(); // Distance between objects - d = constrain(d,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects - force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction) - float strength = (G * mass * m.mass) / (d * d); // Calculate gravitional force magnitude - force.mult(strength); // Get force vector --> magnitude * direction - return force; - } - - // Method to display - void display() { - ellipseMode(CENTER); - strokeWeight(4); - stroke(0); - if (dragging) fill (50); - else if (rollover) fill(100); - else fill(175,200); - ellipse(location.x,location.y,mass*2,mass*2); - } - - // The methods below are for mouse interaction - void clicked(int mx, int my) { - float d = dist(mx,my,location.x,location.y); - if (d < mass) { - dragging = true; - dragOffset.x = location.x-mx; - dragOffset.y = location.y-my; - } - } - - void hover(int mx, int my) { - float d = dist(mx,my,location.x,location.y); - if (d < mass) { - rollover = true; - } - else { - rollover = false; - } - } - - void stopDragging() { - dragging = false; - } - - - - void drag() { - if (dragging) { - location.x = mouseX + dragOffset.x; - location.y = mouseY + dragOffset.y; - } - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/Mover.pde deleted file mode 100644 index 91712f09d..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/Mover.pde +++ /dev/null @@ -1,33 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float mass; - - Mover(float m, float x, float y) { - mass = m; - location = new PVector(random(width), random(height)); - velocity = new PVector(1, 0); - acceleration = new PVector(0, 0); - } - - void applyForce(PVector force) { - PVector f = PVector.div(force, mass); - acceleration.add(f); - } - - void update() { - velocity.add(acceleration); - location.add(velocity); - acceleration.mult(0); - } - - void display() { - stroke(0); - strokeWeight(2); - fill(0,100); - ellipse(location.x, location.y, mass*25, mass*25); - } -} - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/NOC_2_7_attraction_many.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/NOC_2_7_attraction_many.pde deleted file mode 100644 index a213c79be..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/NOC_2_7_attraction_many.pde +++ /dev/null @@ -1,46 +0,0 @@ -Mover[] movers = new Mover[10]; - -Attractor a; - -void setup() { - size(800, 200); - smooth(); - for (int i = 0; i < movers.length; i++) { - movers[i] = new Mover(random(0.1, 2), random(width), random(height)); - } - a = new Attractor(); - } - -void draw() { - background(255); - - a.display(); - a.drag(); - a.hover(mouseX, mouseY); - - for (int i = 0; i < movers.length; i++) { - PVector force = a.attract(movers[i]); - movers[i].applyForce(force); - - movers[i].update(); - movers[i].display(); - } -} - -void mousePressed() { - a.clicked(mouseX, mouseY); -} - -void mouseReleased() { - a.stopDragging(); -} - - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/Mover.pde deleted file mode 100644 index 30c49d701..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/Mover.pde +++ /dev/null @@ -1,48 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float mass; - - Mover(float m, float x, float y) { - mass = m; - location = new PVector(x, y); - velocity = new PVector(0, 0); - acceleration = new PVector(0, 0); - } - - void applyForce(PVector force) { - PVector f = PVector.div(force, mass); - acceleration.add(f); - } - - void update() { - velocity.add(acceleration); - location.add(velocity); - acceleration.mult(0); - } - - void display() { - stroke(0); - strokeWeight(2); - fill(0, 100); - ellipse(location.x, location.y, mass*24, mass*24); - } - - PVector attract(Mover m) { - PVector force = PVector.sub(location, m.location); // Calculate direction of force - float distance = force.mag(); // Distance between objects - distance = constrain(distance, 5.0, 25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects - force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction - - float strength = (g * mass * m.mass) / (distance * distance); // Calculate gravitional force magnitude - force.mult(strength); // Get force vector --> magnitude * direction - return force; - } - - -} - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/NOC_2_8_mutual_attraction.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/NOC_2_8_mutual_attraction.pde deleted file mode 100644 index 905140372..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/NOC_2_8_mutual_attraction.pde +++ /dev/null @@ -1,42 +0,0 @@ -Mover[] movers = new Mover[20]; - -float g = 0.4; - -void setup() { - size(800,200); - smooth(); - for (int i = 0; i < movers.length; i++) { - movers[i] = new Mover(random(0.1,2),random(width),random(height)); - } -} - -void draw() { - background(255); - - - for (int i = 0; i < movers.length; i++) { - for (int j = 0; j < movers.length; j++) { - if (i != j) { - PVector force = movers[j].attract(movers[i]); - movers[i].applyForce(force); - } - } - - movers[i].update(); - movers[i].display(); - } - -} - - - - - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/sketch.properties b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/sketch.properties deleted file mode 100644 index 6d28cd598..000000000 --- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=JavaScript diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/AdditiveWave/AdditiveWave.pde b/java/examples/Books/Nature of Code/chp3_oscillation/AdditiveWave/AdditiveWave.pde deleted file mode 100644 index 888f4b142..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/AdditiveWave/AdditiveWave.pde +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Additive Wave - * by Daniel Shiffman. - * - * Create a more complex wave by adding two waves together. - */ - -// Maybe better for this answer to be OOP??? - -int xspacing = 8; // How far apart should each horizontal location be spaced -int w; // Width of entire wave -int maxwaves = 5; // total # of waves to add together - -float theta = 0.0; -float[] amplitude = new float[maxwaves]; // Height of wave -float[] dx = new float[maxwaves]; // Value for incrementing X, to be calculated as a function of period and xspacing -float[] yvalues; // Using an array to store height values for the wave (not entirely necessary) - -void setup() { - size(640,360); - colorMode(RGB, 255, 255, 255, 100); - smooth(); - w = width + 16; - - for (int i = 0; i < maxwaves; i++) { - amplitude[i] = random(10,30); - float period = random(100,300); // How many pixels before the wave repeats - dx[i] = (TWO_PI / period) * xspacing; - } - - yvalues = new float[w/xspacing]; -} - -void draw() { - background(0); - calcWave(); - renderWave(); -} - -void calcWave() { - // Increment theta (try different values for 'angular velocity' here - theta += 0.02; - - // Set all height values to zero - for (int i = 0; i < yvalues.length; i++) { - yvalues[i] = 0; - } - - // Accumulate wave height values - for (int j = 0; j < maxwaves; j++) { - float x = theta; - for (int i = 0; i < yvalues.length; i++) { - // Every other wave is cosine instead of sine - if (j % 2 == 0) yvalues[i] += sin(x)*amplitude[j]; - else yvalues[i] += cos(x)*amplitude[j]; - x+=dx[j]; - } - } -} - -void renderWave() { - // A simple way to draw the wave with an ellipse at each location - noStroke(); - fill(255,50); - ellipseMode(CENTER); - for (int x = 0; x < yvalues.length; x++) { - ellipse(x*xspacing,height/2+yvalues[x],16,16); - } -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/AttractionArrayWithOscillation.pde b/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/AttractionArrayWithOscillation.pde deleted file mode 100644 index abfa74f4e..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/AttractionArrayWithOscillation.pde +++ /dev/null @@ -1,46 +0,0 @@ -// Attraction Array with Oscillating objects around each Crawler -// Daniel Shiffman -// Nature of Code, Spring 2012 - -// Click and drag attractive body to move throughout space - -Crawler[] crawlers = new Crawler[6]; -Attractor a; - -void setup() { - size(640,360); - smooth(); - - // Some random bodies - for (int i = 0; i < crawlers.length; i++) { - crawlers[i] = new Crawler(); - } - // Create an attractive body - a = new Attractor(new PVector(width/2,height/2),20,0.4); -} - -void draw() { - background(255); - a.rollover(mouseX,mouseY); - a.go(); - - for (int i = 0; i < crawlers.length; i++) { - // Calculate a force exerted by "attractor" on "Crawler" - PVector f = a.attract(crawlers[i]); - // Apply that force to the Crawler - crawlers[i].applyForce(f); - // Update and render - crawlers[i].update(); - crawlers[i].display(); - } - - -} - -void mousePressed() { - a.clicked(mouseX,mouseY); -} - -void mouseReleased() { - a.stopDragging(); -} diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Attractor.pde b/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Attractor.pde deleted file mode 100644 index b725c771a..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Attractor.pde +++ /dev/null @@ -1,81 +0,0 @@ -// Attraction -// Daniel Shiffman -// Nature of Code, Spring 2009 - - -// A class for a draggable attractive body in our world - -class Attractor { - float mass; // Mass, tied to size - float G; // Gravitational Constant - PVector loc; // Location - boolean dragging = false; // Is the object being dragged? - boolean rollover = false; // Is the mouse over the ellipse? - PVector drag; // holds the offset for when object is clicked on - - Attractor(PVector l_,float m_, float g_) { - loc = l_.get(); - mass = m_; - G = g_; - drag = new PVector(0.0,0.0); - } - - void go() { - render(); - drag(); - } - - PVector attract(Crawler c) { - PVector dir = PVector.sub(loc,c.loc); // Calculate direction of force - float d = dir.mag(); // Distance between objects - d = constrain(d,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects - dir.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction) - float force = (G * mass * c.mass) / (d * d); // Calculate gravitional force magnitude - dir.mult(force); // Get force vector --> magnitude * direction - return dir; - } - - // Method to display - void render() { - ellipseMode(CENTER); - stroke(0,100); - if (dragging) fill (50); - else if (rollover) fill(100); - else fill(175,50); - ellipse(loc.x,loc.y,mass*2,mass*2); - } - - // The methods below are for mouse interaction - void clicked(int mx, int my) { - float d = dist(mx,my,loc.x,loc.y); - if (d < mass) { - dragging = true; - drag.x = loc.x-mx; - drag.y = loc.y-my; - } - } - - void rollover(int mx, int my) { - float d = dist(mx,my,loc.x,loc.y); - if (d < mass) { - rollover = true; - } else { - rollover = false; - } - } - - void stopDragging() { - dragging = false; - } - - - - void drag() { - if (dragging) { - loc.x = mouseX + drag.x; - loc.y = mouseY + drag.y; - } - } - -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Crawler.pde b/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Crawler.pde deleted file mode 100644 index 35ae63222..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Crawler.pde +++ /dev/null @@ -1,56 +0,0 @@ -// Attraction -// Daniel Shiffman -// Nature of Code, Spring 2012 - -// A class to describe a thing in our world, has vectors for location, velocity, and acceleration -// Also includes scalar values for mass, maximum velocity, and elasticity - -class Crawler { - PVector loc; - PVector vel; - PVector acc; - float mass; - - Oscillator osc; - - Crawler() { - acc = new PVector(); - vel = new PVector(random(-1,1),random(-1,1)); - loc = new PVector(random(width),random(height)); - mass = random(8,16); - osc = new Oscillator(mass*2); - } - - void applyForce(PVector force) { - PVector f = force.get(); - f.div(mass); - acc.add(f); - } - - // Method to update location - void update() { - vel.add(acc); - loc.add(vel); - // Multiplying by 0 sets the all the components to 0 - acc.mult(0); - - osc.update(vel.mag()/10); - } - - // Method to display - void display() { - float angle = vel.heading2D(); - pushMatrix(); - translate(loc.x,loc.y); - rotate(angle); - ellipseMode(CENTER); - stroke(0); - fill(175,100); - ellipse(0,0,mass*2,mass*2); - - osc.display(loc); - popMatrix(); - - } -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Oscillator.pde b/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Oscillator.pde deleted file mode 100644 index 624156fbf..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Oscillator.pde +++ /dev/null @@ -1,35 +0,0 @@ -// Attraction Array with Oscillating objects around each thing -// Daniel Shiffman -// Nature of Code, Spring 2009 - -class Oscillator { - - // Because we are going to oscillate along the x and y axis we can use PVector for two angles, amplitudes, etc.! - float theta; - float amplitude; - - Oscillator(float r) { - - // Initialize randomly - theta = 0; - amplitude = r; - - } - - // Update theta and offset - void update(float thetaVel) { - theta += thetaVel; - } - - // Display based on a location - void display(PVector loc) { - float x = map(cos(theta),-1,1,0,amplitude); - - stroke(0); - fill(50); - line(0,0,x,0); - ellipse(x,0,8,8); - } -} - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_01_exercise_baton/Exercise_3_01_exercise_baton.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_01_exercise_baton/Exercise_3_01_exercise_baton.pde deleted file mode 100644 index 3eadcc85e..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_01_exercise_baton/Exercise_3_01_exercise_baton.pde +++ /dev/null @@ -1,24 +0,0 @@ -float angle = 0; - -void setup() { - size(750, 150); - smooth(); -} - -void draw() { - background(255); - - fill(127); - stroke(0); - rectMode(CENTER); - translate(width/2, height/2); - rotate(angle); - line(-50, 0, 50, 0); - stroke(0); - strokeWeight(2); - fill(127); - ellipse(50, 0, 16, 16); - ellipse(-50, 0, 16, 16); - angle += 0.05; -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_04_spiral/Exercise_3_04_spiral.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_04_spiral/Exercise_3_04_spiral.pde deleted file mode 100644 index 94611d5b0..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_04_spiral/Exercise_3_04_spiral.pde +++ /dev/null @@ -1,30 +0,0 @@ -// Nature of Code -// Daniel Shiffman -// http://www.learningprocessing.com - -// A Polar coordinate, radius now starts at 0 to spiral outwards -float r = 0; -float theta = 0; - -void setup() { - size(750,200); - background(255); - smooth(); -} - -void draw() { - // Polar to Cartesian conversion - float x = r * cos(theta); - float y = r * sin(theta); - - // Draw an ellipse at x,y - noStroke(); - fill(0); - // Adjust for center of window - ellipse(x+width/2, y+height/2, 16, 16); - - // Increment the angle - theta += 0.01; - // Increment the radius - r += 0.05; -} diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_05_asteroids/Exercise_3_05_asteroids.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_05_asteroids/Exercise_3_05_asteroids.pde deleted file mode 100644 index 239de3fd2..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_05_asteroids/Exercise_3_05_asteroids.pde +++ /dev/null @@ -1,41 +0,0 @@ -// Nature of Code 2011 -// Daniel Shiffman -// Chapter 3: Asteroids exercise -// http://www.shiffman.net - -// Mover object -Spaceship ship; - -void setup() { - size(750, 200); - smooth(); - ship = new Spaceship(); -} - -void draw() { - background(255); - - // Update location - ship.update(); - // Wrape edges - ship.wrapEdges(); - // Draw ship - ship.display(); - - - fill(0); - text("left right arrows to turn, z to thrust",10,height-5); - - // Turn or thrust the ship depending on what key is pressed - if (keyPressed) { - if (key == CODED && keyCode == LEFT) { - ship.turn(-0.03); - } else if (key == CODED && keyCode == RIGHT) { - ship.turn(0.03); - } else if (key == 'z' || key == 'Z') { - ship.thrust(); - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_05_asteroids/Spaceship.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_05_asteroids/Spaceship.pde deleted file mode 100644 index 1910c7243..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_05_asteroids/Spaceship.pde +++ /dev/null @@ -1,97 +0,0 @@ -// Nature of Code 2011 -// Daniel Shiffman -// Chapter 3: Asteroids - -class Spaceship { - // All of our regular motion stuff - PVector location; - PVector velocity; - PVector acceleration; - - // Arbitrary damping to slow down ship - float damping = 0.995; - float topspeed = 6; - - // Variable for heading! - float heading = 0; - - // Size - float r = 16; - - // Are we thrusting (to color boosters) - boolean thrusting = false; - - Spaceship() { - location = new PVector(width/2,height/2); - velocity = new PVector(); - acceleration = new PVector(); - } - - // Standard Euler integration - void update() { - velocity.add(acceleration); - velocity.mult(damping); - velocity.limit(topspeed); - location.add(velocity); - acceleration.mult(0); - } - - // Newton's law: F = M * A - void applyForce(PVector force) { - PVector f = force.get(); - //f.div(mass); // ignoring mass right now - acceleration.add(f); - } - - // Turn changes angle - void turn(float a) { - heading += a; - } - - // Apply a thrust force - void thrust() { - // Offset the angle since we drew the ship vertically - float angle = heading - PI/2; - // Polar to cartesian for force vector! - PVector force = new PVector(cos(angle),sin(angle)); - force.mult(0.1); - applyForce(force); - // To draw booster - thrusting = true; - } - - void wrapEdges() { - float buffer = r*2; - if (location.x > width + buffer) location.x = -buffer; - else if (location.x < -buffer) location.x = width+buffer; - if (location.y > height + buffer) location.y = -buffer; - else if (location.y < -buffer) location.y = height+buffer; - } - - - // Draw the ship - void display() { - stroke(0); - strokeWeight(2); - pushMatrix(); - translate(location.x,location.y+r); - rotate(heading); - fill(175); - if (thrusting) fill(255,0,0); - // Booster rockets - rect(-r/2,r,r/3,r/2); - rect(r/2,r,r/3,r/2); - fill(175); - // A triangle - beginShape(); - vertex(-r,r); - vertex(0,-r); - vertex(r,r); - endShape(CLOSE); - rectMode(CENTER); - popMatrix(); - - thrusting = false; - } -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_10_OOPWave/Exercise_3_10_OOPWave.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_10_OOPWave/Exercise_3_10_OOPWave.pde deleted file mode 100644 index be26ff0f4..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_10_OOPWave/Exercise_3_10_OOPWave.pde +++ /dev/null @@ -1,31 +0,0 @@ -// Sine Wave -// Daniel Shiffman - - -// Two wave objects -Wave wave0; -Wave wave1; - -void setup() { - size(750,200); - smooth(); - // Initialize a wave with starting point, width, amplitude, and period - wave0 = new Wave(new PVector(50,75),100,20,500); - wave1 = new Wave(new PVector(300,100),300,40,220); - -} - -void draw() { - background(255); - - // Update and display waves - wave0.calculate(); - wave0.display(); - - wave1.calculate(); - wave1.display(); - - -} - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_10_OOPWave/Wave.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_10_OOPWave/Wave.pde deleted file mode 100644 index 1ecf976c0..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_10_OOPWave/Wave.pde +++ /dev/null @@ -1,45 +0,0 @@ -class Wave { - - int xspacing = 8; // How far apart should each horizontal location be spaced - int w; // Width of entire wave - - PVector origin; // Where does the wave's first point start - float theta = 0.0; // Start angle at 0 - float amplitude; // Height of wave - float period; // How many pixels before the wave repeats - float dx; // Value for incrementing X, to be calculated as a function of period and xspacing - float[] yvalues; // Using an array to store height values for the wave (not entirely necessary) - - Wave(PVector o, int w_, float a, float p) { - origin = o.get(); - w = w_; - period = p; - amplitude = a; - dx = (TWO_PI / period) * xspacing; - yvalues = new float[w/xspacing]; - } - - - void calculate() { - // Increment theta (try different values for 'angular velocity' here - theta += 0.02; - - // For every x value, calculate a y value with sine function - float x = theta; - for (int i = 0; i < yvalues.length; i++) { - yvalues[i] = sin(x)*amplitude; - x+=dx; - } - } - - void display() { - // A simple way to draw the wave with an ellipse at each location - for (int x = 0; x < yvalues.length; x++) { - stroke(0); - fill(0,50); - ellipseMode(CENTER); - ellipse(origin.x+x*xspacing,origin.y+yvalues[x],48,48); - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_11_AdditiveWave/Exercise_3_11_AdditiveWave.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_11_AdditiveWave/Exercise_3_11_AdditiveWave.pde deleted file mode 100644 index 316721bef..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_11_AdditiveWave/Exercise_3_11_AdditiveWave.pde +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Additive Wave - * by Daniel Shiffman. - * - * Create a more complex wave by adding two waves together. - */ - -// Maybe better for this answer to be OOP??? - -int xspacing = 8; // How far apart should each horizontal location be spaced -int w; // Width of entire wave -int maxwaves = 5; // total # of waves to add together - -float theta = 0.0; -float[] amplitude = new float[maxwaves]; // Height of wave -float[] dx = new float[maxwaves]; // Value for incrementing X, to be calculated as a function of period and xspacing -float[] yvalues; // Using an array to store height values for the wave (not entirely necessary) - -void setup() { - size(750,200); - smooth(); - w = width + 16; - - for (int i = 0; i < maxwaves; i++) { - amplitude[i] = random(10,30); - float period = random(100,300); // How many pixels before the wave repeats - dx[i] = (TWO_PI / period) * xspacing; - } - - yvalues = new float[w/xspacing]; -} - -void draw() { - background(255); - calcWave(); - renderWave(); -} - -void calcWave() { - // Increment theta (try different values for 'angular velocity' here - theta += 0.02; - - // Set all height values to zero - for (int i = 0; i < yvalues.length; i++) { - yvalues[i] = 0; - } - - // Accumulate wave height values - for (int j = 0; j < maxwaves; j++) { - float x = theta; - for (int i = 0; i < yvalues.length; i++) { - // Every other wave is cosine instead of sine - if (j % 2 == 0) yvalues[i] += sin(x)*amplitude[j]; - else yvalues[i] += cos(x)*amplitude[j]; - x+=dx[j]; - } - } -} - -void renderWave() { - // A simple way to draw the wave with an ellipse at each location - stroke(0); - fill(127,50); - ellipseMode(CENTER); - for (int x = 0; x < yvalues.length; x++) { - ellipse(x*xspacing,height/2+yvalues[x],48,48); - } -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_03spring_exercise_sine/NOC_03spring_exercise_sine.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_03spring_exercise_sine/NOC_03spring_exercise_sine.pde deleted file mode 100644 index 26ba2c139..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_03spring_exercise_sine/NOC_03spring_exercise_sine.pde +++ /dev/null @@ -1,21 +0,0 @@ -float angle = 0; -float aVelocity = 0.05; - -void setup() { - size(640,360); - smooth(); -} - -void draw() { - background(255); - - float x = width/2; - float y = map(sin(angle),-1,1,50,250); - angle += aVelocity; - - ellipseMode(CENTER); - stroke(0); - fill(175); - line(x,0,x,y); - ellipse(x,y,20,20); -} diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_01_angular_motion/NOC_3_01_angular_motion.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_01_angular_motion/NOC_3_01_angular_motion.pde deleted file mode 100644 index f88335f6b..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_01_angular_motion/NOC_3_01_angular_motion.pde +++ /dev/null @@ -1,30 +0,0 @@ -float angle = 0; -float aVelocity = 0; -float aAcceleration = 0.0001; - -void setup() { - size(800, 200); - smooth(); -} - -void draw() { - background(255); - - - fill(127); - stroke(0); - - translate(width/2, height/2); - rectMode(CENTER); - rotate(angle); - stroke(0); - strokeWeight(2); - fill(127); - line(-60, 0, 60, 0); - ellipse(60, 0, 16, 16); - ellipse(-60, 0, 16, 16); - - angle += aVelocity; - aVelocity += aAcceleration; -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_01_angular_motion_trail/NOC_3_01_angular_motion_trail.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_01_angular_motion_trail/NOC_3_01_angular_motion_trail.pde deleted file mode 100644 index c33166cf9..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_01_angular_motion_trail/NOC_3_01_angular_motion_trail.pde +++ /dev/null @@ -1,35 +0,0 @@ -float angle = 0; -float aVelocity = 0; -float aAcceleration = 0.0001; - -void setup() { - size(800, 200); - background(255); - smooth(); -} - -void draw() { - //background(255); - rectMode(CORNER); - noStroke(); - fill(255,5); - rect(0,0,width,height); - - - fill(127); - stroke(0); - - translate(width/2, height/2); - rectMode(CENTER); - rotate(angle); - stroke(0); - strokeWeight(2); - fill(127); - line(-60, 0, 60, 0); - ellipse(60, 0, 16, 16); - ellipse(-60, 0, 16, 16); - - angle += aVelocity; - aVelocity += aAcceleration; -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_mot_trails/Attractor.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_mot_trails/Attractor.pde deleted file mode 100644 index 56628fdf1..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_mot_trails/Attractor.pde +++ /dev/null @@ -1,36 +0,0 @@ -// Attraction -// Daniel Shiffman - -// A class for a draggable attractive body in our world - -class Attractor { - float mass; // Mass, tied to size - PVector location; // Location - float g; - - Attractor() { - location = new PVector(width/2, height/2); - mass = 20; - g = 0.4; - } - - - PVector attract(Mover m) { - PVector force = PVector.sub(location, m.location); // Calculate direction of force - float distance = force.mag(); // Distance between objects - distance = constrain(distance, 5.0, 25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects - force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction) - float strength = (g * mass * m.mass) / (distance * distance); // Calculate gravitional force magnitude - force.mult(strength); // Get force vector --> magnitude * direction - return force; - } - - // Method to display - void display() { - stroke(0); - strokeWeight(2); - fill(127); - ellipse(location.x, location.y, 48, 48); - } -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_mot_trails/Mover.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_mot_trails/Mover.pde deleted file mode 100644 index 1ff6e5750..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_mot_trails/Mover.pde +++ /dev/null @@ -1,49 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float mass; - - float angle = 0; - float aVelocity = 0; - float aAcceleration = 0; - - Mover(float m, float x, float y) { - mass = m; - location = new PVector(x,y); - velocity = new PVector(random(-1,1),random(-1,1)); - acceleration = new PVector(0,0); - } - - void applyForce(PVector force) { - PVector f = PVector.div(force,mass); - acceleration.add(f); - } - - void update() { - - velocity.add(acceleration); - location.add(velocity); - - aAcceleration = acceleration.x / 10.0; - aVelocity += aAcceleration; - aVelocity = constrain(aVelocity,-0.1,0.1); - angle += aVelocity; - - acceleration.mult(0); - } - - void display() { - stroke(0); - fill(175,200); - rectMode(CENTER); - pushMatrix(); - translate(location.x,location.y); - rotate(angle); - rect(0,0,mass*16,mass*16); - popMatrix(); - } - -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_mot_trails/NOC_3_02_forces_angular_mot_trails.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_mot_trails/NOC_3_02_forces_angular_mot_trails.pde deleted file mode 100644 index ec850608d..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_mot_trails/NOC_3_02_forces_angular_mot_trails.pde +++ /dev/null @@ -1,44 +0,0 @@ -Mover[] movers = new Mover[20]; - -Attractor a; - -void setup() { - size(800,200); - smooth(); - background(255); - for (int i = 0; i < movers.length; i++) { - movers[i] = new Mover(random(0.1,2),random(width),random(height)); - } - a = new Attractor(); -} - -void draw() { - //background(255); - - rectMode(CORNER); - noStroke(); - fill(255,5); - rect(0,0,width,height); - - a.display(); - - for (int i = 0; i < movers.length; i++) { - PVector force = a.attract(movers[i]); - movers[i].applyForce(force); - - movers[i].update(); - movers[i].display(); - } - -} - - - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/Attractor.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/Attractor.pde deleted file mode 100644 index 56628fdf1..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/Attractor.pde +++ /dev/null @@ -1,36 +0,0 @@ -// Attraction -// Daniel Shiffman - -// A class for a draggable attractive body in our world - -class Attractor { - float mass; // Mass, tied to size - PVector location; // Location - float g; - - Attractor() { - location = new PVector(width/2, height/2); - mass = 20; - g = 0.4; - } - - - PVector attract(Mover m) { - PVector force = PVector.sub(location, m.location); // Calculate direction of force - float distance = force.mag(); // Distance between objects - distance = constrain(distance, 5.0, 25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects - force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction) - float strength = (g * mass * m.mass) / (distance * distance); // Calculate gravitional force magnitude - force.mult(strength); // Get force vector --> magnitude * direction - return force; - } - - // Method to display - void display() { - stroke(0); - strokeWeight(2); - fill(127); - ellipse(location.x, location.y, 48, 48); - } -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/Mover.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/Mover.pde deleted file mode 100644 index 1ff6e5750..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/Mover.pde +++ /dev/null @@ -1,49 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float mass; - - float angle = 0; - float aVelocity = 0; - float aAcceleration = 0; - - Mover(float m, float x, float y) { - mass = m; - location = new PVector(x,y); - velocity = new PVector(random(-1,1),random(-1,1)); - acceleration = new PVector(0,0); - } - - void applyForce(PVector force) { - PVector f = PVector.div(force,mass); - acceleration.add(f); - } - - void update() { - - velocity.add(acceleration); - location.add(velocity); - - aAcceleration = acceleration.x / 10.0; - aVelocity += aAcceleration; - aVelocity = constrain(aVelocity,-0.1,0.1); - angle += aVelocity; - - acceleration.mult(0); - } - - void display() { - stroke(0); - fill(175,200); - rectMode(CENTER); - pushMatrix(); - translate(location.x,location.y); - rotate(angle); - rect(0,0,mass*16,mass*16); - popMatrix(); - } - -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/NOC_3_02_forces_angular_motion.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/NOC_3_02_forces_angular_motion.pde deleted file mode 100644 index c5c454ea5..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/NOC_3_02_forces_angular_motion.pde +++ /dev/null @@ -1,39 +0,0 @@ -Mover[] movers = new Mover[20]; - -Attractor a; - -void setup() { - size(800,200); - smooth(); - background(255); - for (int i = 0; i < movers.length; i++) { - movers[i] = new Mover(random(0.1,2),random(width),random(height)); - } - a = new Attractor(); -} - -void draw() { - background(255); - - a.display(); - - for (int i = 0; i < movers.length; i++) { - PVector force = a.attract(movers[i]); - movers[i].applyForce(force); - - movers[i].update(); - movers[i].display(); - } - -} - - - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/Mover.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/Mover.pde deleted file mode 100644 index b3f9f770b..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/Mover.pde +++ /dev/null @@ -1,65 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float topspeed; - - float xoff, yoff; - - float r = 16; - - Mover() { - location = new PVector(width/2, height/2); - velocity = new PVector(0, 0); - topspeed = 4; - xoff = 1000; - yoff = 0; - } - - void update() { - - PVector mouse = new PVector(mouseX, mouseY); - PVector dir = PVector.sub(mouse, location); - dir.normalize(); - dir.mult(0.5); - acceleration = dir; - - velocity.add(acceleration); - velocity.limit(topspeed); - location.add(velocity); - } - - void display() { - float theta = velocity.heading2D(); - - stroke(0); - strokeWeight(2); - fill(127); - pushMatrix(); - rectMode(CENTER); - translate(location.x, location.y); - rotate(theta); - rect(0, 0, 30, 10); - popMatrix(); - } - - void checkEdges() { - - if (location.x > width) { - location.x = 0; - } - else if (location.x < 0) { - location.x = width; - } - - if (location.y > height) { - location.y = 0; - } - else if (location.y < 0) { - location.y = height; - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/NOC_3_03_pointing_velocity.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/NOC_3_03_pointing_velocity.pde deleted file mode 100644 index eb3d55ee4..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/NOC_3_03_pointing_velocity.pde +++ /dev/null @@ -1,17 +0,0 @@ -Mover mover; - -void setup() { - size(800,200); - smooth(); - mover = new Mover(); -} - -void draw() { - background(255); - - mover.update(); - mover.checkEdges(); - mover.display(); -} - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity_trail/Mover.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity_trail/Mover.pde deleted file mode 100644 index b3f9f770b..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity_trail/Mover.pde +++ /dev/null @@ -1,65 +0,0 @@ -class Mover { - - PVector location; - PVector velocity; - PVector acceleration; - float topspeed; - - float xoff, yoff; - - float r = 16; - - Mover() { - location = new PVector(width/2, height/2); - velocity = new PVector(0, 0); - topspeed = 4; - xoff = 1000; - yoff = 0; - } - - void update() { - - PVector mouse = new PVector(mouseX, mouseY); - PVector dir = PVector.sub(mouse, location); - dir.normalize(); - dir.mult(0.5); - acceleration = dir; - - velocity.add(acceleration); - velocity.limit(topspeed); - location.add(velocity); - } - - void display() { - float theta = velocity.heading2D(); - - stroke(0); - strokeWeight(2); - fill(127); - pushMatrix(); - rectMode(CENTER); - translate(location.x, location.y); - rotate(theta); - rect(0, 0, 30, 10); - popMatrix(); - } - - void checkEdges() { - - if (location.x > width) { - location.x = 0; - } - else if (location.x < 0) { - location.x = width; - } - - if (location.y > height) { - location.y = 0; - } - else if (location.y < 0) { - location.y = height; - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity_trail/NOC_3_03_pointing_velocity_trail.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity_trail/NOC_3_03_pointing_velocity_trail.pde deleted file mode 100644 index d0d7f776e..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity_trail/NOC_3_03_pointing_velocity_trail.pde +++ /dev/null @@ -1,25 +0,0 @@ -Mover mover; - -void setup() { - size(800,200); - background(255); - smooth(); - mover = new Mover(); -} - -void draw() { - if (mousePressed) { - //background(255); - rectMode(CORNER); - noStroke(); - fill(255,5); - rect(0,0,width,height); - - mover.update(); - mover.checkEdges(); - mover.display(); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_04_PolarToCartesian/NOC_3_04_PolarToCartesian.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_04_PolarToCartesian/NOC_3_04_PolarToCartesian.pde deleted file mode 100644 index 070f60e14..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_04_PolarToCartesian/NOC_3_04_PolarToCartesian.pde +++ /dev/null @@ -1,50 +0,0 @@ -/** - * PolarToCartesian - * by Daniel Shiffman. - * - * Convert a polar coordinate (r,theta) to cartesian (x,y): - * x = r * cos(theta) - * y = r * sin(theta) - */ - -float r; -float theta; - - -void setup() { - size(800, 200); - smooth(); - - // Initialize all values - r = height * 0.45; - theta = 0; -} - -void draw() { - - background(255); - - // Translate the origin point to the center of the screen - translate(width/2, height/2); - - // Convert polar to cartesian - float x = r * cos(theta); - float y = r * sin(theta); - - // Draw the ellipse at the cartesian coordinate - ellipseMode(CENTER); - fill(127); - stroke(0); - strokeWeight(2); - line(0,0,x,y); - ellipse(x, y, 48, 48); - - // Increase the angle over time - theta += 0.02; - - -} - - - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_04_PolarToCartesian_trail/NOC_3_04_PolarToCartesian_trail.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_04_PolarToCartesian_trail/NOC_3_04_PolarToCartesian_trail.pde deleted file mode 100644 index 6e8a2ca40..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_04_PolarToCartesian_trail/NOC_3_04_PolarToCartesian_trail.pde +++ /dev/null @@ -1,54 +0,0 @@ -/** - * PolarToCartesian - * by Daniel Shiffman. - * - * Convert a polar coordinate (r,theta) to cartesian (x,y): - * x = r * cos(theta) - * y = r * sin(theta) - */ - -float r; -float theta; - - -void setup() { - size(800, 200); - background(255); - smooth(); - - // Initialize all values - r = height * 0.45; - theta = 0; -} - -void draw() { - - //background(255); - noStroke(); - fill(255,5); - rect(0,0,width,height); - - // Translate the origin point to the center of the screen - translate(width/2, height/2); - - // Convert polar to cartesian - float x = r * cos(theta); - float y = r * sin(theta); - - // Draw the ellipse at the cartesian coordinate - ellipseMode(CENTER); - fill(127); - stroke(0); - strokeWeight(2); - line(0,0,x,y); - ellipse(x, y, 48, 48); - - // Increase the angle over time - theta += 0.02; - - -} - - - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_05_simple_harmonic_mot_trail/NOC_3_05_simple_harmonic_mot_trail.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_05_simple_harmonic_mot_trail/NOC_3_05_simple_harmonic_mot_trail.pde deleted file mode 100644 index 3676ac9f8..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_05_simple_harmonic_mot_trail/NOC_3_05_simple_harmonic_mot_trail.pde +++ /dev/null @@ -1,20 +0,0 @@ -void setup() { - size(800,200); - background(255); -} - -void draw() { - noStroke(); - fill(255,5); - rect(0,0,width,height); - float period = 120; - float amplitude = 300; - // Calculating horizontal location according to formula for simple harmonic motion - float x = amplitude * cos(TWO_PI * frameCount / period); - stroke(0); - strokeWeight(2); - fill(127); - translate(width/2,height/2); - line(0,0,x,0); - ellipse(x,0,48,48); -} diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_05_simple_harmonic_motion/NOC_3_05_simple_harmonic_motion.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_05_simple_harmonic_motion/NOC_3_05_simple_harmonic_motion.pde deleted file mode 100644 index e03a0cb6b..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_05_simple_harmonic_motion/NOC_3_05_simple_harmonic_motion.pde +++ /dev/null @@ -1,18 +0,0 @@ -void setup() { - size(800,200); -} - -void draw() { - background(255); - - float period = 120; - float amplitude = 300; - // Calculating horizontal location according to formula for simple harmonic motion - float x = amplitude * cos(TWO_PI * frameCount / period); - stroke(0); - strokeWeight(2); - fill(127); - translate(width/2,height/2); - line(0,0,x,0); - ellipse(x,0,48,48); -} diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_06_simple_harmonic_motion/NOC_3_06_simple_harmonic_motion.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_06_simple_harmonic_motion/NOC_3_06_simple_harmonic_motion.pde deleted file mode 100644 index 1ce795598..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_06_simple_harmonic_motion/NOC_3_06_simple_harmonic_motion.pde +++ /dev/null @@ -1,23 +0,0 @@ -float angle = 0; -float aVelocity = 0.03; - -void setup() { - size(640,360); - - smooth(); -} - -void draw() { - background(255); - - float amplitude = 300; - float x = amplitude * cos(angle); - angle += aVelocity; - - ellipseMode(CENTER); - stroke(0); - fill(175); - translate(width/2,height/2); - line(0,0,x,0); - ellipse(x,0,20,20); -} diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects/NOC_3_07_oscillating_objects.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects/NOC_3_07_oscillating_objects.pde deleted file mode 100644 index 5f9403c8d..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects/NOC_3_07_oscillating_objects.pde +++ /dev/null @@ -1,33 +0,0 @@ -// Learning Processing -// Daniel Shiffman -// http://www.learningprocessing.com - -// Exercise 13-6: Encapsulate Example 13-6 into an Oscillator object. Create an array -// of Oscillators, each moving at diff erent rates along the x and y axes. Here is some code for the -// Oscillator class to help you get started. - -// An array of objects -Oscillator[] oscillators = new Oscillator[10]; - -void setup() { - size(800,200); - smooth(); - // Initialize all objects - for (int i = 0; i < oscillators.length; i++) { - oscillators[i] = new Oscillator(); - } - background(255); -} - -void draw() { - background(255); - // Run all objects - for (int i = 0; i < oscillators.length; i++) { - oscillators[i].oscillate(); - oscillators[i].display(); - } -} - - - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects/Oscillator.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects/Oscillator.pde deleted file mode 100644 index 3377681b6..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects/Oscillator.pde +++ /dev/null @@ -1,33 +0,0 @@ -class Oscillator { - - PVector angle; - PVector velocity; - PVector amplitude; - - Oscillator() { - angle = new PVector(); - velocity = new PVector(random(-0.05, 0.05), random(-0.05, 0.05)); - amplitude = new PVector(random(20,width/2), random(20,height/2)); - } - - void oscillate() { - angle.add(velocity); - } - - void display() { - - float x = sin(angle.x)*amplitude.x; - float y = sin(angle.y)*amplitude.y; - - pushMatrix(); - translate(width/2, height/2); - stroke(0); - strokeWeight(2); - fill(127,127); - line(0, 0, x, y); - ellipse(x, y, 32, 32); - popMatrix(); - } -} - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects_trail/NOC_3_07_oscillating_objects_trail.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects_trail/NOC_3_07_oscillating_objects_trail.pde deleted file mode 100644 index 2d8c739b3..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects_trail/NOC_3_07_oscillating_objects_trail.pde +++ /dev/null @@ -1,36 +0,0 @@ -// Learning Processing -// Daniel Shiffman -// http://www.learningprocessing.com - -// Exercise 13-6: Encapsulate Example 13-6 into an Oscillator object. Create an array -// of Oscillators, each moving at diff erent rates along the x and y axes. Here is some code for the -// Oscillator class to help you get started. - -// An array of objects -Oscillator[] oscillators = new Oscillator[10]; - -void setup() { - size(800,200); - smooth(); - // Initialize all objects - for (int i = 0; i < oscillators.length; i++) { - oscillators[i] = new Oscillator(); - } - background(255); -} - -void draw() { - rectMode(CORNER); - noStroke(); - fill(255,10); - rect(0,0,width,height); - // Run all objects - for (int i = 0; i < oscillators.length; i++) { - oscillators[i].oscillate(); - oscillators[i].display(); - } -} - - - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects_trail/Oscillator.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects_trail/Oscillator.pde deleted file mode 100644 index 3377681b6..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects_trail/Oscillator.pde +++ /dev/null @@ -1,33 +0,0 @@ -class Oscillator { - - PVector angle; - PVector velocity; - PVector amplitude; - - Oscillator() { - angle = new PVector(); - velocity = new PVector(random(-0.05, 0.05), random(-0.05, 0.05)); - amplitude = new PVector(random(20,width/2), random(20,height/2)); - } - - void oscillate() { - angle.add(velocity); - } - - void display() { - - float x = sin(angle.x)*amplitude.x; - float y = sin(angle.y)*amplitude.y; - - pushMatrix(); - translate(width/2, height/2); - stroke(0); - strokeWeight(2); - fill(127,127); - line(0, 0, x, y); - ellipse(x, y, 32, 32); - popMatrix(); - } -} - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_08_static_wave_lines/NOC_3_08_static_wave_lines.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_08_static_wave_lines/NOC_3_08_static_wave_lines.pde deleted file mode 100644 index 91a3d91d4..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_08_static_wave_lines/NOC_3_08_static_wave_lines.pde +++ /dev/null @@ -1,19 +0,0 @@ -float angle = 0; -float angleVel = 0.1; - -size(800,200); -background(255); -smooth(); - -stroke(0); -strokeWeight(2); -noFill(); - -beginShape(); -for (int x = 0; x <= width; x += 5) { - float y = map(sin(angle),-1,1,0,height); - vertex(x,y); - angle +=angleVel; -} -endShape(); - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_exercise_additive_wave/NOC_3_09_exercise_additive_wave.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_exercise_additive_wave/NOC_3_09_exercise_additive_wave.pde deleted file mode 100644 index 888f4b142..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_exercise_additive_wave/NOC_3_09_exercise_additive_wave.pde +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Additive Wave - * by Daniel Shiffman. - * - * Create a more complex wave by adding two waves together. - */ - -// Maybe better for this answer to be OOP??? - -int xspacing = 8; // How far apart should each horizontal location be spaced -int w; // Width of entire wave -int maxwaves = 5; // total # of waves to add together - -float theta = 0.0; -float[] amplitude = new float[maxwaves]; // Height of wave -float[] dx = new float[maxwaves]; // Value for incrementing X, to be calculated as a function of period and xspacing -float[] yvalues; // Using an array to store height values for the wave (not entirely necessary) - -void setup() { - size(640,360); - colorMode(RGB, 255, 255, 255, 100); - smooth(); - w = width + 16; - - for (int i = 0; i < maxwaves; i++) { - amplitude[i] = random(10,30); - float period = random(100,300); // How many pixels before the wave repeats - dx[i] = (TWO_PI / period) * xspacing; - } - - yvalues = new float[w/xspacing]; -} - -void draw() { - background(0); - calcWave(); - renderWave(); -} - -void calcWave() { - // Increment theta (try different values for 'angular velocity' here - theta += 0.02; - - // Set all height values to zero - for (int i = 0; i < yvalues.length; i++) { - yvalues[i] = 0; - } - - // Accumulate wave height values - for (int j = 0; j < maxwaves; j++) { - float x = theta; - for (int i = 0; i < yvalues.length; i++) { - // Every other wave is cosine instead of sine - if (j % 2 == 0) yvalues[i] += sin(x)*amplitude[j]; - else yvalues[i] += cos(x)*amplitude[j]; - x+=dx[j]; - } - } -} - -void renderWave() { - // A simple way to draw the wave with an ellipse at each location - noStroke(); - fill(255,50); - ellipseMode(CENTER); - for (int x = 0; x < yvalues.length; x++) { - ellipse(x*xspacing,height/2+yvalues[x],16,16); - } -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave/NOC_3_09_wave.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave/NOC_3_09_wave.pde deleted file mode 100644 index 5eb61b28b..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave/NOC_3_09_wave.pde +++ /dev/null @@ -1,28 +0,0 @@ - -float startAngle = 0; -float angleVel = 0.23; - -void setup() { - size(800,200); - smooth(); -} - -void draw() { - background(255); - - startAngle += 0.015; - float angle = startAngle; - - for (int x = 0; x <= width; x += 24) { - float y = map(sin(angle),-1,1,0,height); - stroke(0); - fill(0,50); - strokeWeight(2); - ellipse(x,y,48,48); - angle += angleVel; - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_a/NOC_3_09_wave_a.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_a/NOC_3_09_wave_a.pde deleted file mode 100644 index b4a96efba..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_a/NOC_3_09_wave_a.pde +++ /dev/null @@ -1,28 +0,0 @@ - -float startAngle = 0; -float angleVel = 0.05; - -void setup() { - size(250,200); - smooth(); -} - -void draw() { - background(255); - - startAngle += 0.015; - float angle = startAngle; - - for (int x = 0; x <= width; x += 24) { - float y = map(sin(angle),-1,1,0,height); - stroke(0); - fill(0,50); - strokeWeight(2); - ellipse(x,y,48,48); - angle += angleVel; - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_b/NOC_3_09_wave_b.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_b/NOC_3_09_wave_b.pde deleted file mode 100644 index 9749647db..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_b/NOC_3_09_wave_b.pde +++ /dev/null @@ -1,28 +0,0 @@ - -float startAngle = 0; -float angleVel = 0.2; - -void setup() { - size(250,200); - smooth(); -} - -void draw() { - background(255); - - startAngle += 0.015; - float angle = startAngle; - - for (int x = 0; x <= width; x += 24) { - float y = map(sin(angle),-1,1,0,height); - stroke(0); - fill(0,50); - strokeWeight(2); - ellipse(x,y,48,48); - angle += angleVel; - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_c/NOC_3_09_wave_c.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_c/NOC_3_09_wave_c.pde deleted file mode 100644 index 74349d4f4..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_c/NOC_3_09_wave_c.pde +++ /dev/null @@ -1,28 +0,0 @@ - -float startAngle = 0; -float angleVel = 0.4; - -void setup() { - size(250,200); - smooth(); -} - -void draw() { - background(255); - - startAngle += 0.015; - float angle = startAngle; - - for (int x = 0; x <= width; x += 24) { - float y = map(sin(angle),-1,1,0,height); - stroke(0); - fill(0,50); - strokeWeight(2); - ellipse(x,y,48,48); - angle += angleVel; - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExample/NOC_3_10_PendulumExample.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExample/NOC_3_10_PendulumExample.pde deleted file mode 100644 index 2a455823a..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExample/NOC_3_10_PendulumExample.pde +++ /dev/null @@ -1,43 +0,0 @@ -// Pendulum -// Daniel Shiffman - -// A simple pendulum simulation -// Given a pendulum with an angle theta (0 being the pendulum at rest) and a radius r -// we can use sine to calculate the angular component of the gravitational force. - -// Gravity Force = Mass * Gravitational Constant; -// Pendulum Force = Gravity Force * sine(theta) -// Angular Acceleration = Pendulum Force / Mass = gravitational acceleration * sine(theta); - -// Note this is an ideal world scenario with no tension in the -// pendulum arm, a more realistic formula might be: -// Angular Acceleration = (g / R) * sine(theta) - -// For a more substantial explanation, visit: -// http://www.myphysicslab.com/pendulum1.html - -Pendulum p; - -void setup() { - size(800,200); - smooth(); - - // Make a new Pendulum with an origin location and armlength - p = new Pendulum(new PVector(width/2,0),175); - -} - -void draw() { - - background(255); - p.go(); -} - -void mousePressed() { - p.clicked(mouseX,mouseY); -} - -void mouseReleased() { - p.stopDragging(); -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExample/Pendulum.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExample/Pendulum.pde deleted file mode 100644 index 260f793b2..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExample/Pendulum.pde +++ /dev/null @@ -1,95 +0,0 @@ -// Pendulum -// Daniel Shiffman - -// A Simple Pendulum Class -// Includes functionality for user can click and drag the pendulum - -class Pendulum { - - PVector location; // Location of pendulum ball - PVector origin; // Location of arm origin - float r; // Length of arm - float angle; // Pendulum arm angle - float aVelocity; // Angle velocity - float aAcceleration; // Angle acceleration - - float ballr; // Ball radius - float damping; // Arbitary damping amount - - boolean dragging = false; - - // This constructor could be improved to allow a greater variety of pendulums - Pendulum(PVector origin_, float r_) { - // Fill all variables - origin = origin_.get(); - location = new PVector(); - r = r_; - angle = PI/4; - - aVelocity = 0.0; - aAcceleration = 0.0; - damping = 0.995; // Arbitrary damping - ballr = 48.0; // Arbitrary ball radius - } - - void go() { - update(); - drag(); //for user interaction - display(); - } - - // Function to update location - void update() { - // As long as we aren't dragging the pendulum, let it swing! - if (!dragging) { - float gravity = 0.4; // Arbitrary constant - aAcceleration = (-1 * gravity / r) * sin(angle); // Calculate acceleration (see: http://www.myphysicslab.com/pendulum1.html) - aVelocity += aAcceleration; // Increment velocity - aVelocity *= damping; // Arbitrary damping - angle += aVelocity; // Increment angle - } - } - - void display() { - location.set(r*sin(angle), r*cos(angle), 0); // Polar to cartesian conversion - location.add(origin); // Make sure the location is relative to the pendulum's origin - - stroke(0); - strokeWeight(2); - // Draw the arm - line(origin.x, origin.y, location.x, location.y); - ellipseMode(CENTER); - fill(175); - if (dragging) fill(0); - // Draw the ball - ellipse(location.x, location.y, ballr, ballr); - } - - - // The methods below are for mouse interaction - - // This checks to see if we clicked on the pendulum ball - void clicked(int mx, int my) { - float d = dist(mx, my, location.x, location.y); - if (d < ballr) { - dragging = true; - } - } - - // This tells us we are not longer clicking on the ball - void stopDragging() { - aVelocity = 0; // No velocity once you let go - dragging = false; - } - - void drag() { - // If we are draging the ball, we calculate the angle between the - // pendulum origin and mouse location - // we assign that angle to the pendulum - if (dragging) { - PVector diff = PVector.sub(origin, new PVector(mouseX, mouseY)); // Difference between 2 points - angle = atan2(-1*diff.y, diff.x) - radians(90); // Angle relative to vertical axis - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExampleSimplified/NOC_3_10_PendulumExampleSimplified.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExampleSimplified/NOC_3_10_PendulumExampleSimplified.pde deleted file mode 100644 index b40d7fea8..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExampleSimplified/NOC_3_10_PendulumExampleSimplified.pde +++ /dev/null @@ -1,34 +0,0 @@ -// Pendulum -// Daniel Shiffman - -// A simple pendulum simulation -// Given a pendulum with an angle theta (0 being the pendulum at rest) and a radius r -// we can use sine to calculate the angular component of the gravitational force. - -// Gravity Force = Mass * Gravitational Constant; -// Pendulum Force = Gravity Force * sine(theta) -// Angular Acceleration = Pendulum Force / Mass = Gravitational Constant * sine(theta); - -// Note this is an ideal world scenario with no tension in the -// pendulum arm, a more realistic formula might be: -// Angular Acceleration = (G / R) * sine(theta) - -// For a more substantial explanation, visit: -// http://www.myphysicslab.com/pendulum1.html - -Pendulum p; - -void setup() { - size(800,200); - smooth(); - - // Make a new Pendulum with an origin location and armlength - p = new Pendulum(new PVector(width/2,0),175); - -} - -void draw() { - background(255); - p.go(); -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExampleSimplified/Pendulum.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExampleSimplified/Pendulum.pde deleted file mode 100644 index 72d1e8cf9..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExampleSimplified/Pendulum.pde +++ /dev/null @@ -1,61 +0,0 @@ -// Pendulum -// Daniel Shiffman - -// A Simple Pendulum Class -// Includes functionality for user can click and drag the pendulum - -class Pendulum { - - PVector location; // Location of pendulum ball - PVector origin; // Location of arm origin - float r; // Length of arm - float angle; // Pendulum arm angle - float aVelocity; // Angle velocity - float aAcceleration; // Angle acceleration - float damping; // Arbitary damping amount - - // This constructor could be improved to allow a greater variety of pendulums - Pendulum(PVector origin_, float r_) { - // Fill all variables - origin = origin_.get(); - location = new PVector(); - r = r_; - angle = PI/4; - - aVelocity = 0.0; - aAcceleration = 0.0; - damping = 0.995; // Arbitrary damping - } - - void go() { - update(); - display(); - } - - // Function to update location - void update() { - float gravity = 0.4; // Arbitrary constant - aAcceleration = (-1 * gravity / r) * sin(angle); // Calculate acceleration (see: http://www.myphysicslab.com/pendulum1.html) - aVelocity += aAcceleration; // Increment velocity - aVelocity *= damping; // Arbitrary damping - angle += aVelocity; // Increment angle - } - - void display() { - location.set(r*sin(angle), r*cos(angle), 0); // Polar to cartesian conversion - location.add(origin); // Make sure the location is relative to the pendulum's origin - - stroke(0); - strokeWeight(2); - // Draw the arm - line(origin.x, origin.y, location.x, location.y); - ellipseMode(CENTER); - fill(175); - // Draw the ball - ellipse(location.x, location.y, 48, 48); - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/Mover.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/Mover.pde deleted file mode 100644 index b25dcda65..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/Mover.pde +++ /dev/null @@ -1,78 +0,0 @@ -// Nature of Code 2011 -// Daniel Shiffman -// Chapter 3: Oscillation - -// Bob class, just like our regular Mover (location, velocity, acceleration, mass) - -class Bob { - PVector location; - PVector velocity; - PVector acceleration; - float mass = 24; - - // Arbitrary damping to simulate friction / drag - float damping = 0.98; - - // For mouse interaction - PVector dragOffset; - boolean dragging = false; - - // Constructor - Bob(float x, float y) { - location = new PVector(x,y); - velocity = new PVector(); - acceleration = new PVector(); - dragOffset = new PVector(); - } - - // Standard Euler integration - void update() { - velocity.add(acceleration); - velocity.mult(damping); - location.add(velocity); - acceleration.mult(0); - } - - // Newton's law: F = M * A - void applyForce(PVector force) { - PVector f = force.get(); - f.div(mass); - acceleration.add(f); - } - - - // Draw the bob - void display() { - stroke(0); - strokeWeight(2); - fill(175); - if (dragging) { - fill(50); - } - ellipse(location.x,location.y,mass*2,mass*2); - } - - // The methods below are for mouse interaction - - // This checks to see if we clicked on the mover - void clicked(int mx, int my) { - float d = dist(mx,my,location.x,location.y); - if (d < mass) { - dragging = true; - dragOffset.x = location.x-mx; - dragOffset.y = location.y-my; - } - } - - void stopDragging() { - dragging = false; - } - - void drag(int mx, int my) { - if (dragging) { - location.x = mx + dragOffset.x; - location.y = my + dragOffset.y; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/NOC_3_11_spring.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/NOC_3_11_spring.pde deleted file mode 100644 index 57c8c7212..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/NOC_3_11_spring.pde +++ /dev/null @@ -1,61 +0,0 @@ -// Nature of Code 2011 -// Daniel Shiffman -// Chapter 3: Oscillation -// Mover attached to spring connection -// PVector -// http://www.shiffman.net - - -// Mover object -Bob bob; - -// Spring object -Spring spring; - -void setup() { - size(800,200); - smooth(); - // Create objects at starting location - // Note third argument in Spring constructor is "rest length" - spring = new Spring(width/2,10,100); - bob = new Bob(width/2,100); - -} - -void draw() { - background(255); - // Apply a gravity force to the bob - PVector gravity = new PVector(0,2); - bob.applyForce(gravity); - - // Connect the bob to the spring (this calculates the force) - spring.connect(bob); - // Constrain spring distance between min and max - spring.constrainLength(bob,30,200); - - // Update bob - bob.update(); - // If it's being dragged - bob.drag(mouseX,mouseY); - - // Draw everything - spring.displayLine(bob); // Draw a line between spring and bob - bob.display(); - spring.display(); - - fill(0); - text("click on bob to drag",10,height-5); -} - - -// For mouse interaction with bob - -void mousePressed() { - bob.clicked(mouseX,mouseY); -} - -void mouseReleased() { - bob.stopDragging(); -} - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/Spring.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/Spring.pde deleted file mode 100644 index 565fbb307..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/Spring.pde +++ /dev/null @@ -1,75 +0,0 @@ -// Nature of Code 2011 -// Daniel Shiffman -// Chapter 3: Oscillation - -// Class to describe an anchor point that can connect to "Bob" objects via a spring -// Thank you: http://www.myphysicslab.com/spring2d.html - -class Spring { - - // Location - PVector anchor; - - // Rest length and spring constant - float len; - float k = 0.2; - - // Constructor - Spring(float x, float y, int l) { - anchor = new PVector(x, y); - len = l; - } - - // Calculate spring force - void connect(Bob b) { - // Vector pointing from anchor to bob location - PVector force = PVector.sub(b.location, anchor); - // What is distance - float d = force.mag(); - // Stretch is difference between current distance and rest length - float stretch = d - len; - - // Calculate force according to Hooke's Law - // F = k * stretch - force.normalize(); - force.mult(-1 * k * stretch); - b.applyForce(force); - } - - // Constrain the distance between bob and anchor between min and max - void constrainLength(Bob b, float minlen, float maxlen) { - PVector dir = PVector.sub(b.location, anchor); - float d = dir.mag(); - // Is it too short? - if (d < minlen) { - dir.normalize(); - dir.mult(minlen); - // Reset location and stop from moving (not realistic physics) - b.location = PVector.add(anchor, dir); - b.velocity.mult(0); - // Is it too long? - } - else if (d > maxlen) { - dir.normalize(); - dir.mult(maxlen); - // Reset location and stop from moving (not realistic physics) - b.location = PVector.add(anchor, dir); - b.velocity.mult(0); - } - } - - void display() { - stroke(0); - fill(175); - strokeWeight(2); - rectMode(CENTER); - rect(anchor.x, anchor.y, 10, 10); - } - - void displayLine(Bob b) { - strokeWeight(2); - stroke(0); - line(b.location.x, b.location.y, anchor.x, anchor.y); - } -} - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/sketch.properties b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/sketch.properties deleted file mode 100644 index b3cbe600e..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/sketch.properties +++ /dev/null @@ -1,2 +0,0 @@ -mode.id=processing.mode.java.JavaMode -mode=Standard diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/OOPWaveParticles.pde b/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/OOPWaveParticles.pde deleted file mode 100644 index 9cf9e3b3d..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/OOPWaveParticles.pde +++ /dev/null @@ -1,31 +0,0 @@ -// Sine Wave -// Daniel Shiffman - - -// Two wave objects -Wave wave0; -Wave wave1; - -void setup() { - size(640,360); - smooth(); - // Initialize a wave with starting point, width, amplitude, and period - wave0 = new Wave(new PVector(200,75),100,20,500); - wave1 = new Wave(new PVector(150,250),300,40,220); - -} - -void draw() { - background(255); - - // Update and display waves - wave0.calculate(); - wave0.display(); - - wave1.calculate(); - wave1.display(); - - -} - - diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/Particle.pde b/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/Particle.pde deleted file mode 100644 index ca6d677d2..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/Particle.pde +++ /dev/null @@ -1,20 +0,0 @@ - -class Particle { - PVector location; - - Particle() { - location = new PVector(); - } - - void setLocation(float x, float y) { - location.x = x; - location.y = y; - } - - void display() { - fill(random(255)); - ellipse(location.x,location.y,16,16); - } - - -} diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/Wave.pde b/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/Wave.pde deleted file mode 100644 index cd54393be..000000000 --- a/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/Wave.pde +++ /dev/null @@ -1,52 +0,0 @@ -class Wave { - - int xspacing = 8; // How far apart should each horizontal location be spaced - int w; // Width of entire wave - - PVector origin; // Where does the wave's first point start - float theta = 0.0; // Start angle at 0 - float amplitude; // Height of wave - float period; // How many pixels before the wave repeats - float dx; // Value for incrementing X, to be calculated as a function of period and xspacing - //float[] yvalues; // Using an array to store height values for the wave (not entirely necessary) - Particle[] particles; - - Wave(PVector o, int w_, float a, float p) { - origin = o.get(); - w = w_; - period = p; - amplitude = a; - dx = (TWO_PI / period) * xspacing; - particles = new Particle[w/xspacing]; - for (int i = 0; i < particles.length; i++) { - particles[i] = new Particle(); - } - } - - - void calculate() { - // Increment theta (try different values for 'angular velocity' here - theta += 0.02; - - // For every x value, calculate a y value with sine function - float x = theta; - for (int i = 0; i < particles.length; i++) { - particles[i].setLocation(origin.x+i*xspacing,origin.y+sin(x)*amplitude); - x+=dx; - } - } - - void manipulate() { - // Loop through the array of particles and check stuff regarding the mouse - - } - - void display() { - - // A simple way to draw the wave with an ellipse at each location - for (int i = 0; i < particles.length; i++) { - particles[i].display(); - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/CircleVsBlob.pde b/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/CircleVsBlob.pde deleted file mode 100644 index d552e3d74..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/CircleVsBlob.pde +++ /dev/null @@ -1,28 +0,0 @@ -// Smoke Particle System -// Daniel Shiffman - -// A basic smoke effect using a particle system -// Each particle is rendered as an alpha masked image - - -void setup() { - size(200,200); - smooth(); - PImage img = loadImage("texture.png"); - background(0); - image(img,0,0,width,height); - save("blob.tif"); - - background(0); - fill(255); - noStroke(); - ellipse(100,100,width,height); - save("circle.tif"); -} - -void draw() { - - -} - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/blob.tif b/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/blob.tif deleted file mode 100644 index 62b3058e45db3d32555fa9fd3be07d2ad10481bc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 120768 zcmeF)3A`o!R^Ih{xrF&%z(9xuql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r3cz|l(q%)G zv7BpgMOk?hh%itH%22D1NK~cE;0Lpj8tC$VB4Yw(qK60r1CK#S(=xP62@h|aMuyzV;;sP)OWellM3pPT= z5L>QvfQTc;lJ~~!h_vxLk4#sh*h3Q)y;{?eI}rq964CVtREg&`y0@QQ-LQ0*D^fgC zA2vP#bTC;F+P)c!-{lI%;#yq}9_@D8cl%no%9|0c1W@O1w3@EuBF`xNk-<#2fF<3{ zz)D&u8o#hkVJ7bz;OJ%>JvPbC+k0^;Pdae2=!nt?U`n+kY}h*&(e@O@Fp85a{p#c@ djGbJithRmd^sCdaG|#?Yoqe!d;eXf%e*-a@C7u8P diff --git a/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/circle.tif b/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/circle.tif deleted file mode 100644 index 101ae87753b3f6fc1c7b07684f9bc9cb5ffe9ff5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 120768 zcmeI5ze_Aj7RUXuEUR)+5#7*G+(0IA0#Ps#H1K937^snvkrx9u@CW_@6O16385js= zYW@^NML~p(L_uZ1#85F&cR%;}R)*1;>FKWO>F)aac=xtFRj1DRobT=F>8Uz3I$HCu znwpw_)HKw**Zhs6TK@n2NBy6Fop4;6cU<@9@$c9EUHkXH&ezeV_5XeAYiis7I!~+G zj=aAA{HsmvfBvBV?=gS>rymgzfrt>OtE+2kYwPOj>g($p9UYyVoSd1NnVp@To10r$ zSXf+K!%bS~<2L}iD_xEpaZ~yiC zLtiXl2W!~GGWHpziZN>F5D5JE@ndLch-=Qy&d$}Ee;Hh8R+uOIcw#=e- z&>9RODLH)*n3$M&e0+3J1~x*5Bs?9LR&#T+E>kwt1y$I(sV=_0zrDS+K~**(09yz< zB`s!yFz@K~^;H6}N&v!ec4Y2NOH0fC{=QY7GM-NW+AvS{g{!Bh=lc3OKWZI^Kmg{D zPpY)W#>SqXpF_Z?A-)oTJp7XTA1z@IE6Mq2gt_3P{F)kUh&KM9Zv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Bvbew?ZGdL~)OW|w&l_ju_o7H?##|2<1e9dpS z1lDD<%x~9v9G3-PDR$Q5X#Joiwl14JI5;uDf{d0?rtJ! zC@50|P)J!7eQhu}IB3cN*-0b;6!KLzUe27KpC=NCf(lLmZFrH;w{5hWYHF(~XQcu)AF$Bmy8Yrt19}PxEMiN6wfmBL>?EBD+$1Yo2 zTb25w_6ZCc}fGHgEL6UKBWAEvaRUG+(NK6K)v3lm(KJFR6G zw$%k;I9G8xu@7wo@4{LSEf%vUE!b9NHBE3~1h>H2G%azpAuXteyzVc!7>rwBnYL;^ zm{J!cLtFN4TnWYvQdUA2uHe#wVF(2}jA!4rK`Jb%belhQ!Od!YD%+{IZJ&y86dP16 zQ}6166~ru6(zBiJknK|(RTY@MNDE5F3(1C@>+px8PPn!tD5fsR7_6fnesZfmB3ou? zkDh#WLBq&4B2~|96dYjpC~aB?fq=VcMIn_D^nr~O_xAQ&n{PwBMD2SM$q42#nl7=Y zFxyqL6MFu;Ln4ofkw|^)p&ZS`#lkD5XV1*cB=y#dxQH&+Q_y3fq7qJ~QmITPlgs52 zaLFPHVj-du@#>{82{0Rk&)wN<_Tk|nb^^m^JjZ|6=Cp*Vkbq;=)zzibY33cBoSeM9 zy+u}I_=bo0iMRM1Flu!VlR#Tr+xYnS+S=O1#YGe}h7WjxKX`?2VWQAjmI!bUJTx@4 zxVX5pvvYNI6^_gpg|QfsaT#6r;g*sc9kY#%jlI3S)6>%{D=V9un}>&o_xJZf#718% TUB;{9Ovj?r diff --git a/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/data/texture.gif b/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/data/texture.gif deleted file mode 100644 index 17e84e80677eeefd1f0609e1e2c37d428e6f6f60..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1829 zcmV+=2io{YNk%w1VITk?0QUd@000010RaL60s{jB1Ox;H1qB8M1_uWR2nYxX2?+`c z3JVJh3=9kn4Gj(s4i66x5D*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8jo*K{at`!MW=JVYB%@Q4il%wasl3SnRb-H`M`=zJNF+saq`$d_P(;_(fgXm zjmXVOis6KW$0m#NMvQNs@$kxx+unL--=3W>tzFV(udmk0GkH;AK~O-ZLRU4(I%DCo zH5)f?d2#(y-Cb=BV@KqQQexp(VQ55LicnKhJJ~vY-XlwvFMpzY!7NAPxQd~&41RQ2 z5QI+@KV6(Vyyl)J`}EoOcg?-8-D((Hu2l+>AUl)J4B^HkWJq$0E5}Z1Xtr8g%!Uay zBeaU_l=w(C1R#SI3IUcOR%=TuM~@vpVSL@F@}fK$s8M(^sB|I%`Dr;a4T|5g(qe6% zQkYt{$cB%i!heaBQejqVLTnTYZ#oPhFbE3eM#b`zQZq6If~?H+ zl!UnG@UUQJ02+WKWWWkxb0cG7dHlqL1b+OG=m<_I3{V;s)M$j#1DMDnJTfXeDk?I9 z8wOe!;1u|e{a^4F{Ljw>|Nmgv%Rj#^s@H8DCRw4<*j`oXZ<*(&Y^{>+%Mhc6o!%yS%|B zUfy6cFK@7^mp9nl%NuO+<44gIiC)yuoH*-e6NOw8Hls%o}VH z<_$Ir^9GxSd4tWvyul`7-e5B^1g-C>m^av54CBK0WDG;k_iWrlit{}kgMsh)_ - -// A simple Particle class - -class Particle { - PVector location; - PVector velocity; - PVector acceleration; - float lifespan; - - Particle(PVector l) { - acceleration = new PVector(0, 0.05); - velocity = new PVector(random(-1, 1), random(-1, 0)); - location = l.get(); - lifespan = 255.0; - } - - void run() { - update(); - display(); - } - - // Method to update location - void update() { - velocity.add(acceleration); - location.add(velocity); - lifespan -= 2.0; - } - - // Method to display - void display() { - stroke(0, lifespan); - strokeWeight(2); - fill(127, lifespan); - ellipse(location.x, location.y, 12, 12); - } - - // Is the particle still useful? - boolean isDead() { - if (lifespan < 0.0) { - return true; - } - else { - return false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle_trail/NOC_4_01_SingleParticle_trail.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle_trail/NOC_4_01_SingleParticle_trail.pde deleted file mode 100644 index 5548fb796..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle_trail/NOC_4_01_SingleParticle_trail.pde +++ /dev/null @@ -1,23 +0,0 @@ -Particle p; - -void setup() { - size(800, 200); - p = new Particle(new PVector(width/2, 20)); - background(255); - smooth(); -} - -void draw() { - if (mousePressed) { - noStroke(); - fill(255, 5); - rect(0, 0, width, height); - - p.run(); - if (p.isDead()) { - println("Particle dead!"); - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle_trail/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle_trail/Particle.pde deleted file mode 100644 index 815931e27..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle_trail/Particle.pde +++ /dev/null @@ -1,49 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// A simple Particle class - -class Particle { - PVector location; - PVector velocity; - PVector acceleration; - float lifespan; - - Particle(PVector l) { - acceleration = new PVector(0, 0.05); - velocity = new PVector(random(-1, 1), -1); - location = l.get(); - lifespan = 255.0; - } - - void run() { - update(); - display(); - } - - // Method to update location - void update() { - velocity.add(acceleration); - location.add(velocity); - lifespan -= 2.0; - } - - // Method to display - void display() { - stroke(0, lifespan); - strokeWeight(2); - fill(127); - ellipse(location.x, location.y, 12, 12); - } - - // Is the particle still useful? - boolean isDead() { - if (lifespan < 0.0) { - return true; - } - else { - return false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_02_ArrayListParticles/NOC_4_02_ArrayListParticles.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_02_ArrayListParticles/NOC_4_02_ArrayListParticles.pde deleted file mode 100644 index 09d201c07..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_02_ArrayListParticles/NOC_4_02_ArrayListParticles.pde +++ /dev/null @@ -1,27 +0,0 @@ -ArrayList particles; - -void setup() { - size(800,200); - particles = new ArrayList(); - smooth(); -} - -void draw() { - background(255); - - particles.add(new Particle(new PVector(width/2,50))); - - // Using the iterator - Iterator it = particles.iterator(); - while (it.hasNext()) { - Particle p = it.next(); - p.run(); - if (p.isDead()) { - it.remove(); - } - } -} - - - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_02_ArrayListParticles/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_02_ArrayListParticles/Particle.pde deleted file mode 100644 index 17a447011..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_02_ArrayListParticles/Particle.pde +++ /dev/null @@ -1,49 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// A simple Particle class - -class Particle { - PVector location; - PVector velocity; - PVector acceleration; - float lifespan; - - Particle(PVector l) { - acceleration = new PVector(0, 0.05); - velocity = new PVector(random(-1, 1), random(-2, 0)); - location = l.get(); - lifespan = 255.0; - } - - void run() { - update(); - display(); - } - - // Method to update location - void update() { - velocity.add(acceleration); - location.add(velocity); - lifespan -= 2.0; - } - - // Method to display - void display() { - stroke(0, lifespan); - strokeWeight(2); - fill(127, lifespan); - ellipse(location.x, location.y, 12, 12); - } - - // Is the particle still useful? - boolean isDead() { - if (lifespan < 0.0) { - return true; - } - else { - return false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/NOC_4_03_ParticleSystemClass.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/NOC_4_03_ParticleSystemClass.pde deleted file mode 100644 index a896b7f99..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/NOC_4_03_ParticleSystemClass.pde +++ /dev/null @@ -1,13 +0,0 @@ -ParticleSystem ps; - -void setup() { - size(800,200); - smooth(); - ps = new ParticleSystem(new PVector(width/2,50)); -} - -void draw() { - background(255); - ps.addParticle(); - ps.run(); -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/Particle.pde deleted file mode 100644 index a019abea2..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/Particle.pde +++ /dev/null @@ -1,49 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// A simple Particle class - -class Particle { - PVector location; - PVector velocity; - PVector acceleration; - float lifespan; - - Particle(PVector l) { - acceleration = new PVector(0,0.05); - velocity = new PVector(random(-1,1),random(-2,0)); - location = l.get(); - lifespan = 255.0; - } - - void run() { - update(); - display(); - } - - // Method to update location - void update() { - velocity.add(acceleration); - location.add(velocity); - lifespan -= 2.0; - } - - // Method to display - void display() { - stroke(0,lifespan); - strokeWeight(2); - fill(127,lifespan); - ellipse(location.x,location.y,12,12); - } - - // Is the particle still useful? - boolean isDead() { - if (lifespan < 0.0) { - return true; - } else { - return false; - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/ParticleSystem.pde deleted file mode 100644 index 0df577d0e..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/ParticleSystem.pde +++ /dev/null @@ -1,31 +0,0 @@ -// Using Generics now! comment and annotate, etc. - -class ParticleSystem { - ArrayList particles; - PVector origin; - - ParticleSystem(PVector location) { - origin = location.get(); - particles = new ArrayList(); - } - - void addParticle() { - particles.add(new Particle(origin)); - } - - void run() { - Iterator it = particles.iterator(); - while (it.hasNext()) { - Particle p = it.next(); - p.run(); - if (p.isDead()) { - it.remove(); - } - } - } -} - - - - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/NOC_4_04_SystemofSystems.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/NOC_4_04_SystemofSystems.pde deleted file mode 100644 index 6bfabb89d..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/NOC_4_04_SystemofSystems.pde +++ /dev/null @@ -1,30 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// Particles are generated each cycle through draw(), -// fall with gravity and fade out over time -// A ParticleSystem object manages a variable size (ArrayList) -// list of particles. - -ArrayList systems; - -void setup() { - size(800,200); - systems = new ArrayList(); - smooth(); -} - -void draw() { - background(255); - for (ParticleSystem ps: systems) { - ps.run(); - ps.addParticle(); - } -} - -void mousePressed() { - systems.add(new ParticleSystem(1,new PVector(mouseX,mouseY))); -} - - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/Particle.pde deleted file mode 100644 index a019abea2..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/Particle.pde +++ /dev/null @@ -1,49 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// A simple Particle class - -class Particle { - PVector location; - PVector velocity; - PVector acceleration; - float lifespan; - - Particle(PVector l) { - acceleration = new PVector(0,0.05); - velocity = new PVector(random(-1,1),random(-2,0)); - location = l.get(); - lifespan = 255.0; - } - - void run() { - update(); - display(); - } - - // Method to update location - void update() { - velocity.add(acceleration); - location.add(velocity); - lifespan -= 2.0; - } - - // Method to display - void display() { - stroke(0,lifespan); - strokeWeight(2); - fill(127,lifespan); - ellipse(location.x,location.y,12,12); - } - - // Is the particle still useful? - boolean isDead() { - if (lifespan < 0.0) { - return true; - } else { - return false; - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/ParticleSystem.pde deleted file mode 100644 index 870908e47..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/ParticleSystem.pde +++ /dev/null @@ -1,52 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// A class to describe a group of Particles -// An ArrayList is used to manage the list of Particles - -class ParticleSystem { - - ArrayList particles; // An arraylist for all the particles - PVector origin; // An origin point for where particles are birthed - - ParticleSystem(int num, PVector v) { - particles = new ArrayList(); // Initialize the arraylist - origin = v.get(); // Store the origin point - for (int i = 0; i < num; i++) { - particles.add(new Particle(origin)); // Add "num" amount of particles to the arraylist - } - } - - void run() { - // Using the Iterator b/c we are deleting from list while iterating - Iterator it = particles.iterator(); - while (it.hasNext()) { - Particle p = it.next(); - p.run(); - if (p.isDead()) { - it.remove(); - } - } - } - - void addParticle() { - particles.add(new Particle(origin)); - } - - void addParticle(Particle p) { - particles.add(p); - } - - // A method to test if the particle system still has particles - boolean dead() { - if (particles.isEmpty()) { - return true; - } else { - return false; - } - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_b/NOC_4_04_SystemofSystems_b.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_b/NOC_4_04_SystemofSystems_b.pde deleted file mode 100644 index 70ec0bedc..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_b/NOC_4_04_SystemofSystems_b.pde +++ /dev/null @@ -1,32 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// Particles are generated each cycle through draw(), -// fall with gravity and fade out over time -// A ParticleSystem object manages a variable size (ArrayList) -// list of particles. - -ArrayList systems; - -void setup() { - size(800,200); - systems = new ArrayList(); - systems.add(new ParticleSystem(1,new PVector(100,25))); - - smooth(); -} - -void draw() { - background(255); - for (ParticleSystem ps: systems) { - ps.run(); - ps.addParticle(); - } -} - -void mousePressed() { - systems.add(new ParticleSystem(1,new PVector(mouseX,mouseY))); -} - - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_b/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_b/Particle.pde deleted file mode 100644 index a019abea2..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_b/Particle.pde +++ /dev/null @@ -1,49 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// A simple Particle class - -class Particle { - PVector location; - PVector velocity; - PVector acceleration; - float lifespan; - - Particle(PVector l) { - acceleration = new PVector(0,0.05); - velocity = new PVector(random(-1,1),random(-2,0)); - location = l.get(); - lifespan = 255.0; - } - - void run() { - update(); - display(); - } - - // Method to update location - void update() { - velocity.add(acceleration); - location.add(velocity); - lifespan -= 2.0; - } - - // Method to display - void display() { - stroke(0,lifespan); - strokeWeight(2); - fill(127,lifespan); - ellipse(location.x,location.y,12,12); - } - - // Is the particle still useful? - boolean isDead() { - if (lifespan < 0.0) { - return true; - } else { - return false; - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_b/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_b/ParticleSystem.pde deleted file mode 100644 index 870908e47..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_b/ParticleSystem.pde +++ /dev/null @@ -1,52 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// A class to describe a group of Particles -// An ArrayList is used to manage the list of Particles - -class ParticleSystem { - - ArrayList particles; // An arraylist for all the particles - PVector origin; // An origin point for where particles are birthed - - ParticleSystem(int num, PVector v) { - particles = new ArrayList(); // Initialize the arraylist - origin = v.get(); // Store the origin point - for (int i = 0; i < num; i++) { - particles.add(new Particle(origin)); // Add "num" amount of particles to the arraylist - } - } - - void run() { - // Using the Iterator b/c we are deleting from list while iterating - Iterator it = particles.iterator(); - while (it.hasNext()) { - Particle p = it.next(); - p.run(); - if (p.isDead()) { - it.remove(); - } - } - } - - void addParticle() { - particles.add(new Particle(origin)); - } - - void addParticle(Particle p) { - particles.add(p); - } - - // A method to test if the particle system still has particles - boolean dead() { - if (particles.isEmpty()) { - return true; - } else { - return false; - } - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_c/NOC_4_04_SystemofSystems_c.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_c/NOC_4_04_SystemofSystems_c.pde deleted file mode 100644 index dd84003d6..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_c/NOC_4_04_SystemofSystems_c.pde +++ /dev/null @@ -1,35 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// Particles are generated each cycle through draw(), -// fall with gravity and fade out over time -// A ParticleSystem object manages a variable size (ArrayList) -// list of particles. - -ArrayList systems; - -void setup() { - size(800,200); - systems = new ArrayList(); - systems.add(new ParticleSystem(1,new PVector(100,25))); - for (int i = 0; i < 6; i++) { - systems.add(new ParticleSystem(1,new PVector(random(width),random(height)))); - } - - smooth(); -} - -void draw() { - background(255); - for (ParticleSystem ps: systems) { - ps.run(); - ps.addParticle(); - } -} - -void mousePressed() { - systems.add(new ParticleSystem(1,new PVector(mouseX,mouseY))); -} - - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_c/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_c/Particle.pde deleted file mode 100644 index a019abea2..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_c/Particle.pde +++ /dev/null @@ -1,49 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// A simple Particle class - -class Particle { - PVector location; - PVector velocity; - PVector acceleration; - float lifespan; - - Particle(PVector l) { - acceleration = new PVector(0,0.05); - velocity = new PVector(random(-1,1),random(-2,0)); - location = l.get(); - lifespan = 255.0; - } - - void run() { - update(); - display(); - } - - // Method to update location - void update() { - velocity.add(acceleration); - location.add(velocity); - lifespan -= 2.0; - } - - // Method to display - void display() { - stroke(0,lifespan); - strokeWeight(2); - fill(127,lifespan); - ellipse(location.x,location.y,12,12); - } - - // Is the particle still useful? - boolean isDead() { - if (lifespan < 0.0) { - return true; - } else { - return false; - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_c/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_c/ParticleSystem.pde deleted file mode 100644 index 870908e47..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems_c/ParticleSystem.pde +++ /dev/null @@ -1,52 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// A class to describe a group of Particles -// An ArrayList is used to manage the list of Particles - -class ParticleSystem { - - ArrayList particles; // An arraylist for all the particles - PVector origin; // An origin point for where particles are birthed - - ParticleSystem(int num, PVector v) { - particles = new ArrayList(); // Initialize the arraylist - origin = v.get(); // Store the origin point - for (int i = 0; i < num; i++) { - particles.add(new Particle(origin)); // Add "num" amount of particles to the arraylist - } - } - - void run() { - // Using the Iterator b/c we are deleting from list while iterating - Iterator it = particles.iterator(); - while (it.hasNext()) { - Particle p = it.next(); - p.run(); - if (p.isDead()) { - it.remove(); - } - } - } - - void addParticle() { - particles.add(new Particle(origin)); - } - - void addParticle(Particle p) { - particles.add(p); - } - - // A method to test if the particle system still has particles - boolean dead() { - if (particles.isEmpty()) { - return true; - } else { - return false; - } - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/Confetti.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/Confetti.pde deleted file mode 100644 index c0db00486..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/Confetti.pde +++ /dev/null @@ -1,25 +0,0 @@ -class Confetti extends Particle { - - // We could add variables for only Confetti here if we so - - Confetti(PVector l) { - super(l); - } - - // Inherits update() from parent - - // Override the display method - void display() { - rectMode(CENTER); - fill(127,lifespan); - stroke(0,lifespan); - strokeWeight(2); - pushMatrix(); - translate(location.x,location.y); - float theta = map(location.x,0,width,0,TWO_PI*2); - rotate(theta); - rect(0,0,12,12); - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/NOC_4_05_ParticleSystemInheritancePolymorphism.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/NOC_4_05_ParticleSystemInheritancePolymorphism.pde deleted file mode 100644 index a896b7f99..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/NOC_4_05_ParticleSystemInheritancePolymorphism.pde +++ /dev/null @@ -1,13 +0,0 @@ -ParticleSystem ps; - -void setup() { - size(800,200); - smooth(); - ps = new ParticleSystem(new PVector(width/2,50)); -} - -void draw() { - background(255); - ps.addParticle(); - ps.run(); -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/Particle.pde deleted file mode 100644 index e51908f50..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/Particle.pde +++ /dev/null @@ -1,50 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// A simple Particle class - -class Particle { - - PVector location; - PVector velocity; - PVector acceleration; - float lifespan; - - Particle(PVector l) { - acceleration = new PVector(0,0.05); - velocity = new PVector(random(-1,1),random(-2,0)); - location = l.get(); - lifespan = 255.0; - } - - void run() { - update(); - display(); - } - - // Method to update location - void update() { - velocity.add(acceleration); - location.add(velocity); - lifespan -= 2.0; - } - - // Method to display - void display() { - stroke(0,lifespan); - strokeWeight(2); - fill(127,lifespan); - ellipse(location.x,location.y,12,12); - } - - // Is the particle still useful? - boolean isDead() { - if (lifespan < 0.0) { - return true; - } else { - return false; - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/ParticleSystem.pde deleted file mode 100644 index 8a5be1aaa..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/ParticleSystem.pde +++ /dev/null @@ -1,34 +0,0 @@ - -class ParticleSystem { - ArrayList particles; - PVector origin; - - ParticleSystem(PVector location) { - origin = location.get(); - particles = new ArrayList(); - } - - void addParticle() { - float r = random(1); - if (r < 0.5) { - particles.add(new Particle(origin)); - } else { - particles.add(new Confetti(origin)); - } - } - - void run() { - Iterator it = particles.iterator(); - while (it.hasNext()) { - Particle p = it.next(); - p.run(); - if (p.isDead()) { - it.remove(); - } - } - } -} - - - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/NOC_4_06_ParticleSystemForces.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/NOC_4_06_ParticleSystemForces.pde deleted file mode 100644 index 266c12103..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/NOC_4_06_ParticleSystemForces.pde +++ /dev/null @@ -1,18 +0,0 @@ -ParticleSystem ps; - -void setup() { - size(800,200); - smooth(); - ps = new ParticleSystem(new PVector(width/2,50)); -} - -void draw() { - background(255); - - // Apply gravity force to all Particles - PVector gravity = new PVector(0,0.1); - ps.applyForce(gravity); - - ps.addParticle(); - ps.run(); -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/Particle.pde deleted file mode 100644 index 120eb0e8c..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/Particle.pde +++ /dev/null @@ -1,57 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// A simple Particle class - -class Particle { - PVector location; - PVector velocity; - PVector acceleration; - float lifespan; - - float mass = 1; // Let's do something better here! - - Particle(PVector l) { - acceleration = new PVector(0,0); - velocity = new PVector(random(-1,1),random(-2,0)); - location = l.get(); - lifespan = 255.0; - } - - void run() { - update(); - display(); - } - - void applyForce(PVector force) { - PVector f = force.get(); - f.div(mass); - acceleration.add(f); - } - - // Method to update location - void update() { - velocity.add(acceleration); - location.add(velocity); - acceleration.mult(0); - lifespan -= 2.0; - } - - // Method to display - void display() { - stroke(0,lifespan); - strokeWeight(2); - fill(127,lifespan); - ellipse(location.x,location.y,12,12); - } - - // Is the particle still useful? - boolean isDead() { - if (lifespan < 0.0) { - return true; - } else { - return false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/ParticleSystem.pde deleted file mode 100644 index 5f2223739..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/ParticleSystem.pde +++ /dev/null @@ -1,34 +0,0 @@ - -class ParticleSystem { - ArrayList particles; - PVector origin; - - ParticleSystem(PVector location) { - origin = location.get(); - particles = new ArrayList(); - } - - void addParticle() { - particles.add(new Particle(origin)); - } - - // A function to apply a force to all Particles - void applyForce(PVector f) { - for (Particle p: particles) { - p.applyForce(f); - } - } - - void run() { - Iterator it = particles.iterator(); - while (it.hasNext()) { - Particle p = it.next(); - p.run(); - if (p.isDead()) { - it.remove(); - } - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/NOC_4_07_ParticleSystemForcesRepeller.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/NOC_4_07_ParticleSystemForcesRepeller.pde deleted file mode 100644 index 3450950b5..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/NOC_4_07_ParticleSystemForcesRepeller.pde +++ /dev/null @@ -1,23 +0,0 @@ -ParticleSystem ps; -Repeller repeller; - -void setup() { - size(800,200); - smooth(); - ps = new ParticleSystem(new PVector(width/2,50)); - repeller = new Repeller(width/2-20,height/2); -} - -void draw() { - background(255); - ps.addParticle(); - - // Apply gravity force to all Particles - PVector gravity = new PVector(0,0.1); - ps.applyForce(gravity); - - ps.applyRepeller(repeller); - - repeller.display(); - ps.run(); -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/Particle.pde deleted file mode 100644 index 120eb0e8c..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/Particle.pde +++ /dev/null @@ -1,57 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// A simple Particle class - -class Particle { - PVector location; - PVector velocity; - PVector acceleration; - float lifespan; - - float mass = 1; // Let's do something better here! - - Particle(PVector l) { - acceleration = new PVector(0,0); - velocity = new PVector(random(-1,1),random(-2,0)); - location = l.get(); - lifespan = 255.0; - } - - void run() { - update(); - display(); - } - - void applyForce(PVector force) { - PVector f = force.get(); - f.div(mass); - acceleration.add(f); - } - - // Method to update location - void update() { - velocity.add(acceleration); - location.add(velocity); - acceleration.mult(0); - lifespan -= 2.0; - } - - // Method to display - void display() { - stroke(0,lifespan); - strokeWeight(2); - fill(127,lifespan); - ellipse(location.x,location.y,12,12); - } - - // Is the particle still useful? - boolean isDead() { - if (lifespan < 0.0) { - return true; - } else { - return false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/ParticleSystem.pde deleted file mode 100644 index ba513bf62..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/ParticleSystem.pde +++ /dev/null @@ -1,43 +0,0 @@ - -class ParticleSystem { - ArrayList particles; - PVector origin; - - ParticleSystem(PVector location) { - origin = location.get(); - particles = new ArrayList(); - } - - void addParticle() { - particles.add(new Particle(origin)); - } - - // A function to apply a force to all Particles - void applyForce(PVector f) { - for (Particle p: particles) { - p.applyForce(f); - } - } - - void applyRepeller(Repeller r) { - for (Particle p: particles) { - PVector force = r.repel(p); - p.applyForce(force); - } - } - - - void run() { - Iterator it = particles.iterator(); - while (it.hasNext()) { - Particle p = it.next(); - p.run(); - if (p.isDead()) { - it.remove(); - } - } - } -} - - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/Repeller.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/Repeller.pde deleted file mode 100644 index 973f55a89..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/Repeller.pde +++ /dev/null @@ -1,36 +0,0 @@ -// Particles + Forces -// Daniel Shiffman - -// A very basic Repeller class -class Repeller { - - // Gravitational Constant - float G = 100; - // Location - PVector location; - float r = 10; - - Repeller(float x, float y) { - location = new PVector(x,y); - } - - void display() { - stroke(0); - strokeWeight(2); - fill(175); - ellipse(location.x,location.y,48,48); - } - - // Calculate a force to push particle away from repeller - PVector repel(Particle p) { - PVector dir = PVector.sub(location,p.location); // Calculate direction of force - float d = dir.mag(); // Distance between objects - dir.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction) - d = constrain(d,5,100); // Keep distance within a reasonable range - float force = -1 * G / (d * d); // Repelling force is inversely proportional to distance - dir.mult(force); // Get force vector --> magnitude * direction - return dir; - } -} - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/NOC_4_08_ParticleSystemSmoke.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/NOC_4_08_ParticleSystemSmoke.pde deleted file mode 100644 index db907b374..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/NOC_4_08_ParticleSystemSmoke.pde +++ /dev/null @@ -1,54 +0,0 @@ -// Smoke Particle System -// Daniel Shiffman - -// A basic smoke effect using a particle system -// Each particle is rendered as an alpha masked image - -/* @pjs preload="processingjs/chapter04/_4_08_ParticleSystemSmoke/data/texture.png"; */ - -ParticleSystem ps; -Random generator; - -void setup() { - size(383,200); - generator = new Random(); - PImage img = loadImage("texture.png"); - ps = new ParticleSystem(0,new PVector(width/2,height-25),img); - smooth(); -} - -void draw() { - background(0); - - // Calculate a "wind" force based on mouse horizontal position - float dx = map(mouseX,0,width,-0.2,0.2); - PVector wind = new PVector(dx,0); - ps.applyForce(wind); - ps.run(); - for (int i = 0; i < 2; i++) { - ps.addParticle(); - } - - // Draw an arrow representing the wind force - drawVector(wind, new PVector(width/2,50,0),500); - -} - -// Renders a vector object 'v' as an arrow and a location 'loc' -void drawVector(PVector v, PVector loc, float scayl) { - pushMatrix(); - float arrowsize = 4; - // Translate to location to render vector - translate(loc.x,loc.y); - stroke(255); - // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate - rotate(v.heading2D()); - // Calculate length of vector & scale it to be bigger or smaller if necessary - float len = v.mag()*scayl; - // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction) - line(0,0,len,0); - line(len,0,len-arrowsize,+arrowsize/2); - line(len,0,len-arrowsize,-arrowsize/2); - popMatrix(); -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/Particle.pde deleted file mode 100644 index 709929f41..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/Particle.pde +++ /dev/null @@ -1,64 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// A simple Particle class, renders the particle as an image - -// Created 2 May 2005 - -class Particle { - PVector loc; - PVector vel; - PVector acc; - float lifespan; - PImage img; - - Particle(PVector l,PImage img_) { - acc = new PVector(0,0); - float vx = (float) generator.nextGaussian()*0.3; - float vy = (float) generator.nextGaussian()*0.3 - 1.0; - vel = new PVector(vx,vy); - loc = l.get(); - lifespan = 100.0; - img = img_; - } - - void run() { - update(); - render(); - } - - // Method to apply a force vector to the Particle object - // Note we are ignoring "mass" here - void applyForce(PVector f) { - acc.add(f); - } - - // Method to update location - void update() { - vel.add(acc); - loc.add(vel); - lifespan -= 2.5; - acc.mult(0); // clear Acceleration - } - - // Method to display - void render() { - imageMode(CENTER); - tint(255,lifespan); - image(img,loc.x,loc.y); - // Drawing a circle instead - // fill(255,lifespan); - // noStroke(); - // ellipse(loc.x,loc.y,img.width,img.height); - } - - // Is the particle still useful? - boolean dead() { - if (lifespan <= 0.0) { - return true; - } else { - return false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/ParticleSystem.pde deleted file mode 100644 index e193f63c0..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/ParticleSystem.pde +++ /dev/null @@ -1,62 +0,0 @@ -// Smoke Particle Syste -// Daniel Shiffman - -// A class to describe a group of Particles -// An ArrayList is used to manage the list of Particles - -class ParticleSystem { - - ArrayList particles; // An arraylist for all the particles - PVector origin; // An origin point for where particles are birthed - PImage img; - - ParticleSystem(int num, PVector v, PImage img_) { - particles = new ArrayList(); // Initialize the arraylist - origin = v.get(); // Store the origin point - img = img_; - for (int i = 0; i < num; i++) { - particles.add(new Particle(origin, img)); // Add "num" amount of particles to the arraylist - } - } - - void run() { - Iterator it = particles.iterator(); - while (it.hasNext()) { - Particle p = it.next(); - p.run(); - if (p.dead()) { - it.remove(); - } - } - } - - // Method to add a force vector to all particles currently in the system - void applyForce(PVector dir) { - // Enhanced loop!!! - for (Particle p: particles) { - p.applyForce(dir); - } - - } - - void addParticle() { - particles.add(new Particle(origin,img)); - } - - void addParticle(Particle p) { - particles.add(p); - } - - // A method to test if the particle system still has particles - boolean dead() { - if (particles.isEmpty()) { - return true; - } else { - return false; - } - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/data/texture.psd b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/data/texture.psd deleted file mode 100644 index 8208feb020b9552dba21c52ff59db597e4172699..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 26456 zcmeHP33yY*+CC?Hn{-K&uCz_MZ)vlyT_8 zMMV}-K*5bgL+Yna|_P#Y7676j&XYC2n5TTD(p zzq7?+b!a;C6ZJ-0y-5Q!5(^Xggo(2`KT(Sm{IL~Pe4Wj1;>&U*Ig)IHNFn9Rr8!c$ zL?Mw0_!5ywB@`)zQc<>8r4h+BGBMwMB^Cq%m1j3LXsU}!+yw%cpV;JdwrYgJj*gC; z4rz|f-Y68S)oP(gB9ut7!6Mr+&Fa*5W?LOeE+@TyicAiJ-Q4Ol+pK)#S6^>ybLJ-| zqJsJ^cgtE@`wFr;a)?&u7;G)VPJOFToFfwUd4`O6fQm+EH|d==d#%l8DR8yDs>$ZG zIht&(d|i!VR*Tu7M_n##w;J6Y+1lGP zdBT3vzq;1Y%M}%U6~AQ=wX_It6?_h7aXZANJI-&J(@{IE)g-JoIc#lqgQ>V3aOe+q zcSu%LXv(Y(r`~EXl@%30b#lyRqei4vK~O1WBBey6P>ID_rC6>5iBzf3sYR+nBC-Z% z9T*d!E3z5d5cF=hM&wrd=iGW^y~%B*-3%`yy~V=@)%yS9{uVB7DyG!zfPp%#HyT|d zpNPpC)6{{|-e9$ui5P9w+Z`r^e12jt^q%hlmnW2m=s}I%fa0#efZhxy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e!;1u|e{a^4F{Ljw>|Nmgv%Rj#^s@H8DCRw4<*j`oXZ<*(&Y^{>+%Mhc6o!%yS%|B zUfy6cFK@7^mp9nl%NuO+<44gIiC)yuoH*-e6NOw8Hls%o}VH z<_$Ir^9GxSd4tWvyul`7-e5B^1g-C>m^av54CBK0WDG;k_iWrlit{}kgMsh)_ - -// A basic smoke effect using a particle system -// Each particle is rendered as an alpha masked image - -/* @pjs preload="processingjs/chapter04/_4_08_ParticleSystemSmoke/data/texture.png"; */ - -ParticleSystem ps; -Random generator; - -void setup() { - size(383,200); - generator = new Random(); - PImage img = loadImage("texture.png"); - ps = new ParticleSystem(0,new PVector(width/2,height-25),img); - smooth(); -} - -void draw() { - background(0); - - // Calculate a "wind" force based on mouse horizontal position - float dx = map(mouseX,0,width,-0.2,0.2); - PVector wind = new PVector(dx,0); - ps.applyForce(wind); - ps.run(); - for (int i = 0; i < 2; i++) { - ps.addParticle(); - } - - // Draw an arrow representing the wind force - drawVector(wind, new PVector(width/2,50,0),500); - -} - -// Renders a vector object 'v' as an arrow and a location 'loc' -void drawVector(PVector v, PVector loc, float scayl) { - pushMatrix(); - float arrowsize = 4; - // Translate to location to render vector - translate(loc.x,loc.y); - stroke(255); - // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate - rotate(v.heading2D()); - // Calculate length of vector & scale it to be bigger or smaller if necessary - float len = v.mag()*scayl; - // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction) - line(0,0,len,0); - line(len,0,len-arrowsize,+arrowsize/2); - line(len,0,len-arrowsize,-arrowsize/2); - popMatrix(); -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/Particle.pde deleted file mode 100644 index 45a6e5b06..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/Particle.pde +++ /dev/null @@ -1,64 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// A simple Particle class, renders the particle as an image - -// Created 2 May 2005 - -class Particle { - PVector loc; - PVector vel; - PVector acc; - float lifespan; - PImage img; - - Particle(PVector l,PImage img_) { - acc = new PVector(0,0); - float vx = (float) generator.nextGaussian()*0.3; - float vy = (float) generator.nextGaussian()*0.3 - 1.0; - vel = new PVector(vx,vy); - loc = l.get(); - lifespan = 100.0; - img = img_; - } - - void run() { - update(); - render(); - } - - // Method to apply a force vector to the Particle object - // Note we are ignoring "mass" here - void applyForce(PVector f) { - acc.add(f); - } - - // Method to update location - void update() { - vel.add(acc); - loc.add(vel); - lifespan -= 2.5; - acc.mult(0); // clear Acceleration - } - - // Method to display - void render() { - //imageMode(CENTER); - //tint(255,lifespan); - //image(img,loc.x,loc.y); - // Drawing a circle instead - fill(255,lifespan); - noStroke(); - ellipse(loc.x,loc.y,img.width,img.height); - } - - // Is the particle still useful? - boolean dead() { - if (lifespan <= 0.0) { - return true; - } else { - return false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/ParticleSystem.pde deleted file mode 100644 index e193f63c0..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/ParticleSystem.pde +++ /dev/null @@ -1,62 +0,0 @@ -// Smoke Particle Syste -// Daniel Shiffman - -// A class to describe a group of Particles -// An ArrayList is used to manage the list of Particles - -class ParticleSystem { - - ArrayList particles; // An arraylist for all the particles - PVector origin; // An origin point for where particles are birthed - PImage img; - - ParticleSystem(int num, PVector v, PImage img_) { - particles = new ArrayList(); // Initialize the arraylist - origin = v.get(); // Store the origin point - img = img_; - for (int i = 0; i < num; i++) { - particles.add(new Particle(origin, img)); // Add "num" amount of particles to the arraylist - } - } - - void run() { - Iterator it = particles.iterator(); - while (it.hasNext()) { - Particle p = it.next(); - p.run(); - if (p.dead()) { - it.remove(); - } - } - } - - // Method to add a force vector to all particles currently in the system - void applyForce(PVector dir) { - // Enhanced loop!!! - for (Particle p: particles) { - p.applyForce(dir); - } - - } - - void addParticle() { - particles.add(new Particle(origin,img)); - } - - void addParticle(Particle p) { - particles.add(p); - } - - // A method to test if the particle system still has particles - boolean dead() { - if (particles.isEmpty()) { - return true; - } else { - return false; - } - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/data/texture.psd b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/data/texture.psd deleted file mode 100644 index 8208feb020b9552dba21c52ff59db597e4172699..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 26456 zcmeHP33yY*+CC?Hn{-K&uCz_MZ)vlyT_8 zMMV}-K*5bgL+Yna|_P#Y7676j&XYC2n5TTD(p zzq7?+b!a;C6ZJ-0y-5Q!5(^Xggo(2`KT(Sm{IL~Pe4Wj1;>&U*Ig)IHNFn9Rr8!c$ zL?Mw0_!5ywB@`)zQc<>8r4h+BGBMwMB^Cq%m1j3LXsU}!+yw%cpV;JdwrYgJj*gC; z4rz|f-Y68S)oP(gB9ut7!6Mr+&Fa*5W?LOeE+@TyicAiJ-Q4Ol+pK)#S6^>ybLJ-| zqJsJ^cgtE@`wFr;a)?&u7;G)VPJOFToFfwUd4`O6fQm+EH|d==d#%l8DR8yDs>$ZG zIht&(d|i!VR*Tu7M_n##w;J6Y+1lGP zdBT3vzq;1Y%M}%U6~AQ=wX_It6?_h7aXZANJI-&J(@{IE)g-JoIc#lqgQ>V3aOe+q zcSu%LXv(Y(r`~EXl@%30b#lyRqei4vK~O1WBBey6P>ID_rC6>5iBzf3sYR+nBC-Z% z9T*d!E3z5d5cF=hM&wrd=iGW^y~%B*-3%`yy~V=@)%yS9{uVB7DyG!zfPp%#HyT|d zpNPpC)6{{|-e9$ui5P9w+Z`r^e12jt^q%hlmnW2m=s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XeDk?I9 z8wOe!;1u|e{a^4F{Ljw>|Nmgv%Rj#^s@H8DCRw4<*j`oXZ<*(&Y^{>+%Mhc6o!%yS%|B zUfy6cFK@7^mp9nl%NuO+<44gIiC)yuoH*-e6NOw8Hls%o}VH z<_$Ir^9GxSd4tWvyul`7-e5B^1g-C>m^av54CBK0WDG;k_iWrlit{}kgMsh)_ - -// A basic smoke effect using a particle system -// Each particle is rendered as an alpha masked image - -ParticleSystem ps; - - -PImage img; - -void setup() { - size(800, 200, P2D); - - // Create an alpha masked image to be applied as the particle's texture - img = loadImage("texture.png"); - - ps = new ParticleSystem(0, new PVector(width/2, 50)); - smooth(); - -} - -void draw() { - - blendMode(ADD); - - background(0); - - ps.run(); - for (int i = 0; i < 10; i++) { - ps.addParticle(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/Particle.pde deleted file mode 100644 index 4f08e14f8..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/Particle.pde +++ /dev/null @@ -1,51 +0,0 @@ -// Simple Particle System -// Daniel Shiffman - -// A simple Particle class - -class Particle { - PVector loc; - PVector vel; - PVector acc; - float lifespan; - - // Another constructor (the one we are using here) - Particle(PVector l) { - // Boring example with constant acceleration - acc = new PVector(0,0.05,0); - vel = new PVector(random(-1,1),random(-1,0),0); - vel.mult(2); - loc = l.get(); - lifespan = 255; - } - - void run() { - update(); - render(); - } - - // Method to update location - void update() { - vel.add(acc); - loc.add(vel); - lifespan -= 2.0; - } - - // Method to display - void render() { - imageMode(CENTER); - tint(lifespan); - image(img,loc.x,loc.y); - } - - // Is the particle still useful? - boolean dead() { - if (lifespan <= 0.0) { - return true; - } else { - return false; - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/ParticleSystem.pde deleted file mode 100644 index 1512cf487..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/ParticleSystem.pde +++ /dev/null @@ -1,53 +0,0 @@ -// Smoke Particle Syste -// Daniel Shiffman - -// A class to describe a group of Particles -// An ArrayList is used to manage the list of Particles - -class ParticleSystem { - - ArrayList particles; // An arraylist for all the particles - PVector origin; // An origin point for where particles are birthed - - PImage tex; - - ParticleSystem(int num, PVector v) { - particles = new ArrayList(); // Initialize the arraylist - origin = v.get(); // Store the origin point - for (int i = 0; i < num; i++) { - particles.add(new Particle(origin)); // Add "num" amount of particles to the arraylist - } - } - - void run() { - Iterator it = particles.iterator(); - while (it.hasNext()) { - Particle p = it.next(); - p.run(); - if (p.dead()) { - it.remove(); - } - } - } - - void addParticle() { - particles.add(new Particle(origin)); - } - - void addParticle(Particle p) { - particles.add(p); - } - - // A method to test if the particle system still has particles - boolean dead() { - if (particles.isEmpty()) { - return true; - } else { - return false; - } - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/data/texture.psd b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/data/texture.psd deleted file mode 100644 index d532f15aa97ddc346e880e6801cfa46ec60e78f1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 26028 zcmeHP33yY*x4$<@(=FW>T4+hSZ)w(M?cTJdr7bOOX#o*PliN0Jnv^8n00pstfXbrm z$R;W%f`5=z1Vj*2{_Ns{B8UhmBK{FjLHo|!bh$0d^@;C$?|olxzdQHLIcLtC`OTR- zlj%2CnN?DT;h6nm!GlNME*R6!Dx0Xx$}eI?kvVTWuO}sCktmND@IK(b{IRX;o+#F z?yIw94UOFunXCe`l>(i)LD;Ho6p95RVYg){m;$J%H5Ni^Gh52dW@DPY?IpElo7q}x zZscjol6Xa0oxz0iDZ;+$J@xlkBC@qMB26L^ixWlSM2WIoELO|JYOy2{P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{`mfFRb3U>%hlHj~)GJ z-}X0`&z{t%Ez4C4qe7z+m73zm>)WQ!U%h_IJA3x-*|}-m@_Fq|wIhl$WeMT^!{eo? zdF5kG6Q<8w_VT(nH>_W~dhzV`*1FL{bCN|dyndlk0!2naWtFLI%B;DImM&egV9qm> zo9f4u<)ukz9~2rM4PS;-r)RFs>84#S-Mq`Cn|Qf& zGcT8J>gCeSy - -// A simple Particle class - -class Particle { - - PVector location; - PVector velocity; - PVector acceleration; - float lifespan; - - Particle(PVector l) { - acceleration = new PVector(0,0.05); - velocity = new PVector(random(-1,1),random(-2,0)); - location = l.get(); - lifespan = 255.0; - } - - void run() { - update(); - push(); - display(); - pop(); - } - - // Method to update location - void update() { - velocity.add(acceleration); - location.add(velocity); - lifespan -= 2.0; - } - - - void push() { - pushMatrix(); - } - - void pop() { - popMatrix(); - } - - // Method to display - void display() { - stroke(0,lifespan); - fill(0,lifespan); - translate(location.x,location.y); - ellipse(0,0,8,8); - } - - // Is the particle still useful? - boolean isDead() { - if (lifespan < 0.0) { - return true; - } else { - return false; - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleChild.pde b/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleChild.pde deleted file mode 100644 index 4e2cc630f..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleChild.pde +++ /dev/null @@ -1,20 +0,0 @@ -class ParticleChild extends Particle { - - // We could add variables for only Confetti here if we so - - ParticleChild(PVector l) { - super(l); - } - - // Inherits update() from parent - - // Override the display method - void display() { - super.display(); - float theta = map(location.x,0,width,0,TWO_PI*2); - rotate(theta); - stroke(0); - line(0,0,50,0); - } -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleSystem.pde deleted file mode 100644 index fdba58bf1..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleSystem.pde +++ /dev/null @@ -1,34 +0,0 @@ - -class ParticleSystem { - ArrayList particles; - PVector origin; - - ParticleSystem(PVector location) { - origin = location.get(); - particles = new ArrayList(); - } - - void addParticle() { - float r = random(1); - if (r < 0.5) { - particles.add(new Particle(origin)); - } else { - particles.add(new ParticleChild(origin)); - } - } - - void run() { - Iterator it = particles.iterator(); - while (it.hasNext()) { - Particle p = it.next(); - p.run(); - if (p.isDead()) { - it.remove(); - } - } - } -} - - - - diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/NOC_gl.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/NOC_gl.pde deleted file mode 100644 index d22e4bb0a..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/NOC_gl.pde +++ /dev/null @@ -1,11 +0,0 @@ - - -void renderImage(PImage img, Vec3D _loc, float _diam, color _col, float _alpha ) { - pushMatrix(); - translate( _loc.x, _loc.y, _loc.z ); - tint(red(_col), green(_col), blue(_col), _alpha); - imageMode(CENTER); - image(img,0,0,_diam,_diam); - popMatrix(); -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/emitter.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/emitter.pde deleted file mode 100644 index 479138397..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/emitter.pde +++ /dev/null @@ -1,89 +0,0 @@ - -/* -The emitter is just an object that follows the cursor and -can spawn new particle objects. It would be easier to just make -the location vector match the cursor position but I have opted -to use a velocity vector because later I will be allowing for -multiple emitters. -*/ - -class Emitter{ - Vec3D loc; - Vec3D vel; - Vec3D velToMouse; - - color myColor; - - ArrayList particles; - - Emitter( ){ - loc = new Vec3D(); - vel = new Vec3D(); - velToMouse = new Vec3D(); - - myColor = color( 1, 1, 1 ); - - particles = new ArrayList(); - } - - void exist(){ - setVelToMouse(); - findVelocity(); - setPosition(); - iterateListExist(); - render(); - - gl.glDisable( GL.GL_TEXTURE_2D ); - - if( ALLOWTRAILS ) - iterateListRenderTrails(); - } - - void setVelToMouse(){ - velToMouse.set( mouseX - loc.x, mouseY - loc.y, 0 ); - } - - void findVelocity(){ - vel.interpolateToSelf( velToMouse, .35 ); - } - - void setPosition(){ - loc.addSelf( vel ); - - if( ALLOWFLOOR ){ - if( loc.y > floorLevel ){ - loc.y = floorLevel; - vel.y = 0; - } - } - } - - void iterateListExist(){ - for( Iterator it = particles.iterator(); it.hasNext(); ){ - Particle p = (Particle) it.next(); - if( !p.ISDEAD ){ - p.exist(); - } else { - it.remove(); - } - } - } - - - void render(){ - renderImage( emitterImg, loc, 150, myColor, 1.0 ); - } - - void iterateListRenderTrails(){ - for( Iterator it = particles.iterator(); it.hasNext(); ){ - Particle p = (Particle) it.next(); - p.renderTrails(); - } - } - - void addParticles( int _amt ){ - for( int i=0; i<_amt; i++ ){ - particles.add( new Particle( loc, vel ) ); - } - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/flight404_particles_1_simple.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/flight404_particles_1_simple.pde deleted file mode 100644 index d7018b981..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/flight404_particles_1_simple.pde +++ /dev/null @@ -1,160 +0,0 @@ -// Updated version of flight404 Particle Emitter release 1 -// This works with Processing 1.0 -// All of the advanced openGL direct calls that use display lists, etc. have been stripped out -// It's my intention to redo this example using GlGraphics (http://glgraphics.sourceforge.net/) -// But for now, just want to make sure it works in principal - -// February 28 2011 -// Daniel Shiffman - -// Source Code release 1 -// Particle Emitter -// -// February 11th 2008 -// -// Built with Processing v.135 which you can download at http://www.processing.org/download -// -// Robert Hodgin -// flight404.com -// barbariangroup.com - -// features: -// Toxi's magnificent Vec3D library -// perlin noise flow fields -// ribbon trails -// OpenGL additive blending -// OpenGL display lists -// -// Uses the very useful Vec3D library by Karsten Schmidt (toxi) -// You can download it at http://code.google.com/p/toxiclibs/downloads/list -// -// Please post suggestions and improvements at the flight404 blog. When nicer/faster/better -// practices are suggested, I will incorporate them into the source and repost. I think that -// will be a reasonable system for now. -// -// Future additions will include: -// Rudimentary camera movement -// Magnetic repulsion -// More textures means more iron -// -// UPDATES -// -// February 11th 2008 -// Reorganized some of the OpenGL calls as per Simon Gelfius' suggestion. -// http://www.kinesis.be/ - - -import toxi.geom.*; -import processing.opengl.*; -import javax.media.opengl.*; - -PGraphicsOpenGL pgl; -GL gl; - - -Emitter emitter; -Vec3D gravity; -float floorLevel; - -PImage particleImg; -PImage emitterImg; - -int counter; - - -boolean ALLOWGRAVITY; // add gravity vector? -boolean ALLOWPERLIN; // add perlin noise flow field vector? -boolean ALLOWTRAILS; // render particle trails? -boolean ALLOWFLOOR; // add a floor? - // Turning on all of these options will make things - // slow down. - -void setup(){ - size( 600, 600, OPENGL ); - // Lately I have gotten into the habit of limiting the color range to be - // 0.0 to 1.0. It works this way in OpenGL so I might as well get used to it. - colorMode( RGB, 1.0 ); - - // Turn on 4X antialiasing - hint( ENABLE_OPENGL_4X_SMOOTH ); - - // More OpenGL necessity. - pgl = (PGraphicsOpenGL) g; - gl = pgl.gl; - - // Loads in a particle image from the data folder. Image size should be a power of 2. - particleImg = loadImage( "particle.png" ); - emitterImg = loadImage( "emitter.png" ); - - emitter = new Emitter(); - gravity = new Vec3D( 0, .35, 0 ); // gravity vector - floorLevel = 400; -} - -void draw(){ - background( 0.0 ); - perspective( PI/3.0, (float)width/(float)height, 1, 5000 ); - - // Turns on additive blending so we can draw a bunch of glowing images without - // needing to do any depth testing. - gl.glDepthMask(false); - gl.glEnable( GL.GL_BLEND ); - gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE); - - emitter.exist(); - - // If the mouse button is pressed, then add 10 new particles. - if( mousePressed ){ - if( ALLOWTRAILS && ALLOWFLOOR ){ - emitter.addParticles( 5 ); - } else { - emitter.addParticles( 10 ); - } - } - - counter ++; -} - - -void keyPressed(){ - if( key == 'g' || key == 'G' ) - ALLOWGRAVITY = !ALLOWGRAVITY; - - if( key == 'p' || key == 'P' ) - ALLOWPERLIN = !ALLOWPERLIN; - - if( key == 't' || key == 'T' ) - ALLOWTRAILS = !ALLOWTRAILS; - - if( key == 'f' || key == 'F' ) - ALLOWFLOOR = !ALLOWFLOOR; - -} - - -// This method should be nicer, but it isnt. I use getRads to get a perlin noise -// based angle in radians based on the x and y position of the object asking for it. -// Perlin noise is supposed to give you back a number between 0 and 1, but it wont -// necessarily give you numbers that range from 0 to 1. A usual result is more like -// .25 to .75. -// -// So the point of this method is to try to normalize the values to a -// range of 0 to 1. It's not perfect, and I still get weird results. -// For instance, the mult variable is supposed to be the multiplier for the range. -// So if i wanted a random angle between 0 and TWO_PI, I would set the mult = TWO_PI. -// But when I do that, I find the Perlin noise tends to give me a left-pointing angle. -// To counteract, I end up setting the mult to 10.0 in order to increase the chances -// that I get a nice range from at least 0 to TWO_PI. -float minNoise = 0.499; -float maxNoise = 0.501; -float getRads(float val1, float val2, float mult, float div){ - float rads = noise(val1/div, val2/div, counter/div); - - if (rads < minNoise) minNoise = rads; - if (rads > maxNoise) maxNoise = rads; - - rads -= minNoise; - rads *= 1.0/(maxNoise - minNoise); - - return rads * mult; -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/particle.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/particle.pde deleted file mode 100644 index 16441c9c5..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/particle.pde +++ /dev/null @@ -1,208 +0,0 @@ -/* -General Structure notes. - My classes tend to have a similar naming scheme and flow. I start with the 'exist' method. - Exist is what an object needs to do every frame. Usually 'existing' consists of four main things. - 1) Find the velocity. This involves determining what influences there are on the velocity. - 2) Apply the velocity to the location. - 3) Render the object. - 4) Age the object. - - I also use the metaphor of aging and death. When first made, a particle's age will be zero. - Every frame, the age will increment. If the age reaches the lifeSpan (which is a random number - that I set in the constructor), then the boolean ISDEAD is set to true and the arraylist iterator - removes the dead element from the list. - */ - - - -class Particle { - int len; // number of elements in position array - Vec3D[] loc; // array of position vectors - Vec3D startLoc; // just used to make sure every loc[] is initialized to the same position - Vec3D vel; // velocity vector - Vec3D perlin; // perlin noise vector - float radius; // particle's size - float age; // current age of particle - int lifeSpan; // max allowed age of particle - float agePer; // range from 1.0 (birth) to 0.0 (death) - float bounceAge; // amount to age particle when it bounces off floor - boolean ISDEAD; // if age == lifeSpan, make particle die - boolean ISBOUNCING; // if particle hits the floor... - - - Particle( Vec3D _loc, Vec3D _vel ) { - radius = random( 10, 40 ); - len = (int)( radius ); - loc = new Vec3D[ len ]; - - // This confusing-looking line does three things at once. - // First, you make a random vector. - // new Vec3D().randomVector() - // Next, you multiply that vector by a random number from 0.0 to 5.0. - // scaleSelf( 5.0 ); - // Finally, you add this new vector to the original sent vector. - // _loc.add( ); - // This is just a way to make sure all the particles made this frame - // don't all start on the exact same pixel. This staggering will be useful - // when we incorporate magnetic repulsion in a later tutorial. - startLoc = new Vec3D( _loc.add( new Vec3D().randomVector().scaleSelf( random( 5.0 ) ) ) ); - - for( int i=0; i floorLevel ) { - ISBOUNCING = true; - } - else { - ISBOUNCING = false; - } - } - - if( ISBOUNCING ) { - vel.scaleSelf( .75 ); - vel.y *= -.5; - } - } - - void setPosition() { - // Every frame, the current location will be passed on to - // the next element in the location array. Think 'cursor trail effect'. - for( int i=len-1; i>0; i-- ) { - loc[i].set( loc[i-1] ); - } - - // Set the initial location. - // loc[0] represents the current position of the particle. - loc[0].addSelf( vel ); - } - - void render() { - // As the particle ages, it will gain blue but will lose red and green. - color c = color( agePer, agePer*.75, 1.0 - agePer ); - renderImage(particleImg, loc[0], radius * agePer, c, 1.0 ); - } - - void renderTrails() { - float xp, yp, zp; - float xOff, yOff, zOff; - beginShape(QUAD_STRIP); - for ( int i=0; i lifeSpan ) { - ISDEAD = true; - } - else { - // When spawned, the agePer is 1.0. - // When death occurs, the agePer is 0.0. - agePer = 1.0 - age/(float)lifeSpan; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/NOC_gl.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/NOC_gl.pde deleted file mode 100644 index 2f91c0f1b..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/NOC_gl.pde +++ /dev/null @@ -1,49 +0,0 @@ - -int squareList; -void initGL(){ - pgl.beginGL(); - squareList = gl.glGenLists(1); - gl.glNewList(squareList, GL.GL_COMPILE); - gl.glBegin(GL.GL_POLYGON); - gl.glTexCoord2f(0, 0); gl.glVertex2f(-.5, -.5); - gl.glTexCoord2f(1, 0); gl.glVertex2f( .5, -.5); - gl.glTexCoord2f(1, 1); gl.glVertex2f( .5, .5); - gl.glTexCoord2f(0, 1); gl.glVertex2f(-.5, .5); - gl.glEnd(); - gl.glEndList(); - pgl.endGL(); -} - -void renderImage( Vec3D _loc, float _diam, color _col, float _alpha ){ - gl.glPushMatrix(); - gl.glTranslatef( _loc.x, -_loc.y, _loc.z ); - pov.glReverseCamera(); - gl.glScalef( _diam, _diam, _diam ); - gl.glColor4f( red(_col), green(_col), blue(_col), _alpha ); - gl.glCallList( squareList ); - gl.glPopMatrix(); -} - -// This will allow you to draw images that are oriented to the floor plane. -void renderImageOnFloor( Vec3D _loc, float _diam, color _col, float _aa ){ - gl.glPushMatrix(); - gl.glTranslatef( _loc.x, -_loc.y, _loc.z ); - gl.glScalef( _diam, _diam, _diam ); - gl.glRotatef( 90, 1.0, 0.0, 0.0 ); - gl.glColor4f( red(_col), green(_col), blue(_col), _aa ); - gl.glCallList( squareList ); - gl.glPopMatrix(); -} - -// This will allow you to specify a rotation for images that are oriented perpendicular to the eyeNormal -// which is the vector pointing from the camera's eye to the camera's point of interest. -void renderImageAndRotate( Vec3D _loc, float _diam, color _col, float _aa, float _rot ){ - gl.glPushMatrix(); - gl.glTranslatef( _loc.x, -_loc.y, _loc.z ); - gl.glRotatef( degrees( _rot ), pov.eyeNormal.x, pov.eyeNormal.y, pov.eyeNormal.z ); - pov.glReverseCamera(); - gl.glScalef( _diam, _diam, _diam ); - gl.glColor4f( red(_col), green(_col), blue(_col), _aa ); - gl.glCallList( squareList ); - gl.glPopMatrix(); -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/cursor.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/cursor.pde deleted file mode 100644 index ee2909cb9..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/cursor.pde +++ /dev/null @@ -1,25 +0,0 @@ -class Cursor{ - Vec3D loc; - Vec3D vel; - - Cursor(){ - loc = new Vec3D(); - vel = new Vec3D(); - } - - void exist(){ - // 2.35 is an arbitrary number. Ideally, this cursor would function - // properly regardless of the camera's rotation and distance from the object. - // Im not sure how to make that happen... 3D interaction with the cursor has - // been low on my research list. Think of this as a crappy placeholder. - loc.set( ( mouseX - xMid ) * 2.25, ( mouseY - yMid ) * 2.25, 0 ); - } - - void render(){ - pushMatrix(); - translate( loc.x, loc.y, loc.z ); - fill( 1, 0, 0 ); - sphere( 10 ); - popMatrix(); - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/emitter.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/emitter.pde deleted file mode 100644 index 04eb2045a..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/emitter.pde +++ /dev/null @@ -1,182 +0,0 @@ -class Emitter{ - Vec3D loc; - Vec3D vel; - Vec3D velToMouse; - float radius; - - Texture coronaTex; - Texture emitterTex; - Texture particleTex; - Texture reflectionTex; - - color myColor; - - ArrayList particles; - ArrayList nebulae; - - Emitter( ){ - - try { - coronaTex = TextureIO.newTexture(new File(dataPath("corona.png")), true); - emitterTex = TextureIO.newTexture(new File(dataPath("emitter.png")), true); - particleTex = TextureIO.newTexture(new File(dataPath("particle.png")), true); - reflectionTex = TextureIO.newTexture(new File(dataPath("reflection.png")), true); - } - catch (IOException e) { - println("Texture file is missing"); - exit(); // or handle it some other way - } - - loc = new Vec3D(); - vel = new Vec3D(); - velToMouse = new Vec3D(); - - radius = 100; - - myColor = color( 1, 1, 1 ); - - particles = new ArrayList(); - nebulae = new ArrayList(); - } - - void exist(){ - findVelocity(); - setPosition(); - iterateListExist(); - render(); - - gl.glDisable( GL.GL_TEXTURE_2D ); - - if( ALLOWTRAILS ) - iterateListRenderTrails(); - } - - void findVelocity(){ - Vec3D dirToMouse = new Vec3D( mouse.loc.sub( loc ).scale( .15 ) ); - vel.set( dirToMouse ); - } - - void setPosition(){ - loc.addSelf( vel ); - - if( ALLOWFLOOR ){ - if( loc.y > floorLevel ){ - loc.y = floorLevel; - vel.y = 0; - } - } - } - - void iterateListExist(){ - gl.glEnable( GL.GL_TEXTURE_2D ); - - - int mylength = particles.size(); - for( int i=mylength-1; i>=0; i-- ){ - Particle p = ( Particle )particles.get(i); - if( p.ISSPLIT ) - addParticles( p ); - - if ( !p.ISDEAD ){ - // pgl.bindTexture( images.particle ); - particleTex.bind(); - particleTex.enable(); - p.exist(); - particleTex.disable(); - - } - else { - particles.set( i, particles.get( particles.size() - 1 ) ); - particles.remove( particles.size() - 1 ); - } - } - - if( ALLOWFLOOR ){ - // pgl.bindTexture( images.reflection ); - reflectionTex.bind(); - reflectionTex.enable(); - for( Iterator it = particles.iterator(); it.hasNext(); ){ - Particle p = (Particle) it.next(); - p.renderReflection(); - } - reflectionTex.disable(); - } - - // pgl.bindTexture( images.corona ); - coronaTex.bind(); - coronaTex.enable(); - for( Iterator it = nebulae.iterator(); it.hasNext(); ){ - Nebula n = (Nebula) it.next(); - if( !n.ISDEAD ){ - n.exist(); - } - else { - it.remove(); - } - } - coronaTex.disable(); - } - - - void render(){ - // pgl.bindTexture( images.emitter ); - emitterTex.bind(); - emitterTex.enable(); - renderImage( loc, radius, myColor, 1.0 ); - emitterTex.enable(); - - if( ALLOWNEBULA ){ - nebulae.add( new Nebula( loc, 15.0, true ) ); - nebulae.add( new Nebula( loc, 45.0, true ) ); - } - - - if( ALLOWFLOOR ){ - // pgl.bindTexture( images.reflection ); - reflectionTex.bind(); - reflectionTex.enable(); - renderReflection(); - reflectionTex.disable(); - } - } - - void renderReflection(){ - float altitude = floorLevel - loc.y; - float reflectMaxAltitude = 300.0; - float yPer = 1.0 - altitude/reflectMaxAltitude; - - if( yPer > .05 ) - renderImageOnFloor( new Vec3D( loc.x, floorLevel, loc.z ), radius * 10.0, color( 0.5, 1.0, yPer*.25 ), yPer ); - - if( mousePressed ) - renderImageOnFloor( new Vec3D( loc.x, floorLevel, loc.z ), radius + ( yPer + 1.0 ) * radius * random( 2.0, 3.5 ), color( 1.0, 0, 0 ), yPer ); - } - - void iterateListRenderTrails(){ - for( Iterator it = particles.iterator(); it.hasNext(); ){ - Particle p = (Particle) it.next(); - p.renderTrails(); - } - } - - void addParticles( int _amt ){ - for( int i=0; i<_amt; i++ ){ - particles.add( new Particle( 1, loc, vel ) ); - } - - if( ALLOWNEBULA ){ - nebulae.add( new Nebula( loc, 40.0, false ) ); - nebulae.add( new Nebula( loc, 100.0, false ) ); - } - } - - void addParticles( Particle _p ){ - // play with amt if you want to control how many particles spawn when splitting - int amt = (int)( _p.radius * .15 ); - for( int i=0; i maxNoise) maxNoise = rads; - - rads -= minNoise; - rads *= 1.0/(maxNoise - minNoise); - - return rads * mult; -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/images.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/images.pde deleted file mode 100644 index 821c91230..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/images.pde +++ /dev/null @@ -1,13 +0,0 @@ -class Images{ - PImage particle; - PImage emitter; - PImage corona; - PImage reflection; - - Images(){ - particle = loadImage( "particle.png" ); - emitter = loadImage( "emitter.png" ); - corona = loadImage( "corona.png" ); - reflection = loadImage( "reflection.png" ); - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/nebula.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/nebula.pde deleted file mode 100644 index 573378708..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/nebula.pde +++ /dev/null @@ -1,56 +0,0 @@ -class Nebula{ - Vec3D loc; - Vec3D vel; - float radius; - float scaleFac; - float age; - int lifeSpan; - float agePer; - float rot; - color c; - - boolean ISDEAD; - boolean ISGROUNDED; - - Nebula( Vec3D _loc, float _radius, boolean _ISGROUNDED ){ - loc = new Vec3D( _loc ); - vel = new Vec3D( pov.eyeNormal.scale( 2.0 ) ); - radius = random( _radius*.8, _radius*1.75 ); - - scaleFac = random( 1.005, 1.10 ); - age = 0; - lifeSpan = (int)random(10,30); - rot = random( TWO_PI ); - c = color( random(.75, 1.0), random(.5,.75), random(.2,.8) ); - ISGROUNDED = _ISGROUNDED; - - if( ISGROUNDED ){ - scaleFac = random( 1.01, 1.025 ); - vel.y -= random( 1.0 ); - radius *= 2.0; - } - } - - void exist(){ - move(); - render(); - checkAge(); - } - - void move(){ - radius *= scaleFac; - loc.addSelf( vel ); - } - - void render(){ - renderImageAndRotate( loc, radius, c, sin(agePer*PI) * .4, rot ); - } - - void checkAge(){ - age ++; - agePer = 1.0 - age/(float)lifeSpan; - - if (age > lifeSpan) - ISDEAD = true; - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/particle.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/particle.pde deleted file mode 100644 index 53cbf839b..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/particle.pde +++ /dev/null @@ -1,171 +0,0 @@ - -class Particle{ - int len; // number of elements in position array - Vec3D[] loc; // array of position vectors - Vec3D startLoc; // just used to make sure every loc[] is initialized to the same position - Vec3D vel; // velocity vector - Vec3D perlin; // perlin noise vector - float radius; // particle's size - float age; // current age of particle - int lifeSpan; // max allowed age of particle - float agePer; // range from 1.0 (birth) to 0.0 (death) - int gen; // number of times particle has been involved in a SPLIT - float bounceAge; // amount to age particle when it bounces off floor - float bounceVel; // speed at impact - boolean ISDEAD; // if age == lifeSpan, make particle die - boolean ISBOUNCING; // if particle hits the floor... - boolean ISSPLIT; // if particle hits the floor with enough speed... - - - Particle( int _gen, Vec3D _loc, Vec3D _vel ){ - gen = _gen; - radius = random( 10 - gen, 50 - ( gen-1)*10 ); - - len = (int)( radius*.5 ); - loc = new Vec3D[ len ]; - startLoc = new Vec3D( _loc.add( new Vec3D().randomVector().scaleSelf( random( 1.0 ) ) ) ); - - for( int i=0; i 1 ){ - vel.addSelf( new Vec3D().randomVector().scaleSelf( random( 7.0 ) ) ); - } else { - vel.addSelf( new Vec3D().randomVector().scaleSelf( random( 10.0 ) ) ); - } - - perlin = new Vec3D(); - - age = 0; - bounceAge = 2; - lifeSpan = (int)( radius ); - } - - void exist(){ - if( ALLOWPERLIN ) - findPerlin(); - - findVelocity(); - setPosition(); - render(); - setAge(); - } - - void findPerlin(){ - float xyRads = getRads( loc[0].x, loc[0].z, 20.0, 50.0 ); - float yRads = getRads( loc[0].x, loc[0].y, 20.0, 50.0 ); - perlin.set( cos(xyRads), -sin(yRads), sin(xyRads) ); - perlin.scaleSelf( .5 ); - } - - void findVelocity(){ - if( ALLOWGRAVITY ) - vel.addSelf( gravity ); - - if( ALLOWPERLIN ) - vel.addSelf( perlin ); - - if( ALLOWFLOOR ){ - if( loc[0].y + vel.y > floorLevel ){ - ISBOUNCING = true; - } else { - ISBOUNCING = false; - } - } - - // if the particle is moving fast enough, when it hits the ground it can - // split into a bunch of smaller particles. - if( ISBOUNCING ){ - bounceVel = vel.magnitude(); - - vel.scaleSelf( .7 ); - vel.y *= -( ( radius/40.0 ) * .5 ); - - if( bounceVel > 15.0 && gen < 4 ) - ISSPLIT = true; - - } else { - ISSPLIT = false; - } - } - - void setPosition(){ - for( int i=len-1; i>0; i-- ){ - loc[i].set( loc[i-1] ); - } - - loc[0].addSelf( vel ); - } - - void render(){ - color c = color( agePer - .5, agePer*.25, 1.5 - agePer ); - renderImage( loc[0], radius * agePer, c, 1.0 ); - - // Rendering two graphics here. Makes the particles more vivid, - // but will hinder the performance. - c = color( 1, agePer, agePer ); - renderImage( loc[0], radius * agePer * .5, c, agePer ); - } - - void renderReflection(){ - float altitude = floorLevel - loc[0].y; - float reflectMaxAltitude = 25.0; - float yPer = ( 1.0 - ( altitude/reflectMaxAltitude ) ) * .5; - - if( yPer > .05 ) - renderImageOnFloor( new Vec3D( loc[0].x, floorLevel, loc[0].z ), radius * agePer * 8.0 * yPer, color( agePer, agePer*.25, 0 ), yPer + random( .2 ) ); - } - - void renderTrails(){ - float xp, yp, zp; - float xOff, yOff, zOff; - - gl.glBegin( GL.GL_QUAD_STRIP ); - - for ( int i=0; i lifeSpan ){ - ISDEAD = true; - } else { - agePer = 1.0 - age/(float)lifeSpan; - } - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/pov.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/pov.pde deleted file mode 100644 index 1d5bf01d7..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/pov.pde +++ /dev/null @@ -1,62 +0,0 @@ -// Camera class which uses Kristian Damkjer's OCD library -// http://www.cise.ufl.edu/~kdamkjer/processing/libraries/ocd/ - -class POV{ - PApplet parent; - Camera cam; - - Vec3D eye; - Vec3D center; - - Vec3D eyeNormal; - - boolean ISDRAGGING; - - POV( PApplet _parent ){ - parent = _parent; - cam = new Camera( parent, 0, 100, 1500 ); - - eye = new Vec3D(); - center = new Vec3D(); - eyeNormal = new Vec3D(); - } - - void exist(){ - perspective( PI/3.0, (float)xSize/(float)ySize, .5, 5000 ); - if( ISDRAGGING ){ - cam.circle( radians( ( mouseX - pmouseX ) * .25 ) ); - cam.arc( radians( ( mouseY - pmouseY ) * .25 ) ); - } - - cam.feed(); - setPosition(); - } - - - // Code by JohnG from the Processing forum - // http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1170790832 - // - // Does the camera transformations in reverse to allow for images that always face the camera. - void glReverseCamera(){ - float deltaX = eye.x - center.x; - float deltaY = eye.y - center.y; - float deltaZ = eye.z - center.z; - - float angleZ = atan2( deltaY,deltaX ); - float hyp = sqrt( sq( deltaX ) + sq( deltaY ) ); - float angleY = atan2( hyp,deltaZ ); - - gl.glRotatef( degrees( angleZ ), 0, 0, 1.0 ); - gl.glRotatef( degrees( angleY ), 0, 1.0, 0 ); - } - - - void setPosition(){ - float[] e = cam.position(); - float[] c = cam.target(); - - eye.set( e[0], e[1], e[2] ); - center.set( c[0], c[1], c[2] ); - eyeNormal = eye.sub(center).normalize(); - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/sketch.properties b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/sketch.properties deleted file mode 100644 index 28faa5897..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=Standard diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/NOC_gl.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/NOC_gl.pde deleted file mode 100644 index 44705cdbd..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/NOC_gl.pde +++ /dev/null @@ -1,31 +0,0 @@ - -void renderImage(PImage img, Vec3D _loc, float _diam, color _col, float _alpha ) { - pushMatrix(); - translate( _loc.x, _loc.y, _loc.z ); - pov.glReverseCamera(); - tint(red(_col), green(_col), blue(_col), _alpha); - imageMode(CENTER); - image(img,0,0,_diam,_diam); - popMatrix(); -} - -void renderImageOnFloor(PImage img, Vec3D _loc, float _diam, color _col, float _aa ) { - pushMatrix(); - translate( _loc.x, _loc.y, _loc.z ); - rotateX(PI/2); - //pov.glReverseCamera(); - tint(red(_col), green(_col), blue(_col), _aa); - imageMode(CENTER); - image(img,0,0,_diam,_diam); - popMatrix(); -} - -void renderImageAndRotate(PImage img, Vec3D _loc, float _diam, color _col, float _aa, float _rot ) { - pushMatrix(); - translate( _loc.x, _loc.y, _loc.z ); - pov.glReverseCamera(); - tint(red(_col), green(_col), blue(_col), _aa); - imageMode(CENTER); - image(img,0,0,_diam,_diam); - popMatrix(); -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/cursor.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/cursor.pde deleted file mode 100644 index ee2909cb9..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/cursor.pde +++ /dev/null @@ -1,25 +0,0 @@ -class Cursor{ - Vec3D loc; - Vec3D vel; - - Cursor(){ - loc = new Vec3D(); - vel = new Vec3D(); - } - - void exist(){ - // 2.35 is an arbitrary number. Ideally, this cursor would function - // properly regardless of the camera's rotation and distance from the object. - // Im not sure how to make that happen... 3D interaction with the cursor has - // been low on my research list. Think of this as a crappy placeholder. - loc.set( ( mouseX - xMid ) * 2.25, ( mouseY - yMid ) * 2.25, 0 ); - } - - void render(){ - pushMatrix(); - translate( loc.x, loc.y, loc.z ); - fill( 1, 0, 0 ); - sphere( 10 ); - popMatrix(); - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/emitter.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/emitter.pde deleted file mode 100644 index c22f45bdf..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/emitter.pde +++ /dev/null @@ -1,149 +0,0 @@ -class Emitter{ - Vec3D loc; - Vec3D vel; - Vec3D velToMouse; - float radius; - - color myColor; - - ArrayList particles; - ArrayList nebulae; - - Emitter( ){ - loc = new Vec3D(); - vel = new Vec3D(); - velToMouse = new Vec3D(); - - radius = 100; - - myColor = color( 1, 1, 1 ); - - particles = new ArrayList(); - nebulae = new ArrayList(); - } - - void exist(){ - findVelocity(); - setPosition(); - iterateListExist(); - render(); - - gl.glDisable( GL.GL_TEXTURE_2D ); - - if( ALLOWTRAILS ) - iterateListRenderTrails(); - } - - void findVelocity(){ - Vec3D dirToMouse = new Vec3D( mouse.loc.sub( loc ).scale( .15 ) ); - vel.set( dirToMouse ); - } - - void setPosition(){ - loc.addSelf( vel ); - - if( ALLOWFLOOR ){ - if( loc.y > floorLevel ){ - loc.y = floorLevel; - vel.y = 0; - } - } - } - - void iterateListExist(){ - gl.glEnable( GL.GL_TEXTURE_2D ); - - - int mylength = particles.size(); - for( int i=mylength-1; i>=0; i-- ){ - Particle p = ( Particle )particles.get(i); - if( p.ISSPLIT ) - addParticles( p ); - - if ( !p.ISDEAD ){ - //pgl.bindTexture( images.particle ); - p.exist(); - - } else { - particles.set( i, particles.get( particles.size() - 1 ) ); - particles.remove( particles.size() - 1 ); - } - } - - if( ALLOWFLOOR ){ - //pgl.bindTexture( images.reflection ); - for( Iterator it = particles.iterator(); it.hasNext(); ){ - Particle p = (Particle) it.next(); - p.renderReflection(); - } - } - - //pgl.bindTexture( images.corona ); - for( Iterator it = nebulae.iterator(); it.hasNext(); ){ - Nebula n = (Nebula) it.next(); - if( !n.ISDEAD ){ - n.exist(); - } else { - it.remove(); - } - } - } - - - void render(){ - //pgl.bindTexture( images.emitter ); - renderImage( images.emitter,loc, radius, myColor, 1.0 ); - - - if( ALLOWNEBULA ){ - nebulae.add( new Nebula( loc, 15.0, true ) ); - nebulae.add( new Nebula( loc, 45.0, true ) ); - } - - - if( ALLOWFLOOR ){ - //pgl.bindTexture( images.reflection ); - renderReflection(images.reflection); - } - } - - void renderReflection(PImage img){ - float altitude = floorLevel - loc.y; - float reflectMaxAltitude = 300.0; - float yPer = 1.0 - altitude/reflectMaxAltitude; - - if( yPer > .05 ) - renderImageOnFloor(img, new Vec3D( loc.x, floorLevel, loc.z ), radius * 10.0, color( 0.5, 1.0, yPer*.25 ), yPer ); - - if( mousePressed ) - renderImageOnFloor(img, new Vec3D( loc.x, floorLevel, loc.z ), radius + ( yPer + 1.0 ) * radius * random( 2.0, 3.5 ), color( 1.0, 0, 0 ), yPer ); - } - - void iterateListRenderTrails(){ - for( Iterator it = particles.iterator(); it.hasNext(); ){ - Particle p = (Particle) it.next(); - p.renderTrails(); - } - } - - void addParticles( int _amt ){ - for( int i=0; i<_amt; i++ ){ - particles.add( new Particle( 1, loc, vel ) ); - } - - if( ALLOWNEBULA ){ - nebulae.add( new Nebula( loc, 40.0, false ) ); - nebulae.add( new Nebula( loc, 100.0, false ) ); - } - } - - void addParticles( Particle _p ){ - // play with amt if you want to control how many particles spawn when splitting - int amt = (int)( _p.radius * .15 ); - for( int i=0; i maxNoise) maxNoise = rads; - - rads -= minNoise; - rads *= 1.0/(maxNoise - minNoise); - - return rads * mult; -} - diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/images.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/images.pde deleted file mode 100644 index 821c91230..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/images.pde +++ /dev/null @@ -1,13 +0,0 @@ -class Images{ - PImage particle; - PImage emitter; - PImage corona; - PImage reflection; - - Images(){ - particle = loadImage( "particle.png" ); - emitter = loadImage( "emitter.png" ); - corona = loadImage( "corona.png" ); - reflection = loadImage( "reflection.png" ); - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/nebula.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/nebula.pde deleted file mode 100644 index 3412c110f..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/nebula.pde +++ /dev/null @@ -1,56 +0,0 @@ -class Nebula{ - Vec3D loc; - Vec3D vel; - float radius; - float scaleFac; - float age; - int lifeSpan; - float agePer; - float rot; - color c; - - boolean ISDEAD; - boolean ISGROUNDED; - - Nebula( Vec3D _loc, float _radius, boolean _ISGROUNDED ){ - loc = new Vec3D( _loc ); - vel = new Vec3D( pov.eyeNormal.scale( 2.0 ) ); - radius = random( _radius*.8, _radius*1.75 ); - - scaleFac = random( 1.005, 1.10 ); - age = 0; - lifeSpan = (int)random(10,30); - rot = random( TWO_PI ); - c = color( random(.75, 1.0), random(.5,.75), random(.2,.8) ); - ISGROUNDED = _ISGROUNDED; - - if( ISGROUNDED ){ - scaleFac = random( 1.01, 1.025 ); - vel.y -= random( 1.0 ); - radius *= 2.0; - } - } - - void exist(){ - move(); - render(); - checkAge(); - } - - void move(){ - radius *= scaleFac; - loc.addSelf( vel ); - } - - void render(){ - renderImageAndRotate(images.corona, loc, radius, c, sin(agePer*PI) * .4, rot ); - } - - void checkAge(){ - age ++; - agePer = 1.0 - age/(float)lifeSpan; - - if (age > lifeSpan) - ISDEAD = true; - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/particle.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/particle.pde deleted file mode 100644 index 893d3631f..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/particle.pde +++ /dev/null @@ -1,172 +0,0 @@ - -class Particle{ - int len; // number of elements in position array - Vec3D[] loc; // array of position vectors - Vec3D startLoc; // just used to make sure every loc[] is initialized to the same position - Vec3D vel; // velocity vector - Vec3D perlin; // perlin noise vector - float radius; // particle's size - float age; // current age of particle - int lifeSpan; // max allowed age of particle - float agePer; // range from 1.0 (birth) to 0.0 (death) - int gen; // number of times particle has been involved in a SPLIT - float bounceAge; // amount to age particle when it bounces off floor - float bounceVel; // speed at impact - boolean ISDEAD; // if age == lifeSpan, make particle die - boolean ISBOUNCING; // if particle hits the floor... - boolean ISSPLIT; // if particle hits the floor with enough speed... - - - Particle( int _gen, Vec3D _loc, Vec3D _vel ){ - gen = _gen; - radius = random( 10 - gen, 50 - ( gen-1)*10 ); - - len = (int)( radius*.5 ); - loc = new Vec3D[ len ]; - startLoc = new Vec3D( _loc.add( new Vec3D().randomVector().scaleSelf( random( 1.0 ) ) ) ); - - for( int i=0; i 1 ){ - vel.addSelf( new Vec3D().randomVector().scaleSelf( random( 7.0 ) ) ); - } else { - vel.addSelf( new Vec3D().randomVector().scaleSelf( random( 10.0 ) ) ); - } - - perlin = new Vec3D(); - - age = 0; - bounceAge = 2; - lifeSpan = (int)( radius ); - } - - void exist(){ - if( ALLOWPERLIN ) - findPerlin(); - - findVelocity(); - setPosition(); - render(); - setAge(); - } - - void findPerlin(){ - float xyRads = getRads( loc[0].x, loc[0].z, 20.0, 50.0 ); - float yRads = getRads( loc[0].x, loc[0].y, 20.0, 50.0 ); - perlin.set( cos(xyRads), -sin(yRads), sin(xyRads) ); - perlin.scaleSelf( .5 ); - } - - void findVelocity(){ - if( ALLOWGRAVITY ) - vel.addSelf( gravity ); - - if( ALLOWPERLIN ) - vel.addSelf( perlin ); - - if( ALLOWFLOOR ){ - if( loc[0].y + vel.y > floorLevel ){ - ISBOUNCING = true; - } else { - ISBOUNCING = false; - } - } - - // if the particle is moving fast enough, when it hits the ground it can - // split into a bunch of smaller particles. - if( ISBOUNCING ){ - bounceVel = vel.magnitude(); - - vel.scaleSelf( .7 ); - vel.y *= -( ( radius/40.0 ) * .5 ); - - if( bounceVel > 15.0 && gen < 4 ) - ISSPLIT = true; - - } else { - ISSPLIT = false; - } - } - - void setPosition(){ - for( int i=len-1; i>0; i-- ){ - loc[i].set( loc[i-1] ); - } - - loc[0].addSelf( vel ); - } - - void render(){ - color c = color( agePer - .5, agePer*.25, 1.5 - agePer ); - renderImage(images.particle, loc[0], radius * agePer, c, 1.0 ); - - // Rendering two graphics here. Makes the particles more vivid, - // but will hinder the performance. - c = color( 1, agePer, agePer ); - renderImage(images.particle, loc[0], radius * agePer * .5, c, agePer ); - } - - void renderReflection(){ - float altitude = floorLevel - loc[0].y; - float reflectMaxAltitude = 25.0; - float yPer = ( 1.0 - ( altitude/reflectMaxAltitude ) ) * .5; - - if( yPer > .05 ) - renderImageOnFloor(images.particle, new Vec3D( loc[0].x, floorLevel, loc[0].z ), radius * agePer * 8.0 * yPer, color( agePer, agePer*.25, 0 ), yPer + random( .2 ) ); - } - - void renderTrails(){ - float xp, yp, zp; - float xOff, yOff, zOff; - - beginShape(QUAD_STRIP); - - for ( int i=0; i lifeSpan ){ - ISDEAD = true; - } else { - agePer = 1.0 - age/(float)lifeSpan; - } - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/pov.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/pov.pde deleted file mode 100644 index cc41c1360..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/pov.pde +++ /dev/null @@ -1,64 +0,0 @@ -// Camera class which uses Kristian Damkjer's OCD library -// http://www.cise.ufl.edu/~kdamkjer/processing/libraries/ocd/ - -class POV{ - PApplet parent; - Camera cam; - - Vec3D eye; - Vec3D center; - - Vec3D eyeNormal; - - boolean ISDRAGGING; - - POV( PApplet _parent ){ - parent = _parent; - cam = new Camera( parent, 0, -100, 1500 ); - - eye = new Vec3D(); - center = new Vec3D(); - eyeNormal = new Vec3D(); - } - - void exist(){ - perspective( PI/3.0, (float)xSize/(float)ySize, .5, 5000 ); - if( ISDRAGGING ){ - cam.circle( radians( ( mouseX - pmouseX ) * .25 ) ); - cam.arc( radians( ( mouseY - pmouseY ) * .25 ) ); - } - - cam.feed(); - setPosition(); - } - - - // Code by JohnG from the Processing forum - // http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1170790832 - // - // Does the camera transformations in reverse to allow for images that always face the camera. - void glReverseCamera(){ - float deltaX = eye.x - center.x; - float deltaY = eye.y - center.y; - float deltaZ = eye.z - center.z; - - float angleZ = atan2( deltaY,deltaX ); - float hyp = sqrt( sq( deltaX ) + sq( deltaY ) ); - float angleY = atan2( hyp,deltaZ ); - - rotateZ(angleZ); - rotateY(angleY); - //gl.glRotatef( degrees( angleZ ), 0, 0, 1.0 ); - //gl.glRotatef( degrees( angleY ), 0, 1.0, 0 ); - } - - - void setPosition(){ - float[] e = cam.position(); - float[] c = cam.target(); - - eye.set( e[0], e[1], e[2] ); - center.set( c[0], c[1], c[2] ); - eyeNormal = eye.sub(center).normalize(); - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Circle.pde b/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Circle.pde deleted file mode 100644 index a25a7fa3d..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Circle.pde +++ /dev/null @@ -1,36 +0,0 @@ -// Learning Processing -// Daniel Shiffman -// http://www.learningprocessing.com - -// Example 22-1: Inheritance - -class Circle extends Shape { - - // Inherits all instance variables from parent + adding one - color c; - - Circle(float x_, float y_, float r_, color c_) { - super(x_,y_,r_); // Call the parent constructor - c = c_; // Also deal with this new instance variable - } - - // Call the parent jiggle, but do some more stuff too - void jiggle() { - super.jiggle(); - // The Circle jiggles its size as well as its x,y location. - r += random(-1,1); - r = constrain(r,0,100); - } - - // The changeColor() function is unique to the Circle class. - void changeColor() { - c = color(random(255)); - } - - void display() { - ellipseMode(CENTER); - fill(c); - stroke(0); - ellipse(x,y,r,r); - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Shape.pde b/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Shape.pde deleted file mode 100644 index a4d8a723a..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Shape.pde +++ /dev/null @@ -1,28 +0,0 @@ -// Learning Processing -// Daniel Shiffman -// http://www.learningprocessing.com - -// Example 22-1: Inheritance - -class Shape { - float x; - float y; - float r; - - Shape(float x_, float y_, float r_) { - x = x_; - y = y_; - r = r_; - } - - void jiggle() { - x += random(-1,1); - y += random(-1,1); - } - - // A generic shape does not really know how to be displayed. - // This will be overridden in the child classes. - void display() { - point(x,y); - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Square.pde b/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Square.pde deleted file mode 100644 index 51209d3da..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Square.pde +++ /dev/null @@ -1,25 +0,0 @@ -// Learning Processing -// Daniel Shiffman -// http://www.learningprocessing.com - -// Example 22-1: Inheritance - -class Square extends Shape { - // Variables are inherited from the parent. - // We could also add variables unique to the Square class if we so desire - - Square(float x_, float y_, float r_) { - // If the parent constructor takes arguments then super() needs to pass in those arguments. - super(x_,y_,r_); - } - - // Inherits jiggle() from parent - - // The square overrides its parent for display. - void display() { - rectMode(CENTER); - fill(175); - stroke(0); - rect(x,y,r,r); - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/simpleInheritance.pde b/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/simpleInheritance.pde deleted file mode 100644 index f5ff6dd60..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/simpleInheritance.pde +++ /dev/null @@ -1,27 +0,0 @@ -// Learning Processing -// Daniel Shiffman -// http://www.learningprocessing.com - -// Example 22-1: Inheritance - -// Object oriented programming allows us to defi ne classes in terms of other classes. -// A class can be a subclass (aka " child " ) of a super class (aka "parent"). -// This is a simple example demonstrating this concept, known as "inheritance." -Square s; -Circle c; - -void setup() { - size(200,200); - smooth(); - // A square and circle - s = new Square(75,75,10); - c = new Circle(125,125,20,color(175)); -} - -void draw() { - background(255); - c.jiggle(); - s.jiggle(); - c.display(); - s.display(); -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Circle.pde b/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Circle.pde deleted file mode 100644 index 538f27a4a..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Circle.pde +++ /dev/null @@ -1,36 +0,0 @@ -// Learning Processing -// Daniel Shiffman -// http://www.learningprocessing.com - -// Example 22-2: Polymorphism - -class Circle extends Shape { - - // Inherits all instance variables from parent + adding one - color c; - - Circle(float x_, float y_, float r_, color c_) { - super(x_,y_,r_); // Call the parent constructor - c = c_; // Also deal with this new instance variable - } - - // Call the parent jiggle, but do some more stuff too - void jiggle() { - super.jiggle(); - // The Circle jiggles its size as well as its x,y location. - r += random(-1,1); - r = constrain(r,0,100); - } - - // The changeColor() function is unique to the Circle class. - void changeColor() { - c = color(random(255)); - } - - void display() { - ellipseMode(CENTER); - fill(c); - stroke(0); - ellipse(x,y,r,r); - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Shape.pde b/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Shape.pde deleted file mode 100644 index 54c7fe4a3..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Shape.pde +++ /dev/null @@ -1,28 +0,0 @@ -// Learning Processing -// Daniel Shiffman -// http://www.learningprocessing.com - -// Example 22-2: Polymorphism - -class Shape { - float x; - float y; - float r; - - Shape(float x_, float y_, float r_) { - x = x_; - y = y_; - r = r_; - } - - void jiggle() { - x += random(-1,1); - y += random(-1,1); - } - - // A generic shape does not really know how to be displayed. - // This will be overridden in the child classes. - void display() { - point(x,y); - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Square.pde b/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Square.pde deleted file mode 100644 index 489b99073..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Square.pde +++ /dev/null @@ -1,25 +0,0 @@ -// Learning Processing -// Daniel Shiffman -// http://www.learningprocessing.com - -// Example 22-2: Polymorphism - -class Square extends Shape { - // Variables are inherited from the parent. - // We could also add variables unique to the Square class if we so desire - - Square(float x_, float y_, float r_) { - // If the parent constructor takes arguments then super() needs to pass in those arguments. - super(x_,y_,r_); - } - - // Inherits jiggle() from parent - - // The square overrides its parent for display. - void display() { - rectMode(CENTER); - fill(175); - stroke(0); - rect(x,y,r,r); - } -} diff --git a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/simplePolymorphism.pde b/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/simplePolymorphism.pde deleted file mode 100644 index add4ed517..000000000 --- a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/simplePolymorphism.pde +++ /dev/null @@ -1,32 +0,0 @@ -// Learning Processing -// Daniel Shiffman -// http://www.learningprocessing.com - -// Example 22-2: Polymorphism - -// One array of Shapes -Shape[] shapes = new Shape[30]; - -void setup() { - size(200,200); - smooth(); - - for (int i = 0; i < shapes.length; i++ ) { - int r = int(random(2)); - // Randomly put either circles or squares in our array - if (r == 0) { - shapes[i] = new Circle(100,100,10,color(random(255),100)); - } else { - shapes[i] = new Square(100,100,10); - } - } -} - -void draw() { - background(255); - // Jiggle and display all shapes - for (int i = 0; i < shapes.length; i++ ) { - shapes[i].jiggle(); - shapes[i].display(); - } -} diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/CollisionsEqualMass.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/CollisionsEqualMass.pde deleted file mode 100644 index 4abce573e..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/CollisionsEqualMass.pde +++ /dev/null @@ -1,33 +0,0 @@ -// Collisions -- Elastic, Equal Mass, Two objects only -// Nature of Code, Spring 2009 -// Daniel Shiffman - -// Based off of Chapter 9: Resolving Collisions -// Mathematics and Physics for Programmers by Danny Kodicek - -// A Thing class for idealized collisions - -Mover a; -Mover b; - -boolean showVectors = true; - -void setup() { - size(200,200); - smooth(); - a = new Mover(new PVector(random(5),random(-5,5)),new PVector(10,10)); - b = new Mover(new PVector(-2,1),new PVector(150,150)); -} - -void draw() { - background(255); - a.go(); - b.go(); - - // Note this function will ONLY WORK with two objects - // Needs to be revised in the case of an array of objects - a.collideEqualMass(b); -} - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/Mover.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/Mover.pde deleted file mode 100644 index 48d6389b3..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/Mover.pde +++ /dev/null @@ -1,99 +0,0 @@ -// Collisions -// Daniel Shiffman - -// A Thing class for idealized collision - -class Mover { - - PVector loc; - PVector vel; - float bounce = 1.0; - float r = 20; - boolean colliding = false; - - Mover(PVector v, PVector l) { - vel = v.get(); - loc = l.get(); - } - - // Main method to operate object - void go() { - update(); - borders(); - display(); - } - - // Method to update location - void update() { - loc.add(vel); - } - - // Check for bouncing off borders - void borders() { - if (loc.y > height) { - vel.y *= -bounce; - loc.y = height; - } - else if (loc.y < 0) { - vel.y *= -bounce; - loc.y = 0; - } - if (loc.x > width) { - vel.x *= -bounce; - loc.x = width; - } - else if (loc.x < 0) { - vel.x *= -bounce; - loc.x = 0; - } - } - - // Method to display - void display() { - ellipseMode(CENTER); - stroke(0); - fill(175,200); - ellipse(loc.x,loc.y,r*2,r*2); - if (showVectors) { - drawVector(vel,loc,10); - } - } - - void collideEqualMass(Mover other) { - float d = PVector.dist(loc,other.loc); - float sumR = r + other.r; - // Are they colliding? - if (!colliding && d < sumR) { - // Yes, make new velocities! - colliding = true; - // Direction of one object another - PVector n = PVector.sub(other.loc,loc); - n.normalize(); - - // Difference of velocities so that we think of one object as stationary - PVector u = PVector.sub(vel,other.vel); - - // Separate out components -- one in direction of normal - PVector un = componentVector(u,n); - // Other component - u.sub(un); - // These are the new velocities plus the velocity of the object we consider as stastionary - vel = PVector.add(u,other.vel); - other.vel = PVector.add(un,other.vel); - } - else if (d > sumR) { - colliding = false; - } - } -} - -PVector componentVector (PVector vector, PVector directionVector) { - //--! ARGUMENTS: vector, directionVector (2D vectors) - //--! RETURNS: the component vector of vector in the direction directionVector - //-- normalize directionVector - directionVector.normalize(); - directionVector.mult(vector.dot(directionVector)); - return directionVector; -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/drawVector.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/drawVector.pde deleted file mode 100644 index c3440240d..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/drawVector.pde +++ /dev/null @@ -1,21 +0,0 @@ -void drawVector(PVector v, PVector loc, float scayl) { - pushMatrix(); - float arrowsize = 4; - // Translate to location to render vector - translate(loc.x,loc.y); - stroke(0); - // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate - rotate(v.heading2D()); - // Calculate length of vector & scale it to be bigger or smaller if necessary - float len = v.mag()*scayl; - // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction) - line(0,0,len,0); - line(len,0,len-arrowsize,+arrowsize/2); - line(len,0,len-arrowsize,-arrowsize/2); - popMatrix(); -} - - -void mousePressed() { - showVectors = !showVectors; -} diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Blob.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Blob.pde deleted file mode 100644 index 43c0584a0..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Blob.pde +++ /dev/null @@ -1,196 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A blob skeleton -// Could be used to create blobbly characters a la Nokia Friends -// http://postspectacular.com/work/nokia/friends/start - -class Skeleton { - - // A list to keep track of all the bodies and joints - ArrayList bodies; - ArrayList joints; - - float bodyRadius; // The radius of each body that makes up the skeleton - float radius; // The radius of the entire blob - float totalPoints; // How many points make up the blob - - - // We should modify this constructor to receive arguments - // So that we can make many different types of blobs - Skeleton() { - - // Create the empty ArrayLists - bodies = new ArrayList(); - joints = new ArrayList(); - - // Where and how big is the blob - Vec2 center = new Vec2(width/2, height/2); - radius = 100; - totalPoints = 32; - bodyRadius = 10; - - // Initialize all the points in a circle - for (int i = 0; i < totalPoints; i++) { - // Look polar to cartesian coordinate transformation! - float theta = PApplet.map(i, 0, totalPoints, 0, TWO_PI); - float x = center.x + radius * sin(theta); - float y = center.y + radius * cos(theta); - - // Make each individual body - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - - bd.fixedRotation = true; // no rotation! - bd.position.set(box2d.coordPixelsToWorld(x, y)); - Body body = box2d.createBody(bd); - - // The body is a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(bodyRadius); - - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = cs; - fd.density = 1; - fd.friction = 0.5; - fd.restitution = 0.3; - - // Finalize the body - body.createFixture(fd); - - // Store our own copy for later rendering - bodies.add(body); - } - - // Now connect the outline of the shape all with joints - for (int i = 0; i < bodies.size(); i++) { - DistanceJointDef djd = new DistanceJointDef(); - Body a = bodies.get(i); - int next = i+1; - if (i == bodies.size()-1) { - next = 0; - } - Body b = bodies.get(next); - // Connection between previous particle and this one - djd.bodyA = a; - djd.bodyB = b; - // Equilibrium length is distance between these bodies - Vec2 apos = a.getWorldCenter(); - Vec2 bpos = b.getWorldCenter(); - float d = dist(apos.x, apos.y, bpos.x, bpos.y); - djd.length = d; - // These properties affect how springy the joint is - djd.frequencyHz = 10; - djd.dampingRatio = 0.9; - - // Make the joint. - DistanceJoint dj = (DistanceJoint) box2d.world.createJoint(djd); - joints.add(dj); - } - - - // Make some joints that cross the center of the blob between bodies - for (int i = 0; i < bodies.size(); i++) { - for (int j = i+2; j < bodies.size(); j+=4) { - DistanceJointDef djd = new DistanceJointDef(); - Body a = bodies.get(i); - Body b = bodies.get(j); - // Connection between two bides - djd.bodyA = a; - djd.bodyB = b; - // Equilibrium length is distance between these bodies - Vec2 apos = a.getWorldCenter(); - Vec2 bpos = b.getWorldCenter(); - float d = dist(apos.x, apos.y, bpos.x, bpos.y); - - djd.length = d; - // These properties affect how springy the joint is - djd.frequencyHz = 3; - djd.dampingRatio = 0.1; - - // Make the joint. - DistanceJoint dj = (DistanceJoint) box2d.world.createJoint(djd); - joints.add(dj); - } - } - } - - - // Draw the skeleton as circles for bodies and lines for joints - void displaySkeleton() { - // Draw the outline - stroke(0); - strokeWeight(1); - for (Joint j: joints) { - Body a = j.getBodyA(); - Body b = j.getBodyB(); - Vec2 posa = box2d.getBodyPixelCoord(a); - Vec2 posb = box2d.getBodyPixelCoord(b); - line(posa.x, posa.y, posb.x, posb.y); - } - - // Draw the individual circles - for (Body b: bodies) { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(b); - // Get its angle of rotation - float a = b.getAngle(); - pushMatrix(); - translate(pos.x, pos.y); - rotate(a); - fill(175); - stroke(0); - strokeWeight(1); - ellipse(0, 0, bodyRadius*2, bodyRadius*2); - popMatrix(); - } - } - - - // Draw it as a creature - void displayCreature() { - // Let's compute the center! - Vec2 center = new Vec2(0, 0); - - // Make a curvy polygon - beginShape(); - stroke(175); - strokeWeight(bodyRadius*2); - fill(175); - for (Body b: bodies) { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(b); - curveVertex(pos.x, pos.y); - center.addLocal(pos); - } - endShape(CLOSE); - // Center is average of all points - center.mulLocal(1.0/bodies.size()); - - // Find angle between center and side body - Vec2 pos = box2d.getBodyPixelCoord(bodies.get(0)); - float dx = pos.x - center.x; - float dy = pos.y - center.y; - float angle = atan2(dy, dx)-PI/2; - - // Draw eyes and mouth relative to center - pushMatrix(); - strokeWeight(1); - stroke(0); - translate(center.x, center.y); - rotate(angle); - fill(0); - ellipse(-25, -50, 16, 16); - ellipse(25, -50, 16, 16); - line(-50, 50, 50, 50); - popMatrix(); - } - - Body getFirstBody() { - return bodies.get(0); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/BlobSkeleton.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/BlobSkeleton.pde deleted file mode 100644 index b22248de8..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/BlobSkeleton.pde +++ /dev/null @@ -1,112 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A blob skeleton -// Could be used to create blobbly characters a la Nokia Friends -// http://postspectacular.com/work/nokia/friends/start - -import pbox2d.*; - -import org.jbox2d.collision.shapes.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; -import org.jbox2d.dynamics.joints.*; - -// A reference to our box2d world -PBox2D box2d; - -// A list we'll use to track fixed objects -ArrayList boundaries; - -// Our "blob" object -Skeleton blob; - -// Just a single box this time -Box box; -// The Spring that will attach to the box from the mouse -Spring spring; - -// Draw creature design or skeleton? -boolean skeleton; - -void setup() { - size(640, 360); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - - // Add some boundaries - boundaries = new ArrayList(); - boundaries.add(new Boundary(width/2, height-5, width, 10)); - boundaries.add(new Boundary(width/2, 5, width, 10)); - boundaries.add(new Boundary(width-5, height/2, 10, height)); - boundaries.add(new Boundary(5, height/2, 10, height)); - - // Make a new blob - blob = new Skeleton(); - - // Make the box - box = new Box(width/2, 100); - - // Make the spring (it doesn't really get initialized until the mouse is clicked) - spring = new Spring(); -} - -// When the mouse is released we're done with the spring -void mouseReleased() { - spring.destroy(); -} - -// When the mouse is pressed we. . . -void mousePressed() { - // Check to see if the mouse was clicked on the box - if (box.contains(mouseX, mouseY)) { - // And if so, bind the mouse location to the box with a spring - spring.bind(mouseX, mouseY, box); - } -} - -void draw() { - background(255); - - // We must always step through time! - - box2d.step(); - - - // Show the blob! - if (skeleton) { - blob.displaySkeleton(); - } - else { - blob.displayCreature(); - } - - // Show the boundaries! - for (Boundary wall: boundaries) { - wall.display(); - } - - // Always alert the spring to the new mouse location - spring.update(mouseX, mouseY); - - // Draw the box - box.display(); - // Draw the spring (it only appears when active) - spring.display(); - - fill(0); - text("Space bar to toggle creature/skeleton.\nClick and drag the box.", 20, height-30); -} - - -void keyPressed() { - if (key == ' ') { - skeleton = !skeleton; - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Boundary.pde deleted file mode 100644 index 7b5012517..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Boundary.pde +++ /dev/null @@ -1,54 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A fixed boundary class - -class Boundary { - - // A boundary is a simple rectangle with x,y,width,and height - float x; - float y; - float w; - float h; - - // But we also have to make a body for box2d to know about it - Body b; - - Boundary(float x_,float y_, float w_, float h_) { - x = x_; - y = y_; - w = w_; - h = h_; - - // Define the polygon - PolygonShape sd = new PolygonShape(); - // Figure out the box2d coordinates - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); - // We're just a box - sd.setAsBox(box2dW, box2dH); - - - // Create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.STATIC; - bd.position.set(box2d.coordPixelsToWorld(x,y)); - b = box2d.createBody(bd); - - // Attached the shape to the body using a Fixture - b.createFixture(sd,1); - } - - // Draw the boundary, if it were at an angle we'd have to do something fancier - void display() { - fill(0); - stroke(0); - rectMode(CENTER); - rect(x,y,w,h); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Box.pde deleted file mode 100644 index b38eecedf..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Box.pde +++ /dev/null @@ -1,86 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A rectangular box - -class Box { - - // We need to keep track of a Body and a width and height - Body body; - float w; - float h; - - // Constructor - Box(float x_, float y_) { - float x = x_; - float y = y_; - w = 50; - h = 50; - // Add the box to the box2d world - makeBody(new Vec2(x, y), w, h); - body.setUserData(this); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - boolean contains(float x, float y) { - Vec2 worldPoint = box2d.coordPixelsToWorld(x, y); - Fixture f = body.getFixtureList(); - boolean inside = f.testPoint(worldPoint); - return inside; - } - - // Drawing the box - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - - rectMode(PConstants.CENTER); - pushMatrix(); - translate(pos.x, pos.y); - rotate(-a); - fill(50); - stroke(0); - rect(0, 0, w, h); - popMatrix(); - } - - // This function adds the rectangle to the box2d world - void makeBody(Vec2 center, float w_, float h_) { - // Define and create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - bd.position.set(box2d.coordPixelsToWorld(center)); - body = box2d.createBody(bd); - - // Define a polygon (this is what we use for a rectangle) - PolygonShape sd = new PolygonShape(); - float box2dW = box2d.scalarPixelsToWorld(w_/2); - float box2dH = box2d.scalarPixelsToWorld(h_/2); - sd.setAsBox(box2dW, box2dH); - - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = sd; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.3; - fd.restitution = 0.5; - - body.createFixture(fd); - //body.setMassFromShapes(); - - // Give it some initial random velocity - body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5))); - body.setAngularVelocity(random(-5, 5)); - } -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Spring.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Spring.pde deleted file mode 100644 index 5fc777cc2..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Spring.pde +++ /dev/null @@ -1,76 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// Class to describe the spring joint (displayed as a line) - -class Spring { - - // This is the box2d object we need to create - MouseJoint mouseJoint; - - Spring() { - // At first it doesn't exist - mouseJoint = null; - } - - // If it exists we set its target to the mouse location - void update(float x, float y) { - if (mouseJoint != null) { - // Always convert to world coordinates! - Vec2 mouseWorld = box2d.coordPixelsToWorld(x,y); - mouseJoint.setTarget(mouseWorld); - } - } - - void display() { - if (mouseJoint != null) { - // We can get the two anchor points - Vec2 v1 = new Vec2(0,0); - mouseJoint.getAnchorA(v1); - Vec2 v2 = new Vec2(0,0); - mouseJoint.getAnchorB(v2); - // Convert them to screen coordinates - v1 = box2d.coordWorldToPixels(v1); - v2 = box2d.coordWorldToPixels(v2); - // And just draw a line - stroke(0); - strokeWeight(1); - line(v1.x,v1.y,v2.x,v2.y); - } - } - - - // This is the key function where - // we attach the spring to an x,y location - // and the Box object's location - void bind(float x, float y, Box box) { - // Define the joint - MouseJointDef md = new MouseJointDef(); - // Body A is just a fake ground body for simplicity (there isn't anything at the mouse) - md.bodyA = box2d.getGroundBody(); - // Body 2 is the box's boxy - md.bodyB = box.body; - // Get the mouse location in world coordinates - Vec2 mp = box2d.coordPixelsToWorld(x,y); - // And that's the target - md.target.set(mp); - // Some stuff about how strong and bouncy the spring should be - md.maxForce = 1000.0 * box.body.m_mass; - md.frequencyHz = 5.0; - md.dampingRatio = 0.9; - - // Make the joint! - mouseJoint = (MouseJoint) box2d.world.createJoint(md); - } - - void destroy() { - // We can get rid of the joint when the mouse is released - if (mouseJoint != null) { - box2d.world.destroyJoint(mouseJoint); - mouseJoint = null; - } - } - -} diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Blob.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Blob.pde deleted file mode 100644 index 3cc99fb8b..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Blob.pde +++ /dev/null @@ -1,117 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A blob skeleton -// Could be used to create blobbly characters a la Nokia Friends -// http://postspectacular.com/work/nokia/friends/start - -class Blob { - - // A list to keep track of all the points in our blob - ArrayList skeleton; - - float bodyRadius; // The radius of each body that makes up the skeleton - float radius; // The radius of the entire blob - float totalPoints; // How many points make up the blob - - - // We should modify this constructor to receive arguments - // So that we can make many different types of blobs - Blob() { - - // Create the empty - skeleton = new ArrayList(); - - // Let's make a volume of joints! - ConstantVolumeJointDef cvjd = new ConstantVolumeJointDef(); - - // Where and how big is the blob - Vec2 center = new Vec2(width/2, height/2); - radius = 100; - totalPoints = 20; - bodyRadius = 12; - - - // Initialize all the points - for (int i = 0; i < totalPoints; i++) { - // Look polar to cartesian coordinate transformation! - float theta = PApplet.map(i, 0, totalPoints, 0, TWO_PI); - float x = center.x + radius * sin(theta); - float y = center.y + radius * cos(theta); - - // Make each individual body - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - - bd.fixedRotation = true; // no rotation! - bd.position.set(box2d.coordPixelsToWorld(x, y)); - Body body = box2d.createBody(bd); - - // The body is a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(bodyRadius); - - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = cs; - - // For filtering out collisions - //fd.filter.groupIndex = -2; - - // Parameters that affect physics - fd.density = 1; - - // Finalize the body - body.createFixture(fd); - // Add it to the volume - cvjd.addBody(body); - - - // Store our own copy for later rendering - skeleton.add(body); - } - - // These parameters control how stiff vs. jiggly the blob is - cvjd.frequencyHz = 10.0f; - cvjd.dampingRatio = 1.0f; - - // Put the joint thing in our world! - box2d.world.createJoint(cvjd); - } - - - // Time to draw the blob! - // Can you make it a cute character, a la http://postspectacular.com/work/nokia/friends/start - void display() { - - // Draw the outline - beginShape(); - noFill(); - stroke(0); - strokeWeight(1); - for (Body b: skeleton) { - Vec2 pos = box2d.getBodyPixelCoord(b); - vertex(pos.x, pos.y); - } - endShape(CLOSE); - - // Draw the individual circles - for (Body b: skeleton) { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(b); - // Get its angle of rotation - float a = b.getAngle(); - pushMatrix(); - translate(pos.x, pos.y); - rotate(a); - fill(175); - stroke(0); - strokeWeight(1); - ellipse(0, 0, bodyRadius*2, bodyRadius*2); - popMatrix(); - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Blobby.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Blobby.pde deleted file mode 100644 index 8ebcdbfda..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Blobby.pde +++ /dev/null @@ -1,66 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A blob skeleton -// Could be used to create blobbly characters a la Nokia Friends -// http://postspectacular.com/work/nokia/friends/start - -// This seems to be broken with the Box2D 2.1.2 version I'm using - -import pbox2d.*; - -import org.jbox2d.collision.shapes.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; -import org.jbox2d.dynamics.joints.*; - -// A reference to our box2d world -PBox2D box2d; - -// A list we'll use to track fixed objects -ArrayList boundaries; - -// Our "blob" object -Blob blob; - - void setup() { - size(400,300); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - - // Add some boundaries - boundaries = new ArrayList(); - boundaries.add(new Boundary(width/2,height-5,width,10)); - boundaries.add(new Boundary(width/2,5,width,10)); - boundaries.add(new Boundary(width-5,height/2,10,height)); - boundaries.add(new Boundary(5,height/2,10,height)); - - // Make a new blob - blob = new Blob(); -} - - void draw() { - background(255); - - // We must always step through time! - box2d.step(); - - // Show the blob! - blob.display(); - - // Show the boundaries! - for (Boundary wall: boundaries) { - wall.display(); - } - - -} - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Boundary.pde deleted file mode 100644 index 7b5012517..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Boundary.pde +++ /dev/null @@ -1,54 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A fixed boundary class - -class Boundary { - - // A boundary is a simple rectangle with x,y,width,and height - float x; - float y; - float w; - float h; - - // But we also have to make a body for box2d to know about it - Body b; - - Boundary(float x_,float y_, float w_, float h_) { - x = x_; - y = y_; - w = w_; - h = h_; - - // Define the polygon - PolygonShape sd = new PolygonShape(); - // Figure out the box2d coordinates - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); - // We're just a box - sd.setAsBox(box2dW, box2dH); - - - // Create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.STATIC; - bd.position.set(box2d.coordPixelsToWorld(x,y)); - b = box2d.createBody(bd); - - // Attached the shape to the body using a Fixture - b.createFixture(sd,1); - } - - // Draw the boundary, if it were at an angle we'd have to do something fancier - void display() { - fill(0); - stroke(0); - rectMode(CENTER); - rect(x,y,w,h); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/Boundary.pde deleted file mode 100644 index 06c5bf80d..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/Boundary.pde +++ /dev/null @@ -1,56 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A fixed boundary class - -class Boundary { - - // A boundary is a simple rectangle with x,y,width,and height - float x; - float y; - float w; - float h; - - // But we also have to make a body for box2d to know about it - Body b; - - Boundary(float x_,float y_, float w_, float h_) { - x = x_; - y = y_; - w = w_; - h = h_; - - // Define the polygon - PolygonShape sd = new PolygonShape(); - // Figure out the box2d coordinates - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); - // We're just a box - sd.setAsBox(box2dW, box2dH); - - - // Create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.STATIC; - bd.position.set(box2d.coordPixelsToWorld(x,y)); - b = box2d.createBody(bd); - - // Attached the shape to the body using a Fixture - b.createFixture(sd,1); - - b.setUserData(this); - } - - // Draw the boundary, if it were at an angle we'd have to do something fancier - void display() { - fill(0); - stroke(0); - rectMode(CENTER); - rect(x,y,w,h); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/CollisionListeningDeletionExercise.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/CollisionListeningDeletionExercise.pde deleted file mode 100644 index b99e9108e..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/CollisionListeningDeletionExercise.pde +++ /dev/null @@ -1,121 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Basic example of controlling an object with our own motion (by attaching a MouseJoint) -// Also demonstrates how to know which object was hit - -import pbox2d.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.joints.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.collision.shapes.Shape; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; -import org.jbox2d.dynamics.contacts.*; - -// A reference to our box2d world -PBox2D box2d; - -// An ArrayList of particles that will fall on the surface -ArrayList particles; - -Boundary wall; - -void setup() { - size(400, 300); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - - // Turn on collision listening! - box2d.listenForCollisions(); - - // Create the empty list - particles = new ArrayList(); - - wall = new Boundary(width/2, height-5, width, 10); -} - -void draw() { - background(255); - - if (random(1) < 0.1) { - float sz = random(4, 8); - particles.add(new Particle(random(width), 20, sz)); - } - - - // We must always step through time! - box2d.step(); - - // Look at all particles - for (int i = particles.size()-1; i >= 0; i--) { - Particle p = particles.get(i); - p.display(); - // Particles that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - if (p.done()) { - particles.remove(i); - } - } - - wall.display(); -} - - -// Collision event functions! -void beginContact(Contact cp) { - // Get both shapes - Fixture f1 = cp.getFixtureA(); - Fixture f2 = cp.getFixtureB(); - // Get both bodies - Body b1 = f1.getBody(); - Body b2 = f2.getBody(); - - // Get our objects that reference these bodies - Object o1 = b1.getUserData(); - Object o2 = b2.getUserData(); - - if (o1.getClass() == Particle.class && o2.getClass() == Particle.class) { - Particle p1 = (Particle) o1; - p1.delete(); - Particle p2 = (Particle) o2; - p2.delete(); - } - - if (o1.getClass() == Boundary.class) { - Particle p = (Particle) o2; - p.change(); - } - if (o2.getClass() == Boundary.class) { - Particle p = (Particle) o1; - p.change(); - } - - -} - -// Objects stop touching each other -void endContact(Contact cp) { -} - - - - - - - - - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/Particle.pde deleted file mode 100644 index 7fe629d81..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/Particle.pde +++ /dev/null @@ -1,96 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A circular particle - -class Particle { - - // We need to keep track of a Body and a radius - Body body; - float r; - - color col; - - boolean delete = false; - - Particle(float x, float y, float r_) { - r = r_; - // This function puts the particle in the Box2d world - makeBody(x, y, r); - body.setUserData(this); - col = color(175); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - void delete() { - delete = true; - } - - // Change color when hit - void change() { - col = color(255, 0, 0); - } - - // Is the particle ready for deletion? - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+r*2 || delete) { - killBody(); - return true; - } - return false; - } - // - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - pushMatrix(); - translate(pos.x, pos.y); - rotate(a); - fill(col); - stroke(0); - strokeWeight(1); - ellipse(0, 0, r*2, r*2); - // Let's add a line so we can see the rotation - line(0, 0, r, 0); - popMatrix(); - } - - // Here's our function that adds the particle to the Box2D world - void makeBody(float x, float y, float r) { - // Define a body - BodyDef bd = new BodyDef(); - // Set its position - bd.position = box2d.coordPixelsToWorld(x, y); - bd.type = BodyType.DYNAMIC; - body = box2d.createBody(bd); - - // Make the body's shape a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(r); - - FixtureDef fd = new FixtureDef(); - fd.shape = cs; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.01; - fd.restitution = 0.3; - - // Attach fixture to body - body.createFixture(fd); - - body.setAngularVelocity(random(-10, 10)); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Box.pde deleted file mode 100644 index 8eab06230..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Box.pde +++ /dev/null @@ -1,86 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A rectangular box - -class Box { - - // We need to keep track of a Body and a width and height - Body body; - float w; - float h; - - // Constructor - Box(float x_, float y_) { - float x = x_; - float y = y_; - w = 24; - h = 24; - // Add the box to the box2d world - makeBody(new Vec2(x, y), w, h); - body.setUserData(this); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - boolean contains(float x, float y) { - Vec2 worldPoint = box2d.coordPixelsToWorld(x, y); - Fixture f = body.getFixtureList(); - boolean inside = f.testPoint(worldPoint); - return inside; - } - - // Drawing the box - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - - rectMode(PConstants.CENTER); - pushMatrix(); - translate(pos.x, pos.y); - rotate(-a); - fill(175); - stroke(0); - rect(0, 0, w, h); - popMatrix(); - } - - // This function adds the rectangle to the box2d world - void makeBody(Vec2 center, float w_, float h_) { - // Define and create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - bd.position.set(box2d.coordPixelsToWorld(center)); - body = box2d.createBody(bd); - - // Define a polygon (this is what we use for a rectangle) - PolygonShape sd = new PolygonShape(); - float box2dW = box2d.scalarPixelsToWorld(w_/2); - float box2dH = box2d.scalarPixelsToWorld(h_/2); - sd.setAsBox(box2dW, box2dH); - - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = sd; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.3; - fd.restitution = 0.5; - - body.createFixture(fd); - //body.setMassFromShapes(); - - // Give it some initial random velocity - body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5))); - body.setAngularVelocity(random(-5, 5)); - } -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/CollisionsAndControl.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/CollisionsAndControl.pde deleted file mode 100644 index 7377f497f..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/CollisionsAndControl.pde +++ /dev/null @@ -1,153 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Basic example of controlling an object with our own motion (by attaching a MouseJoint) -// Also demonstrates how to know which object was hit - -import pbox2d.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.joints.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.collision.shapes.Shape; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; -import org.jbox2d.dynamics.contacts.*; - -// A reference to our box2d world -PBox2D box2d; - -// Just a single box this time -Box box; - -// An ArrayList of particles that will fall on the surface -ArrayList particles; - -// The Spring that will attach to the box from the mouse -Spring spring; - -// Perlin noise values -float xoff = 0; -float yoff = 1000; - - -void setup() { - size(400,300); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - - // Turn on collision listening! - box2d.listenForCollisions(); - - // Make the box - box = new Box(width/2,height/2); - - // Make the spring (it doesn't really get initialized until the mouse is clicked) - spring = new Spring(); - spring.bind(width/2,height/2,box); - - // Create the empty list - particles = new ArrayList(); - - -} - -void draw() { - background(255); - - if (random(1) < 0.2) { - float sz = random(4,8); - particles.add(new Particle(width/2,-20,sz)); - } - - - // We must always step through time! - box2d.step(); - - // Make an x,y coordinate out of perlin noise - float x = noise(xoff)*width; - float y = noise(yoff)*height; - xoff += 0.01; - yoff += 0.01; - - // This is tempting but will not work! - // box.body.setXForm(box2d.screenToWorld(x,y),0); - - // Instead update the spring which pulls the mouse along - if (mousePressed) { - spring.update(mouseX,mouseY); - spring.display(); - } else { - spring.update(x,y); - } - box.body.setAngularVelocity(0); - - // Look at all particles - for (int i = particles.size()-1; i >= 0; i--) { - Particle p = particles.get(i); - p.display(); - // Particles that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - if (p.done()) { - particles.remove(i); - } - } - - // Draw the box - box.display(); - - // Draw the spring - // spring.display(); -} - - -// Collision event functions! -void beginContact(Contact cp) { - // Get both fixtures - Fixture f1 = cp.getFixtureA(); - Fixture f2 = cp.getFixtureB(); - // Get both bodies - Body b1 = f1.getBody(); - Body b2 = f2.getBody(); - // Get our objects that reference these bodies - Object o1 = b1.getUserData(); - Object o2 = b2.getUserData(); - - // If object 1 is a Box, then object 2 must be a particle - // Note we are ignoring particle on particle collisions - if (o1.getClass() == Box.class) { - Particle p = (Particle) o2; - p.change(); - } - // If object 2 is a Box, then object 1 must be a particle - else if (o2.getClass() == Box.class) { - Particle p = (Particle) o1; - p.change(); - } -} - - -// Objects stop touching each other -void endContact(Contact cp) { -} - - - - - - - - - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Particle.pde deleted file mode 100644 index d21b5f819..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Particle.pde +++ /dev/null @@ -1,92 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A circular particle - -class Particle { - - // We need to keep track of a Body and a radius - Body body; - float r; - - color col; - - - Particle(float x, float y, float r_) { - r = r_; - // This function puts the particle in the Box2d world - makeBody(x, y, r); - body.setUserData(this); - col = color(175); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Change color when hit - void change() { - col = color(255, 0, 0); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+r*2) { - killBody(); - return true; - } - return false; - } - - - // - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - pushMatrix(); - translate(pos.x, pos.y); - rotate(a); - fill(col); - stroke(0); - strokeWeight(1); - ellipse(0, 0, r*2, r*2); - // Let's add a line so we can see the rotation - line(0, 0, r, 0); - popMatrix(); - } - - // Here's our function that adds the particle to the Box2D world - void makeBody(float x, float y, float r) { - // Define a body - BodyDef bd = new BodyDef(); - // Set its position - bd.position = box2d.coordPixelsToWorld(x, y); - bd.type = BodyType.DYNAMIC; - body = box2d.createBody(bd); - - // Make the body's shape a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(r); - - FixtureDef fd = new FixtureDef(); - fd.shape = cs; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.01; - fd.restitution = 0.3; - - // Attach fixture to body - body.createFixture(fd); - - body.setAngularVelocity(random(-10, 10)); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Spring.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Spring.pde deleted file mode 100644 index a9fcbc6c5..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Spring.pde +++ /dev/null @@ -1,82 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// Class to describe the spring joint (displayed as a line) - -class Spring { - - // This is the box2d object we need to create - MouseJoint mouseJoint; - - Spring() { - // At first it doesn't exist - mouseJoint = null; - } - - // If it exists we set its target to the mouse location - void update(float x, float y) { - if (mouseJoint != null) { - // Always convert to world coordinates! - Vec2 mouseWorld = box2d.coordPixelsToWorld(x,y); - mouseJoint.setTarget(mouseWorld); - } - } - - void display() { - if (mouseJoint != null) { - // We can get the two anchor points - Vec2 v1 = new Vec2(0,0); - mouseJoint.getAnchorA(v1); - Vec2 v2 = new Vec2(0,0); - mouseJoint.getAnchorB(v2); - // Convert them to screen coordinates - v1 = box2d.coordWorldToPixels(v1); - v2 = box2d.coordWorldToPixels(v2); - // And just draw a line - stroke(0); - strokeWeight(1); - line(v1.x,v1.y,v2.x,v2.y); - } - } - - - // This is the key function where - // we attach the spring to an x,y location - // and the Box object's location - void bind(float x, float y, Box box) { - // Define the joint - MouseJointDef md = new MouseJointDef(); - - // Body A is just a fake ground body for simplicity (there isn't anything at the mouse) - md.bodyA = box2d.getGroundBody(); - // Body 2 is the box's boxy - md.bodyB = box.body; - // Get the mouse location in world coordinates - Vec2 mp = box2d.coordPixelsToWorld(x,y); - // And that's the target - md.target.set(mp); - // Some stuff about how strong and bouncy the spring should be - md.maxForce = 1000.0 * box.body.m_mass; - md.frequencyHz = 5.0; - md.dampingRatio = 0.9; - - // Wake up body! - //box.body.wakeUp(); - - // Make the joint! - mouseJoint = (MouseJoint) box2d.world.createJoint(md); - } - - void destroy() { - // We can get rid of the joint when the mouse is released - if (mouseJoint != null) { - box2d.world.destroyJoint(mouseJoint); - mouseJoint = null; - } - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Box.pde deleted file mode 100644 index 8eab06230..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Box.pde +++ /dev/null @@ -1,86 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A rectangular box - -class Box { - - // We need to keep track of a Body and a width and height - Body body; - float w; - float h; - - // Constructor - Box(float x_, float y_) { - float x = x_; - float y = y_; - w = 24; - h = 24; - // Add the box to the box2d world - makeBody(new Vec2(x, y), w, h); - body.setUserData(this); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - boolean contains(float x, float y) { - Vec2 worldPoint = box2d.coordPixelsToWorld(x, y); - Fixture f = body.getFixtureList(); - boolean inside = f.testPoint(worldPoint); - return inside; - } - - // Drawing the box - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - - rectMode(PConstants.CENTER); - pushMatrix(); - translate(pos.x, pos.y); - rotate(-a); - fill(175); - stroke(0); - rect(0, 0, w, h); - popMatrix(); - } - - // This function adds the rectangle to the box2d world - void makeBody(Vec2 center, float w_, float h_) { - // Define and create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - bd.position.set(box2d.coordPixelsToWorld(center)); - body = box2d.createBody(bd); - - // Define a polygon (this is what we use for a rectangle) - PolygonShape sd = new PolygonShape(); - float box2dW = box2d.scalarPixelsToWorld(w_/2); - float box2dH = box2d.scalarPixelsToWorld(h_/2); - sd.setAsBox(box2dW, box2dH); - - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = sd; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.3; - fd.restitution = 0.5; - - body.createFixture(fd); - //body.setMassFromShapes(); - - // Give it some initial random velocity - body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5))); - body.setAngularVelocity(random(-5, 5)); - } -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/CollisionsAndControlInterface.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/CollisionsAndControlInterface.pde deleted file mode 100644 index 64c6ec3e9..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/CollisionsAndControlInterface.pde +++ /dev/null @@ -1,114 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// Basic example of controlling an object with our own motion (by attaching a MouseJoint) -// Also demonstrates how to know which object was hit - -import pbox2d.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.joints.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.collision.shapes.Shape; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; -import org.jbox2d.dynamics.contacts.*; - -// A reference to our box2d world -PBox2D box2d; - -// Just a single box this time -Box box; - -// An ArrayList of particles that will fall on the surface -ArrayList particles; - -// The Spring that will attach to the box from the mouse -Spring spring; - -// Perlin noise values -float xoff = 0; -float yoff = 1000; - - -void setup() { - size(400,300); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - - // Add a listener to listen for collisions! - box2d.world.setContactListener(new CustomListener()); - - // Make the box - box = new Box(width/2,height/2); - - // Make the spring (it doesn't really get initialized until the mouse is clicked) - spring = new Spring(); - spring.bind(width/2,height/2,box); - - // Create the empty list - particles = new ArrayList(); - - -} - -void draw() { - background(255); - - if (random(1) < 0.2) { - float sz = random(4,8); - particles.add(new Particle(width/2,-20,sz)); - } - - - // We must always step through time! - box2d.step(); - - // Make an x,y coordinate out of perlin noise - float x = noise(xoff)*width; - float y = noise(yoff)*height; - xoff += 0.01; - yoff += 0.01; - - // This is tempting but will not work! - // box.body.setXForm(box2d.screenToWorld(x,y),0); - - // Instead update the spring which pulls the mouse along - if (mousePressed) { - spring.update(mouseX,mouseY); - } else { - spring.update(x,y); - } - //box.body.setAngularVelocity(0); - - // Look at all particles - for (int i = particles.size()-1; i >= 0; i--) { - Particle p = particles.get(i); - p.display(); - // Particles that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - if (p.done()) { - particles.remove(i); - } - } - - // Draw the box - box.display(); - - // Draw the spring - // spring.display(); -} - - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/ContactListener.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/ContactListener.pde deleted file mode 100644 index dafe17f7e..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/ContactListener.pde +++ /dev/null @@ -1,57 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// ContactListener to listen for collisions! - -import org.jbox2d.callbacks.ContactImpulse; -import org.jbox2d.callbacks.ContactListener; -import org.jbox2d.collision.Manifold; -import org.jbox2d.dynamics.contacts.Contact; - - class CustomListener implements ContactListener { - CustomListener() { - } - - // This function is called when a new collision occurs - void beginContact(Contact cp) { - // Get both fixtures - Fixture f1 = cp.getFixtureA(); - Fixture f2 = cp.getFixtureB(); - // Get both bodies - Body b1 = f1.getBody(); - Body b2 = f2.getBody(); - // Get our objects that reference these bodies - Object o1 = b1.getUserData(); - Object o2 = b2.getUserData(); - - // If object 1 is a Box, then object 2 must be a particle - // Note we are ignoring particle on particle collisions - if (o1.getClass() == Box.class) { - Particle p = (Particle) o2; - p.change(); - } - // If object 2 is a Box, then object 1 must be a particle - else if (o2.getClass() == Box.class) { - Particle p = (Particle) o1; - p.change(); - } - } - - void endContact(Contact contact) { - // TODO Auto-generated method stub - } - - void preSolve(Contact contact, Manifold oldManifold) { - // TODO Auto-generated method stub - } - - void postSolve(Contact contact, ContactImpulse impulse) { - // TODO Auto-generated method stub - } -} - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Particle.pde deleted file mode 100644 index d21b5f819..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Particle.pde +++ /dev/null @@ -1,92 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A circular particle - -class Particle { - - // We need to keep track of a Body and a radius - Body body; - float r; - - color col; - - - Particle(float x, float y, float r_) { - r = r_; - // This function puts the particle in the Box2d world - makeBody(x, y, r); - body.setUserData(this); - col = color(175); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Change color when hit - void change() { - col = color(255, 0, 0); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+r*2) { - killBody(); - return true; - } - return false; - } - - - // - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - pushMatrix(); - translate(pos.x, pos.y); - rotate(a); - fill(col); - stroke(0); - strokeWeight(1); - ellipse(0, 0, r*2, r*2); - // Let's add a line so we can see the rotation - line(0, 0, r, 0); - popMatrix(); - } - - // Here's our function that adds the particle to the Box2D world - void makeBody(float x, float y, float r) { - // Define a body - BodyDef bd = new BodyDef(); - // Set its position - bd.position = box2d.coordPixelsToWorld(x, y); - bd.type = BodyType.DYNAMIC; - body = box2d.createBody(bd); - - // Make the body's shape a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(r); - - FixtureDef fd = new FixtureDef(); - fd.shape = cs; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.01; - fd.restitution = 0.3; - - // Attach fixture to body - body.createFixture(fd); - - body.setAngularVelocity(random(-10, 10)); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Spring.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Spring.pde deleted file mode 100644 index 62cac8a4b..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Spring.pde +++ /dev/null @@ -1,82 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// Class to describe the spring joint (displayed as a line) - -class Spring { - - // This is the box2d object we need to create - MouseJoint mouseJoint; - - Spring() { - // At first it doesn't exist - mouseJoint = null; - } - - // If it exists we set its target to the mouse location - void update(float x, float y) { - if (mouseJoint != null) { - // Always convert to world coordinates! - Vec2 mouseWorld = box2d.coordPixelsToWorld(x,y); - mouseJoint.setTarget(mouseWorld); - } - } - - void display() { - if (mouseJoint != null) { - // We can get the two anchor points - Vec2 v1 = null; - mouseJoint.getAnchorA(v1); - Vec2 v2 = null; - mouseJoint.getAnchorB(v2); - // Convert them to screen coordinates - v1 = box2d.coordWorldToPixels(v1); - v2 = box2d.coordWorldToPixels(v2); - // And just draw a line - stroke(0); - strokeWeight(1); - line(v1.x,v1.y,v2.x,v2.y); - } - } - - - // This is the key function where - // we attach the spring to an x,y location - // and the Box object's location - void bind(float x, float y, Box box) { - // Define the joint - MouseJointDef md = new MouseJointDef(); - - // Body A is just a fake ground body for simplicity (there isn't anything at the mouse) - md.bodyA = box2d.getGroundBody(); - // Body 2 is the box's boxy - md.bodyB = box.body; - // Get the mouse location in world coordinates - Vec2 mp = box2d.coordPixelsToWorld(x,y); - // And that's the target - md.target.set(mp); - // Some stuff about how strong and bouncy the spring should be - md.maxForce = 1000.0f * box.body.m_mass; - md.frequencyHz = 5.0f; - md.dampingRatio = 0.9f; - - // Wake up body! - //box.body.wakeUp(); - - // Make the joint! - mouseJoint = (MouseJoint) box2d.world.createJoint(md); - } - - void destroy() { - // We can get rid of the joint when the mouse is released - if (mouseJoint != null) { - box2d.world.destroyJoint(mouseJoint); - mouseJoint = null; - } - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Boundary.pde deleted file mode 100644 index 7b5012517..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Boundary.pde +++ /dev/null @@ -1,54 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A fixed boundary class - -class Boundary { - - // A boundary is a simple rectangle with x,y,width,and height - float x; - float y; - float w; - float h; - - // But we also have to make a body for box2d to know about it - Body b; - - Boundary(float x_,float y_, float w_, float h_) { - x = x_; - y = y_; - w = w_; - h = h_; - - // Define the polygon - PolygonShape sd = new PolygonShape(); - // Figure out the box2d coordinates - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); - // We're just a box - sd.setAsBox(box2dW, box2dH); - - - // Create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.STATIC; - bd.position.set(box2d.coordPixelsToWorld(x,y)); - b = box2d.createBody(bd); - - // Attached the shape to the body using a Fixture - b.createFixture(sd,1); - } - - // Draw the boundary, if it were at an angle we'd have to do something fancier - void display() { - fill(0); - stroke(0); - rectMode(CENTER); - rect(x,y,w,h); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Box.pde deleted file mode 100644 index 9319bfbc7..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Box.pde +++ /dev/null @@ -1,97 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A rectangular box -class Box { - - // We need to keep track of a Body and a width and height - Body body; - float w; - float h; - - // Constructor - Box(float x, float y) { - w = random(8,16); - h = w; - // Add the box to the box2d world - makeBody(new Vec2(x,y),w,h); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+w*h) { - killBody(); - return true; - } - return false; - } - - void attract(float x,float y) { - // From BoxWrap2D example - Vec2 worldTarget = box2d.coordPixelsToWorld(x,y); - Vec2 bodyVec = body.getWorldCenter(); - // First find the vector going from this body to the specified point - worldTarget.subLocal(bodyVec); - // Then, scale the vector to the specified force - worldTarget.normalize(); - worldTarget.mulLocal((float) 50); - // Now apply it to the body's center of mass. - body.applyForce(worldTarget, bodyVec); - } - - - // Drawing the box - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - - rectMode(CENTER); - pushMatrix(); - translate(pos.x,pos.y); - rotate(-a); - fill(175); - stroke(0); - rect(0,0,w,h); - popMatrix(); - } - - // This function adds the rectangle to the box2d world - void makeBody(Vec2 center, float w_, float h_) { - - // Define a polygon (this is what we use for a rectangle) - PolygonShape sd = new PolygonShape(); - float box2dW = box2d.scalarPixelsToWorld(w_/2); - float box2dH = box2d.scalarPixelsToWorld(h_/2); - sd.setAsBox(box2dW, box2dH); - - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = sd; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.3; - fd.restitution = 0.5; - - // Define the body and make it from the shape - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - bd.position.set(box2d.coordPixelsToWorld(center)); - - body = box2d.createBody(bd); - body.createFixture(fd); - } -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Exercise_5_10_ApplyForceAttractMouse.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Exercise_5_10_ApplyForceAttractMouse.pde deleted file mode 100644 index fbc54c32e..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Exercise_5_10_ApplyForceAttractMouse.pde +++ /dev/null @@ -1,85 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Basic example of falling rectangles - -import pbox2d.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; - -// A reference to our box2d world -PBox2D box2d; - -// A list we'll use to track fixed objects -ArrayList boundaries; -// A list for all of our rectangles -ArrayList boxes; - -void setup() { - size(640,360); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - // We are setting a custom gravity - box2d.setGravity(0, -20); - - // Create ArrayLists - boxes = new ArrayList(); - boundaries = new ArrayList(); - - // Add a bunch of fixed boundaries - boundaries.add(new Boundary(width/4,height-5,width/2-50,10)); - boundaries.add(new Boundary(3*width/4,height-5,width/2-50,10)); - boundaries.add(new Boundary(width-5,height/2,10,height)); - boundaries.add(new Boundary(5,height/2,10,height)); -} - -void draw() { - background(255); - - // We must always step through time! - box2d.step(); - - // When the mouse is clicked, add a new Box object - if (random(1) < 0.1) { - Box p = new Box(random(width),10); - boxes.add(p); - } - - if (mousePressed) { - for (Box b: boxes) { - b.attract(mouseX,mouseY); - } - } - - // Display all the boundaries - for (Boundary wall: boundaries) { - wall.display(); - } - - // Display all the boxes - for (Box b: boxes) { - b.display(); - } - - // Boxes that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - for (int i = boxes.size()-1; i >= 0; i--) { - Box b = boxes.get(i); - if (b.done()) { - boxes.remove(i); - } - } - - fill(0); - text("Click mouse to attract boxes",20,20); -} - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Boundary.pde deleted file mode 100644 index 7b5012517..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Boundary.pde +++ /dev/null @@ -1,54 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A fixed boundary class - -class Boundary { - - // A boundary is a simple rectangle with x,y,width,and height - float x; - float y; - float w; - float h; - - // But we also have to make a body for box2d to know about it - Body b; - - Boundary(float x_,float y_, float w_, float h_) { - x = x_; - y = y_; - w = w_; - h = h_; - - // Define the polygon - PolygonShape sd = new PolygonShape(); - // Figure out the box2d coordinates - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); - // We're just a box - sd.setAsBox(box2dW, box2dH); - - - // Create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.STATIC; - bd.position.set(box2d.coordPixelsToWorld(x,y)); - b = box2d.createBody(bd); - - // Attached the shape to the body using a Fixture - b.createFixture(sd,1); - } - - // Draw the boundary, if it were at an angle we'd have to do something fancier - void display() { - fill(0); - stroke(0); - rectMode(CENTER); - rect(x,y,w,h); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Box.pde deleted file mode 100644 index 6dbb25b3f..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Box.pde +++ /dev/null @@ -1,88 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A rectangular box -class Box { - - // We need to keep track of a Body and a width and height - Body body; - float w; - float h; - - // Constructor - Box(float x, float y) { - w = random(8, 16); - h = w; - // Add the box to the box2d world - makeBody(new Vec2(x, y), w, h); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+w*h) { - killBody(); - return true; - } - return false; - } - - void applyForce(Vec2 force) { - Vec2 pos = body.getWorldCenter(); - body.applyForce(force, pos); - } - - // Drawing the box - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - - rectMode(CENTER); - pushMatrix(); - translate(pos.x, pos.y); - rotate(-a); - fill(175); - stroke(0); - rect(0, 0, w, h); - popMatrix(); - } - - // This function adds the rectangle to the box2d world - void makeBody(Vec2 center, float w_, float h_) { - - // Define a polygon (this is what we use for a rectangle) - PolygonShape sd = new PolygonShape(); - float box2dW = box2d.scalarPixelsToWorld(w_/2); - float box2dH = box2d.scalarPixelsToWorld(h_/2); - sd.setAsBox(box2dW, box2dH); - - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = sd; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.3; - fd.restitution = 0.2; - - // Define the body and make it from the shape - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - bd.position.set(box2d.coordPixelsToWorld(center)); - bd.angle = random(TWO_PI); - - body = box2d.createBody(bd); - body.createFixture(fd); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Exercise_5_10_ApplyForceSimpleWind.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Exercise_5_10_ApplyForceSimpleWind.pde deleted file mode 100644 index 95364b7da..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Exercise_5_10_ApplyForceSimpleWind.pde +++ /dev/null @@ -1,86 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Basic example of falling rectangles - -import pbox2d.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; - -// A reference to our box2d world -PBox2D box2d; - -// A list we'll use to track fixed objects -ArrayList boundaries; -// A list for all of our rectangles -ArrayList boxes; - -void setup() { - size(640,360); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - // We are setting a custom gravity - box2d.setGravity(0, -20); - - // Create ArrayLists - boxes = new ArrayList(); - boundaries = new ArrayList(); - - // Add a bunch of fixed boundaries - boundaries.add(new Boundary(width/4,height-5,width/2-100,10)); - boundaries.add(new Boundary(3*width/4,height-5,width/2-100,10)); - boundaries.add(new Boundary(width-5,height/2,10,height)); - boundaries.add(new Boundary(5,height/2,10,height)); -} - -void draw() { - background(255); - - // We must always step through time! - box2d.step(); - - // When the mouse is clicked, add a new Box object - if (random(1) < 0.1) { - Box p = new Box(random(width),10); - boxes.add(p); - } - - if (mousePressed) { - for (Box b: boxes) { - Vec2 wind = new Vec2(20,0); - b.applyForce(wind); - } - } - - // Display all the boundaries - for (Boundary wall: boundaries) { - wall.display(); - } - - // Display all the boxes - for (Box b: boxes) { - b.display(); - } - - // Boxes that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - for (int i = boxes.size()-1; i >= 0; i--) { - Box b = boxes.get(i); - if (b.done()) { - boxes.remove(i); - } - } - - fill(0); - text("Click mouse to apply a wind force.",20,20); -} - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Attractor.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Attractor.pde deleted file mode 100644 index 8de891160..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Attractor.pde +++ /dev/null @@ -1,70 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Showing how to use applyForce() with box2d - -// Fixed Attractor (this is redundant with Mover) - -class Attractor { - - // We need to keep track of a Body and a radius - Body body; - float r; - - Attractor(float r_, float x, float y) { - r = r_; - // Define a body - BodyDef bd = new BodyDef(); - bd.type = BodyType.STATIC; - // Set its position - bd.position = box2d.coordPixelsToWorld(x,y); - body = box2d.world.createBody(bd); - - // Make the body's shape a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(r); - - body.createFixture(cs,1); - - } - - - // Formula for gravitational attraction - // We are computing this in "world" coordinates - // No need to convert to pixels and back - Vec2 attract(Mover m) { - float G = 100; // Strength of force - // clone() makes us a copy - Vec2 pos = body.getWorldCenter(); - Vec2 moverPos = m.body.getWorldCenter(); - // Vector pointing from mover to attractor - Vec2 force = pos.sub(moverPos); - float distance = force.length(); - // Keep force within bounds - distance = constrain(distance,1,5); - force.normalize(); - // Note the attractor's mass is 0 because it's fixed so can't use that - float strength = (G * 1 * m.body.m_mass) / (distance * distance); // Calculate gravitional force magnitude - force.mulLocal(strength); // Get force vector --> magnitude * direction - return force; - } - - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - pushMatrix(); - translate(pos.x,pos.y); - rotate(a); - fill(175); - stroke(0); - strokeWeight(2); - ellipse(0,0,r*2,r*2); - popMatrix(); - } -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Exercise_5_10_AttractionApplyForce.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Exercise_5_10_AttractionApplyForce.pde deleted file mode 100644 index 7d7d49224..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Exercise_5_10_AttractionApplyForce.pde +++ /dev/null @@ -1,60 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Showing how to use applyForce() with box2d - -import pbox2d.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; - -// A reference to our box2d world -PBox2D box2d; - -// Movers, jsut like before! -Mover[] movers = new Mover[25]; - -// Attractor, just like before! -Attractor a; - -void setup() { - size(800,200); - smooth(); - - box2d = new PBox2D(this); - box2d.createWorld(); - // No global gravity force - box2d.setGravity(0,0); - - for (int i = 0; i < movers.length; i++) { - movers[i] = new Mover(random(8,16),random(width),random(height)); - } - a = new Attractor(32,width/2,height/2); -} - -void draw() { - background(255); - - // We must always step through time! - box2d.step(); - - a.display(); - - for (int i = 0; i < movers.length; i++) { - // Look, this is just like what we had before! - Vec2 force = a.attract(movers[i]); - movers[i].applyForce(force); - movers[i].display(); - } -} - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Mover.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Mover.pde deleted file mode 100644 index dcf446eeb..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Mover.pde +++ /dev/null @@ -1,64 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Showing how to use applyForce() with box2d - -class Mover { - - // We need to keep track of a Body and a radius - Body body; - float r; - - Mover(float r_, float x, float y) { - r = r_; - // Define a body - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - - // Set its position - bd.position = box2d.coordPixelsToWorld(x,y); - body = box2d.world.createBody(bd); - - // Make the body's shape a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(r); - - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = cs; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.3; - fd.restitution = 0.5; - - body.createFixture(fd); - - body.setLinearVelocity(new Vec2(random(-5,5),random(-5,-5))); - body.setAngularVelocity(random(-1,1)); - } - - void applyForce(Vec2 v) { - body.applyForce(v, body.getWorldCenter()); - } - - - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - pushMatrix(); - translate(pos.x,pos.y); - rotate(a); - fill(127); - stroke(0); - strokeWeight(2); - ellipse(0,0,r*2,r*2); - // Let's add a line so we can see the rotation - line(0,0,r,0); - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Exercise_5_3_NoiseChain.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Exercise_5_3_NoiseChain.pde deleted file mode 100644 index 708e99688..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Exercise_5_3_NoiseChain.pde +++ /dev/null @@ -1,72 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// An uneven surface - -import pbox2d.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; -import org.jbox2d.dynamics.*; - -// A reference to our box2d world -PBox2D box2d; - -// An ArrayList of particles that will fall on the surface -ArrayList particles; - -// An object to store information about the uneven surface -Surface surface; - -void setup() { - size(383,200); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - // We are setting a custom gravity - box2d.setGravity(0, -20); - - // Create the empty list - particles = new ArrayList(); - // Create the surface - surface = new Surface(); -} - -void draw() { - // If the mouse is pressed, we make new particles - if (mousePressed) { - float sz = random(2,6); - particles.add(new Particle(mouseX,mouseY,sz)); - } - - // We must always step through time! - box2d.step(); - - background(255); - - // Draw the surface - surface.display(); - - // Draw all particles - for (Particle p: particles) { - p.display(); - } - - // Particles that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - for (int i = particles.size()-1; i >= 0; i--) { - Particle p = particles.get(i); - if (p.done()) { - particles.remove(i); - } - } -} - - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Particle.pde deleted file mode 100644 index be9a07e7e..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Particle.pde +++ /dev/null @@ -1,90 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A circular particle - -class Particle { - - // We need to keep track of a Body and a radius - Body body; - float r; - - Particle(float x, float y, float r_) { - r = r_; - // This function puts the particle in the Box2d world - makeBody(x,y,r); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+r*2) { - killBody(); - return true; - } - return false; - } - - // - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - pushMatrix(); - translate(pos.x,pos.y); - rotate(-a); - fill(175); - stroke(0); - strokeWeight(1); - ellipse(0,0,r*2,r*2); - // Let's add a line so we can see the rotation - line(0,0,r,0); - popMatrix(); - } - - // Here's our function that adds the particle to the Box2D world - void makeBody(float x, float y, float r) { - // Define a body - BodyDef bd = new BodyDef(); - // Set its position - bd.position = box2d.coordPixelsToWorld(x,y); - bd.type = BodyType.DYNAMIC; - body = box2d.world.createBody(bd); - - // Make the body's shape a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(r); - - FixtureDef fd = new FixtureDef(); - fd.shape = cs; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.01; - fd.restitution = 0.3; - - // Attach fixture to body - body.createFixture(fd); - - // Give it a random initial velocity (and angular velocity) - body.setLinearVelocity(new Vec2(random(-10f,10f),random(5f,10f))); - body.setAngularVelocity(random(-10,10)); - } - - - - - - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Surface.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Surface.pde deleted file mode 100644 index a8d72166a..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Surface.pde +++ /dev/null @@ -1,79 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// An uneven surface boundary - -class Surface { - // We'll keep track of all of the surface points - ArrayList surface; - - - Surface() { - surface = new ArrayList(); - - // This is what box2d uses to put the surface in its world - ChainShape chain = new ChainShape(); - - // Perlin noise argument - float xoff = 0.0; - - // This has to go backwards so that the objects bounce off the top of the surface - // This "edgechain" will only work in one direction! - for (float x = width+10; x > -10; x -= 5) { - - // Doing some stuff with perlin noise to calculate a surface that points down on one side - // and up on the other - float y; - if (x > width/2) { - y = 50 + (width - x)*1.1 + map(noise(xoff),0,1,-80,80); - } - else { - y = 50 + x*1.1 + map(noise(xoff),0,1,-40,40); - } - - // Store the vertex in screen coordinates - surface.add(new Vec2(x,y)); - - // Move through perlin noise - xoff += 0.1; - - } - - // Build an array of vertices in Box2D coordinates - // from the ArrayList we made - Vec2[] vertices = new Vec2[surface.size()]; - for (int i = 0; i < vertices.length; i++) { - Vec2 edge = box2d.coordPixelsToWorld(surface.get(i)); - vertices[i] = edge; - } - - // Create the chain! - chain.createChain(vertices,vertices.length); - - // The edge chain is now attached to a body via a fixture - BodyDef bd = new BodyDef(); - bd.position.set(0.0f,0.0f); - Body body = box2d.createBody(bd); - // Shortcut, we could define a fixture if we - // want to specify frictions, restitution, etc. - body.createFixture(chain,1); - - } - - // A simple function to just draw the edge chain as a series of vertex points - void display() { - strokeWeight(2); - stroke(0); - noFill(); - beginShape(); - for (Vec2 v: surface) { - vertex(v.x,v.y); - } - endShape(); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Exercise_5_3_SineChain.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Exercise_5_3_SineChain.pde deleted file mode 100644 index f96ba5619..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Exercise_5_3_SineChain.pde +++ /dev/null @@ -1,72 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// An uneven surface - -import pbox2d.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; -import org.jbox2d.dynamics.*; - -// A reference to our box2d world -PBox2D box2d; - -// An ArrayList of particles that will fall on the surface -ArrayList particles; - -// An object to store information about the uneven surface -Surface surface; - -void setup() { - size(383,200); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - // We are setting a custom gravity - box2d.setGravity(0, -10); - - // Create the empty list - particles = new ArrayList(); - // Create the surface - surface = new Surface(); -} - -void draw() { - // If the mouse is pressed, we make new particles - if (random(1) < 0.5) { - float sz = random(2,6); - particles.add(new Particle(width/2,10,sz)); - } - - // We must always step through time! - box2d.step(); - - background(255); - - // Draw the surface - surface.display(); - - // Draw all particles - for (Particle p: particles) { - p.display(); - } - - // Particles that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - for (int i = particles.size()-1; i >= 0; i--) { - Particle p = particles.get(i); - if (p.done()) { - particles.remove(i); - } - } -} - - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Particle.pde deleted file mode 100644 index 8ef8d65b2..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Particle.pde +++ /dev/null @@ -1,90 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A circular particle - -class Particle { - - // We need to keep track of a Body and a radius - Body body; - float r; - - Particle(float x, float y, float r_) { - r = r_; - // This function puts the particle in the Box2d world - makeBody(x,y,r); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+r*2) { - killBody(); - return true; - } - return false; - } - - // - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - pushMatrix(); - translate(pos.x,pos.y); - rotate(-a); - fill(175); - stroke(0); - strokeWeight(1); - ellipse(0,0,r*2,r*2); - // Let's add a line so we can see the rotation - line(0,0,r,0); - popMatrix(); - } - - // Here's our function that adds the particle to the Box2D world - void makeBody(float x, float y, float r) { - // Define a body - BodyDef bd = new BodyDef(); - // Set its position - bd.position = box2d.coordPixelsToWorld(x,y); - bd.type = BodyType.DYNAMIC; - body = box2d.world.createBody(bd); - - // Make the body's shape a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(r); - - FixtureDef fd = new FixtureDef(); - fd.shape = cs; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.01; - fd.restitution = 0.3; - - // Attach fixture to body - body.createFixture(fd); - - // Give it a random initial velocity (and angular velocity) - body.setLinearVelocity(new Vec2(random(-10f,10f),random(5f,10f))); - body.setAngularVelocity(random(-10,10)); - } - - - - - - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Surface.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Surface.pde deleted file mode 100644 index ec00f3e54..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Surface.pde +++ /dev/null @@ -1,70 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// An uneven surface boundary - -class Surface { - // We'll keep track of all of the surface points - ArrayList surface; - - - Surface() { - surface = new ArrayList(); - - // This is what box2d uses to put the surface in its world - ChainShape chain = new ChainShape(); - - float theta = 0; - - // This has to go backwards so that the objects bounce off the top of the surface - // This "edgechain" will only work in one direction! - for (float x = width+10; x > -10; x -= 5) { - - // Doing some stuff with perlin noise to calculate a surface that points down on one side - // and up on the other - float y = map(cos(theta),-1,1,75,height-10); - theta += 0.15; - - // Store the vertex in screen coordinates - surface.add(new Vec2(x,y)); - - } - - // Build an array of vertices in Box2D coordinates - // from the ArrayList we made - Vec2[] vertices = new Vec2[surface.size()]; - for (int i = 0; i < vertices.length; i++) { - Vec2 edge = box2d.coordPixelsToWorld(surface.get(i)); - vertices[i] = edge; - } - - // Create the chain! - chain.createChain(vertices,vertices.length); - - // The edge chain is now attached to a body via a fixture - BodyDef bd = new BodyDef(); - bd.position.set(0.0f,0.0f); - Body body = box2d.createBody(bd); - // Shortcut, we could define a fixture if we - // want to specify frictions, restitution, etc. - body.createFixture(chain,1); - - } - - // A simple function to just draw the edge chain as a series of vertex points - void display() { - strokeWeight(2); - stroke(0); - noFill(); - beginShape(); - for (Vec2 v: surface) { - vertex(v.x,v.y); - } - endShape(); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Box.pde deleted file mode 100644 index 19c610cb2..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Box.pde +++ /dev/null @@ -1,89 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A rectangular box -class Box { - - // We need to keep track of a Body and a width and height - Body body; - float w; - float h; - - // Constructor - Box(float x, float y) { - w = random(4, 16); - h = random(4, 16); - // Add the box to the box2d world - makeBody(new Vec2(x, y), w, h); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+w*h) { - killBody(); - return true; - } - return false; - } - - // Drawing the box - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - - rectMode(CENTER); - pushMatrix(); - translate(pos.x, pos.y); - rotate(-a); - stroke(0); - fill(127); - strokeWeight(2); - rect(0, 0, w, h); - popMatrix(); - } - - // This function adds the rectangle to the box2d world - void makeBody(Vec2 center, float w_, float h_) { - - // Define a polygon (this is what we use for a rectangle) - PolygonShape sd = new PolygonShape(); - float box2dW = box2d.scalarPixelsToWorld(w_/2); - float box2dH = box2d.scalarPixelsToWorld(h_/2); - sd.setAsBox(box2dW, box2dH); - - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = sd; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.3; - fd.restitution = 0.5; - - // Define the body and make it from the shape - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - bd.position.set(box2d.coordPixelsToWorld(center)); - - body = box2d.createBody(bd); - body.createFixture(fd); - //body.setMassFromShapes(); - - // Give it some initial random velocity - body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5))); - body.setAngularVelocity(random(-5, 5)); - } -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Bridge.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Bridge.pde deleted file mode 100644 index 4fcf14477..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Bridge.pde +++ /dev/null @@ -1,67 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Series of Particles connected with distance joints - -class Bridge { - - // Bridge properties - float totalLength; // How long - int numPoints; // How many points - - // Our chain is a list of particles - ArrayList particles; - - // Chain constructor - Bridge(float l, int n) { - - totalLength = l; - numPoints = n; - - particles = new ArrayList(); - - float len = totalLength / numPoints; - - // Here is the real work, go through and add particles to the chain itself - for(int i=0; i < numPoints+1; i++) { - // Make a new particle - Particle p = null; - - // First and last particles are made with density of zero - if (i == 0 || i == numPoints) p = new Particle(i*len,height/4,4,true); - else p = new Particle(i*len,height/4,4,false); - particles.add(p); - - // Connect the particles with a distance joint - if (i > 0) { - DistanceJointDef djd = new DistanceJointDef(); - Particle previous = particles.get(i-1); - // Connection between previous particle and this one - djd.bodyA = previous.body; - djd.bodyB = p.body; - // Equilibrium length - djd.length = box2d.scalarPixelsToWorld(len); - // These properties affect how springy the joint is - djd.frequencyHz = 0; - djd.dampingRatio = 0; - - // Make the joint. Note we aren't storing a reference to the joint ourselves anywhere! - // We might need to someday, but for now it's ok - DistanceJoint dj = (DistanceJoint) box2d.world.createJoint(djd); - } - } - } - - // Draw the bridge - void display() { - for (Particle p: particles) { - p.display(); - } - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Exercise_5_6_Bridge.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Exercise_5_6_Bridge.pde deleted file mode 100644 index 4d341ed96..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Exercise_5_6_Bridge.pde +++ /dev/null @@ -1,85 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Example demonstrating distance joints -// A bridge is formed by connected a series of particles with joints - -import pbox2d.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.joints.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.collision.shapes.Shape; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; -import org.jbox2d.dynamics.contacts.*; - -// A reference to our box2d world -PBox2D box2d; - -// An object to describe a Bridget (a list of particles with joint connections) -Bridge bridge; - -// A list for all of our rectangles -ArrayList boxes; - -void setup() { - size(800, 200); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - - - // Make the bridge - bridge = new Bridge(width, width/10); - - // Create ArrayLists - boxes = new ArrayList(); -} - -void draw() { - background(255); - - // We must always step through time! - box2d.step(); - - - // When the mouse is clicked, add a new Box object - if (mousePressed) { - Box p = new Box(mouseX, mouseY); - boxes.add(p); - } - - // Display all the boxes - for (Box b: boxes) { - b.display(); - } - - // Boxes that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - for (int i = boxes.size()-1; i >= 0; i--) { - Box b = boxes.get(i); - if (b.done()) { - boxes.remove(i); - } - } - - // Draw the windmill - bridge.display(); - - - fill(0); - //text("Click mouse to add boxes.", 10, height-10); -} - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Particle.pde deleted file mode 100644 index e3c8b0097..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Particle.pde +++ /dev/null @@ -1,79 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A circular particle - -class Particle { - - // We need to keep track of a Body and a radius - Body body; - float r; - - Particle(float x, float y, float r_, boolean fixed) { - r = r_; - - // Define a body - BodyDef bd = new BodyDef(); - if (fixed) bd.type = BodyType.STATIC; - else bd.type = BodyType.DYNAMIC; - - // Set its position - bd.position = box2d.coordPixelsToWorld(x,y); - body = box2d.world.createBody(bd); - - // Make the body's shape a circle - // Make the body's shape a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(r); - - FixtureDef fd = new FixtureDef(); - fd.shape = cs; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.3; - fd.restitution = 0.5; - - body.createFixture(fd); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+r*2) { - killBody(); - return true; - } - return false; - } - - // - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - pushMatrix(); - translate(pos.x,pos.y); - rotate(a); - stroke(0); - fill(127); - strokeWeight(2); - ellipse(0,0,r*2,r*2); - // Let's add a line so we can see the rotation - line(0,0,r,0); - popMatrix(); - } - - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/Box.pde deleted file mode 100644 index 02d085bac..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/Box.pde +++ /dev/null @@ -1,103 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A rectangular box - -class Box { - - // We need to keep track of a Body and a width and height - Body body; - float w; - float h; - - boolean dragged = false; - - // Constructor - Box(float x_, float y_) { - float x = x_; - float y = y_; - w = 24; - h = 24; - // Add the box to the box2d world - makeBody(new Vec2(x,y),w,h); - body.setUserData(this); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - boolean contains(float x, float y) { - Vec2 worldPoint = box2d.coordPixelsToWorld(x, y); - Fixture f = body.getFixtureList(); - boolean inside = f.testPoint(worldPoint); - return inside; - } - - void setAngularVelocity(float a) { - body.setAngularVelocity(a); - } - void setVelocity(Vec2 v) { - body.setLinearVelocity(v); - } - - void setLocation(float x, float y) { - Vec2 pos = body.getWorldCenter(); - Vec2 target = box2d.coordPixelsToWorld(x,y); - Vec2 diff = new Vec2(target.x-pos.x,target.y-pos.y); - diff.mulLocal(50); - setVelocity(diff); - setAngularVelocity(0); - } - - // Drawing the box - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - - rectMode(PConstants.CENTER); - pushMatrix(); - translate(pos.x,pos.y); - rotate(a); - fill(175); - stroke(0); - rect(0,0,w,h); - popMatrix(); - } - - - // This function adds the rectangle to the box2d world - void makeBody(Vec2 center, float w_, float h_) { - // Define and create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.KINEMATIC; - bd.position.set(box2d.coordPixelsToWorld(center)); - bd.fixedRotation = true; - body = box2d.createBody(bd); - - // Define a polygon (this is what we use for a rectangle) - PolygonShape ps = new PolygonShape(); - float box2dW = box2d.scalarPixelsToWorld(w_/2); - float box2dH = box2d.scalarPixelsToWorld(h_/2); - ps.setAsBox(box2dW, box2dH); - - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = ps; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.3; - fd.restitution = 0.5; - - body.createFixture(fd); - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/KinematicTest.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/KinematicTest.pde deleted file mode 100644 index 15f86aca3..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/KinematicTest.pde +++ /dev/null @@ -1,144 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Basic example of controlling an object with our own motion (by attaching a MouseJoint) -// Also demonstrates how to know which object was hit - -import pbox2d.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.joints.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.collision.shapes.Shape; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; -import org.jbox2d.dynamics.contacts.*; - -// A reference to our box2d world -PBox2D box2d; - -// Just a single box this time -Box box; - -// An ArrayList of particles that will fall on the surface -ArrayList particles; - -// Perlin noise values -float xoff = 0; -float yoff = 1000; - - -void setup() { - size(640,360); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - - // Turn on collision listening! - box2d.listenForCollisions(); - - // Make the box - box = new Box(width/2,height/2); - - // Create the empty list - particles = new ArrayList(); - - -} - -void draw() { - background(255); - - if (random(1) < 0.2) { - float sz = random(4,8); - particles.add(new Particle(width/2,-20,sz)); - } - - - // We must always step through time! - box2d.step(); - - // Make an x,y coordinate out of perlin noise - float x = noise(xoff)*width; - float y = noise(yoff)*height; - xoff += 0.01; - yoff += 0.01; - - // This is tempting but will not work! - // box.body.setXForm(box2d.screenToWorld(x,y),0); - - // Instead update the spring which pulls the mouse along - if (mousePressed) { - box.setLocation(mouseX,mouseY); - } else { - //box.setLocation(x,y); - } - - // Look at all particles - for (int i = particles.size()-1; i >= 0; i--) { - Particle p = particles.get(i); - p.display(); - // Particles that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - if (p.done()) { - particles.remove(i); - } - } - - // Draw the box - box.display(); - - // Draw the spring - // spring.display(); -} - - -// Collision event functions! -void beginContact(Contact cp) { - // Get both fixtures - Fixture f1 = cp.getFixtureA(); - Fixture f2 = cp.getFixtureB(); - // Get both bodies - Body b1 = f1.getBody(); - Body b2 = f2.getBody(); - // Get our objects that reference these bodies - Object o1 = b1.getUserData(); - Object o2 = b2.getUserData(); - - // If object 1 is a Box, then object 2 must be a particle - // Note we are ignoring particle on particle collisions - if (o1.getClass() == Box.class) { - Particle p = (Particle) o2; - p.change(); - } - // If object 2 is a Box, then object 1 must be a particle - else if (o2.getClass() == Box.class) { - Particle p = (Particle) o1; - p.change(); - } -} - - -// Objects stop touching each other -void endContact(Contact cp) { -} - - - - - - - - - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/Particle.pde deleted file mode 100644 index 12c50f772..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/Particle.pde +++ /dev/null @@ -1,93 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A circular particle - -class Particle { - - // We need to keep track of a Body and a radius - Body body; - float r; - - color col; - - - Particle(float x, float y, float r_) { - r = r_; - // This function puts the particle in the Box2d world - makeBody(x, y, r); - body.setUserData(this); - col = color(175); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Change color when hit - void change() { - col = color(255, 0, 0); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+r*2) { - killBody(); - return true; - } - return false; - } - - - // - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - pushMatrix(); - translate(pos.x, pos.y); - rotate(a); - fill(col); - stroke(0); - strokeWeight(1); - ellipse(0, 0, r*2, r*2); - // Let's add a line so we can see the rotation - line(0, 0, r, 0); - popMatrix(); - } - - // Here's our function that adds the particle to the Box2D world - void makeBody(float x, float y, float r) { - // Define a body - BodyDef bd = new BodyDef(); - // Set its position - bd.position = box2d.coordPixelsToWorld(x, y); - bd.type = BodyType.DYNAMIC; - - body = box2d.createBody(bd); - - // Make the body's shape a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(r); - - FixtureDef fd = new FixtureDef(); - fd.shape = cs; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.01; - fd.restitution = 0.3; - - // Attach fixture to body - body.createFixture(fd); - - body.setAngularVelocity(random(-10, 10)); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Boundary.pde deleted file mode 100644 index d3ff672da..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Boundary.pde +++ /dev/null @@ -1,62 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A fixed boundary class (now incorporates angle) - -class Boundary { - - // A boundary is a simple rectangle with x,y,width,and height - float x; - float y; - float w; - float h; - // But we also have to make a body for box2d to know about it - Body b; - - Boundary(float x_,float y_, float w_, float h_, float a) { - x = x_; - y = y_; - w = w_; - h = h_; - - // Define the polygon - PolygonShape sd = new PolygonShape(); - // Figure out the box2d coordinates - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); - // We're just a box - sd.setAsBox(box2dW, box2dH); - - - // Create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.STATIC; - bd.angle = a; - bd.position.set(box2d.coordPixelsToWorld(x,y)); - b = box2d.createBody(bd); - - // Attached the shape to the body using a Fixture - b.createFixture(sd,1); - } - - // Draw the boundary, if it were at an angle we'd have to do something fancier - void display() { - noFill(); - stroke(0); - strokeWeight(1); - rectMode(CENTER); - - float a = b.getAngle(); - - pushMatrix(); - translate(x,y); - rotate(-a); - rect(0,0,w,h); - popMatrix(); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Liquidy.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Liquidy.pde deleted file mode 100644 index 73e61f25c..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Liquidy.pde +++ /dev/null @@ -1,74 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Box2D particle system example - -import pbox2d.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; - - - -// A reference to our box2d world -PBox2D box2d; - -// A list we'll use to track fixed objects -ArrayList boundaries; - -// A list for all particle systems -ArrayList systems; - -void setup() { - size(400,300); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - - // We are setting a custom gravity - box2d.setGravity(0, -20); - - // Create ArrayLists - systems = new ArrayList(); - boundaries = new ArrayList(); - - // Add a bunch of fixed boundaries - boundaries.add(new Boundary(50,100,300,5,-0.3)); - boundaries.add(new Boundary(250,175,300,5,0.5)); - -} - -void draw() { - background(255); - - // We must always step through time! - box2d.step(); - - // Run all the particle systems - for (ParticleSystem system: systems) { - system.run(); - - int n = (int) random(0,2); - system.addParticles(n); - } - - // Display all the boundaries - for (Boundary wall: boundaries) { - wall.display(); - } -} - - -void mousePressed() { - // Add a new Particle System whenever the mouse is clicked - systems.add(new ParticleSystem(0, new PVector(mouseX,mouseY))); -} - - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Particle.pde deleted file mode 100644 index 145b22276..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Particle.pde +++ /dev/null @@ -1,99 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A Particle - -class Particle { - - // We need to keep track of a Body - Body body; - - PVector[] trail; - - // Constructor - Particle(float x_, float y_) { - float x = x_; - float y = y_; - trail = new PVector[6]; - for (int i = 0; i < trail.length; i++) { - trail[i] = new PVector(x, y); - } - - // Add the box to the box2d world - // Here's a little trick, let's make a tiny tiny radius - // This way we have collisions, but they don't overwhelm the system - makeBody(new Vec2(x, y), 0.2f); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+20) { - killBody(); - return true; - } - return false; - } - - // Drawing the box - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - - // Keep track of a history of screen positions in an array - for (int i = 0; i < trail.length-1; i++) { - trail[i] = trail[i+1]; - } - trail[trail.length-1] = new PVector(pos.x, pos.y); - - // Draw particle as a trail - beginShape(); - noFill(); - strokeWeight(2); - stroke(0, 150); - for (int i = 0; i < trail.length; i++) { - vertex(trail[i].x, trail[i].y); - } - endShape(); - } - - // This function adds the rectangle to the box2d world - void makeBody(Vec2 center, float r) { - // Define and create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - - bd.position.set(box2d.coordPixelsToWorld(center)); - body = box2d.createBody(bd); - - // Give it some initial random velocity - body.setLinearVelocity(new Vec2(random(-1, 1), random(-1, 1))); - - // Make the body's shape a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(r); - - FixtureDef fd = new FixtureDef(); - fd.shape = cs; - - fd.density = 1; - fd.friction = 0; // Slippery when wet! - fd.restitution = 0.5; - - // We could use this if we want to turn collisions off - //cd.filter.groupIndex = -10; - - // Attach fixture to body - body.createFixture(fd); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/ParticleSystem.pde deleted file mode 100644 index 9c232f914..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/ParticleSystem.pde +++ /dev/null @@ -1,59 +0,0 @@ -// Box2D Particle System -// -// Spring 2010 - -// A class to describe a group of Particles -// An ArrayList is used to manage the list of Particles - -class ParticleSystem { - - ArrayList particles; // An ArrayList for all the particles - PVector origin; // An origin point for where particles are birthed - - ParticleSystem(int num, PVector v) { - particles = new ArrayList(); // Initialize the ArrayList - origin = v.get(); // Store the origin point - - for (int i = 0; i < num; i++) { - particles.add(new Particle(origin.x,origin.y)); // Add "num" amount of particles to the ArrayList - } - } - - void run() { - // Display all the particles - for (Particle p: particles) { - p.display(); - } - - // Particles that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - for (int i = particles.size()-1; i >= 0; i--) { - Particle p = particles.get(i); - if (p.done()) { - particles.remove(i); - } - } - } - - void addParticles(int n) { - for (int i = 0; i < n; i++) { - particles.add(new Particle(origin.x,origin.y)); - } - } - - // A method to test if the particle system still has particles - boolean dead() { - if (particles.isEmpty()) { - return true; - } - else { - return false; - } - } - -} - - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/Boundary.pde deleted file mode 100644 index d3ff672da..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/Boundary.pde +++ /dev/null @@ -1,62 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A fixed boundary class (now incorporates angle) - -class Boundary { - - // A boundary is a simple rectangle with x,y,width,and height - float x; - float y; - float w; - float h; - // But we also have to make a body for box2d to know about it - Body b; - - Boundary(float x_,float y_, float w_, float h_, float a) { - x = x_; - y = y_; - w = w_; - h = h_; - - // Define the polygon - PolygonShape sd = new PolygonShape(); - // Figure out the box2d coordinates - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); - // We're just a box - sd.setAsBox(box2dW, box2dH); - - - // Create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.STATIC; - bd.angle = a; - bd.position.set(box2d.coordPixelsToWorld(x,y)); - b = box2d.createBody(bd); - - // Attached the shape to the body using a Fixture - b.createFixture(sd,1); - } - - // Draw the boundary, if it were at an angle we'd have to do something fancier - void display() { - noFill(); - stroke(0); - strokeWeight(1); - rectMode(CENTER); - - float a = b.getAngle(); - - pushMatrix(); - translate(x,y); - rotate(-a); - rect(0,0,w,h); - popMatrix(); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/Box.pde deleted file mode 100644 index 27682e42b..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/Box.pde +++ /dev/null @@ -1,106 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A rectangular box - -class Box { - - // We need to keep track of a Body and a width and height - Body body; - float w; - float h; - - boolean dragged = false; - - // Constructor - Box(float x_, float y_) { - float x = x_; - float y = y_; - w = 24; - h = 24; - // Add the box to the box2d world - makeBody(new Vec2(x,y),w,h); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - boolean contains(float x, float y) { - Vec2 worldPoint = box2d.coordPixelsToWorld(x, y); - Fixture f = body.getFixtureList(); - boolean inside = f.testPoint(worldPoint); - return inside; - } - - void setAngularVelocity(float a) { - body.setAngularVelocity(a); - } - void setVelocity(Vec2 v) { - body.setLinearVelocity(v); - } - - void setLocation(float x, float y) { - Vec2 pos = body.getWorldCenter(); - Vec2 target = box2d.coordPixelsToWorld(x,y); - Vec2 diff = target.sub(pos); - diff.mulLocal(50); - setVelocity(diff); - setAngularVelocity(0); - } - - // Drawing the box - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - - rectMode(PConstants.CENTER); - pushMatrix(); - translate(pos.x,pos.y); - rotate(a); - fill(175); - stroke(0); - rect(0,0,w,h); - popMatrix(); - } - - - // This function adds the rectangle to the box2d world - void makeBody(Vec2 center, float w_, float h_) { - // Define and create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.KINEMATIC; - bd.position.set(box2d.coordPixelsToWorld(center)); - body = box2d.createBody(bd); - - // Define a polygon (this is what we use for a rectangle) - PolygonShape sd = new PolygonShape(); - float box2dW = box2d.scalarPixelsToWorld(w_/2); - float box2dH = box2d.scalarPixelsToWorld(h_/2); - sd.setAsBox(box2dW, box2dH); - - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = sd; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.3; - fd.restitution = 0.5; - - body.createFixture(fd); - //body.setMassFromShapes(); - - // Give it some initial random velocity - body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5))); - body.setAngularVelocity(random(-5, 5)); - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/MouseKinematic.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/MouseKinematic.pde deleted file mode 100644 index cad1269d7..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/MouseKinematic.pde +++ /dev/null @@ -1,78 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Basic example of controlling an object with the mouse (by attaching a spring) - -import pbox2d.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.joints.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.collision.shapes.Shape; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; - -// A reference to our box2d world -PBox2D box2d; - -// A list we'll use to track fixed objects -ArrayList boundaries; - -// Just a single box this time -Box box; - -void setup() { - size(640,360); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - - // Make the box - box = new Box(width/2,height/2); - - // Add a bunch of fixed boundaries - boundaries = new ArrayList(); - boundaries.add(new Boundary(width/2,height-5,width,10,0)); - boundaries.add(new Boundary(width/2,5,width,10,0)); - boundaries.add(new Boundary(width-5,height/2,10,height,0)); - boundaries.add(new Boundary(5,height/2,10,height,0)); -} - - -void draw() { - background(255); - - // We must always step through time! - - //if (box.dragged) { - box.setLocation(mouseX,mouseY); - //} - - box2d.step(); - - // Draw the boundaries - for (Boundary wall : boundaries) { - wall.display(); - } - - // Draw the box - box.display(); - - -} - -void mousePressed() { - if (box.contains(mouseX,mouseY)) { - box.dragged = true; - } -} - -void mouseReleased() { - box.dragged = false; -} - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise/Box.pde deleted file mode 100644 index 3ffd2de0f..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise/Box.pde +++ /dev/null @@ -1,23 +0,0 @@ -// A rectangular box -class Box { - - float x,y; - float w,h; - - // Constructor - Box(float x_, float y_) { - x = x_; - y = y_; - w = 16; - h = 16; - } - - // Drawing the box - void display() { - fill(127); - stroke(0); - strokeWeight(2); - rectMode(CENTER); - rect(x,y,w,h); - } -} diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise/NOC_5_1_box2d_exercise.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise/NOC_5_1_box2d_exercise.pde deleted file mode 100644 index 2f5ddc73b..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise/NOC_5_1_box2d_exercise.pde +++ /dev/null @@ -1,24 +0,0 @@ -// A list for all of our rectangles -ArrayList boxes; - -void setup() { - size(800,200); - smooth(); - // Create ArrayLists - boxes = new ArrayList(); -} - -void draw() { - background(255); - - // When the mouse is clicked, add a new Box object - if (mousePressed) { - Box p = new Box(mouseX,mouseY); - boxes.add(p); - } - - // Display all the boxes - for (Box b: boxes) { - b.display(); - } -} diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise_solved/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise_solved/Box.pde deleted file mode 100644 index 8eff285ae..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise_solved/Box.pde +++ /dev/null @@ -1,55 +0,0 @@ -// A rectangular box -class Box { - // Instead of any of the usual variables, we will store a reference to a Box2D Body - Body body; - - float w,h; - - Box(float x, float y) { - w = 16; - h = 16; - - // Build Body - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - bd.position.set(box2d.coordPixelsToWorld(x,y)); - body = box2d.createBody(bd); - - - // Define a polygon (this is what we use for a rectangle) - PolygonShape ps = new PolygonShape(); - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); // Box2D considers the width and height of a - ps.setAsBox(box2dW, box2dH); // rectangle to be the distance from the - // center to the edge (so half of what we - // normally think of as width or height.) - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = ps; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.3; - fd.restitution = 0.5; - - // Attach Fixture to Body - body.createFixture(fd); - } - - void display() { - // We need the Body’s location and angle - Vec2 pos = box2d.getBodyPixelCoord(body); - float a = body.getAngle(); - - pushMatrix(); - translate(pos.x,pos.y); // Using the Vec2 position and float angle to - rotate(-a); // translate and rotate the rectangle - fill(127); - stroke(0); - strokeWeight(2); - rectMode(CENTER); - rect(0,0,w,h); - popMatrix(); - } - -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise_solved/NOC_5_1_box2d_exercise_solved.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise_solved/NOC_5_1_box2d_exercise_solved.pde deleted file mode 100644 index 34b4a8acd..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise_solved/NOC_5_1_box2d_exercise_solved.pde +++ /dev/null @@ -1,37 +0,0 @@ -import pbox2d.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; - -// A list for all of our rectangles -ArrayList boxes; - -PBox2D box2d; - -void setup() { - size(800, 200); - smooth(); - // Initialize and create the Box2D world - box2d = new PBox2D(this); - box2d.createWorld(); - - // Create ArrayLists - boxes = new ArrayList(); -} - -void draw() { - background(255); - - // We must always step through time! - box2d.step(); - - // When the mouse is clicked, add a new Box object - Box p = new Box(mouseX, mouseY); - boxes.add(p); - - // Display all the boxes - for (Box b: boxes) { - b.display(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/Boundary.pde deleted file mode 100644 index d180aa86d..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/Boundary.pde +++ /dev/null @@ -1,54 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A fixed boundary class - -class Boundary { - - // A boundary is a simple rectangle with x,y,width,and height - float x; - float y; - float w; - float h; - - // But we also have to make a body for box2d to know about it - Body b; - - Boundary(float x_,float y_, float w_, float h_) { - x = x_; - y = y_; - w = w_; - h = h_; - - // Define the polygon - PolygonShape ps = new PolygonShape(); - // Figure out the box2d coordinates - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); - // We're just a box - ps.setAsBox(box2dW, box2dH); - - - // Create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.STATIC; - bd.position.set(box2d.coordPixelsToWorld(x,y)); - b = box2d.createBody(bd); - - // Attached the shape to the body using a Fixture - b.createFixture(ps,1); - } - - // Draw the boundary, if it were at an angle we'd have to do something fancier - void display() { - fill(0); - stroke(0); - rectMode(CENTER); - rect(x,y,w,h); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/Box.pde deleted file mode 100644 index 5f76a87fa..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/Box.pde +++ /dev/null @@ -1,88 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A rectangular box -class Box { - - // We need to keep track of a Body and a width and height - Body body; - float w; - float h; - - // Constructor - Box(float x, float y) { - w = random(4, 16); - h = random(4, 16); - // Add the box to the box2d world - makeBody(new Vec2(x, y), w, h); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+w*h) { - killBody(); - return true; - } - return false; - } - - // Drawing the box - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - - rectMode(CENTER); - pushMatrix(); - translate(pos.x, pos.y); - rotate(-a); - fill(127); - stroke(0); - strokeWeight(2); - rect(0, 0, w, h); - popMatrix(); - } - - // This function adds the rectangle to the box2d world - void makeBody(Vec2 center, float w_, float h_) { - - // Define a polygon (this is what we use for a rectangle) - PolygonShape sd = new PolygonShape(); - float box2dW = box2d.scalarPixelsToWorld(w_/2); - float box2dH = box2d.scalarPixelsToWorld(h_/2); - sd.setAsBox(box2dW, box2dH); - - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = sd; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.3; - fd.restitution = 0.5; - - // Define the body and make it from the shape - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - bd.position.set(box2d.coordPixelsToWorld(center)); - - body = box2d.createBody(bd); - body.createFixture(fd); - - // Give it some initial random velocity - body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5))); - body.setAngularVelocity(random(-5, 5)); - } -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/NOC_5_2_Boxes.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/NOC_5_2_Boxes.pde deleted file mode 100644 index 7a80fac21..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/NOC_5_2_Boxes.pde +++ /dev/null @@ -1,74 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Basic example of falling rectangles - -import pbox2d.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; - -// A reference to our box2d world -PBox2D box2d; - -// A list we'll use to track fixed objects -ArrayList boundaries; -// A list for all of our rectangles -ArrayList boxes; - -void setup() { - size(800,200); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - // We are setting a custom gravity - box2d.setGravity(0, -10); - - // Create ArrayLists - boxes = new ArrayList(); - boundaries = new ArrayList(); - - // Add a bunch of fixed boundaries - boundaries.add(new Boundary(width/4,height-5,width/2-50,10)); - boundaries.add(new Boundary(3*width/4,height-50,width/2-50,10)); -} - -void draw() { - background(255); - - // We must always step through time! - box2d.step(); - - // Boxes fall from the top every so often - if (random(1) < 0.2) { - Box p = new Box(width/2,30); - boxes.add(p); - } - - // Display all the boundaries - for (Boundary wall: boundaries) { - wall.display(); - } - - // Display all the boxes - for (Box b: boxes) { - b.display(); - } - - // Boxes that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - for (int i = boxes.size()-1; i >= 0; i--) { - Box b = boxes.get(i); - if (b.done()) { - boxes.remove(i); - } - } -} - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/NOC_5_3_ChainShape_Simple.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/NOC_5_3_ChainShape_Simple.pde deleted file mode 100644 index 899555fab..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/NOC_5_3_ChainShape_Simple.pde +++ /dev/null @@ -1,72 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// An uneven surface - -import pbox2d.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; -import org.jbox2d.dynamics.*; - -// A reference to our box2d world -PBox2D box2d; - -// An ArrayList of particles that will fall on the surface -ArrayList particles; - -// An object to store information about the uneven surface -Surface surface; - -void setup() { - size(800,200); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - // We are setting a custom gravity - box2d.setGravity(0, -10); - - // Create the empty list - particles = new ArrayList(); - // Create the surface - surface = new Surface(); -} - -void draw() { - // If the mouse is pressed, we make new particles - if (random(1) < 0.5) { - float sz = random(4,8); - particles.add(new Particle(width/2,10,sz)); - } - - // We must always step through time! - box2d.step(); - - background(255); - - // Draw the surface - surface.display(); - - // Draw all particles - for (Particle p: particles) { - p.display(); - } - - // Particles that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - for (int i = particles.size()-1; i >= 0; i--) { - Particle p = particles.get(i); - if (p.done()) { - particles.remove(i); - } - } -} - - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/Particle.pde deleted file mode 100644 index bfd3acdf5..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/Particle.pde +++ /dev/null @@ -1,90 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A circular particle - -class Particle { - - // We need to keep track of a Body and a radius - Body body; - float r; - - Particle(float x, float y, float r_) { - r = r_; - // This function puts the particle in the Box2d world - makeBody(x,y,r); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+r*2) { - killBody(); - return true; - } - return false; - } - - // - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - pushMatrix(); - translate(pos.x,pos.y); - rotate(-a); - fill(127); - stroke(0); - strokeWeight(2); - ellipse(0,0,r*2,r*2); - // Let's add a line so we can see the rotation - line(0,0,r,0); - popMatrix(); - } - - // Here's our function that adds the particle to the Box2D world - void makeBody(float x, float y, float r) { - // Define a body - BodyDef bd = new BodyDef(); - // Set its position - bd.position = box2d.coordPixelsToWorld(x,y); - bd.type = BodyType.DYNAMIC; - body = box2d.world.createBody(bd); - - // Make the body's shape a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(r); - - FixtureDef fd = new FixtureDef(); - fd.shape = cs; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.01; - fd.restitution = 0.3; - - // Attach fixture to body - body.createFixture(fd); - - // Give it a random initial velocity (and angular velocity) - body.setLinearVelocity(new Vec2(random(-10f,10f),random(5f,10f))); - body.setAngularVelocity(random(-10,10)); - } - - - - - - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/Surface.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/Surface.pde deleted file mode 100644 index 13e19576b..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/Surface.pde +++ /dev/null @@ -1,53 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// An uneven surface boundary - -class Surface { - // We'll keep track of all of the surface points - ArrayList surface; - - - Surface() { - surface = new ArrayList(); - // Here we keep track of the screen coordinates of the chain - surface.add(new Vec2(0, height/2)); - //surface.add(new Vec2(width/2, height/2+50)); - surface.add(new Vec2(width, height/2)); - - // This is what box2d uses to put the surface in its world - ChainShape chain = new ChainShape(); - - // We can add 3 vertices by making an array of 3 Vec2 objects - Vec2[] vertices = new Vec2[surface.size()]; - for (int i = 0; i < vertices.length; i++) { - vertices[i] = box2d.coordPixelsToWorld(surface.get(i)); - } - - chain.createChain(vertices, vertices.length); - - // The edge chain is now a body! - BodyDef bd = new BodyDef(); - Body body = box2d.world.createBody(bd); - // Shortcut, we could define a fixture if we - // want to specify frictions, restitution, etc. - body.createFixture(chain, 1); - } - - // A simple function to just draw the edge chain as a series of vertex points - void display() { - strokeWeight(1); - stroke(0); - fill(0); - beginShape(); - for (Vec2 v: surface) { - vertex(v.x, v.y); - } - vertex(width, height); - vertex(0, height); - endShape(CLOSE); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/Boundary.pde deleted file mode 100644 index 1a35aca9c..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/Boundary.pde +++ /dev/null @@ -1,60 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A fixed boundary class (now incorporates angle) - -class Boundary { - - // A boundary is a simple rectangle with x,y,width,and height - float x; - float y; - float w; - float h; - // But we also have to make a body for box2d to know about it - Body b; - - Boundary(float x_,float y_, float w_, float h_, float a) { - x = x_; - y = y_; - w = w_; - h = h_; - - // Define the polygon - PolygonShape sd = new PolygonShape(); - // Figure out the box2d coordinates - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); - // We're just a box - sd.setAsBox(box2dW, box2dH); - - - // Create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.STATIC; - bd.angle = a; - bd.position.set(box2d.coordPixelsToWorld(x,y)); - b = box2d.createBody(bd); - - // Attached the shape to the body using a Fixture - b.createFixture(sd,1); - } - - // Draw the boundary, it doesn't move so we don't have to ask the Body for location - void display() { - fill(0); - stroke(0); - strokeWeight(1); - rectMode(CENTER); - float a = b.getAngle(); - pushMatrix(); - translate(x,y); - rotate(-a); - rect(0,0,w,h); - popMatrix(); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/CustomShape.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/CustomShape.pde deleted file mode 100644 index fcd1cb5b0..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/CustomShape.pde +++ /dev/null @@ -1,91 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// A rectangular box -class CustomShape { - - // We need to keep track of a Body and a width and height - Body body; - - // Constructor - CustomShape(float x, float y) { - // Add the box to the box2d world - makeBody(new Vec2(x, y)); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height) { - killBody(); - return true; - } - return false; - } - - // Drawing the box - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - - Fixture f = body.getFixtureList(); - PolygonShape ps = (PolygonShape) f.getShape(); - - - rectMode(CENTER); - pushMatrix(); - translate(pos.x, pos.y); - rotate(-a); - fill(127); - stroke(0); - strokeWeight(2); - beginShape(); - //println(vertices.length); - // For every vertex, convert to pixel vector - for (int i = 0; i < ps.getVertexCount(); i++) { - Vec2 v = box2d.vectorWorldToPixels(ps.getVertex(i)); - vertex(v.x, v.y); - } - endShape(CLOSE); - popMatrix(); - } - - // This function adds the rectangle to the box2d world - void makeBody(Vec2 center) { - - Vec2[] vertices = new Vec2[4]; - vertices[0] = box2d.vectorPixelsToWorld(new Vec2(-15, 25)); - vertices[1] = box2d.vectorPixelsToWorld(new Vec2(15, 0)); - vertices[2] = box2d.vectorPixelsToWorld(new Vec2(20, -15)); - vertices[3] = box2d.vectorPixelsToWorld(new Vec2(-10, -10)); - - // Define a polygon (this is what we use for a rectangle) - PolygonShape ps = new PolygonShape(); - ps.set(vertices, vertices.length); - - // Define the body and make it from the shape - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - bd.position.set(box2d.coordPixelsToWorld(center)); - body = box2d.createBody(bd); - - body.createFixture(ps, 1.0); - - - // Give it some initial random velocity - body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5))); - body.setAngularVelocity(random(-5, 5)); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/NOC_5_4_Polygons.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/NOC_5_4_Polygons.pde deleted file mode 100644 index c3dc6d811..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/NOC_5_4_Polygons.pde +++ /dev/null @@ -1,74 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Basic example of falling rectangles - -import pbox2d.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; - -// A reference to our box2d world -PBox2D box2d; - -// A list we'll use to track fixed objects -ArrayList boundaries; -// A list for all of our rectangles -ArrayList polygons; - -void setup() { - size(800,200); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - // We are setting a custom gravity - box2d.setGravity(0, -20); - - // Create ArrayLists - polygons = new ArrayList(); - boundaries = new ArrayList(); - - // Add a bunch of fixed boundaries - boundaries.add(new Boundary(width/4,height-5,width/2-50,10,0)); - boundaries.add(new Boundary(3*width/4,height-50,width/2-50,10,0)); - boundaries.add(new Boundary(width-5,height/2,10,height,0)); - boundaries.add(new Boundary(5,height/2,10,height,0)); -} - -void draw() { - background(255); - - // We must always step through time! - box2d.step(); - - // Display all the boundaries - for (Boundary wall: boundaries) { - wall.display(); - } - - // Display all the people - for (CustomShape cs: polygons) { - cs.display(); - } - - // people that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - for (int i = polygons.size()-1; i >= 0; i--) { - CustomShape cs = polygons.get(i); - if (cs.done()) { - polygons.remove(i); - } - } -} - -void mousePressed() { - CustomShape cs = new CustomShape(mouseX,mouseY); - polygons.add(cs); -} - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/Boundary.pde deleted file mode 100644 index ea4eebb75..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/Boundary.pde +++ /dev/null @@ -1,62 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A fixed boundary class (now incorporates angle) - -class Boundary { - - // A boundary is a simple rectangle with x,y,width,and height - float x; - float y; - float w; - float h; - // But we also have to make a body for box2d to know about it - Body b; - - Boundary(float x_,float y_, float w_, float h_, float a) { - x = x_; - y = y_; - w = w_; - h = h_; - - // Define the polygon - PolygonShape sd = new PolygonShape(); - // Figure out the box2d coordinates - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); - // We're just a box - sd.setAsBox(box2dW, box2dH); - - - // Create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.STATIC; - bd.angle = a; - bd.position.set(box2d.coordPixelsToWorld(x,y)); - b = box2d.createBody(bd); - - // Attached the shape to the body using a Fixture - b.createFixture(sd,1); - } - - // Draw the boundary, if it were at an angle we'd have to do something fancier - void display() { - fill(0); - stroke(0); - strokeWeight(1); - rectMode(CENTER); - - float a = b.getAngle(); - - pushMatrix(); - translate(x,y); - rotate(-a); - rect(0,0,w,h); - popMatrix(); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/Lollipop.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/Lollipop.pde deleted file mode 100644 index 7d07373b5..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/Lollipop.pde +++ /dev/null @@ -1,89 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// A rectangular box -class Lollipop { - - // We need to keep track of a Body and a width and height - Body body; - float w; - float h; - float r; - - // Constructor - Lollipop(float x, float y) { - w = 8; - h = 24; - r = 8; - // Add the box to the box2d world - makeBody(new Vec2(x, y)); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+w*h) { - killBody(); - return true; - } - return false; - } - - // Drawing the lollipop - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - - rectMode(CENTER); - pushMatrix(); - translate(pos.x, pos.y); - rotate(-a); - fill(127); - stroke(0); - strokeWeight(2); - - rect(0,0,w,h); - ellipse(0, -h/2, r*2, r*2); - popMatrix(); - } - - // This function adds the rectangle to the box2d world - void makeBody(Vec2 center) { - - // Define the body and make it from the shape - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - bd.position.set(box2d.coordPixelsToWorld(center)); - body = box2d.createBody(bd); - - CircleShape circle = new CircleShape(); - circle.m_radius = box2d.scalarPixelsToWorld(r); - Vec2 offset = new Vec2(0,-h/2); - offset = box2d.vectorPixelsToWorld(offset); - circle.m_p.set(offset.x,offset.y); - - PolygonShape ps = new PolygonShape(); - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); - ps.setAsBox(box2dW, box2dH); - - body.createFixture(ps,1.0); - body.createFixture(circle, 1.0); - - // Give it some initial random velocity - body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5))); - body.setAngularVelocity(random(-5, 5)); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/NOC_5_5_MultiShapes.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/NOC_5_5_MultiShapes.pde deleted file mode 100644 index 4ebfedfd7..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/NOC_5_5_MultiShapes.pde +++ /dev/null @@ -1,74 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Basic example of falling rectangles - -import pbox2d.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; - -// A reference to our box2d world -PBox2D box2d; - -// A list we'll use to track fixed objects -ArrayList boundaries; -// A list for all of our rectangles -ArrayList pops; - -void setup() { - size(800,200); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this,20); - box2d.createWorld(); - // We are setting a custom gravity - box2d.setGravity(0, -20); - - // Create ArrayLists - pops = new ArrayList(); - boundaries = new ArrayList(); - - // Add a bunch of fixed boundaries - boundaries.add(new Boundary(width/4,height-5,width/2-50,10,0)); - boundaries.add(new Boundary(3*width/4,height-50,width/2-50,10,0)); - boundaries.add(new Boundary(width-5,height/2,10,height,0)); - boundaries.add(new Boundary(5,height/2,10,height,0)); -} - -void draw() { - background(255); - - // We must always step through time! - if (mousePressed) box2d.step(); - - // Display all the boundaries - for (Boundary wall: boundaries) { - wall.display(); - } - - // Display all the people - for (Lollipop p: pops) { - p.display(); - } - - // people that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - for (int i = pops.size()-1; i >= 0; i--) { - Lollipop p = pops.get(i); - if (p.done()) { - pops.remove(i); - } - } -} - -void mousePressed() { - Lollipop p = new Lollipop(mouseX,mouseY); - pops.add(p); -} - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Boundary.pde deleted file mode 100644 index 7b5012517..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Boundary.pde +++ /dev/null @@ -1,54 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A fixed boundary class - -class Boundary { - - // A boundary is a simple rectangle with x,y,width,and height - float x; - float y; - float w; - float h; - - // But we also have to make a body for box2d to know about it - Body b; - - Boundary(float x_,float y_, float w_, float h_) { - x = x_; - y = y_; - w = w_; - h = h_; - - // Define the polygon - PolygonShape sd = new PolygonShape(); - // Figure out the box2d coordinates - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); - // We're just a box - sd.setAsBox(box2dW, box2dH); - - - // Create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.STATIC; - bd.position.set(box2d.coordPixelsToWorld(x,y)); - b = box2d.createBody(bd); - - // Attached the shape to the body using a Fixture - b.createFixture(sd,1); - } - - // Draw the boundary, if it were at an angle we'd have to do something fancier - void display() { - fill(0); - stroke(0); - rectMode(CENTER); - rect(x,y,w,h); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/NOC_5_6_DistanceJoint.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/NOC_5_6_DistanceJoint.pde deleted file mode 100644 index c68edd589..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/NOC_5_6_DistanceJoint.pde +++ /dev/null @@ -1,81 +0,0 @@ -// The Nature of Code -// -// Spring 201 -// PBox2D example - -// Example demonstrating distance joints -// A bridge is formed by connected a series of particles with joints - -import pbox2d.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.joints.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.collision.shapes.Shape; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; -import org.jbox2d.dynamics.contacts.*; - -// A reference to our box2d world -PBox2D box2d; - -// A list we'll use to track fixed objects -ArrayList boundaries; - - -// A list for all of our rectangles -ArrayList pairs; - -void setup() { - size(800,200); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - - // Create ArrayLists - pairs = new ArrayList(); - - boundaries = new ArrayList(); - - // Add a bunch of fixed boundaries - boundaries.add(new Boundary(width/4,height-5,width/2-50,10)); - boundaries.add(new Boundary(3*width/4,height-50,width/2-50,10)); - -} - -void draw() { - background(255); - - // We must always step through time! - box2d.step(); - - // When the mouse is clicked, add a new Box object - - // Display all the boxes - for (Pair p: pairs) { - p.display(); - } - - // Display all the boundaries - for (Boundary wall: boundaries) { - wall.display(); - } - - fill(0); - text("Click mouse to add connected particles.",10,20); -} - -void mousePressed() { - Pair p = new Pair(mouseX,mouseY); - pairs.add(p); -} - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Pair.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Pair.pde deleted file mode 100644 index d250ad1ed..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Pair.pde +++ /dev/null @@ -1,48 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Series of Particles connected with distance joints - -class Pair { - - Particle p1; - Particle p2; - - float len; - // Chain constructor - Pair(float x, float y) { - len = 32; - - p1 = new Particle(x,y); - p2 = new Particle(x+random(-1,1),y+random(-1,1)); - - DistanceJointDef djd = new DistanceJointDef(); - // Connection between previous particle and this one - djd.bodyA = p1.body; - djd.bodyB = p2.body; - // Equilibrium length - djd.length = box2d.scalarPixelsToWorld(len); - - // These properties affect how springy the joint is - djd.frequencyHz = 3; // Try a value less than 5 (0 for no elasticity) - djd.dampingRatio = 0.1; // Ranges between 0 and 1 (1 for no springiness) - - // Make the joint. Note we aren't storing a reference to the joint ourselves anywhere! - // We might need to someday, but for now it's ok - DistanceJoint dj = (DistanceJoint) box2d.world.createJoint(djd); - } - - void display() { - Vec2 pos1 = box2d.getBodyPixelCoord(p1.body); - Vec2 pos2 = box2d.getBodyPixelCoord(p2.body); - stroke(0); - strokeWeight(2); - line(pos1.x,pos1.y,pos2.x,pos2.y); - - p1.display(); - p2.display(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Particle.pde deleted file mode 100644 index c66da98cd..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Particle.pde +++ /dev/null @@ -1,77 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A circular particle - -class Particle { - - // We need to keep track of a Body and a radius - Body body; - float r; - - Particle(float x, float y) { - r = 8; - - // Define a body - BodyDef bd = new BodyDef(); - // Set its position - bd.position = box2d.coordPixelsToWorld(x,y); - bd.type = BodyType.DYNAMIC; - body = box2d.world.createBody(bd); - - // Make the body's shape a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(r); - - FixtureDef fd = new FixtureDef(); - fd.shape = cs; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.01; - fd.restitution = 0.3; - - // Attach fixture to body - body.createFixture(fd); - body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5))); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+r*2) { - killBody(); - return true; - } - return false; - } - - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - pushMatrix(); - translate(pos.x,pos.y); - rotate(a); - fill(127); - stroke(0); - strokeWeight(2); - ellipse(0,0,r*2,r*2); - // Let's add a line so we can see the rotation - line(0,0,r,0); - popMatrix(); - } - - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Box.pde deleted file mode 100644 index 06410e87a..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Box.pde +++ /dev/null @@ -1,73 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// A rectangular box - -class Box { - - // We need to keep track of a Body and a width and height - Body body; - float w; - float h; - - // Constructor - Box(float x, float y, float w_, float h_, boolean lock) { - w = w_; - h = h_; - - // Define and create the body - BodyDef bd = new BodyDef(); - bd.position.set(box2d.coordPixelsToWorld(new Vec2(x,y))); - if (lock) bd.type = BodyType.STATIC; - else bd.type = BodyType.DYNAMIC; - - body = box2d.createBody(bd); - - // Define the shape -- a (this is what we use for a rectangle) - PolygonShape sd = new PolygonShape(); - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); - sd.setAsBox(box2dW, box2dH); - - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = sd; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.3; - fd.restitution = 0.5; - - body.createFixture(fd); - - // Give it some initial random velocity - body.setLinearVelocity(new Vec2(random(-5,5),random(2,5))); - body.setAngularVelocity(random(-5,5)); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Drawing the box - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - - rectMode(PConstants.CENTER); - pushMatrix(); - translate(pos.x,pos.y); - rotate(-a); - fill(127); - stroke(0); - strokeWeight(2); - rect(0,0,w,h); - popMatrix(); - } -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/NOC_5_7_RevoluteJoint.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/NOC_5_7_RevoluteJoint.pde deleted file mode 100644 index be3681432..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/NOC_5_7_RevoluteJoint.pde +++ /dev/null @@ -1,90 +0,0 @@ -// The Nature of Code -// -// Spring 201 -// PBox2D example - -// Example demonstrating revolute joint - -import pbox2d.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.joints.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.collision.shapes.Shape; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; -import org.jbox2d.dynamics.contacts.*; - -// A reference to our box2d world -PBox2D box2d; - -// An object to describe a Windmill (two bodies and one joint) -Windmill windmill; - -// An ArrayList of particles that will fall on the surface -ArrayList particles; - -void setup() { - size(800,200); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - - // Make the windmill at an x,y location - windmill = new Windmill(width/2,175); - - // Create the empty list - particles = new ArrayList(); - -} - -// Click the mouse to turn on or off the motor -void mousePressed() { - windmill.toggleMotor(); -} - -void draw() { - background(255); - - if (random(1) < 0.1) { - float sz = random(4,8); - particles.add(new Particle(random(width/2-100,width/2+100),-20,sz)); - } - - - // We must always step through time! - box2d.step(); - - // Look at all particles - for (int i = particles.size()-1; i >= 0; i--) { - Particle p = particles.get(i); - p.display(); - // Particles that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - if (p.done()) { - particles.remove(i); - } - } - - // Draw the windmill - windmill.display(); - - String status = "OFF"; - if (windmill.motorOn()) status = "ON"; - - fill(0); - text("Click mouse to toggle motor.\nMotor: " + status,10,height-30); - - -} - - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Particle.pde deleted file mode 100644 index 0f64a5204..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Particle.pde +++ /dev/null @@ -1,85 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A circular particle - -class Particle { - - // We need to keep track of a Body and a radius - Body body; - float r; - - Particle(float x, float y, float r_) { - r = r_; - // This function puts the particle in the Box2d world - makeBody(x, y, r); - body.setUserData(this); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+r*2) { - killBody(); - return true; - } - return false; - } - - // - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - pushMatrix(); - translate(pos.x, pos.y); - - rotate(-a); - fill(127); - stroke(0); - strokeWeight(2); - ellipse(0, 0, r*2, r*2); - // Let's add a line so we can see the rotation - line(0, 0, r, 0); - popMatrix(); - } - - // Here's our function that adds the particle to the Box2D world - void makeBody(float x, float y, float r) { - // Define a body - BodyDef bd = new BodyDef(); - // Set its position - bd.position = box2d.coordPixelsToWorld(x, y); - bd.type = BodyType.DYNAMIC; - - body = box2d.world.createBody(bd); - - // Make the body's shape a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(r); - - FixtureDef fd = new FixtureDef(); - fd.shape = cs; - - fd.density = 2.0; - fd.friction = 0.01; - fd.restitution = 0.3; // Restitution is bounciness - - body.createFixture(fd); - - // Give it a random initial velocity (and angular velocity) - //body.setLinearVelocity(new Vec2(random(-10f,10f),random(5f,10f))); - body.setAngularVelocity(random(-10, 10)); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Windmill.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Windmill.pde deleted file mode 100644 index a25423e9b..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Windmill.pde +++ /dev/null @@ -1,62 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// Class to describe a fixed spinning object - -class Windmill { - - // Our object is two boxes and one joint - // Consider making the fixed box much smaller and not drawing it - RevoluteJoint joint; - Box box1; - Box box2; - - Windmill(float x, float y) { - - // Initialize locations of two boxes - box1 = new Box(x, y-20, 120, 10, false); - box2 = new Box(x, y, 10, 40, true); - - // Define joint as between two bodies - RevoluteJointDef rjd = new RevoluteJointDef(); - - rjd.initialize(box1.body, box2.body, box1.body.getWorldCenter()); - - // Turning on a motor (optional) - rjd.motorSpeed = PI*2; // how fast? - rjd.maxMotorTorque = 1000.0; // how powerful? - rjd.enableMotor = false; // is it on? - - // There are many other properties you can set for a Revolute joint - // For example, you can limit its angle between a minimum and a maximum - // See box2d manual for more - - - // Create the joint - joint = (RevoluteJoint) box2d.world.createJoint(rjd); - } - - // Turn the motor on or off - void toggleMotor() { - joint.enableMotor(!joint.isMotorEnabled()); - } - - boolean motorOn() { - return joint.isMotorEnabled(); - } - - - void display() { - box2.display(); - box1.display(); - - // Draw anchor just for debug - Vec2 anchor = box2d.coordWorldToPixels(box1.body.getWorldCenter()); - fill(0); - noStroke(); - ellipse(anchor.x, anchor.y, 8, 8); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Boundary.pde deleted file mode 100644 index a05edbf8b..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Boundary.pde +++ /dev/null @@ -1,63 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A fixed boundary class (now incorporates angle) - -class Boundary { - - // A boundary is a simple rectangle with x,y,width,and height - float x; - float y; - float w; - float h; - // But we also have to make a body for box2d to know about it - Body b; - - Boundary(float x_,float y_, float w_, float h_, float a) { - x = x_; - y = y_; - w = w_; - h = h_; - - // Define the polygon - PolygonShape sd = new PolygonShape(); - // Figure out the box2d coordinates - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); - // We're just a box - sd.setAsBox(box2dW, box2dH); - - - // Create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.STATIC; - bd.angle = a; - bd.position.set(box2d.coordPixelsToWorld(x,y)); - b = box2d.createBody(bd); - - // Attached the shape to the body using a Fixture - b.createFixture(sd,1); - } - - // Draw the boundary, if it were at an angle we'd have to do something fancier - void display() { - noFill(); - stroke(127); - fill(127); - strokeWeight(1); - rectMode(CENTER); - - float a = b.getAngle(); - - pushMatrix(); - translate(x,y); - rotate(-a); - rect(0,0,w,h); - popMatrix(); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Box.pde deleted file mode 100644 index f3a872879..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Box.pde +++ /dev/null @@ -1,89 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A rectangular box - -class Box { - - // We need to keep track of a Body and a width and height - Body body; - float w; - float h; - - // Constructor - Box(float x_, float y_) { - float x = x_; - float y = y_; - w = 24; - h = 24; - // Add the box to the box2d world - makeBody(new Vec2(x,y),w,h); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - boolean contains(float x, float y) { - Vec2 worldPoint = box2d.coordPixelsToWorld(x, y); - Fixture f = body.getFixtureList(); - boolean inside = f.testPoint(worldPoint); - return inside; - } - - // Drawing the box - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - - rectMode(PConstants.CENTER); - pushMatrix(); - translate(pos.x,pos.y); - rotate(a); - fill(127); - stroke(0); - strokeWeight(2); - rect(0,0,w,h); - popMatrix(); - } - - - // This function adds the rectangle to the box2d world - void makeBody(Vec2 center, float w_, float h_) { - // Define and create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - bd.position.set(box2d.coordPixelsToWorld(center)); - body = box2d.createBody(bd); - - // Define a polygon (this is what we use for a rectangle) - PolygonShape sd = new PolygonShape(); - float box2dW = box2d.scalarPixelsToWorld(w_/2); - float box2dH = box2d.scalarPixelsToWorld(h_/2); - sd.setAsBox(box2dW, box2dH); - - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = sd; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.3; - fd.restitution = 0.5; - - body.createFixture(fd); - //body.setMassFromShapes(); - - // Give it some initial random velocity - body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5))); - body.setAngularVelocity(random(-5, 5)); - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/NOC_5_8_MouseJoint.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/NOC_5_8_MouseJoint.pde deleted file mode 100644 index 564f716cd..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/NOC_5_8_MouseJoint.pde +++ /dev/null @@ -1,86 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Basic example of controlling an object with the mouse (by attaching a spring) - -import pbox2d.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.joints.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.collision.shapes.Shape; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; - -// A reference to our box2d world -PBox2D box2d; - -// A list we'll use to track fixed objects -ArrayList boundaries; - -// Just a single box this time -Box box; - -// The Spring that will attach to the box from the mouse -Spring spring; - -void setup() { - size(800,200); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - - // Make the box - box = new Box(width/2,height/2); - - // Make the spring (it doesn't really get initialized until the mouse is clicked) - spring = new Spring(); - - // Add a bunch of fixed boundaries - boundaries = new ArrayList(); - boundaries.add(new Boundary(width/2,height-5,width,10,0)); - boundaries.add(new Boundary(width/2,5,width,10,0)); - boundaries.add(new Boundary(width-5,height/2,10,height,0)); - boundaries.add(new Boundary(5,height/2,10,height,0)); -} - -// When the mouse is released we're done with the spring -void mouseReleased() { - spring.destroy(); -} - -// When the mouse is pressed we. . . -void mousePressed() { - // Check to see if the mouse was clicked on the box - if (box.contains(mouseX, mouseY)) { - // And if so, bind the mouse location to the box with a spring - spring.bind(mouseX,mouseY,box); - } -} - -void draw() { - background(255); - - // We must always step through time! - box2d.step(); - - // Always alert the spring to the new mouse location - spring.update(mouseX,mouseY); - - // Draw the boundaries - for (int i = 0; i < boundaries.size(); i++) { - Boundary wall = (Boundary) boundaries.get(i); - wall.display(); - } - - // Draw the box - box.display(); - // Draw the spring (it only appears when active) - spring.display(); -} - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Spring.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Spring.pde deleted file mode 100644 index 76c445d50..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Spring.pde +++ /dev/null @@ -1,78 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// Class to describe the spring joint (displayed as a line) - -class Spring { - - // This is the box2d object we need to create - MouseJoint mouseJoint; - - Spring() { - // At first it doesn't exist - mouseJoint = null; - } - - // If it exists we set its target to the mouse location - void update(float x, float y) { - if (mouseJoint != null) { - // Always convert to world coordinates! - Vec2 mouseWorld = box2d.coordPixelsToWorld(x,y); - mouseJoint.setTarget(mouseWorld); - } - } - - void display() { - if (mouseJoint != null) { - // We can get the two anchor points - Vec2 v1 = new Vec2(0,0); - mouseJoint.getAnchorA(v1); - Vec2 v2 = new Vec2(0,0); - mouseJoint.getAnchorB(v2); - // Convert them to screen coordinates - v1 = box2d.coordWorldToPixels(v1); - v2 = box2d.coordWorldToPixels(v2); - // And just draw a line - stroke(0); - strokeWeight(1); - line(v1.x,v1.y,v2.x,v2.y); - } - } - - - // This is the key function where - // we attach the spring to an x,y location - // and the Box object's location - void bind(float x, float y, Box box) { - // Define the joint - MouseJointDef md = new MouseJointDef(); - // Body A is just a fake ground body for simplicity (there isn't anything at the mouse) - md.bodyA = box2d.getGroundBody(); - // Body 2 is the box's boxy - md.bodyB = box.body; - // Get the mouse location in world coordinates - Vec2 mp = box2d.coordPixelsToWorld(x,y); - // And that's the target - md.target.set(mp); - // Some stuff about how strong and bouncy the spring should be - md.maxForce = 1000.0 * box.body.m_mass; - md.frequencyHz = 5.0; - md.dampingRatio = 0.9; - - // Make the joint! - mouseJoint = (MouseJoint) box2d.world.createJoint(md); - } - - void destroy() { - // We can get rid of the joint when the mouse is released - if (mouseJoint != null) { - box2d.world.destroyJoint(mouseJoint); - mouseJoint = null; - } - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/Boundary.pde deleted file mode 100644 index 06c5bf80d..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/Boundary.pde +++ /dev/null @@ -1,56 +0,0 @@ -// The Nature of Code -// -// Spring 2012 -// PBox2D example - -// A fixed boundary class - -class Boundary { - - // A boundary is a simple rectangle with x,y,width,and height - float x; - float y; - float w; - float h; - - // But we also have to make a body for box2d to know about it - Body b; - - Boundary(float x_,float y_, float w_, float h_) { - x = x_; - y = y_; - w = w_; - h = h_; - - // Define the polygon - PolygonShape sd = new PolygonShape(); - // Figure out the box2d coordinates - float box2dW = box2d.scalarPixelsToWorld(w/2); - float box2dH = box2d.scalarPixelsToWorld(h/2); - // We're just a box - sd.setAsBox(box2dW, box2dH); - - - // Create the body - BodyDef bd = new BodyDef(); - bd.type = BodyType.STATIC; - bd.position.set(box2d.coordPixelsToWorld(x,y)); - b = box2d.createBody(bd); - - // Attached the shape to the body using a Fixture - b.createFixture(sd,1); - - b.setUserData(this); - } - - // Draw the boundary, if it were at an angle we'd have to do something fancier - void display() { - fill(0); - stroke(0); - rectMode(CENTER); - rect(x,y,w,h); - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/NOC_5_9_CollisionListening.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/NOC_5_9_CollisionListening.pde deleted file mode 100644 index 2d5f843e3..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/NOC_5_9_CollisionListening.pde +++ /dev/null @@ -1,111 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Basic example of controlling an object with our own motion (by attaching a MouseJoint) -// Also demonstrates how to know which object was hit - -import pbox2d.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.joints.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.collision.shapes.Shape; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; -import org.jbox2d.dynamics.contacts.*; - -// A reference to our box2d world -PBox2D box2d; - -// An ArrayList of particles that will fall on the surface -ArrayList particles; - -Boundary wall; - -void setup() { - size(800, 200); - smooth(); - - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - - // Turn on collision listening! - box2d.listenForCollisions(); - - // Create the empty list - particles = new ArrayList(); - - wall = new Boundary(width/2, height-5, width, 10); -} - -void draw() { - background(255); - - if (random(1) < 0.1) { - float sz = random(4, 8); - particles.add(new Particle(random(width), 20, sz)); - } - - - // We must always step through time! - box2d.step(); - - // Look at all particles - for (int i = particles.size()-1; i >= 0; i--) { - Particle p = particles.get(i); - p.display(); - // Particles that leave the screen, we delete them - // (note they have to be deleted from both the box2d world and our list - if (p.done()) { - particles.remove(i); - } - } - - wall.display(); -} - - -// Collision event functions! -void beginContact(Contact cp) { - // Get both fixtures - Fixture f1 = cp.getFixtureA(); - Fixture f2 = cp.getFixtureB(); - // Get both bodies - Body b1 = f1.getBody(); - Body b2 = f2.getBody(); - - // Get our objects that reference these bodies - Object o1 = b1.getUserData(); - Object o2 = b2.getUserData(); - - if (o1.getClass() == Particle.class && o2.getClass() == Particle.class) { - Particle p1 = (Particle) o1; - p1.change(); - Particle p2 = (Particle) o2; - p2.change(); - } - -} - -// Objects stop touching each other -void endContact(Contact cp) { -} - - - - - - - - - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/Particle.pde deleted file mode 100644 index 7d92ef9f6..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/Particle.pde +++ /dev/null @@ -1,91 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// PBox2D example - -// A circular particle - -class Particle { - - // We need to keep track of a Body and a radius - Body body; - float r; - - color col; - - Particle(float x, float y, float r_) { - r = r_; - // This function puts the particle in the Box2d world - makeBody(x, y, r); - body.setUserData(this); - col = color(127); - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - // Change color when hit - void change() { - col = color(255, 0, 0); - } - - // Is the particle ready for deletion? - boolean done() { - // Let's find the screen position of the particle - Vec2 pos = box2d.getBodyPixelCoord(body); - // Is it off the bottom of the screen? - if (pos.y > height+r*2) { - killBody(); - return true; - } - return false; - } - - - // - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - // Get its angle of rotation - float a = body.getAngle(); - pushMatrix(); - translate(pos.x, pos.y); - rotate(a); - fill(col); - stroke(0); - strokeWeight(2); - ellipse(0, 0, r*2, r*2); - // Let's add a line so we can see the rotation - line(0, 0, r, 0); - popMatrix(); - } - - // Here's our function that adds the particle to the Box2D world - void makeBody(float x, float y, float r) { - // Define a body - BodyDef bd = new BodyDef(); - // Set its position - bd.position = box2d.coordPixelsToWorld(x, y); - bd.type = BodyType.DYNAMIC; - body = box2d.createBody(bd); - - // Make the body's shape a circle - CircleShape cs = new CircleShape(); - cs.m_radius = box2d.scalarPixelsToWorld(r); - - FixtureDef fd = new FixtureDef(); - fd.shape = cs; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.01; - fd.restitution = 0.3; - - // Attach fixture to body - body.createFixture(fd); - - body.setAngularVelocity(random(-10, 10)); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/VectorStuff/VectorStuff.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/VectorStuff/VectorStuff.pde deleted file mode 100644 index a89fd6eb5..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/VectorStuff/VectorStuff.pde +++ /dev/null @@ -1,57 +0,0 @@ -// The Nature of Code -// -// Spring 2011 -// PBox2D example - -// Just demo-ing the basics of Vec2 vs. PVector - -import org.jbox2d.common.*; - -void setup() { - size(400,300); -// PVector a = new PVector(1,-1); -// PVector b = new PVector(3,4); -// a.add(b); -// -// PVector a = new PVector(1,-1); -// PVector b = new PVector(3,4); -// PVector c = PVector.add(a,b); -// -// Vec2 a = new Vec2(1,-1); -// Vec2 b = new Vec2(3,4); -// a.addLocal(b); -// -// Vec2 a = new Vec2(1,-1); -// Vec2 b = new Vec2(3,4); -// Vec2 c = a.add(b); -// -// PVector a = new PVector(1,-1); -// float n = 5; -// a.mult(n); -// -// PVector a = new PVector(1,-1); -// float n = 5; -// PVector c = PVector.mult(a,n); -// -// Vec2 a = new Vec2(1,-1); -// float n = 5; -// a.mulLocal(n); -// -// Vec2 a = new Vec2(1,-1); -// float n = 5; -// Vec2 c = a.mul(n); -// -// PVector a = new PVector(1,-1); -// float m = a.mag(); -// a.normalize(); - - Vec2 a = new Vec2(1,-1); - float m = a.length(); - a.normalize(); - println(a.x + "," + a.y); -} - -void draw() { - noLoop(); -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/readme.txt b/java/examples/Books/Nature of Code/chp5_physicslibraries/readme.txt deleted file mode 100644 index 99d3a27ad..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/readme.txt +++ /dev/null @@ -1,3 +0,0 @@ -For the box2d examples you will need PBox2D! - -https://github.com/shiffman/PBox2D \ No newline at end of file diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Blanket.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Blanket.pde deleted file mode 100644 index 70a45340b..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Blanket.pde +++ /dev/null @@ -1,51 +0,0 @@ -class Blanket { - ArrayList particles; - ArrayList springs; - - Blanket() { - particles = new ArrayList(); - springs = new ArrayList(); - - int w = 20; - int h = 20; - - float len = 10; - float strength = 0.125; - - for(int y=0; y< h; y++) { - for(int x=0; x < w; x++) { - - Particle p = new Particle(new Vec2D(width/2+x*len-w*len/2,y*len)); - physics.addParticle(p); - particles.add(p); - - if (x > 0) { - Particle previous = particles.get(particles.size()-2); - Connection c = new Connection(p,previous,len,strength); - physics.addSpring(c); - springs.add(c); - } - - if (y > 0) { - Particle above = particles.get(particles.size()-w-1); - Connection c=new Connection(p,above,len,strength); - physics.addSpring(c); - springs.add(c); - } - } - } - - Particle topleft= particles.get(0); - topleft.lock(); - - Particle topright = particles.get(w-1); - topright.lock(); - } - - void display() { - for (Connection c : springs) { - c.display(); - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Connection.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Connection.pde deleted file mode 100644 index 692d3f9ab..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Connection.pde +++ /dev/null @@ -1,11 +0,0 @@ -class Connection extends VerletSpring2D { - Connection(Particle p1, Particle p2, float len, float strength) { - super(p1,p2,len,strength); - } - - void display() { - stroke(0); - line(a.x,a.y,b.x,b.y); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Exercise_5_13_SoftBodySquareAdapted.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Exercise_5_13_SoftBodySquareAdapted.pde deleted file mode 100644 index 78aa8c09b..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Exercise_5_13_SoftBodySquareAdapted.pde +++ /dev/null @@ -1,63 +0,0 @@ -/** - * This example is adapted from Karsten Schmidt's SoftBodySquare example - * Daniel Shiffman, 2011 - * The Nature of Code book - */ - -/*

Softbody square demo is showing how to create a 2D square mesh out of - * verlet particles and make it stable enough to avoid total structural - * deformation by including an inner skeleton.

- * - *

Usage: move mouse to drag/deform the square

- */ - -/* - * Copyright (c) 2008-2009 Karsten Schmidt - * - * This demo & library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * http://creativecommons.org/licenses/LGPL/2.1/ - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - -import toxi.physics2d.behaviors.*; -import toxi.physics2d.*; - -import toxi.geom.*; -import toxi.math.*; - -VerletPhysics2D physics; - -Blanket b; - - -void setup() { - size(800,240); - smooth(); - physics=new VerletPhysics2D(); - physics.addBehavior(new GravityBehavior(new Vec2D(0,0.1))); - - b = new Blanket(); -} - -void draw() { - - background(255); - - physics.update(); - - b.display(); -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Particle.pde deleted file mode 100644 index 41a73d4c2..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Particle.pde +++ /dev/null @@ -1,17 +0,0 @@ -// Notice how we are using inheritance here! -// We could have just stored a reference to a VerletParticle object -// inside the Particle class, but inheritance is a nice alternative - -class Particle extends VerletParticle2D { - - Particle(Vec2D loc) { - super(loc); - } - - // All we're doing really is adding a display() function to a VerletParticle - void display() { - fill(175); - stroke(0); - ellipse(x,y,16,16); - } -} diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Cluster.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Cluster.pde deleted file mode 100644 index e2629412e..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Cluster.pde +++ /dev/null @@ -1,99 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// Toxiclibs example: http://toxiclibs.org/ - -// Force directed graph -// Heavily based on: http://code.google.com/p/fidgen/ - -class Cluster { - - // A cluster is a grouping of nodes - ArrayList nodes; - - float diameter; - - // We initialize a Cluster with a number of nodes, a diameter, and centerpoint - Cluster(int n, float d, Vec2D center) { - - // Initialize the ArrayList - nodes = new ArrayList(); - - // Set the diameter - diameter = d; - - // Create the nodes - for (int i = 0; i < n; i++) { - // We can't put them right on top of each other - nodes.add(new Node(center.add(Vec2D.randomVector()))); - } - - // Connect all the nodes with a Spring - for (int i = 1; i < nodes.size(); i++) { - VerletParticle2D pi = (VerletParticle2D) nodes.get(i); - for (int j = 0; j < i; j++) { - VerletParticle2D pj = (VerletParticle2D) nodes.get(j); - // A Spring needs two particles, a resting length, and a strength - physics.addSpring(new VerletSpring2D(pi,pj,diameter,0.01)); - } - } - } - - void display() { - // Show all the nodes - for (int i = 0; i < nodes.size(); i++) { - Node n = (Node) nodes.get(i); - n.display(); - } - } - - // This functons connects one cluster to another - // Each point of one cluster connects to each point of the other cluster - // The connection is a "VerletMinDistanceSpring" - // A VerletMinDistanceSpring is a string which only enforces its rest length if the - // current distance is less than its rest length. This is handy if you just want to - // ensure objects are at least a certain distance from each other, but don't - // care if it's bigger than the enforced minimum. - void connect(Cluster other) { - ArrayList otherNodes = other.getNodes(); - for (int i = 0; i < nodes.size(); i++) { - VerletParticle2D pi = (VerletParticle2D) nodes.get(i); - for (int j = 0; j < otherNodes.size(); j++) { - VerletParticle2D pj = (VerletParticle2D) otherNodes.get(j); - // Create the spring - physics.addSpring(new VerletMinDistanceSpring2D(pi,pj,(diameter+other.diameter)*0.5,0.05)); - } - } - } - - - // Draw all the internal connections - void showConnections() { - stroke(0,150); - for (int i = 0; i < nodes.size(); i++) { - VerletParticle2D pi = (VerletParticle2D) nodes.get(i); - for (int j = i+1; j < nodes.size(); j++) { - VerletParticle2D pj = (VerletParticle2D) nodes.get(j); - line(pi.x,pi.y,pj.x,pj.y); - } - } - } - - // Draw all the connections between this Cluster and another Cluster - void showConnections(Cluster other) { - stroke(0,50); - strokeWeight(2); - ArrayList otherNodes = other.getNodes(); - for (int i = 0; i < nodes.size(); i++) { - VerletParticle2D pi = (VerletParticle2D) nodes.get(i); - for (int j = 0; j < otherNodes.size(); j++) { - VerletParticle2D pj = (VerletParticle2D) otherNodes.get(j); - line(pi.x,pi.y,pj.x,pj.y); - } - } - } - - ArrayList getNodes() { - return nodes; - } -} diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Exercise_5_15_ForceDirectedGraph.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Exercise_5_15_ForceDirectedGraph.pde deleted file mode 100644 index b6e4982d1..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Exercise_5_15_ForceDirectedGraph.pde +++ /dev/null @@ -1,134 +0,0 @@ -/** - *
- */ - -/* - * Copyright (c) 2010 Daniel Schiffmann - * - * This demo & library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * http://creativecommons.org/licenses/LGPL/2.1/ - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -import toxi.geom.*; -import toxi.physics2d.*; -import toxi.physics2d.behaviors.*; - -// Reference to physics world -VerletPhysics2D physics; - -// A list of cluster objects -ArrayList clusters; - -// Boolean that indicates whether we draw connections or not -boolean showPhysics = true; -boolean showParticles = true; - -// Font -PFont f; - -void setup() { - size(800,300); - smooth(); - f = createFont("Georgia",12,true); - - // Initialize the physics - physics=new VerletPhysics2D(); - physics.setWorldBounds(new Rect(10,10,width-20,height-20)); - - // Spawn a new random graph - newGraph(); - -} - -// Spawn a new random graph -void newGraph() { - - // Clear physics - physics.clear(); - - // Create new ArrayList (clears old one) - clusters = new ArrayList(); - - // Create 8 random clusters - for (int i = 0; i < 8; i++) { - Vec2D center = new Vec2D(width/2,height/2); - clusters.add(new Cluster((int) random(3,8),random(20,100),center)); - } - - // All clusters connect to all clusters - for (int i = 0; i < clusters.size(); i++) { - for (int j = i+1; j < clusters.size(); j++) { - Cluster ci = (Cluster) clusters.get(i); - Cluster cj = (Cluster) clusters.get(j); - ci.connect(cj); - } - } - -} - -void draw() { - - // Update the physics world - physics.update(); - - background(255); - - // Display all points - if (showParticles) { - for (int i = 0; i < clusters.size(); i++) { - Cluster c = (Cluster) clusters.get(i); - c.display(); - } - } - - // If we want to see the physics - if (showPhysics) { - for (int i = 0; i < clusters.size(); i++) { - // Cluster internal connections - Cluster ci = (Cluster) clusters.get(i); - ci.showConnections(); - - // Cluster connections to other clusters - for (int j = i+1; j < clusters.size(); j++) { - Cluster cj = (Cluster) clusters.get(j); - ci.showConnections(cj); - } - } - } - - // Instructions - fill(0); - textFont(f); - text("'p' to display or hide particles\n'c' to display or hide connections\n'n' for new graph",10,20); -} - -// Key press commands -void keyPressed() { - if (key == 'c') { - showPhysics = !showPhysics; - if (!showPhysics) showParticles = true; - } - else if (key == 'p') { - showParticles = !showParticles; - if (!showParticles) showPhysics = true; - } - else if (key == 'n') { - newGraph(); - } -} diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Node.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Node.pde deleted file mode 100644 index 6fe3b5144..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Node.pde +++ /dev/null @@ -1,27 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// Toxiclibs example: http://toxiclibs.org/ - -// Force directed graph -// Heavily based on: http://code.google.com/p/fidgen/ - -// Notice how we are using inheritance here! -// We could have just stored a reference to a VerletParticle object -// inside the Node class, but inheritance is a nice alternative - -class Node extends VerletParticle2D { - - Node(Vec2D pos) { - super(pos); - } - - // All we're doing really is adding a display() function to a VerletParticle - void display() { - fill(0,150); - stroke(0); - strokeWeight(2); - ellipse(x,y,16,16); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_10_SimpleSpring/NOC_5_10_SimpleSpring.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_10_SimpleSpring/NOC_5_10_SimpleSpring.pde deleted file mode 100644 index 95b877cf7..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_10_SimpleSpring/NOC_5_10_SimpleSpring.pde +++ /dev/null @@ -1,70 +0,0 @@ -// The Nature of Code -// -// PBox2D example - -// Simple Toxiclibs Spring - -import toxi.physics2d.*; -import toxi.physics2d.behaviors.*; -import toxi.geom.*; - -// Reference to physics world -VerletPhysics2D physics; - -Particle p1; -Particle p2; - -void setup() { - size(800,200); - smooth(); - frameRate(30); - - // Initialize the physics - physics=new VerletPhysics2D(); - physics.addBehavior(new GravityBehavior(new Vec2D(0,0.5))); - - // Set the world's bounding box - physics.setWorldBounds(new Rect(0,0,width,height)); - - // Make two particles - p1 = new Particle(new Vec2D(width/2,20)); - p2 = new Particle(new Vec2D(width,180)); - // Lock one in place - p1.lock(); - - // Make a spring connecting both Particles - VerletSpring2D spring=new VerletSpring2D(p1,p2,80,0.01); - - // Anything we make, we have to add into the physics world - physics.addParticle(p1); - physics.addParticle(p2); - physics.addSpring(spring); -} - -void draw() { - - // Update the physics world - physics.update(); - - background(255); - - // Draw a line between the particles - stroke(0); - strokeWeight(2); - line(p1.x,p1.y,p2.x,p2.y); - - // Display the particles - p1.display(); - p2.display(); - - // Move the second one according to the mouse - if (mousePressed) { - p2.lock(); - p2.x = mouseX; - p2.y = mouseY; - p2.unlock(); - } -} - - - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_10_SimpleSpring/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_10_SimpleSpring/Particle.pde deleted file mode 100644 index 5d15d4d44..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_10_SimpleSpring/Particle.pde +++ /dev/null @@ -1,18 +0,0 @@ -// Notice how we are using inheritance here! -// We could have just stored a reference to a VerletParticle object -// inside the Particle class, but inheritance is a nice alternative - -class Particle extends VerletParticle2D { - - Particle(Vec2D loc) { - super(loc); - } - - // All we're doing really is adding a display() function to a VerletParticle - void display() { - fill(127); - stroke(0); - strokeWeight(2); - ellipse(x,y,32,32); - } -} diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/Chain.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/Chain.pde deleted file mode 100644 index e9703ed21..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/Chain.pde +++ /dev/null @@ -1,104 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// Toxiclibs example - -// A soft pendulum (series of connected springs) - -class Chain { - - // Chain properties - float totalLength; // How long - int numPoints; // How many points - float strength; // Strength of springs - float radius; // Radius of ball at tail - - // This list is redundant since we can ask for physics.particles, but in case we have many of these - // it's a convenient to keep track of our own list - ArrayList particles; - - // Let's keep an extra reference to the tail particle - // This is just the last particle in the ArrayList - Particle tail; - - // Some variables for mouse dragging - PVector offset = new PVector(); - boolean dragged = false; - - // Chain constructor - Chain(float l, int n, float r, float s) { - particles = new ArrayList(); - - totalLength = l; - numPoints = n; - radius = r; - strength = s; - - float len = totalLength / numPoints; - - // Here is the real work, go through and add particles to the chain itself - for(int i=0; i < numPoints; i++) { - // Make a new particle with an initial starting location - Particle particle=new Particle(width/2,i*len); - - // Redundancy, we put the particles both in physics and in our own ArrayList - physics.addParticle(particle); - particles.add(particle); - - // Connect the particles with a Spring (except for the head) - if (i != 0) { - Particle previous = particles.get(i-1); - VerletSpring2D spring = new VerletSpring2D(particle,previous,len,strength); - // Add the spring to the physics world - physics.addSpring(spring); - } - } - - // Keep the top fixed - Particle head=particles.get(0); - head.lock(); - - // Store reference to the tail - tail = particles.get(numPoints-1); - tail.radius = radius; - } - - // Check if a point is within the ball at the end of the chain - // If so, set dragged = true; - void contains(int x, int y) { - float d = dist(x,y,tail.x,tail.y); - if (d < radius) { - offset.x = tail.x - x; - offset.y = tail.y - y; - tail.lock(); - dragged = true; - } - } - - // Release the ball - void release() { - tail.unlock(); - dragged = false; - } - - // Update tail location if being dragged - void updateTail(int x, int y) { - if (dragged) { - tail.set(x+offset.x,y+offset.y); - } - } - - // Draw the chain - void display() { - // Draw line connecting all points - beginShape(); - stroke(0); - strokeWeight(2); - noFill(); - for (Particle p : particles) { - vertex(p.x,p.y); - } - endShape(); - tail.display(); - } -} diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/NOC_5_11_SoftStringPendulum.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/NOC_5_11_SoftStringPendulum.pde deleted file mode 100644 index c79572ca2..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/NOC_5_11_SoftStringPendulum.pde +++ /dev/null @@ -1,70 +0,0 @@ -/** - *

A soft pendulum (series of connected springs)
- * The Nature of Code
- * Spring 2010

- */ - -/* - * Copyright (c) 2010 Daniel Shiffmann - * - * This demo & library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * http://creativecommons.org/licenses/LGPL/2.1/ - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -import toxi.physics2d.*; -import toxi.physics2d.behaviors.*; -import toxi.geom.*; - -// Reference to physics "world" (2D) -VerletPhysics2D physics; - -// Our "Chain" object -Chain chain; - -void setup() { - size(800, 200); - smooth(); - - // Initialize the physics world - physics=new VerletPhysics2D(); - physics.addBehavior(new GravityBehavior(new Vec2D(0, 0.1))); - physics.setWorldBounds(new Rect(0, 0, width, height)); - - // Initialize the chain - chain = new Chain(180, 20, 16, 0.2); -} - -void draw() { - background(255); - - // Update physics - physics.update(); - // Update chain's tail according to mouse location - chain.updateTail(mouseX, mouseY); - // Display chain - chain.display(); -} - -void mousePressed() { - // Check to see if we're grabbing the chain - chain.contains(mouseX, mouseY); -} - -void mouseReleased() { - // Release the chain - chain.release(); -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/Particle.pde deleted file mode 100644 index da2de8b4f..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/Particle.pde +++ /dev/null @@ -1,20 +0,0 @@ -// Notice how we are using inheritance here! -// We could have just stored a reference to a VerletParticle object -// inside the Particle class, but inheritance is a nice alternative - -class Particle extends VerletParticle2D { - - float radius = 4; // Adding a radius for each particle - - Particle(float x, float y) { - super(x,y); - } - - // All we're doing really is adding a display() function to a VerletParticle - void display() { - fill(127); - stroke(0); - strokeWeight(2); - ellipse(x,y,radius*2,radius*2); - } -} diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/Cluster.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/Cluster.pde deleted file mode 100644 index 241520f2b..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/Cluster.pde +++ /dev/null @@ -1,64 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// Toxiclibs example: http://toxiclibs.org/ - -// Force directed graph -// Heavily based on: http://code.google.com/p/fidgen/ - -class Cluster { - - // A cluster is a grouping of nodes - ArrayList nodes; - - float diameter; - - // We initialize a Cluster with a number of nodes, a diameter, and centerpoint - Cluster(int n, float d, Vec2D center) { - - // Initialize the ArrayList - nodes = new ArrayList(); - - // Set the diameter - diameter = d; - - // Create the nodes - for (int i = 0; i < n; i++) { - // We can't put them right on top of each other - nodes.add(new Node(center.add(Vec2D.randomVector()))); - } - - // Connect all the nodes with a Spring - for (int i = 0; i < nodes.size()-1; i++) { - VerletParticle2D ni = nodes.get(i); - for (int j = i+1; j < nodes.size(); j++) { - VerletParticle2D nj = nodes.get(j); - // A Spring needs two particles, a resting length, and a strength - physics.addSpring(new VerletSpring2D(ni, nj, diameter, 0.01)); - } - } - } - - void display() { - // Show all the nodes - for (Node n : nodes) { - n.display(); - } - } - - - // Draw all the internal connections - void showConnections() { - stroke(0, 150); - strokeWeight(2); - for (int i = 0; i < nodes.size()-1; i++) { - VerletParticle2D pi = (VerletParticle2D) nodes.get(i); - for (int j = i+1; j < nodes.size(); j++) { - VerletParticle2D pj = (VerletParticle2D) nodes.get(j); - - line(pi.x, pi.y, pj.x, pj.y); - } - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/NOC_5_12_SimpleCluster.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/NOC_5_12_SimpleCluster.pde deleted file mode 100644 index 0191d5201..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/NOC_5_12_SimpleCluster.pde +++ /dev/null @@ -1,76 +0,0 @@ -/** - *

Force directed graph, - * heavily based on: fid.gen
- * The Nature of Code
- * Spring 2010

- */ - -import toxi.geom.*; -import toxi.physics2d.*; - -// Reference to physics world -VerletPhysics2D physics; - -// A list of cluster objects -Cluster cluster; - -// Boolean that indicates whether we draw connections or not -boolean showPhysics = true; -boolean showParticles = true; - -// Font -PFont f; - -void setup() { - size(800, 200); - smooth(); - frameRate(30); - f = createFont("Georgia", 12, true); - - // Initialize the physics - physics=new VerletPhysics2D(); - physics.setWorldBounds(new Rect(10, 10, width-20, height-20)); - - // Spawn a new random graph - cluster = new Cluster(8, 100, new Vec2D(width/2, height/2)); -} - -void draw() { - - // Update the physics world - physics.update(); - - background(255); - - // Display all points - if (showParticles) { - cluster.display(); - } - - // If we want to see the physics - if (showPhysics) { - cluster.showConnections(); - } - - // Instructions - fill(0); - textFont(f); - text("'p' to display or hide particles\n'c' to display or hide connections\n'n' for new graph",10,20); -} - -// Key press commands -void keyPressed() { - if (key == 'c') { - showPhysics = !showPhysics; - if (!showPhysics) showParticles = true; - } - else if (key == 'p') { - showParticles = !showParticles; - if (!showParticles) showPhysics = true; - } - else if (key == 'n') { - physics.clear(); - cluster = new Cluster(int(random(2, 20)), random(10, width/2), new Vec2D(width/2, height/2)); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/Node.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/Node.pde deleted file mode 100644 index 6fe3b5144..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/Node.pde +++ /dev/null @@ -1,27 +0,0 @@ -// The Nature of Code -// -// Spring 2010 -// Toxiclibs example: http://toxiclibs.org/ - -// Force directed graph -// Heavily based on: http://code.google.com/p/fidgen/ - -// Notice how we are using inheritance here! -// We could have just stored a reference to a VerletParticle object -// inside the Node class, but inheritance is a nice alternative - -class Node extends VerletParticle2D { - - Node(Vec2D pos) { - super(pos); - } - - // All we're doing really is adding a display() function to a VerletParticle - void display() { - fill(0,150); - stroke(0); - strokeWeight(2); - ellipse(x,y,16,16); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/Attractor.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/Attractor.pde deleted file mode 100644 index e82810ee1..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/Attractor.pde +++ /dev/null @@ -1,17 +0,0 @@ -class Attractor extends VerletParticle2D { - - float r; - - Attractor (Vec2D loc) { - super (loc); - r = 24; - physics.addParticle(this); - physics.addBehavior(new AttractionBehavior(this, width, 0.1)); - } - - void display () { - fill(0); - ellipse (x, y, r*2, r*2); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/NOC_5_13_AttractRepel.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/NOC_5_13_AttractRepel.pde deleted file mode 100644 index 7d4c3362f..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/NOC_5_13_AttractRepel.pde +++ /dev/null @@ -1,41 +0,0 @@ -import toxi.geom.*; -import toxi.physics2d.*; -import toxi.physics2d.behaviors.*; - -ArrayList particles; -Attractor attractor; - -VerletPhysics2D physics; - -void setup () { - size (800, 200); - smooth(); - physics = new VerletPhysics2D (); - physics.setDrag (0.01); - - particles = new ArrayList(); - for (int i = 0; i < 50; i++) { - particles.add(new Particle(new Vec2D(random(width),random(height)))); - } - - attractor = new Attractor(new Vec2D(width/2,height/2)); -} - - -void draw () { - background (255); - physics.update (); - - attractor.display(); - for (Particle p: particles) { - p.display(); - } - - if (mousePressed) { - attractor.lock(); - attractor.set(mouseX,mouseY); - } else { - attractor.unlock(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/Particle.pde deleted file mode 100644 index a33163d71..000000000 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/Particle.pde +++ /dev/null @@ -1,20 +0,0 @@ -// class Spore extends the class "VerletParticle2D" -class Particle extends VerletParticle2D { - - float r; - - Particle (Vec2D loc) { - super(loc); - r = 8; - physics.addParticle(this); - physics.addBehavior(new AttractionBehavior(this, r*4, -1)); - } - - void display () { - fill (127); - stroke (0); - strokeWeight(2); - ellipse (x, y, r*2, r*2); - } -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/Cohesion/Cohesion.pde b/java/examples/Books/Nature of Code/chp6_agents/Cohesion/Cohesion.pde deleted file mode 100644 index 976fb2308..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/Cohesion/Cohesion.pde +++ /dev/null @@ -1,49 +0,0 @@ -// Separation -// Daniel Shiffman -// The Nature of Code, 2011 - -// Via Reynolds: http://www.red3d.com/cwr/steer/ - -// A list of vehicles -ArrayList vehicles; - -void setup() { - size(640,360); - smooth(); - - // We are now making random vehicles and storing them in an ArrayList - vehicles = new ArrayList(); - for (int i = 0; i < 100; i++) { - vehicles.add(new Vehicle(random(width),random(height))); - } -} - -void draw() { - background(255); - - for (Vehicle v : vehicles) { - // Path following and separation are worked on in this function - v.cohesion(vehicles); - // Call the generic run method (update, borders, display, etc.) - v.update(); - v.borders(); - v.display(); - } - - // Instructions - fill(0); - text("Drag the mouse to generate new vehicles.",10,height-16); -} - - -void mouseDragged() { - vehicles.add(new Vehicle(mouseX,mouseY)); - - if (vehicles.size() > 200) { - vehicles.remove(0); - } - -} - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/Cohesion/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/Cohesion/Vehicle.pde deleted file mode 100644 index bbd8719a9..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/Cohesion/Vehicle.pde +++ /dev/null @@ -1,99 +0,0 @@ -// Separation -// Daniel Shiffman -// The Nature of Code, 2011 - -// Vehicle class - -class Vehicle { - - // All the usual stuff - PVector location; - PVector velocity; - PVector acceleration; - float r; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - // Constructor initialize all values - Vehicle(float x, float y) { - location = new PVector(x, y); - r = 12; - maxspeed = 3; - maxforce = 0.2; - acceleration = new PVector(0, 0); - velocity = new PVector(0, 0); - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - // Separation - // Method checks for nearby vehicles and steers away - void cohesion (ArrayList vehicles) { - float desiredseparation = r*2; - PVector sum = new PVector(); - int count = 0; - // For every boid in the system, check if it's too close - for (Vehicle other : vehicles) { - float d = PVector.dist(location, other.location); - // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself) - if (d > desiredseparation) { - // Calculate vector pointing away from neighbor - PVector diff = PVector.sub(location, other.location); - diff.normalize(); - diff.mult(-d); // Weight by distance - sum.add(diff); - count++; // Keep track of how many - } - } - // Average -- divide by how many - if (count > 0) { - sum.div(count); - // Our desired vector is the average scaled to maximum speed - sum.normalize(); - sum.mult(maxspeed); - // Implement Reynolds: Steering = Desired - Velocity - PVector steer = PVector.sub(sum, velocity); - steer.limit(maxforce); - applyForce(steer); - } - } - - - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelertion to 0 each cycle - acceleration.mult(0); - } - - void display() { - fill(175); - stroke(0); - pushMatrix(); - translate(location.x, location.y); - ellipse(0, 0, r, r); - popMatrix(); - } - - // Wraparound - void borders() { - if (location.x < -r) location.x = width+r; - if (location.y < -r) location.y = height+r; - if (location.x > width+r) location.x = -r; - if (location.y > height+r) location.y = -r; - } -} - - - - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/CrowdPathFollowing.pde b/java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/CrowdPathFollowing.pde deleted file mode 100644 index d8281dd00..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/CrowdPathFollowing.pde +++ /dev/null @@ -1,76 +0,0 @@ -// Crowd Path Following -// Daniel Shiffman -// The Nature of Code, Spring 2009 - -// Via Reynolds: http://www.red3d.com/cwr/steer/CrowdPath.html - -// Using this variable to decide whether to draw all the stuff -boolean debug = false; - - -// A path object (series of connected points) -Path path; - -// Two vehicles -ArrayList vehicles; - -void setup() { - size(640,360); - smooth(); - // Call a function to generate new Path object - newPath(); - - // We are now making random vehicles and storing them in an ArrayList - vehicles = new ArrayList(); - for (int i = 0; i < 120; i++) { - newVehicle(random(width),random(height)); - } -} - -void draw() { - background(255); - // Display the path - path.display(); - - for (Vehicle v : vehicles) { - // Path following and separation are worked on in this function - v.applyBehaviors(vehicles,path); - // Call the generic run method (update, borders, display, etc.) - v.run(); - } - - // Instructions - fill(0); - text("Hit 'd' to toggle debugging lines. Click the mouse to generate new vehicles.",10,height-16); -} - -void newPath() { - // A path is a series of connected points - // A more sophisticated path might be a curve - path = new Path(); - float offset = 60; - path.addPoint(offset,offset); - path.addPoint(width-offset,offset); - path.addPoint(width-offset,height-offset); - path.addPoint(width/2,height-offset*3); - path.addPoint(offset,height-offset); -} - -void newVehicle(float x, float y) { - float maxspeed = random(2,4); - float maxforce = 0.3; - vehicles.add(new Vehicle(new PVector(x,y),maxspeed,maxforce)); -} - -void keyPressed() { - if (key == 'd') { - debug = !debug; - } -} - -void mousePressed() { - newVehicle(mouseX,mouseY); -} - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/Path.pde b/java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/Path.pde deleted file mode 100644 index d6ea21a57..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/Path.pde +++ /dev/null @@ -1,50 +0,0 @@ -// Path Following -// Daniel Shiffman -// The Nature of Code - -class Path { - - // A Path is an arraylist of points (PVector objects) - ArrayList points; - // A path has a radius, i.e how far is it ok for the boid to wander off - float radius; - - Path() { - // Arbitrary radius of 20 - radius = 20; - points = new ArrayList(); - } - - // Add a point to the path - void addPoint(float x, float y) { - PVector point = new PVector(x, y); - points.add(point); - } - - // Draw the path - void display() { - strokeJoin(ROUND); - - // Draw thick line for radius - stroke(175); - strokeWeight(radius*2); - noFill(); - beginShape(); - for (PVector v : points) { - vertex(v.x, v.y); - } - endShape(CLOSE); - // Draw thin line for center of path - stroke(0); - strokeWeight(1); - noFill(); - beginShape(); - for (PVector v : points) { - vertex(v.x, v.y); - } - endShape(CLOSE); - } -} - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/Vehicle.pde deleted file mode 100644 index be7811b49..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/Vehicle.pde +++ /dev/null @@ -1,239 +0,0 @@ -// Path Following -// Daniel Shiffman -// The Nature of Code, Spring 2009 - -// Vehicle class - -class Vehicle { - - // All the usual stuff - PVector location; - PVector velocity; - PVector acceleration; - float r; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - // Constructor initialize all values - Vehicle( PVector l, float ms, float mf) { - location = l.get(); - r = 12; - maxspeed = ms; - maxforce = mf; - acceleration = new PVector(0, 0); - velocity = new PVector(maxspeed, 0); - } - - // A function to deal with path following and separation - void applyBehaviors(ArrayList vehicles, Path path) { - // Follow path force - PVector f = follow(path); - // Separate from other boids force - PVector s = separate(vehicles); - // Arbitrary weighting - f.mult(3); - s.mult(1); - // Accumulate in acceleration - applyForce(f); - applyForce(s); - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - - - // Main "run" function - public void run() { - update(); - borders(); - render(); - } - - - // This function implements Craig Reynolds' path following algorithm - // http://www.red3d.com/cwr/steer/PathFollow.html - PVector follow(Path p) { - - // Predict location 25 (arbitrary choice) frames ahead - PVector predict = velocity.get(); - predict.normalize(); - predict.mult(25); - PVector predictLoc = PVector.add(location, predict); - - // Now we must find the normal to the path from the predicted location - // We look at the normal for each line segment and pick out the closest one - PVector normal = null; - PVector target = null; - float worldRecord = 1000000; // Start with a very high worldRecord distance that can easily be beaten - - // Loop through all points of the path - for (int i = 0; i < p.points.size(); i++) { - - // Look at a line segment - PVector a = p.points.get(i); - PVector b = p.points.get((i+1)%p.points.size()); // Note Path has to wraparound - - // Get the normal point to that line - PVector normalPoint = getNormalPoint(predictLoc, a, b); - - // Check if normal is on line segment - PVector dir = PVector.sub(b, a); - // If it's not within the line segment, consider the normal to just be the end of the line segment (point b) - //if (da + db > line.mag()+1) { - if (normalPoint.x < min(a.x,b.x) || normalPoint.x > max(a.x,b.x) || normalPoint.y < min(a.y,b.y) || normalPoint.y > max(a.y,b.y)) { - normalPoint = b.get(); - // If we're at the end we really want the next line segment for looking ahead - a = p.points.get((i+1)%p.points.size()); - b = p.points.get((i+2)%p.points.size()); // Path wraps around - dir = PVector.sub(b, a); - } - - // How far away are we from the path? - float d = PVector.dist(predictLoc, normalPoint); - // Did we beat the worldRecord and find the closest line segment? - if (d < worldRecord) { - worldRecord = d; - normal = normalPoint; - - // Look at the direction of the line segment so we can seek a little bit ahead of the normal - dir.normalize(); - // This is an oversimplification - // Should be based on distance to path & velocity - dir.mult(25); - target = normal.get(); - target.add(dir); - - } - } - - // Draw the debugging stuff - if (debug) { - // Draw predicted future location - stroke(0); - fill(0); - line(location.x, location.y, predictLoc.x, predictLoc.y); - ellipse(predictLoc.x, predictLoc.y, 4, 4); - - // Draw normal location - stroke(0); - fill(0); - ellipse(normal.x, normal.y, 4, 4); - // Draw actual target (red if steering towards it) - line(predictLoc.x, predictLoc.y, target.x, target.y); - if (worldRecord > p.radius) fill(255, 0, 0); - noStroke(); - ellipse(target.x, target.y, 8, 8); - } - - // Only if the distance is greater than the path's radius do we bother to steer - if (worldRecord > p.radius) { - return seek(target); - } - else { - return new PVector(0, 0); - } - } - - - // A function to get the normal point from a point (p) to a line segment (a-b) - // This function could be optimized to make fewer new Vector objects - PVector getNormalPoint(PVector p, PVector a, PVector b) { - // Vector from a to p - PVector ap = PVector.sub(p, a); - // Vector from a to b - PVector ab = PVector.sub(b, a); - ab.normalize(); // Normalize the line - // Project vector "diff" onto line by using the dot product - ab.mult(ap.dot(ab)); - PVector normalPoint = PVector.add(a, ab); - return normalPoint; - } - - // Separation - // Method checks for nearby boids and steers away - PVector separate (ArrayList boids) { - float desiredseparation = r*2; - PVector steer = new PVector(0, 0, 0); - int count = 0; - // For every boid in the system, check if it's too close - for (int i = 0 ; i < boids.size(); i++) { - Vehicle other = (Vehicle) boids.get(i); - float d = PVector.dist(location, other.location); - // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself) - if ((d > 0) && (d < desiredseparation)) { - // Calculate vector pointing away from neighbor - PVector diff = PVector.sub(location, other.location); - diff.normalize(); - diff.div(d); // Weight by distance - steer.add(diff); - count++; // Keep track of how many - } - } - // Average -- divide by how many - if (count > 0) { - steer.div((float)count); - } - - // As long as the vector is greater than 0 - if (steer.mag() > 0) { - // Implement Reynolds: Steering = Desired - Velocity - steer.normalize(); - steer.mult(maxspeed); - steer.sub(velocity); - steer.limit(maxforce); - } - return steer; - } - - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelertion to 0 each cycle - acceleration.mult(0); - } - - // A method that calculates and applies a steering force towards a target - // STEER = DESIRED MINUS VELOCITY - PVector seek(PVector target) { - PVector desired = PVector.sub(target, location); // A vector pointing from the location to the target - - // Normalize desired and scale to maximum speed - desired.normalize(); - desired.mult(maxspeed); - // Steering = Desired minus Velocationity - PVector steer = PVector.sub(desired, velocity); - steer.limit(maxforce); // Limit to maximum steering force - - return steer; - } - - - void render() { - // Simpler boid is just a circle - fill(75); - stroke(0); - pushMatrix(); - translate(location.x, location.y); - ellipse(0, 0, r, r); - popMatrix(); - } - - // Wraparound - void borders() { - if (location.x < -r) location.x = width+r; - //if (location.y < -r) location.y = height+r; - if (location.x > width+r) location.x = -r; - //if (location.y > height+r) location.y = -r; - } -} - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/sketch.properties b/java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/sketch.properties deleted file mode 100644 index 28faa5897..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/CrowdPathFollowing/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=Standard diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Exercise_6_04_Wander.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Exercise_6_04_Wander.pde deleted file mode 100644 index 734b1db00..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Exercise_6_04_Wander.pde +++ /dev/null @@ -1,30 +0,0 @@ -// Wander -// Daniel Shiffman -// The Nature of Code - -// Demonstration of Craig Reynolds' "Wandering" behavior -// See: http://www.red3d.com/cwr/ - -// Click mouse to turn on and off rendering of the wander circle - - -Vehicle wanderer; -boolean debug = true; - -void setup() { - size(740,200); - wanderer = new Vehicle(width/2,height/2); - smooth(); -} - -void draw() { - background(255); - wanderer.wander(); - wanderer.run(); -} - -void mousePressed() { - debug = !debug; -} - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Vehicle.pde deleted file mode 100644 index 87a836746..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Vehicle.pde +++ /dev/null @@ -1,123 +0,0 @@ -// Wander -// Daniel Shiffman -// The Nature of Code - -// The "Vehicle" class (for wandering) - -class Vehicle { - - PVector location; - PVector velocity; - PVector acceleration; - float r; - float wandertheta; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - Vehicle(float x, float y) { - acceleration = new PVector(0,0); - velocity = new PVector(0,0); - location = new PVector(x,y); - r = 6; - wandertheta = 0; - maxspeed = 2; - maxforce = 0.05; - } - - void run() { - update(); - borders(); - display(); - } - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelertion to 0 each cycle - acceleration.mult(0); - } - - void wander() { - float wanderR = 25; // Radius for our "wander circle" - float wanderD = 80; // Distance for our "wander circle" - float change = 0.3; - wandertheta += random(-change,change); // Randomly change wander theta - - // Now we have to calculate the new location to steer towards on the wander circle - PVector circleloc = velocity.get(); // Start with velocity - circleloc.normalize(); // Normalize to get heading - circleloc.mult(wanderD); // Multiply by distance - circleloc.add(location); // Make it relative to boid's location - - float h = velocity.heading2D(); // We need to know the heading to offset wandertheta - - PVector circleOffSet = new PVector(wanderR*cos(wandertheta+h),wanderR*sin(wandertheta+h)); - PVector target = PVector.add(circleloc,circleOffSet); - seek(target); - - // Render wandering circle, etc. - if (debug) drawWanderStuff(location,circleloc,target,wanderR); - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - - // A method that calculates and applies a steering force towards a target - // STEER = DESIRED MINUS VELOCITY - void seek(PVector target) { - PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target - - // Normalize desired and scale to maximum speed - desired.normalize(); - desired.mult(maxspeed); - // Steering = Desired minus Velocity - PVector steer = PVector.sub(desired,velocity); - steer.limit(maxforce); // Limit to maximum steering force - - applyForce(steer); - } - - void display() { - // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); - fill(127); - stroke(0); - pushMatrix(); - translate(location.x,location.y); - rotate(theta); - beginShape(TRIANGLES); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(); - popMatrix(); - } - - // Wraparound - void borders() { - if (location.x < -r) location.x = width+r; - if (location.y < -r) location.y = height+r; - if (location.x > width+r) location.x = -r; - if (location.y > height+r) location.y = -r; - } -} - - -// A method just to draw the circle associated with wandering -void drawWanderStuff(PVector location, PVector circle, PVector target, float rad) { - stroke(0); - noFill(); - ellipseMode(CENTER); - ellipse(circle.x,circle.y,rad*2,rad*2); - ellipse(target.x,target.y,4,4); - line(location.x,location.y,circle.x,circle.y); - line(circle.x,circle.y,target.x,target.y); -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_09_AngleBetween/Exercise_6_09_AngleBetween.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_09_AngleBetween/Exercise_6_09_AngleBetween.pde deleted file mode 100644 index fb9e3b9ce..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_09_AngleBetween/Exercise_6_09_AngleBetween.pde +++ /dev/null @@ -1,54 +0,0 @@ -// Angle Between Two Vectors -// Daniel Shiffman -// The Nature of Code - -// Using the dot product to compute the angle between two vectors - -void setup() { - size(383, 200); - smooth(); -} - -void draw() { - background(255); - - // A "vector" (really a point) to store the mouse location and screen center location - PVector mouseLoc = new PVector(mouseX, mouseY); - PVector centerLoc = new PVector(width/2, height/2); - - // Aha, a vector to store the displacement between the mouse and center - PVector v = PVector.sub(mouseLoc, centerLoc); - v.normalize(); - v.mult(75); - - PVector xaxis = new PVector(75, 0); - // Render the vector - drawVector(v, centerLoc, 1.0); - drawVector(xaxis, centerLoc, 1.0); - - - float theta = PVector.angleBetween(v, xaxis); - - fill(0); - text(int(degrees(theta)) + " degrees\n" + theta + " radians", 10, 160); -} - -// Renders a vector object 'v' as an arrow and a location 'loc' -void drawVector(PVector v, PVector loc, float scayl) { - pushMatrix(); - float arrowsize = 6; - // Translate to location to render vector - translate(loc.x, loc.y); - stroke(0); - strokeWeight(2); - // Call vector heading function to get direction (pointing up is a heading of 0) - rotate(v.heading2D()); - // Calculate length of vector & scale it to be bigger or smaller if necessary - float len = v.mag()*scayl; - // Draw three lines to make an arrow - line(0, 0, len, 0); - line(len, 0, len-arrowsize, +arrowsize/2); - line(len, 0, len-arrowsize, -arrowsize/2); - popMatrix(); -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Exercise_6_13_CrowdPathFollowing.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Exercise_6_13_CrowdPathFollowing.pde deleted file mode 100644 index 8815cbb25..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Exercise_6_13_CrowdPathFollowing.pde +++ /dev/null @@ -1,77 +0,0 @@ -// Crowd Path Following -// Daniel Shiffman -// The Nature of Code, Spring 2009 - -// Via Reynolds: http://www.red3d.com/cwr/steer/CrowdPath.html - -// Using this variable to decide whether to draw all the stuff -boolean debug = false; - - -// A path object (series of connected points) -Path path; - -// Two vehicles -ArrayList vehicles; - -void setup() { - size(720,200); - smooth(); - // Call a function to generate new Path object - newPath(); - - // We are now making random vehicles and storing them in an ArrayList - vehicles = new ArrayList(); - for (int i = 0; i < 120; i++) { - newVehicle(random(width),random(height)); - } -} - -void draw() { - background(255); - // Display the path - path.display(); - - for (Vehicle v : vehicles) { - // Path following and separation are worked on in this function - v.applyBehaviors(vehicles,path); - // Call the generic run method (update, borders, display, etc.) - v.run(); - } - - // Instructions - fill(0); - textAlign(CENTER); - text("Hit 'd' to toggle debugging lines.\nClick the mouse to generate new vehicles.",width/2,height-20); -} - -void newPath() { - // A path is a series of connected points - // A more sophisticated path might be a curve - path = new Path(); - float offset = 30; - path.addPoint(offset,offset); - path.addPoint(width-offset,offset); - path.addPoint(width-offset,height-offset); - path.addPoint(width/2,height-offset*3); - path.addPoint(offset,height-offset); -} - -void newVehicle(float x, float y) { - float maxspeed = random(2,4); - float maxforce = 0.3; - vehicles.add(new Vehicle(new PVector(x,y),maxspeed,maxforce)); -} - -void keyPressed() { - if (key == 'd') { - debug = !debug; - } -} - -void mousePressed() { - newVehicle(mouseX,mouseY); -} - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Path.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Path.pde deleted file mode 100644 index d6ea21a57..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Path.pde +++ /dev/null @@ -1,50 +0,0 @@ -// Path Following -// Daniel Shiffman -// The Nature of Code - -class Path { - - // A Path is an arraylist of points (PVector objects) - ArrayList points; - // A path has a radius, i.e how far is it ok for the boid to wander off - float radius; - - Path() { - // Arbitrary radius of 20 - radius = 20; - points = new ArrayList(); - } - - // Add a point to the path - void addPoint(float x, float y) { - PVector point = new PVector(x, y); - points.add(point); - } - - // Draw the path - void display() { - strokeJoin(ROUND); - - // Draw thick line for radius - stroke(175); - strokeWeight(radius*2); - noFill(); - beginShape(); - for (PVector v : points) { - vertex(v.x, v.y); - } - endShape(CLOSE); - // Draw thin line for center of path - stroke(0); - strokeWeight(1); - noFill(); - beginShape(); - for (PVector v : points) { - vertex(v.x, v.y); - } - endShape(CLOSE); - } -} - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Vehicle.pde deleted file mode 100644 index be7811b49..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Vehicle.pde +++ /dev/null @@ -1,239 +0,0 @@ -// Path Following -// Daniel Shiffman -// The Nature of Code, Spring 2009 - -// Vehicle class - -class Vehicle { - - // All the usual stuff - PVector location; - PVector velocity; - PVector acceleration; - float r; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - // Constructor initialize all values - Vehicle( PVector l, float ms, float mf) { - location = l.get(); - r = 12; - maxspeed = ms; - maxforce = mf; - acceleration = new PVector(0, 0); - velocity = new PVector(maxspeed, 0); - } - - // A function to deal with path following and separation - void applyBehaviors(ArrayList vehicles, Path path) { - // Follow path force - PVector f = follow(path); - // Separate from other boids force - PVector s = separate(vehicles); - // Arbitrary weighting - f.mult(3); - s.mult(1); - // Accumulate in acceleration - applyForce(f); - applyForce(s); - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - - - // Main "run" function - public void run() { - update(); - borders(); - render(); - } - - - // This function implements Craig Reynolds' path following algorithm - // http://www.red3d.com/cwr/steer/PathFollow.html - PVector follow(Path p) { - - // Predict location 25 (arbitrary choice) frames ahead - PVector predict = velocity.get(); - predict.normalize(); - predict.mult(25); - PVector predictLoc = PVector.add(location, predict); - - // Now we must find the normal to the path from the predicted location - // We look at the normal for each line segment and pick out the closest one - PVector normal = null; - PVector target = null; - float worldRecord = 1000000; // Start with a very high worldRecord distance that can easily be beaten - - // Loop through all points of the path - for (int i = 0; i < p.points.size(); i++) { - - // Look at a line segment - PVector a = p.points.get(i); - PVector b = p.points.get((i+1)%p.points.size()); // Note Path has to wraparound - - // Get the normal point to that line - PVector normalPoint = getNormalPoint(predictLoc, a, b); - - // Check if normal is on line segment - PVector dir = PVector.sub(b, a); - // If it's not within the line segment, consider the normal to just be the end of the line segment (point b) - //if (da + db > line.mag()+1) { - if (normalPoint.x < min(a.x,b.x) || normalPoint.x > max(a.x,b.x) || normalPoint.y < min(a.y,b.y) || normalPoint.y > max(a.y,b.y)) { - normalPoint = b.get(); - // If we're at the end we really want the next line segment for looking ahead - a = p.points.get((i+1)%p.points.size()); - b = p.points.get((i+2)%p.points.size()); // Path wraps around - dir = PVector.sub(b, a); - } - - // How far away are we from the path? - float d = PVector.dist(predictLoc, normalPoint); - // Did we beat the worldRecord and find the closest line segment? - if (d < worldRecord) { - worldRecord = d; - normal = normalPoint; - - // Look at the direction of the line segment so we can seek a little bit ahead of the normal - dir.normalize(); - // This is an oversimplification - // Should be based on distance to path & velocity - dir.mult(25); - target = normal.get(); - target.add(dir); - - } - } - - // Draw the debugging stuff - if (debug) { - // Draw predicted future location - stroke(0); - fill(0); - line(location.x, location.y, predictLoc.x, predictLoc.y); - ellipse(predictLoc.x, predictLoc.y, 4, 4); - - // Draw normal location - stroke(0); - fill(0); - ellipse(normal.x, normal.y, 4, 4); - // Draw actual target (red if steering towards it) - line(predictLoc.x, predictLoc.y, target.x, target.y); - if (worldRecord > p.radius) fill(255, 0, 0); - noStroke(); - ellipse(target.x, target.y, 8, 8); - } - - // Only if the distance is greater than the path's radius do we bother to steer - if (worldRecord > p.radius) { - return seek(target); - } - else { - return new PVector(0, 0); - } - } - - - // A function to get the normal point from a point (p) to a line segment (a-b) - // This function could be optimized to make fewer new Vector objects - PVector getNormalPoint(PVector p, PVector a, PVector b) { - // Vector from a to p - PVector ap = PVector.sub(p, a); - // Vector from a to b - PVector ab = PVector.sub(b, a); - ab.normalize(); // Normalize the line - // Project vector "diff" onto line by using the dot product - ab.mult(ap.dot(ab)); - PVector normalPoint = PVector.add(a, ab); - return normalPoint; - } - - // Separation - // Method checks for nearby boids and steers away - PVector separate (ArrayList boids) { - float desiredseparation = r*2; - PVector steer = new PVector(0, 0, 0); - int count = 0; - // For every boid in the system, check if it's too close - for (int i = 0 ; i < boids.size(); i++) { - Vehicle other = (Vehicle) boids.get(i); - float d = PVector.dist(location, other.location); - // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself) - if ((d > 0) && (d < desiredseparation)) { - // Calculate vector pointing away from neighbor - PVector diff = PVector.sub(location, other.location); - diff.normalize(); - diff.div(d); // Weight by distance - steer.add(diff); - count++; // Keep track of how many - } - } - // Average -- divide by how many - if (count > 0) { - steer.div((float)count); - } - - // As long as the vector is greater than 0 - if (steer.mag() > 0) { - // Implement Reynolds: Steering = Desired - Velocity - steer.normalize(); - steer.mult(maxspeed); - steer.sub(velocity); - steer.limit(maxforce); - } - return steer; - } - - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelertion to 0 each cycle - acceleration.mult(0); - } - - // A method that calculates and applies a steering force towards a target - // STEER = DESIRED MINUS VELOCITY - PVector seek(PVector target) { - PVector desired = PVector.sub(target, location); // A vector pointing from the location to the target - - // Normalize desired and scale to maximum speed - desired.normalize(); - desired.mult(maxspeed); - // Steering = Desired minus Velocationity - PVector steer = PVector.sub(desired, velocity); - steer.limit(maxforce); // Limit to maximum steering force - - return steer; - } - - - void render() { - // Simpler boid is just a circle - fill(75); - stroke(0); - pushMatrix(); - translate(location.x, location.y); - ellipse(0, 0, r, r); - popMatrix(); - } - - // Wraparound - void borders() { - if (location.x < -r) location.x = width+r; - //if (location.y < -r) location.y = height+r; - if (location.x > width+r) location.x = -r; - //if (location.y > height+r) location.y = -r; - } -} - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/NOC_6_01_Seek.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/NOC_6_01_Seek.pde deleted file mode 100644 index 91534778c..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/NOC_6_01_Seek.pde +++ /dev/null @@ -1,36 +0,0 @@ -// Seek_Arrive -// Daniel Shiffman -// Nature of Code, Spring 2011 - -// Two "vehicles" follow the mouse position - -// Implements Craig Reynold's autonomous steering behaviors -// One vehicle "seeks" -// One vehicle "arrives" -// See: http://www.red3d.com/cwr/ - -Vehicle v; - -void setup() { - size(800, 200); - v = new Vehicle(width/2, height/2); - smooth(); -} - -void draw() { - background(255); - - PVector mouse = new PVector(mouseX, mouseY); - - // Draw an ellipse at the mouse location - fill(200); - stroke(0); - strokeWeight(2); - ellipse(mouse.x, mouse.y, 48, 48); - - // Call the appropriate steering behaviors for our agents - v.seek(mouse); - v.update(); - v.display(); -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/Vehicle.pde deleted file mode 100644 index 55d5e83e9..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/Vehicle.pde +++ /dev/null @@ -1,74 +0,0 @@ -// Seek_Arrive -// Daniel Shiffman - -// The "Vehicle" class - -class Vehicle { - - PVector location; - PVector velocity; - PVector acceleration; - float r; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - Vehicle(float x, float y) { - acceleration = new PVector(0,0); - velocity = new PVector(0,-2); - location = new PVector(x,y); - r = 6; - maxspeed = 4; - maxforce = 0.1; - } - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelerationelertion to 0 each cycle - acceleration.mult(0); - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - // A method that calculates a steering force towards a target - // STEER = DESIRED MINUS VELOCITY - void seek(PVector target) { - PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target - - // Normalize desired and scale to maximum speed - desired.normalize(); - desired.mult(maxspeed); - // Steering = Desired minus velocity - PVector steer = PVector.sub(desired,velocity); - steer.limit(maxforce); // Limit to maximum steering force - - applyForce(steer); - } - - void display() { - // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + PI/2; - fill(127); - stroke(0); - strokeWeight(1); - pushMatrix(); - translate(location.x,location.y); - rotate(theta); - beginShape(); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(CLOSE); - popMatrix(); - - - } -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/NOC_6_01_Seek_trail.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/NOC_6_01_Seek_trail.pde deleted file mode 100644 index 129a44bcc..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/NOC_6_01_Seek_trail.pde +++ /dev/null @@ -1,39 +0,0 @@ -// Seek_Arrive -// Daniel Shiffman -// Nature of Code, Spring 2011 - -// Two "vehicles" follow the mouse position - -// Implements Craig Reynold's autonomous steering behaviors -// One vehicle "seeks" -// One vehicle "arrives" -// See: http://www.red3d.com/cwr/ - -Vehicle v; - -void setup() { - size(800, 200); - v = new Vehicle(width/2, height/2); - smooth(); -} - -void draw() { - if (mousePressed) { - - background(255); - - PVector mouse = new PVector(mouseX, mouseY); - - // Draw an ellipse at the mouse location - fill(200); - stroke(0); - strokeWeight(2); - ellipse(mouse.x, mouse.y, 48, 48); - - // Call the appropriate steering behaviors for our agents - v.seek(mouse); - v.update(); - v.display(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/Vehicle.pde deleted file mode 100644 index 0491c53ea..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/Vehicle.pde +++ /dev/null @@ -1,90 +0,0 @@ -// Seek_Arrive -// Daniel Shiffman - -// The "Vehicle" class - -class Vehicle { - ArrayList history = new ArrayList(); - - PVector location; - PVector velocity; - PVector acceleration; - float r; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - Vehicle(float x, float y) { - acceleration = new PVector(0,0); - velocity = new PVector(0,-2); - location = new PVector(x,y); - r = 6; - maxspeed = 4; - maxforce = 0.1; - } - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelerationelertion to 0 each cycle - acceleration.mult(0); - - history.add(location.get()); - if (history.size() > 100) { - history.remove(0); - } - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - // A method that calculates a steering force towards a target - // STEER = DESIRED MINUS VELOCITY - void seek(PVector target) { - PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target - - // Normalize desired and scale to maximum speed - desired.normalize(); - desired.mult(maxspeed); - // Steering = Desired minus velocity - PVector steer = PVector.sub(desired,velocity); - steer.limit(maxforce); // Limit to maximum steering force - - applyForce(steer); - } - - void display() { - beginShape(); - stroke(0); - strokeWeight(1); - noFill(); - for(PVector v: history) { - vertex(v.x,v.y); - } - endShape(); - - - // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + PI/2; - fill(127); - stroke(0); - strokeWeight(1); - pushMatrix(); - translate(location.x,location.y); - rotate(theta); - beginShape(); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(CLOSE); - popMatrix(); - - - } -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/NOC_6_02_Arrive.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/NOC_6_02_Arrive.pde deleted file mode 100644 index 0d6037343..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/NOC_6_02_Arrive.pde +++ /dev/null @@ -1,35 +0,0 @@ -// Seek_Arrive -// Daniel Shiffman -// Nature of Code, Spring 2011 - -// Two "vehicles" follow the mouse position - -// Implements Craig Reynold's autonomous steering behaviors -// One vehicle "seeks" -// One vehicle "arrives" -// See: http://www.red3d.com/cwr/ - -Vehicle v; - -void setup() { - size(800, 200); - v = new Vehicle(width/2, height/2); - smooth(); -} - -void draw() { - background(255); - - PVector mouse = new PVector(mouseX, mouseY); - - // Draw an ellipse at the mouse location - fill(200); - stroke(0); - strokeWeight(2); - ellipse(mouse.x, mouse.y, 48, 48); - - // Call the appropriate steering behaviors for our agents - v.arrive(mouse); - v.update(); - v.display(); -} diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/Vehicle.pde deleted file mode 100644 index d16f0fc94..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/Vehicle.pde +++ /dev/null @@ -1,80 +0,0 @@ -// Seek_Arrive -// Daniel Shiffman - -// The "Vehicle" class - -class Vehicle { - - PVector location; - PVector velocity; - PVector acceleration; - float r; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - Vehicle(float x, float y) { - acceleration = new PVector(0,0); - velocity = new PVector(0,0); - location = new PVector(x,y); - r = 6; - maxspeed = 4; - maxforce = 0.1; - } - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelerationelertion to 0 each cycle - acceleration.mult(0); - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - // A method that calculates a steering force towards a target - // STEER = DESIRED MINUS VELOCITY - void arrive(PVector target) { - PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target - float d = desired.mag(); - // Normalize desired and scale with arbitrary damping within 100 pixels - desired.normalize(); - if (d < 100) { - float m = map(d,0,100,0,maxspeed); - desired.mult(m); - } else { - desired.mult(maxspeed); - } - - // Steering = Desired minus Velocity - PVector steer = PVector.sub(desired,velocity); - steer.limit(maxforce); // Limit to maximum steering force - applyForce(steer); - } - - void display() { - - // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + PI/2; - fill(127); - stroke(0); - strokeWeight(1); - pushMatrix(); - translate(location.x,location.y); - rotate(theta); - beginShape(); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(CLOSE); - popMatrix(); - - - } -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive_trail/NOC_6_02_Arrive_trail.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive_trail/NOC_6_02_Arrive_trail.pde deleted file mode 100644 index c0efbc4f5..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive_trail/NOC_6_02_Arrive_trail.pde +++ /dev/null @@ -1,38 +0,0 @@ -// Seek_Arrive -// Daniel Shiffman -// Nature of Code, Spring 2011 - -// Two "vehicles" follow the mouse position - -// Implements Craig Reynold's autonomous steering behaviors -// One vehicle "seeks" -// One vehicle "arrives" -// See: http://www.red3d.com/cwr/ - -Vehicle v; - -void setup() { - size(800, 200); - v = new Vehicle(width/2, height/2); - smooth(); -} - -void draw() { - if (mousePressed) { - background(255); - - PVector mouse = new PVector(mouseX, mouseY); - - // Draw an ellipse at the mouse location - fill(200); - stroke(0); - strokeWeight(2); - ellipse(mouse.x, mouse.y, 48, 48); - - // Call the appropriate steering behaviors for our agents - v.arrive(mouse); - v.update(); - v.display(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive_trail/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive_trail/Vehicle.pde deleted file mode 100644 index b6c0f4649..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive_trail/Vehicle.pde +++ /dev/null @@ -1,96 +0,0 @@ -// Seek_Arrive -// Daniel Shiffman - -// The "Vehicle" class - -class Vehicle { - - ArrayList history = new ArrayList(); - - PVector location; - PVector velocity; - PVector acceleration; - float r; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - Vehicle(float x, float y) { - acceleration = new PVector(0,0); - velocity = new PVector(0,0); - location = new PVector(x,y); - r = 6; - maxspeed = 4; - maxforce = 0.1; - } - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelerationelertion to 0 each cycle - acceleration.mult(0); - - history.add(location.get()); - if (history.size() > 100) { - history.remove(0); - } - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - // A method that calculates a steering force towards a target - // STEER = DESIRED MINUS VELOCITY - void arrive(PVector target) { - PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target - float d = desired.mag(); - // Normalize desired and scale with arbitrary damping within 100 pixels - desired.normalize(); - if (d < 100) { - float m = map(d,0,100,0,maxspeed); - desired.mult(m); - } else { - desired.mult(maxspeed); - } - - // Steering = Desired minus Velocity - PVector steer = PVector.sub(desired,velocity); - steer.limit(maxforce); // Limit to maximum steering force - applyForce(steer); - } - - void display() { - - beginShape(); - stroke(0); - strokeWeight(1); - noFill(); - for(PVector v: history) { - vertex(v.x,v.y); - } - endShape(); - - // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + PI/2; - fill(127); - stroke(0); - strokeWeight(1); - pushMatrix(); - translate(location.x,location.y); - rotate(theta); - beginShape(); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(CLOSE); - popMatrix(); - - - } -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/NOC_6_03_StayWithinWalls.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/NOC_6_03_StayWithinWalls.pde deleted file mode 100644 index 5f54281c5..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/NOC_6_03_StayWithinWalls.pde +++ /dev/null @@ -1,37 +0,0 @@ -// Stay Within Walls -// Daniel Shiffman -// The Nature of Code - -// "Made-up" Steering behavior to stay within walls - - -Vehicle v; -boolean debug = true; - -float d = 25; - - -void setup() { - size(800, 200); - v = new Vehicle(width/2, height/2); - smooth(); -} - -void draw() { - background(255); - - if (debug) { - stroke(175); - noFill(); - rectMode(CENTER); - rect(width/2, height/2, width-d*2, height-d*2); - } - - v.boundaries(); - v.run(); -} - -void mousePressed() { - debug = !debug; -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/Vehicle.pde deleted file mode 100644 index 7f557cdd2..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/Vehicle.pde +++ /dev/null @@ -1,92 +0,0 @@ -// Wander -// Daniel Shiffman -// The Nature of Code - -// The "Vehicle" class - -class Vehicle { - - PVector location; - PVector velocity; - PVector acceleration; - float r; - - float maxspeed; - float maxforce; - - Vehicle(float x, float y) { - acceleration = new PVector(0, 0); - velocity = new PVector(3, -2); - velocity.mult(5); - location = new PVector(x, y); - r = 6; - maxspeed = 3; - maxforce = 0.15; - } - - void run() { - update(); - display(); - } - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelertion to 0 each cycle - acceleration.mult(0); - } - - void boundaries() { - - PVector desired = null; - - if (location.x < d) { - desired = new PVector(maxspeed, velocity.y); - } - else if (location.x > width -d) { - desired = new PVector(-maxspeed, velocity.y); - } - - if (location.y < d) { - desired = new PVector(velocity.x, maxspeed); - } - else if (location.y > height-d) { - desired = new PVector(velocity.x, -maxspeed); - } - - if (desired != null) { - desired.normalize(); - desired.mult(maxspeed); - PVector steer = PVector.sub(desired, velocity); - steer.limit(maxforce); - applyForce(steer); - } - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - - void display() { - // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); - fill(127); - stroke(0); - pushMatrix(); - translate(location.x, location.y); - rotate(theta); - beginShape(TRIANGLES); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(); - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/NOC_6_03_StayWithinWalls_trail.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/NOC_6_03_StayWithinWalls_trail.pde deleted file mode 100644 index 5f54281c5..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/NOC_6_03_StayWithinWalls_trail.pde +++ /dev/null @@ -1,37 +0,0 @@ -// Stay Within Walls -// Daniel Shiffman -// The Nature of Code - -// "Made-up" Steering behavior to stay within walls - - -Vehicle v; -boolean debug = true; - -float d = 25; - - -void setup() { - size(800, 200); - v = new Vehicle(width/2, height/2); - smooth(); -} - -void draw() { - background(255); - - if (debug) { - stroke(175); - noFill(); - rectMode(CENTER); - rect(width/2, height/2, width-d*2, height-d*2); - } - - v.boundaries(); - v.run(); -} - -void mousePressed() { - debug = !debug; -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/Vehicle.pde deleted file mode 100644 index 0d94054a4..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/Vehicle.pde +++ /dev/null @@ -1,108 +0,0 @@ -// Wander -// Daniel Shiffman -// The Nature of Code - -// The "Vehicle" class - -class Vehicle { - ArrayList history = new ArrayList(); - - PVector location; - PVector velocity; - PVector acceleration; - float r; - - float maxspeed; - float maxforce; - - Vehicle(float x, float y) { - acceleration = new PVector(0, 0); - velocity = new PVector(3, -2); - velocity.mult(5); - location = new PVector(x, y); - r = 6; - maxspeed = 3; - maxforce = 0.15; - } - - void run() { - update(); - display(); - } - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelertion to 0 each cycle - acceleration.mult(0); - - history.add(location.get()); - if (history.size() > 500) { - history.remove(0); - } - } - - void boundaries() { - - PVector desired = null; - - if (location.x < d) { - desired = new PVector(maxspeed, velocity.y); - } - else if (location.x > width -d) { - desired = new PVector(-maxspeed, velocity.y); - } - - if (location.y < d) { - desired = new PVector(velocity.x, maxspeed); - } - else if (location.y > height-d) { - desired = new PVector(velocity.x, -maxspeed); - } - - if (desired != null) { - desired.normalize(); - desired.mult(maxspeed); - PVector steer = PVector.sub(desired, velocity); - steer.limit(maxforce); - applyForce(steer); - } - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - - void display() { - beginShape(); - stroke(0); - strokeWeight(1); - noFill(); - for(PVector v: history) { - vertex(v.x,v.y); - } - endShape(); - - - // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); - fill(127); - stroke(0); - pushMatrix(); - translate(location.x, location.y); - rotate(theta); - beginShape(TRIANGLES); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(); - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/FlowField.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/FlowField.pde deleted file mode 100644 index b3c4c4a73..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/FlowField.pde +++ /dev/null @@ -1,92 +0,0 @@ -// Flow Field Following -// Daniel Shiffman -// The Nature of Code, Spring 2011 - -class FlowField { - - // A flow field is a two dimensional array of PVectors - PVector[][] field; - int cols, rows; // Columns and Rows - int resolution; // How large is each "cell" of the flow field - - FlowField(int r) { - resolution = r; - // Determine the number of columns and rows based on sketch's width and height - cols = width/resolution; - rows = height/resolution; - field = new PVector[cols][rows]; - init(); - } - - void init() { - // Reseed noise so we get a new flow field every time - noiseSeed((int)random(10000)); - float xoff = 0; - for (int i = 0; i < cols; i++) { - float yoff = 0; - for (int j = 0; j < rows; j++) { - //float theta = random(TWO_PI); - //float theta = map(noise(xoff,yoff),0,1,0,TWO_PI); - float x = i*resolution; - float y = j*resolution; - PVector v = new PVector(width/2-x,-y); - v.normalize(); - // Polar to cartesian coordinate transformation to get x and y components of the vector - field[i][j] = v;// new PVector(cos(theta),sin(theta)); - yoff += 0.1; - } - xoff += 0.1; - } - } - - // Draw every vector - void display() { - for (int i = 0; i < cols; i++) { - for (int j = 0; j < rows; j++) { - //drawVector(field[i][j],i*resolution,j*resolution,resolution-2); - pushMatrix(); - //translate(i*resolution+arrow.width/2,j*resolution+arrow.height/2); - translate(i*resolution,j*resolution); - rotate(field[i][j].heading2D()); - imageMode(CENTER); - //scale(0.2); - image(a,0,0); - //shape(arrow,-arrow.width/2,-arrow.height/2); - //ellipse(0,0,8,8); - popMatrix(); - } - } - - } - - // Renders a vector object 'v' as an arrow and a location 'x,y' - void drawVector(PVector v, float x, float y, float scayl) { - pushMatrix(); - float arrowsize = 4; - // Translate to location to render vector - translate(x,y); - stroke(0,100); - // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate - rotate(v.heading2D()); - // Calculate length of vector & scale it to be bigger or smaller if necessary - float len = v.mag()*scayl; - // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction) - line(0,0,len,0); - line(len,0,len-arrowsize,+arrowsize/2); - line(len,0,len-arrowsize,-arrowsize/2); - popMatrix(); - } - - PVector lookup(PVector lookup) { - int column = int(constrain(lookup.x/resolution,0,cols-1)); - int row = int(constrain(lookup.y/resolution,0,rows-1)); - return field[column][row].get(); - } - - -} - - - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/NOC_6_04_Flow_Figures.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/NOC_6_04_Flow_Figures.pde deleted file mode 100644 index d688f62f6..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/NOC_6_04_Flow_Figures.pde +++ /dev/null @@ -1,34 +0,0 @@ -// Flow Field Following -// Daniel Shiffman -// The Nature of Code - -// Via Reynolds: http://www.red3d.com/cwr/steer/FlowFollow.html - -// Flowfield object -FlowField flowfield; -PShape arrow; -PImage a; - -void setup() { - size(1800, 60*9); - smooth(); - // Make a new flow field with "resolution" of 16 - flowfield = new FlowField(60); - arrow = loadShape("arrow.svg"); - a = loadImage("arrow60.png"); -} - -void draw() { - background(255); - // Display the flowfield in "debug" mode - translate(30,30); - flowfield.display(); - saveFrame("ch6_exc6.png"); - noLoop(); -} -// Make a new flowfield -void mousePressed() { - flowfield.init(); -} - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/Vehicle.pde deleted file mode 100644 index bd4149236..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/Vehicle.pde +++ /dev/null @@ -1,85 +0,0 @@ -// Flow Field Following -// Daniel Shiffman -// The Nature of Code, Spring 2011 - -class Vehicle { - - // The usual stuff - PVector location; - PVector velocity; - PVector acceleration; - float r; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - Vehicle(PVector l, float ms, float mf) { - location = l.get(); - r = 3.0; - maxspeed = ms; - maxforce = mf; - acceleration = new PVector(0,0); - velocity = new PVector(0,0); - } - - public void run() { - update(); - borders(); - display(); - } - - - // Implementing Reynolds' flow field following algorithm - // http://www.red3d.com/cwr/steer/FlowFollow.html - void follow(FlowField flow) { - // What is the vector at that spot in the flow field? - PVector desired = flow.lookup(location); - // Scale it up by maxspeed - desired.mult(maxspeed); - // Steering is desired minus velocity - PVector steer = PVector.sub(desired, velocity); - steer.limit(maxforce); // Limit to maximum steering force - applyForce(steer); - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelertion to 0 each cycle - acceleration.mult(0); - } - - void display() { - // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); - fill(175); - stroke(0); - pushMatrix(); - translate(location.x,location.y); - rotate(theta); - beginShape(TRIANGLES); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(); - popMatrix(); - } - - // Wraparound - void borders() { - if (location.x < -r) location.x = width+r; - if (location.y < -r) location.y = height+r; - if (location.x > width+r) location.x = -r; - if (location.y > height+r) location.y = -r; - } -} - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/data/arrow.svg b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/data/arrow.svg deleted file mode 100644 index 0f34115e7..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/data/arrow.svg +++ /dev/null @@ -1,5149 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/FlowField.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/FlowField.pde deleted file mode 100644 index 9ce11b4fe..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/FlowField.pde +++ /dev/null @@ -1,77 +0,0 @@ -// Flow Field Following -// Daniel Shiffman -// The Nature of Code, Spring 2011 - -class FlowField { - - // A flow field is a two dimensional array of PVectors - PVector[][] field; - int cols, rows; // Columns and Rows - int resolution; // How large is each "cell" of the flow field - - FlowField(int r) { - resolution = r; - // Determine the number of columns and rows based on sketch's width and height - cols = width/resolution; - rows = height/resolution; - field = new PVector[cols][rows]; - init(); - } - - void init() { - // Reseed noise so we get a new flow field every time - noiseSeed((int)random(10000)); - float xoff = 0; - for (int i = 0; i < cols; i++) { - float yoff = 0; - for (int j = 0; j < rows; j++) { - float theta = map(noise(xoff,yoff),0,1,0,TWO_PI); - // Polar to cartesian coordinate transformation to get x and y components of the vector - field[i][j] = new PVector(cos(theta),sin(theta)); - yoff += 0.1; - } - xoff += 0.1; - } - } - - // Draw every vector - void display() { - for (int i = 0; i < cols; i++) { - for (int j = 0; j < rows; j++) { - drawVector(field[i][j],i*resolution,j*resolution,resolution-2); - } - } - - } - - // Renders a vector object 'v' as an arrow and a location 'x,y' - void drawVector(PVector v, float x, float y, float scayl) { - pushMatrix(); - float arrowsize = 4; - // Translate to location to render vector - translate(x,y); - stroke(0,100); - // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate - rotate(v.heading2D()); - // Calculate length of vector & scale it to be bigger or smaller if necessary - float len = v.mag()*scayl; - // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction) - line(0,0,len,0); - //line(len,0,len-arrowsize,+arrowsize/2); - //line(len,0,len-arrowsize,-arrowsize/2); - popMatrix(); - } - - PVector lookup(PVector lookup) { - int column = int(constrain(lookup.x/resolution,0,cols-1)); - int row = int(constrain(lookup.y/resolution,0,rows-1)); - return field[column][row].get(); - } - - -} - - - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/NOC_6_04_Flowfield.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/NOC_6_04_Flowfield.pde deleted file mode 100644 index 805ea5962..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/NOC_6_04_Flowfield.pde +++ /dev/null @@ -1,55 +0,0 @@ -// Flow Field Following -// Daniel Shiffman -// The Nature of Code - -// Via Reynolds: http://www.red3d.com/cwr/steer/FlowFollow.html - -// Using this variable to decide whether to draw all the stuff -boolean debug = true; - -// Flowfield object -FlowField flowfield; -// An ArrayList of vehicles -ArrayList vehicles; - -void setup() { - size(800, 200); - smooth(); - // Make a new flow field with "resolution" of 16 - flowfield = new FlowField(20); - vehicles = new ArrayList(); - // Make a whole bunch of vehicles with random maxspeed and maxforce values - for (int i = 0; i < 120; i++) { - vehicles.add(new Vehicle(new PVector(random(width), random(height)), random(2, 5), random(0.1, 0.5))); - } -} - -void draw() { - background(255); - // Display the flowfield in "debug" mode - if (debug) flowfield.display(); - // Tell all the vehicles to follow the flow field - for (Vehicle v : vehicles) { - v.follow(flowfield); - v.run(); - } - - // Instructions - fill(0); - text("Hit space bar to toggle debugging lines.\nClick the mouse to generate a new flow field.",10,height-20); -} - - -void keyPressed() { - if (key == ' ') { - debug = !debug; - } -} - -// Make a new flowfield -void mousePressed() { - flowfield.init(); -} - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/Vehicle.pde deleted file mode 100644 index bd4149236..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/Vehicle.pde +++ /dev/null @@ -1,85 +0,0 @@ -// Flow Field Following -// Daniel Shiffman -// The Nature of Code, Spring 2011 - -class Vehicle { - - // The usual stuff - PVector location; - PVector velocity; - PVector acceleration; - float r; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - Vehicle(PVector l, float ms, float mf) { - location = l.get(); - r = 3.0; - maxspeed = ms; - maxforce = mf; - acceleration = new PVector(0,0); - velocity = new PVector(0,0); - } - - public void run() { - update(); - borders(); - display(); - } - - - // Implementing Reynolds' flow field following algorithm - // http://www.red3d.com/cwr/steer/FlowFollow.html - void follow(FlowField flow) { - // What is the vector at that spot in the flow field? - PVector desired = flow.lookup(location); - // Scale it up by maxspeed - desired.mult(maxspeed); - // Steering is desired minus velocity - PVector steer = PVector.sub(desired, velocity); - steer.limit(maxforce); // Limit to maximum steering force - applyForce(steer); - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelertion to 0 each cycle - acceleration.mult(0); - } - - void display() { - // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); - fill(175); - stroke(0); - pushMatrix(); - translate(location.x,location.y); - rotate(theta); - beginShape(TRIANGLES); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(); - popMatrix(); - } - - // Wraparound - void borders() { - if (location.x < -r) location.x = width+r; - if (location.y < -r) location.y = height+r; - if (location.x > width+r) location.x = -r; - if (location.y > height+r) location.y = -r; - } -} - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/sketch.properties b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/sketch.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/NOC_6_05_PathFollowingSimple.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/NOC_6_05_PathFollowingSimple.pde deleted file mode 100644 index 0fe9f7b0e..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/NOC_6_05_PathFollowingSimple.pde +++ /dev/null @@ -1,52 +0,0 @@ -// Path Following -// Daniel Shiffman -// The Nature of Code - -// Path is a just a straight line in this example -// Via Reynolds: // http://www.red3d.com/cwr/steer/PathFollow.html - -// Using this variable to decide whether to draw all the stuff -boolean debug = true; - -// A path object (series of connected points) -Path path; - -// Two vehicles -Vehicle car1; -Vehicle car2; - -void setup() { - size(800, 200); - smooth(); - - path = new Path(); - - // Each vehicle has different maxspeed and maxforce for demo purposes - car1 = new Vehicle(new PVector(0, height/2), 3, 0.05); - car2 = new Vehicle(new PVector(0, height/2), 5, 0.1); -} - -void draw() { - background(255); - // Display the path - path.display(); - // The boids follow the path - car1.follow(path); - car2.follow(path); - // Call the generic run method (update, borders, display, etc.) - car1.run(); - car2.run(); - - // Instructions - fill(0); - text("Hit space bar to toggle debugging lines.", 10, height-30); -} - -public void keyPressed() { - if (key == ' ') { - debug = !debug; - } -} - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Path.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Path.pde deleted file mode 100644 index 611babb5b..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Path.pde +++ /dev/null @@ -1,46 +0,0 @@ -// Path Following -// Daniel Shiffman -// The Nature of Code, Spring 2009 - -// Path Following -// Daniel Shiffman -// The Nature of Code, Spring 2009 - -class Path { - - // A Path is line between two points (PVector objects) - PVector start; - PVector end; - // A path has a radius, i.e how far is it ok for the boid to wander off - float radius; - - Path() { - // Arbitrary radius of 20 - radius = 20; - start = new PVector(0,height/3); - end = new PVector(width,2*height/3); - } - - // Draw the path - void display() { - - strokeWeight(radius*2); - stroke(0,100); - line(start.x,start.y,end.x,end.y); - - strokeWeight(1); - stroke(0); - line(start.x,start.y,end.x,end.y); - } -} - - - - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Vehicle.pde deleted file mode 100644 index 109d7d658..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Vehicle.pde +++ /dev/null @@ -1,161 +0,0 @@ -// Path Following -// Daniel Shiffman -// The Nature of Code, Spring 2009 - -// Vehicle class - -class Vehicle { - - // All the usual stuff - PVector location; - PVector velocity; - PVector acceleration; - float r; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - // Constructor initialize all values - Vehicle( PVector l, float ms, float mf) { - location = l.get(); - r = 4.0; - maxspeed = ms; - maxforce = mf; - acceleration = new PVector(0, 0); - velocity = new PVector(maxspeed, 0); - } - - // Main "run" function - void run() { - update(); - borders(); - render(); - } - - - // This function implements Craig Reynolds' path following algorithm - // http://www.red3d.com/cwr/steer/PathFollow.html - void follow(Path p) { - - // Predict location 25 (arbitrary choice) frames ahead - PVector predict = velocity.get(); - predict.normalize(); - predict.mult(25); - PVector predictLoc = PVector.add(location, predict); - - // Look at the line segment - PVector a = p.start; - PVector b = p.end; - - // Get the normal point to that line - PVector normalPoint = getNormalPoint(predictLoc, a, b); - - // Find target point a little further ahead of normal - PVector dir = PVector.sub(b, a); - dir.normalize(); - dir.mult(10); // This could be based on velocity instead of just an arbitrary 10 pixels - PVector target = PVector.add(normalPoint, dir); - - // How far away are we from the path? - float distance = PVector.dist(predictLoc, normalPoint); - // Only if the distance is greater than the path's radius do we bother to steer - if (distance > p.radius) { - seek(target); - } - - - // Draw the debugging stuff - if (debug) { - fill(0); - stroke(0); - line(location.x, location.y, predictLoc.x, predictLoc.y); - ellipse(predictLoc.x, predictLoc.y, 4, 4); - - // Draw normal location - fill(0); - stroke(0); - line(predictLoc.x, predictLoc.y, normalPoint.x, normalPoint.y); - ellipse(normalPoint.x, normalPoint.y, 4, 4); - stroke(0); - if (distance > p.radius) fill(255, 0, 0); - noStroke(); - ellipse(target.x+dir.x, target.y+dir.y, 8, 8); - } - } - - - // A function to get the normal point from a point (p) to a line segment (a-b) - // This function could be optimized to make fewer new Vector objects - PVector getNormalPoint(PVector p, PVector a, PVector b) { - // Vector from a to p - PVector ap = PVector.sub(p, a); - // Vector from a to b - PVector ab = PVector.sub(b, a); - ab.normalize(); // Normalize the line - // Project vector "diff" onto line by using the dot product - ab.mult(ap.dot(ab)); - PVector normalPoint = PVector.add(a, ab); - return normalPoint; - } - - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelertion to 0 each cycle - acceleration.mult(0); - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - - // A method that calculates and applies a steering force towards a target - // STEER = DESIRED MINUS VELOCITY - void seek(PVector target) { - PVector desired = PVector.sub(target, location); // A vector pointing from the location to the target - - // If the magnitude of desired equals 0, skip out of here - // (We could optimize this to check if x and y are 0 to avoid mag() square root - if (desired.mag() == 0) return; - - // Normalize desired and scale to maximum speed - desired.normalize(); - desired.mult(maxspeed); - // Steering = Desired minus Velocity - PVector steer = PVector.sub(desired, velocity); - steer.limit(maxforce); // Limit to maximum steering force - - applyForce(steer); - } - - void render() { - // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); - fill(175); - stroke(0); - pushMatrix(); - translate(location.x, location.y); - rotate(theta); - beginShape(PConstants.TRIANGLES); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(); - popMatrix(); - } - - // Wraparound - void borders() { - if (location.x < -r) location.x = width+r; - //if (location.y < -r) location.y = height+r; - if (location.x > width+r) location.x = -r; - //if (location.y > height+r) location.y = -r; - } -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/sketch.properties b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/sketch.properties deleted file mode 100644 index 6d28cd598..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=JavaScript diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/NOC_6_06_PathFollowing.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/NOC_6_06_PathFollowing.pde deleted file mode 100644 index 09b097ddb..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/NOC_6_06_PathFollowing.pde +++ /dev/null @@ -1,65 +0,0 @@ -// Path Following -// Daniel Shiffman -// The Nature of Code - -// Via Reynolds: // http://www.red3d.com/cwr/steer/PathFollow.html - -// Using this variable to decide whether to draw all the stuff -boolean debug = true; - -// A path object (series of connected points) -Path path; - -// Two vehicles -Vehicle car1; -Vehicle car2; - -void setup() { - size(800, 200); - smooth(); - - // Call a function to generate new Path object - newPath(); - - // Each vehicle has different maxspeed and maxforce for demo purposes - car1 = new Vehicle(new PVector(0, height/2), 3, 0.1); - car2 = new Vehicle(new PVector(0, height/2), 5, 0.2); -} - -void draw() { - background(255); - // Display the path - path.display(); - // The boids follow the path - car1.follow(path); - car2.follow(path); - // Call the generic run method (update, borders, display, etc.) - car1.run(); - car2.run(); - - // Instructions - fill(0); - text("Hit space bar to toggle debugging lines.\nClick the mouse to generate a new path.", 10, height-30); -} - -void newPath() { - // A path is a series of connected points - // A more sophisticated path might be a curve - path = new Path(); - path.addPoint(0, height/2); - path.addPoint(random(0, width/2), random(0, height)); - path.addPoint(random(width/2, width), random(0, height)); - path.addPoint(width, height/2); -} - -public void keyPressed() { - if (key == ' ') { - debug = !debug; - } -} - -public void mousePressed() { - newPath(); -} - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Path.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Path.pde deleted file mode 100644 index d408cd460..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Path.pde +++ /dev/null @@ -1,48 +0,0 @@ -// Path Following -// Daniel Shiffman -// The Nature of Code - -class Path { - - // A Path is an arraylist of points (PVector objects) - ArrayList points; - // A path has a radius, i.e how far is it ok for the boid to wander off - float radius; - - Path() { - // Arbitrary radius of 20 - radius = 20; - points = new ArrayList(); - } - - // Add a point to the path - void addPoint(float x, float y) { - PVector point = new PVector(x, y); - points.add(point); - } - - // Draw the path - void display() { - // Draw thick line for radius - stroke(175); - strokeWeight(radius*2); - noFill(); - beginShape(); - for (PVector v : points) { - vertex(v.x, v.y); - } - endShape(); - // Draw thin line for center of path - stroke(0); - strokeWeight(1); - noFill(); - beginShape(); - for (PVector v : points) { - vertex(v.x, v.y); - } - endShape(); - } -} - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Vehicle.pde deleted file mode 100644 index 543e45c8e..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Vehicle.pde +++ /dev/null @@ -1,190 +0,0 @@ -// Path Following -// Daniel Shiffman -// The Nature of Code - -// Vehicle class - -class Vehicle { - - // All the usual stuff - PVector location; - PVector velocity; - PVector acceleration; - float r; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - // Constructor initialize all values - Vehicle( PVector l, float ms, float mf) { - location = l.get(); - r = 4.0; - maxspeed = ms; - maxforce = mf; - acceleration = new PVector(0, 0); - velocity = new PVector(maxspeed, 0); - } - - // Main "run" function - public void run() { - update(); - borders(); - render(); - } - - - // This function implements Craig Reynolds' path following algorithm - // http://www.red3d.com/cwr/steer/PathFollow.html - void follow(Path p) { - - // Predict location 25 (arbitrary choice) frames ahead - PVector predict = velocity.get(); - predict.normalize(); - predict.mult(25); - PVector predictLoc = PVector.add(location, predict); - - // Now we must find the normal to the path from the predicted location - // We look at the normal for each line segment and pick out the closest one - - PVector normal = null; - PVector target = null; - float worldRecord = 1000000; // Start with a very high record distance that can easily be beaten - - // Loop through all points of the path - for (int i = 0; i < p.points.size()-1; i++) { - - // Look at a line segment - PVector a = p.points.get(i); - PVector b = p.points.get(i+1); - - // Get the normal point to that line - PVector normalPoint = getNormalPoint(predictLoc, a, b); - // This only works because we know our path goes from left to right - // We could have a more sophisticated test to tell if the point is in the line segment or not - if (normalPoint.x < a.x || normalPoint.x > b.x) { - // This is something of a hacky solution, but if it's not within the line segment - // consider the normal to just be the end of the line segment (point b) - normalPoint = b.get(); - } - - // How far away are we from the path? - float distance = PVector.dist(predictLoc, normalPoint); - // Did we beat the record and find the closest line segment? - if (distance < worldRecord) { - worldRecord = distance; - // If so the target we want to steer towards is the normal - normal = normalPoint; - - // Look at the direction of the line segment so we can seek a little bit ahead of the normal - PVector dir = PVector.sub(b, a); - dir.normalize(); - // This is an oversimplification - // Should be based on distance to path & velocity - dir.mult(10); - target = normalPoint.get(); - target.add(dir); - } - } - - // Only if the distance is greater than the path's radius do we bother to steer - if (worldRecord > p.radius) { - seek(target); - } - - - // Draw the debugging stuff - if (debug) { - // Draw predicted future location - stroke(0); - fill(0); - line(location.x, location.y, predictLoc.x, predictLoc.y); - ellipse(predictLoc.x, predictLoc.y, 4, 4); - - // Draw normal location - stroke(0); - fill(0); - ellipse(normal.x, normal.y, 4, 4); - // Draw actual target (red if steering towards it) - line(predictLoc.x, predictLoc.y, normal.x, normal.y); - if (worldRecord > p.radius) fill(255, 0, 0); - noStroke(); - ellipse(target.x, target.y, 8, 8); - } - } - - - // A function to get the normal point from a point (p) to a line segment (a-b) - // This function could be optimized to make fewer new Vector objects - PVector getNormalPoint(PVector p, PVector a, PVector b) { - // Vector from a to p - PVector ap = PVector.sub(p, a); - // Vector from a to b - PVector ab = PVector.sub(b, a); - ab.normalize(); // Normalize the line - // Project vector "diff" onto line by using the dot product - ab.mult(ap.dot(ab)); - PVector normalPoint = PVector.add(a, ab); - return normalPoint; - } - - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelertion to 0 each cycle - acceleration.mult(0); - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - - // A method that calculates and applies a steering force towards a target - // STEER = DESIRED MINUS VELOCITY - void seek(PVector target) { - PVector desired = PVector.sub(target, location); // A vector pointing from the location to the target - - // If the magnitude of desired equals 0, skip out of here - // (We could optimize this to check if x and y are 0 to avoid mag() square root - if (desired.mag() == 0) return; - - // Normalize desired and scale to maximum speed - desired.normalize(); - desired.mult(maxspeed); - // Steering = Desired minus Velocity - PVector steer = PVector.sub(desired, velocity); - steer.limit(maxforce); // Limit to maximum steering force - - applyForce(steer); - } - - void render() { - // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); - fill(175); - stroke(0); - pushMatrix(); - translate(location.x, location.y); - rotate(theta); - beginShape(PConstants.TRIANGLES); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(); - popMatrix(); - } - - // Wraparound - void borders() { - if (location.x < -r) location.x = width+r; - //if (location.y < -r) location.y = height+r; - if (location.x > width+r) location.x = -r; - //if (location.y > height+r) location.y = -r; - } -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_07_Separation/NOC_6_07_Separation.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_07_Separation/NOC_6_07_Separation.pde deleted file mode 100644 index 92d96bb0e..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_07_Separation/NOC_6_07_Separation.pde +++ /dev/null @@ -1,45 +0,0 @@ -// Separation -// Daniel Shiffman -// The Nature of Code, 2011 - -// Via Reynolds: http://www.red3d.com/cwr/steer/ - -// A list of vehicles -ArrayList vehicles; - -void setup() { - size(800,200); - smooth(); - - // We are now making random vehicles and storing them in an ArrayList - vehicles = new ArrayList(); - for (int i = 0; i < 100; i++) { - vehicles.add(new Vehicle(random(width),random(height))); - } -} - -void draw() { - background(255); - - for (Vehicle v : vehicles) { - // Path following and separation are worked on in this function - v.separate(vehicles); - // Call the generic run method (update, borders, display, etc.) - v.update(); - v.borders(); - v.display(); - } - - // Instructions - fill(0); - text("Drag the mouse to generate new vehicles.",10,height-16); -} - - -void mouseDragged() { - vehicles.add(new Vehicle(mouseX,mouseY)); -} - - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_07_Separation/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_07_Separation/Vehicle.pde deleted file mode 100644 index e115f2394..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_07_Separation/Vehicle.pde +++ /dev/null @@ -1,99 +0,0 @@ -// Separation -// Daniel Shiffman -// The Nature of Code, 2011 - -// Vehicle class - -class Vehicle { - - // All the usual stuff - PVector location; - PVector velocity; - PVector acceleration; - float r; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - // Constructor initialize all values - Vehicle(float x, float y) { - location = new PVector(x, y); - r = 12; - maxspeed = 3; - maxforce = 0.2; - acceleration = new PVector(0, 0); - velocity = new PVector(0, 0); - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - // Separation - // Method checks for nearby vehicles and steers away - void separate (ArrayList vehicles) { - float desiredseparation = r*2; - PVector sum = new PVector(); - int count = 0; - // For every boid in the system, check if it's too close - for (Vehicle other : vehicles) { - float d = PVector.dist(location, other.location); - // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself) - if ((d > 0) && (d < desiredseparation)) { - // Calculate vector pointing away from neighbor - PVector diff = PVector.sub(location, other.location); - diff.normalize(); - diff.div(d); // Weight by distance - sum.add(diff); - count++; // Keep track of how many - } - } - // Average -- divide by how many - if (count > 0) { - sum.div(count); - // Our desired vector is the average scaled to maximum speed - sum.normalize(); - sum.mult(maxspeed); - // Implement Reynolds: Steering = Desired - Velocity - PVector steer = PVector.sub(sum, velocity); - steer.limit(maxforce); - applyForce(steer); - } - } - - - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelertion to 0 each cycle - acceleration.mult(0); - } - - void display() { - fill(175); - stroke(0); - pushMatrix(); - translate(location.x, location.y); - ellipse(0, 0, r, r); - popMatrix(); - } - - // Wraparound - void borders() { - if (location.x < -r) location.x = width+r; - if (location.y < -r) location.y = height+r; - if (location.x > width+r) location.x = -r; - if (location.y > height+r) location.y = -r; - } -} - - - - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/NOC_6_08_SeparationAndSeek.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/NOC_6_08_SeparationAndSeek.pde deleted file mode 100644 index c1614c97f..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/NOC_6_08_SeparationAndSeek.pde +++ /dev/null @@ -1,43 +0,0 @@ -// Separation -// Daniel Shiffman -// The Nature of Code, 2011 - -// Via Reynolds: http://www.red3d.com/cwr/steer/ - -// A list of vehicles -ArrayList vehicles; - -void setup() { - size(800,200); - smooth(); - - // We are now making random vehicles and storing them in an ArrayList - vehicles = new ArrayList(); - for (int i = 0; i < 100; i++) { - vehicles.add(new Vehicle(random(width),random(height))); - } -} - -void draw() { - background(255); - - for (Vehicle v : vehicles) { - // Path following and separation are worked on in this function - v.applyBehaviors(vehicles); - // Call the generic run method (update, borders, display, etc.) - v.update(); - v.display(); - } - - // Instructions - fill(0); - text("Drag the mouse to generate new vehicles.",10,height-16); -} - - -void mouseDragged() { - vehicles.add(new Vehicle(mouseX,mouseY)); -} - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/Vehicle.pde deleted file mode 100644 index a78653ffe..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/Vehicle.pde +++ /dev/null @@ -1,115 +0,0 @@ -// Separation -// Daniel Shiffman -// The Nature of Code, 2011 - -// Vehicle class - -class Vehicle { - - // All the usual stuff - PVector location; - PVector velocity; - PVector acceleration; - float r; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - // Constructor initialize all values - Vehicle(float x, float y) { - location = new PVector(x, y); - r = 12; - maxspeed = 3; - maxforce = 0.2; - acceleration = new PVector(0, 0); - velocity = new PVector(0, 0); - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - void applyBehaviors(ArrayList vehicles) { - PVector separateForce = separate(vehicles); - PVector seekForce = seek(new PVector(mouseX,mouseY)); - separateForce.mult(2); - seekForce.mult(1); - applyForce(separateForce); - applyForce(seekForce); - } - - // A method that calculates a steering force towards a target - // STEER = DESIRED MINUS VELOCITY - PVector seek(PVector target) { - PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target - - // Normalize desired and scale to maximum speed - desired.normalize(); - desired.mult(maxspeed); - // Steering = Desired minus velocity - PVector steer = PVector.sub(desired,velocity); - steer.limit(maxforce); // Limit to maximum steering force - - return steer; - } - - // Separation - // Method checks for nearby vehicles and steers away - PVector separate (ArrayList vehicles) { - float desiredseparation = r*2; - PVector sum = new PVector(); - int count = 0; - // For every boid in the system, check if it's too close - for (Vehicle other : vehicles) { - float d = PVector.dist(location, other.location); - // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself) - if ((d > 0) && (d < desiredseparation)) { - // Calculate vector pointing away from neighbor - PVector diff = PVector.sub(location, other.location); - diff.normalize(); - diff.div(d); // Weight by distance - sum.add(diff); - count++; // Keep track of how many - } - } - // Average -- divide by how many - if (count > 0) { - sum.div(count); - // Our desired vector is the average scaled to maximum speed - sum.normalize(); - sum.mult(maxspeed); - // Implement Reynolds: Steering = Desired - Velocity - sum.sub(velocity); - sum.limit(maxforce); - } - return sum; - } - - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelertion to 0 each cycle - acceleration.mult(0); - } - - void display() { - fill(175); - stroke(0); - pushMatrix(); - translate(location.x, location.y); - ellipse(0, 0, r, r); - popMatrix(); - } - -} - - - - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/sketch.properties b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/sketch.properties deleted file mode 100644 index 6d28cd598..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=JavaScript diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Boid.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Boid.pde deleted file mode 100644 index 282e12f29..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Boid.pde +++ /dev/null @@ -1,182 +0,0 @@ -// Flocking -// Daniel Shiffman -// The Nature of Code, Spring 2009 - -// Boid class -// Methods for Separation, Cohesion, Alignment added - -class Boid { - - PVector location; - PVector velocity; - PVector acceleration; - float r; - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - Boid(float x, float y) { - acceleration = new PVector(0,0); - velocity = new PVector(random(-1,1),random(-1,1)); - location = new PVector(x,y); - r = 3.0; - maxspeed = 3; - maxforce = 0.05; - } - - void run(ArrayList boids) { - flock(boids); - update(); - borders(); - render(); - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - // We accumulate a new acceleration each time based on three rules - void flock(ArrayList boids) { - PVector sep = separate(boids); // Separation - PVector ali = align(boids); // Alignment - PVector coh = cohesion(boids); // Cohesion - // Arbitrarily weight these forces - sep.mult(1.5); - ali.mult(1.0); - coh.mult(1.0); - // Add the force vectors to acceleration - applyForce(sep); - applyForce(ali); - applyForce(coh); - } - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelertion to 0 each cycle - acceleration.mult(0); - } - - // A method that calculates and applies a steering force towards a target - // STEER = DESIRED MINUS VELOCITY - PVector seek(PVector target) { - PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target - // Normalize desired and scale to maximum speed - desired.normalize(); - desired.mult(maxspeed); - // Steering = Desired minus Velocity - PVector steer = PVector.sub(desired,velocity); - steer.limit(maxforce); // Limit to maximum steering force - return steer; - } - - void render() { - // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); - fill(175); - stroke(0); - pushMatrix(); - translate(location.x,location.y); - rotate(theta); - beginShape(TRIANGLES); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(); - popMatrix(); - } - - // Wraparound - void borders() { - if (location.x < -r) location.x = width+r; - if (location.y < -r) location.y = height+r; - if (location.x > width+r) location.x = -r; - if (location.y > height+r) location.y = -r; - } - - // Separation - // Method checks for nearby boids and steers away - PVector separate (ArrayList boids) { - float desiredseparation = 25.0f; - PVector steer = new PVector(0,0,0); - int count = 0; - // For every boid in the system, check if it's too close - for (Boid other : boids) { - float d = PVector.dist(location,other.location); - // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself) - if ((d > 0) && (d < desiredseparation)) { - // Calculate vector pointing away from neighbor - PVector diff = PVector.sub(location,other.location); - diff.normalize(); - diff.div(d); // Weight by distance - steer.add(diff); - count++; // Keep track of how many - } - } - // Average -- divide by how many - if (count > 0) { - steer.div((float)count); - } - - // As long as the vector is greater than 0 - if (steer.mag() > 0) { - // Implement Reynolds: Steering = Desired - Velocity - steer.normalize(); - steer.mult(maxspeed); - steer.sub(velocity); - steer.limit(maxforce); - } - return steer; - } - - // Alignment - // For every nearby boid in the system, calculate the average velocity - PVector align (ArrayList boids) { - float neighbordist = 50; - PVector sum = new PVector(0,0); - int count = 0; - for (Boid other : boids) { - float d = PVector.dist(location,other.location); - if ((d > 0) && (d < neighbordist)) { - sum.add(other.velocity); - count++; - } - } - if (count > 0) { - sum.div((float)count); - sum.normalize(); - sum.mult(maxspeed); - PVector steer = PVector.sub(sum,velocity); - steer.limit(maxforce); - return steer; - } else { - return new PVector(0,0); - } - } - - // Cohesion - // For the average location (i.e. center) of all nearby boids, calculate steering vector towards that location - PVector cohesion (ArrayList boids) { - float neighbordist = 50; - PVector sum = new PVector(0,0); // Start with empty vector to accumulate all locations - int count = 0; - for (Boid other : boids) { - float d = PVector.dist(location,other.location); - if ((d > 0) && (d < neighbordist)) { - sum.add(other.location); // Add location - count++; - } - } - if (count > 0) { - sum.div(count); - return seek(sum); // Steer towards the location - } else { - return new PVector(0,0); - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Flock.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Flock.pde deleted file mode 100644 index eb7458e5a..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Flock.pde +++ /dev/null @@ -1,25 +0,0 @@ -// Flocking -// Daniel Shiffman -// The Nature of Code, Spring 2011 - -// Flock class -// Does very little, simply manages the ArrayList of all the boids - -class Flock { - ArrayList boids; // An ArrayList for all the boids - - Flock() { - boids = new ArrayList(); // Initialize the ArrayList - } - - void run() { - for (Boid b : boids) { - b.run(boids); // Passing the entire list of boids to each boid individually - } - } - - void addBoid(Boid b) { - boids.add(b); - } - -} diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/NOC_6_09_Flocking.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/NOC_6_09_Flocking.pde deleted file mode 100644 index c1c12b7f3..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/NOC_6_09_Flocking.pde +++ /dev/null @@ -1,38 +0,0 @@ -// Flocking -// Daniel Shiffman -// The Nature of Code, Spring 2009 - -// Demonstration of Craig Reynolds' "Flocking" behavior -// See: http://www.red3d.com/cwr/ -// Rules: Cohesion, Separation, Alignment - -// Click mouse to add boids into the system - -Flock flock; - -void setup() { - size(800,200); - flock = new Flock(); - // Add an initial set of boids into the system - for (int i = 0; i < 200; i++) { - Boid b = new Boid(width/2,height/2); - flock.addBoid(b); - } - smooth(); -} - -void draw() { - background(255); - flock.run(); - - // Instructions - fill(0); - //text("Drag the mouse to generate new boids.",10,height-16); -} - -// Add a new boid into the System -void mouseDragged() { - flock.addBoid(new Boid(mouseX,mouseY)); -} - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/StayWithinCircle.pde b/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/StayWithinCircle.pde deleted file mode 100644 index 0b42a37be..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/StayWithinCircle.pde +++ /dev/null @@ -1,43 +0,0 @@ -// Stay Within Walls -// Daniel Shiffman -// The Nature of Code - -// "Made-up" Steering behavior to stay within walls - - -Vehicle v; -boolean debug = true; - - -PVector circleLocation; -float circleRadius; - - - -void setup() { - size(640, 360); - v = new Vehicle(width/2, height/4); - - circleLocation = new PVector(width/2,height/2); - circleRadius = height/2-25; - - smooth(); -} - -void draw() { - background(255); - - if (debug) { - stroke(175); - noFill(); - ellipse(circleLocation.x,circleLocation.y, circleRadius*2,circleRadius*2); - } - - v.boundaries(); - v.run(); -} - -void mousePressed() { - debug = !debug; -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/Vehicle.pde deleted file mode 100644 index fcd3e7a56..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/Vehicle.pde +++ /dev/null @@ -1,95 +0,0 @@ -// Wander -// Daniel Shiffman -// The Nature of Code - -// The "Vehicle" class (for wandering) - -class Vehicle { - - PVector location; - PVector velocity; - PVector acceleration; - float r; - - float maxspeed; - float maxforce; - - Vehicle(float x, float y) { - acceleration = new PVector(0, 0); - velocity = new PVector(1,0); - velocity.mult(5); - location = new PVector(x, y); - r = 3; - maxspeed = 3; - maxforce = 0.15; - } - - void run() { - update(); - display(); - } - - // Method to update location - void update() { - // Update velocity - velocity.add(acceleration); - // Limit speed - velocity.limit(maxspeed); - location.add(velocity); - // Reset accelertion to 0 each cycle - acceleration.mult(0); - } - - void boundaries() { - - PVector desired = null; - - // Predict location 25 (arbitrary choice) frames ahead - PVector predict = velocity.get(); - predict.mult(25); - PVector futureLocation = PVector.add(location, predict); - float distance = PVector.dist(futureLocation,circleLocation); - - if (distance > circleRadius) { - PVector toCenter = PVector.sub(circleLocation,location); - toCenter.normalize(); - toCenter.mult(velocity.mag()); - desired = PVector.add(velocity,toCenter); - desired.normalize(); - desired.mult(maxspeed); - } - - if (desired != null) { - PVector steer = PVector.sub(desired, velocity); - steer.limit(maxforce); - applyForce(steer); - } - - fill(255,0,0); - ellipse(futureLocation.x,futureLocation.y,4,4); - - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acceleration.add(force); - } - - - void display() { - // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); - fill(175); - stroke(0); - pushMatrix(); - translate(location.x, location.y); - rotate(theta); - beginShape(TRIANGLES); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(); - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection/Thing.pde b/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection/Thing.pde deleted file mode 100644 index 5618479db..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection/Thing.pde +++ /dev/null @@ -1,32 +0,0 @@ -// Daniel Shiffman -// -// April 6, 2006 - -// Simple class describing an ellipse living on our screen - -class Thing { - - float x,y; - boolean highlight; - float r; - - Thing (float x_, float y_) { - x = x_; - y = y_; - highlight = false; - r = random(8) + 1; - } - - void move() { - x += random(-1,1); - y += random(-1,1); - } - - void render() { - noStroke(); - if (highlight) fill(255); - else fill(100); - ellipse(x,y,r,r); - } - -} diff --git a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection/intersection.pde b/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection/intersection.pde deleted file mode 100644 index 542c90d3b..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection/intersection.pde +++ /dev/null @@ -1,106 +0,0 @@ -// Daniel Shiffman -// - -// Bin-Lattice Spatial Subdivision -// http://www.red3d.com/cwr/papers/2000/pip.pdf - -// Example demonstrating optimized intersection test for large # of objects -// Each object registers its location in a virtual grid -// Only the objects in neighboring cells on the grid are tested against each other - -int totalThings = 2000; - -ArrayList a; // ArrayList for all "things" -ArrayList[][] grid; // Grid of ArrayLists for intersection test -int scl = 4; // Size of each grid cell -int cols, rows; // Total coluns and rows - -void setup() { - size(640,360); - smooth(); - - a = new ArrayList(); // Create the list - cols = width/scl; // Calculate cols & rows - rows = height/scl; - - // Initialize grid as 2D array of empty ArrayLists - grid = new ArrayList[cols][rows]; - for (int i = 0; i < cols; i++) { - for (int j = 0; j < rows; j++) { - grid[i][j] = new ArrayList(); - } - } - - // Put 2000 Things in the system - for (int i = 0; i < totalThings; i++) { - a.add(new Thing(random(width),random(height))); - } - -} - -void draw() { - background(0); - - // Every time through draw clear all the lists - for (int i = 0; i < cols; i++) { - for (int j = 0; j < rows; j++) { - grid[i][j].clear(); - } - } - - // Register every Thing object in the grid according to it's location - for (Thing t : a) { - t.highlight = false; - int x = int(t.x) / scl; - int y = int (t.y) /scl; - // It goes in 9 cells, i.e. every Thing is tested against other Things in its cell - // as well as its 8 neighbors - for (int n = -1; n <= 1; n++) { - for (int m = -1; m <= 1; m++) { - if (x+n >= 0 && x+n < cols && y+m >= 0 && y+m< rows) grid[x+n][y+m].add(t); - } - } - } - - // Run through the Grid - stroke(255); - for (int i = 0; i < cols; i++) { - //line(i*scl,0,i*scl,height); - for (int j = 0; j < rows; j++) { - //line(0,j*scl,width,j*scl); - - // For every list in the grid - ArrayList temp = grid[i][j]; - // Check every Thing - for (Thing t : temp) { - // Against every other Thing - for (Thing other : temp) { - // As long as its not the same one - if (other != t) { - // Check to see if they are touching - // (We could do many other things here besides just intersection tests, such - // as apply forces, etc.) - float d = dist(t.x,t.y,other.x,other.y); - if (d < t.r/2 + other.r/2) { - t.highlight = true; - } - } - } - } - } - } - - // Display and move all Things - for (Thing t : a) { - t.render(); - t.move(); - } - - fill(0); - rect(0,height-20,width,20); - fill(255); - text("Framerate: " + int(frameRate),10,height-6); - - - -} diff --git a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection_slow/Thing.pde b/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection_slow/Thing.pde deleted file mode 100644 index 5618479db..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection_slow/Thing.pde +++ /dev/null @@ -1,32 +0,0 @@ -// Daniel Shiffman -// -// April 6, 2006 - -// Simple class describing an ellipse living on our screen - -class Thing { - - float x,y; - boolean highlight; - float r; - - Thing (float x_, float y_) { - x = x_; - y = y_; - highlight = false; - r = random(8) + 1; - } - - void move() { - x += random(-1,1); - y += random(-1,1); - } - - void render() { - noStroke(); - if (highlight) fill(255); - else fill(100); - ellipse(x,y,r,r); - } - -} diff --git a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection_slow/intersection_slow.pde b/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection_slow/intersection_slow.pde deleted file mode 100644 index 5c3beae4e..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection_slow/intersection_slow.pde +++ /dev/null @@ -1,59 +0,0 @@ -// Daniel Shiffman -// - -// The old way to do intersection tests, look how slow!! - - -int totalThings = 2000; - -ArrayList a; // ArrayList for all "things" - -void setup() { - size(640,360); - a = new ArrayList(); // Create the list - - // Put 2000 Things in the system - for (int i = 0; i < totalThings; i++) { - a.add(new Thing(random(width),random(height))); - } - -} - -void draw() { - background(0); - fill(255); - noStroke(); - smooth(); - - // Run through the Grid - stroke(255); - for (Thing t : a) { - t.highlight = false; - for (Thing other : a) { - // As long as its not the same one - if (t != other) { - // Check to see if they are touching - // (We could do many other things here besides just intersection tests, such - // as apply forces, etc.) - float d = dist(t.x,t.y,other.x,other.y); - if (d < t.r/2 + other.r/2) { - t.highlight = true; - } - } - } - } - - // Display and move all Things - for (Thing t : a) { - t.render(); - t.move(); - } - - fill(0); - rect(0,height-20,width,20); - fill(255); - text("Framerate: " + int(frameRate),10,height-6); - - - -} diff --git a/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Boid.pde b/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Boid.pde deleted file mode 100644 index c46398ee9..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Boid.pde +++ /dev/null @@ -1,255 +0,0 @@ -// Flocking -// Daniel Shiffman -// The Nature of Code - -// Boid class -// Methods for Separation, Cohesion, Alignment added - -class Boid { - - // We need to keep track of a Body and a width and height - Body body; - float w; - float h; - - float maxforce; // Maximum steering force - float maxspeed; // Maximum speed - - Boid(PVector loc) { - w = 12; - h = 12; - // Add the box to the box2d world - makeBody(new Vec2(loc.x,loc.y),w,h,new Vec2(0,0),0); - maxspeed = 20; - maxforce = 10; - } - - // This function removes the particle from the box2d world - void killBody() { - box2d.destroyBody(body); - } - - void run(ArrayList boids) { - flock(boids); - borders(); - display(); - } - - // We accumulate a new acceleration each time based on three rules - void flock(ArrayList boids) { - Vec2 sep = separate(boids); // Separation - Vec2 ali = align(boids); // Alignment - Vec2 coh = cohesion(boids); // Cohesion - // Arbitrarily weight these forces - sep.mulLocal(1.5); - ali.mulLocal(1); - coh.mulLocal(1); - // Add the force vectors to acceleration - Vec2 loc = body.getWorldCenter(); - body.applyForce(sep,loc); - body.applyForce(ali,loc); - body.applyForce(coh,loc); - } - - // A method that calculates and applies a steering force towards a target - // STEER = DESIRED MINUS VELOCITY - Vec2 seek(Vec2 target) { - Vec2 loc = body.getWorldCenter(); - Vec2 desired = target.sub(loc); // A vector pointing from the location to the target - - // If the magnitude of desired equals 0, skip out of here - // (We could optimize this to check if x and y are 0 to avoid mag() square root - if (desired.length() == 0) return new Vec2(0,0); - - // Normalize desired and scale to maximum speed - desired.normalize(); - desired.mulLocal(maxspeed); - // Steering = Desired minus Velocity - - Vec2 vel = body.getLinearVelocity(); - Vec2 steer = desired.sub(vel); - - float len = steer.length(); - if (len > maxforce) { - steer.normalize(); - steer.mulLocal(maxforce); - } - return steer; - } - - - - // Drawing the box - void display() { - // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); - - // Get its angle of rotation - float a = body.getAngle(); - - rectMode(CENTER); - pushMatrix(); - translate(pos.x,pos.y); - rotate(-a); - fill(175); - strokeWeight(2); - stroke(0); - rect(0,0,w,h); - popMatrix(); - } - - // Wraparound - void borders() { - Vec2 loc = box2d.getBodyPixelCoord(body); - Vec2 vel = body.getLinearVelocity(); - float a = body.getAngularVelocity(); - if (loc.x < -w) { - killBody(); - makeBody(new Vec2(width+w,loc.y),w,h,vel,a); - } else if (loc.y < -w) { - killBody(); - makeBody(new Vec2(loc.x,height+w),w,h,vel,a); - } else if (loc.x > width+w) { - killBody(); - makeBody(new Vec2(-w,loc.y),w,h,vel,a); - } else if (loc.y > height+w) { - killBody(); - makeBody(new Vec2(loc.x,-w),w,h,vel,a); - } - } - - // Separation - // Method checks for nearby boids and steers away - Vec2 separate (ArrayList boids) { - float desiredseparation = box2d.scalarPixelsToWorld(30); - - Vec2 steer = new Vec2(0,0); - int count = 0; - // For every boid in the system, check if it's too close - Vec2 locA = body.getWorldCenter(); - for (Boid other : boids) { - Vec2 locB = other.body.getWorldCenter(); - float d = dist(locA.x,locA.y,locB.x,locB.y); - // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself) - if ((d > 0) && (d < desiredseparation)) { - // Calculate vector pointing away from neighbor - Vec2 diff = locA.sub(locB); - diff.normalize(); - diff.mulLocal(1.0/d); // Weight by distance - steer.addLocal(diff); - count++; // Keep track of how many - } - } - // Average -- divide by how many - if (count > 0) { - steer.mulLocal(1.0/count); - } - - // As long as the vector is greater than 0 - if (steer.length() > 0) { - // Implement Reynolds: Steering = Desired - Velocity - steer.normalize(); - steer.mulLocal(maxspeed); - Vec2 vel = body.getLinearVelocity(); - steer.subLocal(vel); - float len = steer.length(); - if (len > maxforce) { - steer.normalize(); - steer.mulLocal(maxforce); - } - } - return steer; - } - - // Alignment - // For every nearby boid in the system, calculate the average velocity - Vec2 align (ArrayList boids) { - float neighbordist = box2d.scalarPixelsToWorld(50); - Vec2 steer = new Vec2(0,0); - int count = 0; - Vec2 locA = body.getWorldCenter(); - for (Boid other : boids) { - Vec2 locB = other.body.getWorldCenter(); - float d = dist(locA.x,locA.y,locB.x,locB.y); - if ((d > 0) && (d < neighbordist)) { - Vec2 vel = other.body.getLinearVelocity(); - steer.addLocal(vel); - count++; - } - } - if (count > 0) { - steer.mulLocal(1.0/count); - } - - // As long as the vector is greater than 0 - if (steer.length() > 0) { - // Implement Reynolds: Steering = Desired - Velocity - steer.normalize(); - steer.mulLocal(maxspeed); - Vec2 vel = body.getLinearVelocity(); - steer.subLocal(vel); - float len = steer.length(); - if (len > maxforce) { - steer.normalize(); - steer.mulLocal(maxforce); - } - } - return steer; - } - - // Cohesion - // For the average location (i.e. center) of all nearby boids, calculate steering vector towards that location - Vec2 cohesion (ArrayList boids) { - float neighbordist = box2d.scalarPixelsToWorld(50); - Vec2 sum = new Vec2(0,0); // Start with empty vector to accumulate all locations - int count = 0; - Vec2 locA = body.getWorldCenter(); - for (Boid other : boids) { - Vec2 locB = other.body.getWorldCenter(); - - float d = dist(locA.x,locA.y,locB.x,locB.y); - if ((d > 0) && (d < neighbordist)) { - sum.addLocal(locB); // Add location - count++; - } - } - if (count > 0) { - sum.mulLocal(1.0/count); - return seek(sum); // Steer towards the location - } - return sum; - } - - // This function adds the rectangle to the box2d world - void makeBody(Vec2 center, float w_, float h_, Vec2 vel, float avel) { - - // Define a polygon (this is what we use for a rectangle) - PolygonShape sd = new PolygonShape(); - float box2dW = box2d.scalarPixelsToWorld(w_/2); - float box2dH = box2d.scalarPixelsToWorld(h_/2); - sd.setAsBox(box2dW, box2dH); - - // Define a fixture - FixtureDef fd = new FixtureDef(); - fd.shape = sd; - // Parameters that affect physics - fd.density = 1; - fd.friction = 0.3; - fd.restitution = 0.5; - - // Define the body and make it from the shape - BodyDef bd = new BodyDef(); - bd.type = BodyType.DYNAMIC; - bd.position.set(box2d.coordPixelsToWorld(center)); - - body = box2d.createBody(bd); - body.createFixture(fd); - - body.setLinearVelocity(vel); - body.setAngularVelocity(avel); - - } - - -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Flock.pde b/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Flock.pde deleted file mode 100644 index b497c279c..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Flock.pde +++ /dev/null @@ -1,25 +0,0 @@ -// Flocking -// Daniel Shiffman -// The Nature of Code - -// Flock class -// Does very little, simply manages the ArrayList of all the boids - -class Flock { - ArrayList boids; // An arraylist for all the boids - - Flock() { - boids = new ArrayList(); // Initialize the arraylist - } - - void run() { - for (Boid b : boids) { - b.run(boids); // Passing the entire list of boids to each boid individually - } - } - - void addBoid(Boid b) { - boids.add(b); - } - -} diff --git a/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Flocking_box2d.pde b/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Flocking_box2d.pde deleted file mode 100644 index 3a5934e66..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Flocking_box2d.pde +++ /dev/null @@ -1,56 +0,0 @@ -// Flocking -// Daniel Shiffman -// The Nature of Code - -// Demonstration of Craig Reynolds' "Flocking" behavior -// See: http://www.red3d.com/cwr/ -// Rules: Cohesion, Separation, Alignment - -// Click mouse to add boids into the system - -import pbox2d.*; -import org.jbox2d.collision.shapes.*; -import org.jbox2d.common.*; -import org.jbox2d.dynamics.*; - -// A reference to our box2d world -PBox2D box2d; - -Flock flock; - -void setup() { - size(640,360); - // Initialize box2d physics and create the world - box2d = new PBox2D(this); - box2d.createWorld(); - // We are setting a custom gravity - box2d.setGravity(0,0); - - flock = new Flock(); - // Add an initial set of boids into the system - for (int i = 0; i < 50; i++) { - flock.addBoid(new Boid(new PVector(random(width),random(height)))); - } - smooth(); -} - -void draw() { - - - // We must always step through time! - box2d.step(); - - background(255); - flock.run(); - -} - -void mousePressed() { - flock.addBoid(new Boid(new PVector(mouseX,mouseY))); -} - -void mouseDragged() { - flock.addBoid(new Boid(new PVector(mouseX,mouseY))); -} - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Boid.pde b/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Boid.pde deleted file mode 100644 index ee361fe01..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Boid.pde +++ /dev/null @@ -1,181 +0,0 @@ -float swt = 25.0; //sep.mult(25.0f); -float awt = 4.0; //ali.mult(4.0f); -float cwt = 5.0; //coh.mult(5.0f); -float maxspeed = 1; -float maxforce = 0.025; - - -// Flocking -// Daniel Shiffman -// The Nature of Code, Spring 2009 - -// Boid class -// Methods for Separation, Cohesion, Alignment added - -class Boid { - - PVector loc; - PVector vel; - PVector acc; - float r; - - Boid(float x, float y) { - acc = new PVector(0,0); - vel = new PVector(random(-1,1),random(-1,1)); - loc = new PVector(x,y); - r = 2.0; - } - - void run(ArrayList boids) { - flock(boids); - update(); - borders(); - render(); - } - - void applyForce(PVector force) { - // We could add mass here if we want A = F / M - acc.add(force); - } - - // We accumulate a new acceleration each time based on three rules - void flock(ArrayList boids) { - PVector sep = separate(boids); // Separation - PVector ali = align(boids); // Alignment - PVector coh = cohesion(boids); // Cohesion - // Arbitrarily weight these forces - sep.mult(swt); - ali.mult(awt); - coh.mult(cwt); - // Add the force vectors to acceleration - applyForce(sep); - applyForce(ali); - applyForce(coh); - } - - // Method to update location - void update() { - // Update velocity - vel.add(acc); - // Limit speed - vel.limit(maxspeed); - loc.add(vel); - // Reset accelertion to 0 each cycle - acc.mult(0); - } - - // A method that calculates and applies a steering force towards a target - // STEER = DESIRED MINUS VELOCITY - PVector seek(PVector target) { - PVector desired = PVector.sub(target,loc); // A vector pointing from the location to the target - - // Normalize desired and scale to maximum speed - desired.normalize(); - desired.mult(maxspeed); - // Steering = Desired minus Velocity - PVector steer = PVector.sub(desired,vel); - steer.limit(maxforce); // Limit to maximum steering force - - return steer; - } - - void render() { - // Draw a triangle rotated in the direction of velocity - float theta = vel.heading2D() + radians(90); - fill(175); - stroke(0); - pushMatrix(); - translate(loc.x,loc.y); - rotate(theta); - beginShape(TRIANGLES); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(); - popMatrix(); - } - - // Wraparound - void borders() { - if (loc.x < -r) loc.x = width+r; - if (loc.y < -r) loc.y = height+r; - if (loc.x > width+r) loc.x = -r; - if (loc.y > height+r) loc.y = -r; - } - - // Separation - // Method checks for nearby boids and steers away - PVector separate (ArrayList boids) { - float desiredseparation = 25.0; - PVector steer = new PVector(0,0); - int count = 0; - // For every boid in the system, check if it's too close - for (Boid other : boids) { - float d = PVector.dist(loc,other.loc); - // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself) - if ((d > 0) && (d < desiredseparation)) { - // Calculate vector pointing away from neighbor - PVector diff = PVector.sub(loc,other.loc); - diff.normalize(); - diff.div(d); // Weight by distance - steer.add(diff); - count++; // Keep track of how many - } - } - // Average -- divide by how many - if (count > 0) { - steer.div((float)count); - // Implement Reynolds: Steering = Desired - Velocity - steer.normalize(); - steer.mult(maxspeed); - steer.sub(vel); - steer.limit(maxforce); - } - return steer; - } - - // Alignment - // For every nearby boid in the system, calculate the average velocity - PVector align (ArrayList boids) { - float neighbordist = 50.0; - PVector steer = new PVector(); - int count = 0; - for (Boid other : boids) { - float d = PVector.dist(loc,other.loc); - if ((d > 0) && (d < neighbordist)) { - steer.add(other.vel); - count++; - } - } - if (count > 0) { - steer.div((float)count); - // Implement Reynolds: Steering = Desired - Velocity - steer.normalize(); - steer.mult(maxspeed); - steer.sub(vel); - steer.limit(maxforce); - } - return steer; - } - - // Cohesion - // For the average location (i.e. center) of all nearby boids, calculate steering vector towards that location - PVector cohesion (ArrayList boids) { - float neighbordist = 50.0; - PVector sum = new PVector(0,0); // Start with empty vector to accumulate all locations - int count = 0; - for (Boid other : boids) { - float d = PVector.dist(loc,other.loc); - if ((d > 0) && (d < neighbordist)) { - sum.add(other.loc); // Add location - count++; - } - } - if (count > 0) { - sum.div((float)count); - return seek(sum); // Steer towards the location - } - return sum; - } -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Flock.pde b/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Flock.pde deleted file mode 100644 index eb7458e5a..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Flock.pde +++ /dev/null @@ -1,25 +0,0 @@ -// Flocking -// Daniel Shiffman -// The Nature of Code, Spring 2011 - -// Flock class -// Does very little, simply manages the ArrayList of all the boids - -class Flock { - ArrayList boids; // An ArrayList for all the boids - - Flock() { - boids = new ArrayList(); // Initialize the ArrayList - } - - void run() { - for (Boid b : boids) { - b.run(boids); // Passing the entire list of boids to each boid individually - } - } - - void addBoid(Boid b) { - boids.add(b); - } - -} diff --git a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/flocking_sliders.pde b/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/flocking_sliders.pde deleted file mode 100644 index 16314225a..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/flocking_sliders.pde +++ /dev/null @@ -1,60 +0,0 @@ - -// Flocking -// Daniel Shiffman - -// Demonstration of Craig Reynolds' "Flocking" behavior -// See: http://www.red3d.com/cwr/ -// Rules: Cohesion, Separation, Alignment - -// Click mouse to add boids into the system - -import processing.opengl.*; - - -Flock flock; -PVector center; - -boolean showvalues = true; -boolean scrollbar = false; - - -void setup() { - size(1024,768,OPENGL); - setupScrollbars(); - center = new PVector(width/2,height/2); - colorMode(RGB,255,255,255,100); - flock = new Flock(); - // Add an initial set of boids into the system - for (int i = 0; i < 120; i++) { - flock.addBoid(new Boid(width/2,height/2)); - } - smooth(); -} - - -void draw() { - - background(255); - smooth(); - flock.run(); - drawScrollbars(); - - if (mousePressed && !scrollbar) { - flock.addBoid(new Boid(mouseX,mouseY)); - } - - - if (showvalues) { - fill(0); - textAlign(LEFT); - text("Total boids: " + flock.boids.size() + "\n" + "Framerate: " + round(frameRate) + "\nPress any key to show/hide sliders and text\nClick mouse to add more boids",5,100); - } -} - -void keyPressed() { - showvalues = !showvalues; -} - -void mousePressed() { -} - diff --git a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/keyPressed.pde b/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/keyPressed.pde deleted file mode 100644 index b28b04f64..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/keyPressed.pde +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/scrollbar.pde b/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/scrollbar.pde deleted file mode 100644 index ded631f29..000000000 --- a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/scrollbar.pde +++ /dev/null @@ -1,133 +0,0 @@ -// Code based on "Scrollbar" by Casey Reas - -HScrollbar[] hs = new HScrollbar[5];// -String[] labels = {"separation", "alignment","cohesion","maxspeed","maxforce"}; - -int x = 5; -int y = 20; -int w = 50; -int h = 8; -int l = 2; -int spacing = 4; - -void setupScrollbars() { - for (int i = 0; i < hs.length; i++) { - hs[i] = new HScrollbar(x, y + i*(h+spacing), w, h, l); - } - - hs[0].setPos(0.5); - hs[1].setPos(0.5); - hs[2].setPos(0.5); - hs[3].setPos(0.5); - hs[4].setPos(0.05); - -} - -void drawScrollbars() { - //if (showvalues) { - swt = hs[0].getPos()*10.0f; //sep.mult(25.0f); - awt = hs[1].getPos()*2.0f; //sep.mult(25.0f); - cwt = hs[2].getPos()*2.0f; //sep.mult(25.0f); - maxspeed = hs[3].getPos()*10.0f; - maxforce = hs[4].getPos()*0.5; - - - if (showvalues) { - for (int i = 0; i < hs.length; i++) { - hs[i].update(); - hs[i].draw(); - fill(0); - textAlign(LEFT); - text(labels[i],x+w+spacing,y+i*(h+spacing)+spacing); - //text(hs[i].getPos(),x+w+spacing+75,y+i*(h+spacing)+spacing); - } - } -} - - -class HScrollbar -{ - int swidth, sheight; // width and height of bar - int xpos, ypos; // x and y position of bar - float spos, newspos; // x position of slider - int sposMin, sposMax; // max and min values of slider - int loose; // how loose/heavy - boolean over; // is the mouse over the slider? - boolean locked; - float ratio; - - HScrollbar (int xp, int yp, int sw, int sh, int l) { - swidth = sw; - sheight = sh; - int widthtoheight = sw - sh; - ratio = (float)sw / (float)widthtoheight; - xpos = xp; - ypos = yp-sheight/2; - spos = xpos; - newspos = spos; - sposMin = xpos; - sposMax = xpos + swidth - sheight; - loose = l; - } - - void update() { - if(over()) { - over = true; - } - else { - over = false; - } - if(mousePressed && over) { - scrollbar = true; - locked = true; - } - if(!mousePressed) { - locked = false; - scrollbar = false; - } - if(locked) { - newspos = constrain(mouseX-sheight/2, sposMin, sposMax); - } - if(abs(newspos - spos) > 0) { - spos = spos + (newspos-spos)/loose; - } - } - - int constrain(int val, int minv, int maxv) { - return min(max(val, minv), maxv); - } - - boolean over() { - if(mouseX > xpos && mouseX < xpos+swidth && - mouseY > ypos && mouseY < ypos+sheight) { - return true; - } - else { - return false; - } - } - - void draw() { - fill(255); - rectMode(CORNER); - rect(xpos, ypos, swidth, sheight); - if(over || locked) { - fill(153, 102, 0); - } - else { - fill(102, 102, 102); - } - rect(spos, ypos, sheight, sheight); - } - - void setPos(float s) { - spos = xpos + s*(sposMax-sposMin); - newspos = spos; - } - - float getPos() { - // convert spos to be values between - // 0 and the total width of the scrollbar - return ((spos-xpos))/(sposMax-sposMin);// * ratio; - } -} diff --git a/java/examples/Books/Nature of Code/chp7_CA/Ex7_09_HexagonCells/Cell.pde b/java/examples/Books/Nature of Code/chp7_CA/Ex7_09_HexagonCells/Cell.pde deleted file mode 100644 index 3f4a43fb5..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Ex7_09_HexagonCells/Cell.pde +++ /dev/null @@ -1,38 +0,0 @@ -class Cell { - - float x, y; - float w; - float xoff; - float yoff; - - int state; - - Cell(float x_, float y_, float w_) { - x = x_; - y = y_; - w = w_; - xoff = w/2; - yoff = sin(radians(60))*w; - state = int(random(2)); - } - - - void display() { - - fill(state*255); - stroke(0); - pushMatrix(); - translate(x,y); - beginShape(); - vertex(0, yoff); - vertex(xoff, 0); - vertex(xoff+w, 0); - vertex(2*w, yoff); - vertex(xoff+w, 2*yoff); - vertex(xoff, 2*yoff); - vertex(0, yoff); - endShape(); - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/Ex7_09_HexagonCells/Ex7_09_HexagonCells.pde b/java/examples/Books/Nature of Code/chp7_CA/Ex7_09_HexagonCells/Ex7_09_HexagonCells.pde deleted file mode 100644 index 072897b33..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Ex7_09_HexagonCells/Ex7_09_HexagonCells.pde +++ /dev/null @@ -1,24 +0,0 @@ -// Daniel Shiffman, Nature of Code -// - -// Outline for game of life -// This is just a grid of hexagons right now - -GOL gol; - -void setup() { - size(800, 200); - smooth(); - gol = new GOL(); -} - -void draw() { - background(255); - gol.display(); -} - -// reset board when mouse is pressed -void mousePressed() { - gol.init(); -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/Ex7_09_HexagonCells/GOL.pde b/java/examples/Books/Nature of Code/chp7_CA/Ex7_09_HexagonCells/GOL.pde deleted file mode 100644 index c72710b1d..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Ex7_09_HexagonCells/GOL.pde +++ /dev/null @@ -1,40 +0,0 @@ -class GOL { - - float w = 20; - float h = sin(radians(60))*w; - int columns, rows; - - // Game of life board - Cell[][] board; - - - GOL() { - // Initialize rows, columns and set-up arrays - columns = width/int(w*3); - rows = height/int(h); - board = new Cell[columns][rows]; - init(); - } - - void init() { - float h = sin(radians(60))*w; - for (int i = 0; i < columns; i++) { - for (int j = 0; j < rows; j++) { - if (j % 2 == 0) board[i][j] = new Cell(i*w*3, j*h,w); - else board[i][j] = new Cell(i*w*3+w+h/2, j*h, w); - } - } - } - - - - // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0' - void display() { - for ( int i = 0; i < columns;i++) { - for ( int j = 0; j < rows;j++) { - board[i][j].display(); - } - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_01_WolframCA_randomizedrules/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_01_WolframCA_randomizedrules/CA.pde deleted file mode 100644 index c172ad832..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_01_WolframCA_randomizedrules/CA.pde +++ /dev/null @@ -1,95 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// A class to manage the CA - -class CA { - - int[] cells; // An array of 0s and 1s - int generation; // How many generations? - - int[] ruleset; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1} - - int w = 5; - - CA(int[] r) { - ruleset = r; - cells = new int[width/w]; - restart(); - } - - // Make a random ruleset - void randomize() { - for (int i = 0; i < 8; i++) { - ruleset[i] = int(random(2)); - } - } - - // Reset to generation 0 - void restart() { - for (int i = 0; i < cells.length; i++) { - cells[i] = 0; - } - cells[cells.length/2] = 1; // We arbitrarily start with just the middle cell having a state of "1" - generation = 0; - } - - - // The process of creating the new generation - void generate() { - // First we create an empty array for the new values - int[] nextgen = new int[cells.length]; - // For every spot, determine new state by examing current state, and neighbor states - // Ignore edges that only have one neighor - for (int i = 1; i < cells.length-1; i++) { - int left = cells[i-1]; // Left neighbor state - int me = cells[i]; // Current state - int right = cells[i+1]; // Right neighbor state - nextgen[i] = rules(left, me, right); // Compute next generation state based on ruleset - } - // The current generation is the new generation - cells = nextgen; - generation++; - } - - // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0' - void display() { - for (int i = 0; i < cells.length; i++) { - if (cells[i] == 1) fill(0); - else fill(255); - noStroke(); - rect(i*w, generation*w, w, w); - } - } - - // Implementing the Wolfram rules - // This is the concise conversion to binary way - /*int rules (int a, int b, int c) { - String s = "" + a + b + c; - int index = Integer.parseInt(s, 2); - return ruleset[index]; - }*/ - // For JavaScript Mode - int rules (int a, int b, int c) { - if (a == 1 && b == 1 && c == 1) return ruleset[0]; - if (a == 1 && b == 1 && c == 0) return ruleset[1]; - if (a == 1 && b == 0 && c == 1) return ruleset[2]; - if (a == 1 && b == 0 && c == 0) return ruleset[3]; - if (a == 0 && b == 1 && c == 1) return ruleset[4]; - if (a == 0 && b == 1 && c == 0) return ruleset[5]; - if (a == 0 && b == 0 && c == 1) return ruleset[6]; - if (a == 0 && b == 0 && c == 0) return ruleset[7]; - return 0; - } - - // The CA is done if it reaches the bottom of the screen - boolean finished() { - if (generation > height/w) { - return true; - } - else { - return false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_01_WolframCA_randomizedrules/Exercise_7_01_WolframCA_randomizedrules.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_01_WolframCA_randomizedrules/Exercise_7_01_WolframCA_randomizedrules.pde deleted file mode 100644 index 95ebb0808..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_01_WolframCA_randomizedrules/Exercise_7_01_WolframCA_randomizedrules.pde +++ /dev/null @@ -1,42 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// Simple demonstration of a Wolfram 1-dimensional cellular automata -// When the system reaches bottom of the window, it restarts with a new ruleset -// Mouse click restarts as well - -CA ca; // An object to describe a Wolfram elementary Cellular Automata - -int delay = 0; - -void setup() { - size(800, 200); - background(255); - int[] ruleset = { - 0, 1, 0, 1, 1, 0, 1, 0 - }; // An initial rule system - ca = new CA(ruleset); // Initialize CA - frameRate(30); -} - -void draw() { - ca.display(); // Draw the CA - ca.generate(); - - if (ca.finished()) { // If we're done, clear the screen, pick a new ruleset and restart - delay++; - if (delay > 30) { - background(255); - ca.randomize(); - ca.restart(); - delay = 0; - } - } -} - -void mousePressed() { - background(255); - ca.randomize(); - ca.restart(); -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling/CA.pde deleted file mode 100644 index 545d0bb83..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling/CA.pde +++ /dev/null @@ -1,92 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// A class to manage the CA - -class CA { - - int generation; // How many generations? - int[] ruleset; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1} - int w = 5; - int[][] matrix; // Store a history of generations in 2D array, not just one - - int cols; - int rows; - - - CA(int[] r) { - ruleset = r; - cols = width/w; - rows = height/w; - matrix = new int[cols][rows]; - restart(); - } - - // Make a random ruleset - void randomize() { - for (int i = 0; i < 8; i++) { - ruleset[i] = int(random(2)); - } - } - - // Reset to generation 0 - void restart() { - for (int i = 0; i < cols; i++) { - for (int j = 0; j < rows; j++) { - matrix[i][j] = 0; - } - } - matrix[cols/2][0] = 1; // We arbitrarily start with just the middle cell having a state of "1" - generation = 0; - } - - - // The process of creating the new generation - void generate() { - - // For every spot, determine new state by examing current state, and neighbor states - // Ignore edges that only have one neighor - for (int i = 0; i < cols; i++) { - int left = matrix[(i+cols-1)%cols][generation%rows]; // Left neighbor state - int me = matrix[i][generation%rows]; // Current state - int right = matrix[(i+1)%cols][generation%rows]; // Right neighbor state - matrix[i][(generation+1)%rows] = rules(left, me, right); // Compute next generation state based on ruleset - } - generation++; - } - - // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0' - void display() { - int offset = generation%rows; - - for (int i = 0; i < cols; i++) { - for (int j = 0; j < rows; j++) { - int y = j - offset; - if (y <= 0) y = rows + y; - if (matrix[i][j] == 1) fill(0); - else fill(255); - noStroke(); - rect(i*w, (y-1)*w, w, w); - } - } - } - - // Implementing the Wolfram rules - // This is the concise conversion to binary way - int rules (int a, int b, int c) { - String s = "" + a + b + c; - int index = Integer.parseInt(s, 2); - return ruleset[index]; - } - - // The CA is done if it reaches the bottom of the screen - boolean finished() { - if (generation > height/w) { - return true; - } - else { - return false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling/Exercise_7_04_WolframCA_scrolling.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling/Exercise_7_04_WolframCA_scrolling.pde deleted file mode 100644 index 7c1c0c787..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling/Exercise_7_04_WolframCA_scrolling.pde +++ /dev/null @@ -1,34 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// Simple demonstration of a Wolfram 1-dimensional cellular automata -// with the system scrolling by -// Also implements wrap around - -CA ca; // An object to describe a Wolfram elementary Cellular Automata - - -void setup() { - size(800, 200); - frameRate(30); - background(255); - int[] ruleset = {0,1,1,1,1,0,1,1}; // Rule 222 - //int[] ruleset = {0,1,1,1,1,1,0,1}; // Rule 190 - //int[] ruleset = {0,1,1,1,1,0,0,0}; // Rule 30 - //int[] ruleset = {0,1,1,1,0,1,1,0}; // Rule 110 - - ca = new CA(ruleset); // Initialize CA -} - -void draw() { - ca.display(); // Draw the CA - ca.generate(); -} - -void mousePressed() { - saveFrame("222-####.png"); - //background(255); - //ca.randomize(); - //ca.restart(); -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_110/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_110/CA.pde deleted file mode 100644 index fdfd10d50..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_110/CA.pde +++ /dev/null @@ -1,104 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// A class to manage the CA - -class CA { - - int generation; // How many generations? - int[] ruleset; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1} - int w = 5; - int[][] matrix; // Store a history of generations in 2D array, not just one - - int cols; - int rows; - - - CA(int[] r) { - ruleset = r; - cols = width/w; - rows = height/w; - matrix = new int[cols][rows]; - restart(); - } - - // Make a random ruleset - void randomize() { - for (int i = 0; i < 8; i++) { - ruleset[i] = int(random(2)); - } - } - - // Reset to generation 0 - void restart() { - for (int i = 0; i < cols; i++) { - for (int j = 0; j < rows; j++) { - matrix[i][j] = 0; - } - } - matrix[cols/2][0] = 1; // We arbitrarily start with just the middle cell having a state of "1" - generation = 0; - } - - - // The process of creating the new generation - void generate() { - - // For every spot, determine new state by examing current state, and neighbor states - // Ignore edges that only have one neighor - for (int i = 0; i < cols; i++) { - int left = matrix[(i+cols-1)%cols][generation%rows]; // Left neighbor state - int me = matrix[i][generation%rows]; // Current state - int right = matrix[(i+1)%cols][generation%rows]; // Right neighbor state - matrix[i][(generation+1)%rows] = rules(left, me, right); // Compute next generation state based on ruleset - } - generation++; - } - - // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0' - void display() { - int offset = generation%rows; - - for (int i = 0; i < cols; i++) { - for (int j = 0; j < rows; j++) { - int y = j - offset; - if (y <= 0) y = rows + y; - if (matrix[i][j] == 1) fill(0); - else fill(255); - noStroke(); - rect(i*w, (y-1)*w, w, w); - } - } - } - - // Implementing the Wolfram rules - // This is the concise conversion to binary way - /*int rules (int a, int b, int c) { - String s = "" + a + b + c; - int index = Integer.parseInt(s, 2); - return ruleset[index]; - }*/ - // For JavaScript Mode - int rules (int a, int b, int c) { - if (a == 1 && b == 1 && c == 1) return ruleset[7]; - if (a == 1 && b == 1 && c == 0) return ruleset[6]; - if (a == 1 && b == 0 && c == 1) return ruleset[5]; - if (a == 1 && b == 0 && c == 0) return ruleset[4]; - if (a == 0 && b == 1 && c == 1) return ruleset[3]; - if (a == 0 && b == 1 && c == 0) return ruleset[2]; - if (a == 0 && b == 0 && c == 1) return ruleset[1]; - if (a == 0 && b == 0 && c == 0) return ruleset[0]; - return 0; - } - - // The CA is done if it reaches the bottom of the screen - boolean finished() { - if (generation > height/w) { - return true; - } - else { - return false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_110/Exercise_7_04_WolframCA_scrolling_110.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_110/Exercise_7_04_WolframCA_scrolling_110.pde deleted file mode 100644 index 034c8cc75..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_110/Exercise_7_04_WolframCA_scrolling_110.pde +++ /dev/null @@ -1,26 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// Simple demonstration of a Wolfram 1-dimensional cellular automata -// with the system scrolling by -// Also implements wrap around - -CA ca; // An object to describe a Wolfram elementary Cellular Automata - - -void setup() { - size(800, 100); - frameRate(30); - background(255); - //int[] ruleset = {0,1,1,1,1,0,1,1}; // Rule 222 - //int[] ruleset = {0,1,1,1,1,1,0,1}; // Rule 190 - //int[] ruleset = {0,1,1,1,1,0,0,0}; // Rule 30 - int[] ruleset = {0,1,1,1,0,1,1,0}; // Rule 110 - - ca = new CA(ruleset); // Initialize CA -} - -void draw() { - ca.display(); // Draw the CA - ca.generate(); -} diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_190/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_190/CA.pde deleted file mode 100644 index fdfd10d50..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_190/CA.pde +++ /dev/null @@ -1,104 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// A class to manage the CA - -class CA { - - int generation; // How many generations? - int[] ruleset; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1} - int w = 5; - int[][] matrix; // Store a history of generations in 2D array, not just one - - int cols; - int rows; - - - CA(int[] r) { - ruleset = r; - cols = width/w; - rows = height/w; - matrix = new int[cols][rows]; - restart(); - } - - // Make a random ruleset - void randomize() { - for (int i = 0; i < 8; i++) { - ruleset[i] = int(random(2)); - } - } - - // Reset to generation 0 - void restart() { - for (int i = 0; i < cols; i++) { - for (int j = 0; j < rows; j++) { - matrix[i][j] = 0; - } - } - matrix[cols/2][0] = 1; // We arbitrarily start with just the middle cell having a state of "1" - generation = 0; - } - - - // The process of creating the new generation - void generate() { - - // For every spot, determine new state by examing current state, and neighbor states - // Ignore edges that only have one neighor - for (int i = 0; i < cols; i++) { - int left = matrix[(i+cols-1)%cols][generation%rows]; // Left neighbor state - int me = matrix[i][generation%rows]; // Current state - int right = matrix[(i+1)%cols][generation%rows]; // Right neighbor state - matrix[i][(generation+1)%rows] = rules(left, me, right); // Compute next generation state based on ruleset - } - generation++; - } - - // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0' - void display() { - int offset = generation%rows; - - for (int i = 0; i < cols; i++) { - for (int j = 0; j < rows; j++) { - int y = j - offset; - if (y <= 0) y = rows + y; - if (matrix[i][j] == 1) fill(0); - else fill(255); - noStroke(); - rect(i*w, (y-1)*w, w, w); - } - } - } - - // Implementing the Wolfram rules - // This is the concise conversion to binary way - /*int rules (int a, int b, int c) { - String s = "" + a + b + c; - int index = Integer.parseInt(s, 2); - return ruleset[index]; - }*/ - // For JavaScript Mode - int rules (int a, int b, int c) { - if (a == 1 && b == 1 && c == 1) return ruleset[7]; - if (a == 1 && b == 1 && c == 0) return ruleset[6]; - if (a == 1 && b == 0 && c == 1) return ruleset[5]; - if (a == 1 && b == 0 && c == 0) return ruleset[4]; - if (a == 0 && b == 1 && c == 1) return ruleset[3]; - if (a == 0 && b == 1 && c == 0) return ruleset[2]; - if (a == 0 && b == 0 && c == 1) return ruleset[1]; - if (a == 0 && b == 0 && c == 0) return ruleset[0]; - return 0; - } - - // The CA is done if it reaches the bottom of the screen - boolean finished() { - if (generation > height/w) { - return true; - } - else { - return false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_190/Exercise_7_04_WolframCA_scrolling_190.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_190/Exercise_7_04_WolframCA_scrolling_190.pde deleted file mode 100644 index ea30685db..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_190/Exercise_7_04_WolframCA_scrolling_190.pde +++ /dev/null @@ -1,27 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// Simple demonstration of a Wolfram 1-dimensional cellular automata -// with the system scrolling by -// Also implements wrap around - -CA ca; // An object to describe a Wolfram elementary Cellular Automata - - -void setup() { - size(800, 100); - frameRate(30); - background(255); - //int[] ruleset = {0,1,1,1,1,0,1,1}; // Rule 222 - int[] ruleset = {0,1,1,1,1,1,0,1}; // Rule 190 - //int[] ruleset = {0,1,1,1,1,0,0,0}; // Rule 30 - //int[] ruleset = {0,1,1,1,0,1,1,0}; // Rule 110 - - ca = new CA(ruleset); // Initialize CA -} - -void draw() { - ca.display(); // Draw the CA - ca.generate(); -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_222/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_222/CA.pde deleted file mode 100644 index fdfd10d50..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_222/CA.pde +++ /dev/null @@ -1,104 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// A class to manage the CA - -class CA { - - int generation; // How many generations? - int[] ruleset; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1} - int w = 5; - int[][] matrix; // Store a history of generations in 2D array, not just one - - int cols; - int rows; - - - CA(int[] r) { - ruleset = r; - cols = width/w; - rows = height/w; - matrix = new int[cols][rows]; - restart(); - } - - // Make a random ruleset - void randomize() { - for (int i = 0; i < 8; i++) { - ruleset[i] = int(random(2)); - } - } - - // Reset to generation 0 - void restart() { - for (int i = 0; i < cols; i++) { - for (int j = 0; j < rows; j++) { - matrix[i][j] = 0; - } - } - matrix[cols/2][0] = 1; // We arbitrarily start with just the middle cell having a state of "1" - generation = 0; - } - - - // The process of creating the new generation - void generate() { - - // For every spot, determine new state by examing current state, and neighbor states - // Ignore edges that only have one neighor - for (int i = 0; i < cols; i++) { - int left = matrix[(i+cols-1)%cols][generation%rows]; // Left neighbor state - int me = matrix[i][generation%rows]; // Current state - int right = matrix[(i+1)%cols][generation%rows]; // Right neighbor state - matrix[i][(generation+1)%rows] = rules(left, me, right); // Compute next generation state based on ruleset - } - generation++; - } - - // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0' - void display() { - int offset = generation%rows; - - for (int i = 0; i < cols; i++) { - for (int j = 0; j < rows; j++) { - int y = j - offset; - if (y <= 0) y = rows + y; - if (matrix[i][j] == 1) fill(0); - else fill(255); - noStroke(); - rect(i*w, (y-1)*w, w, w); - } - } - } - - // Implementing the Wolfram rules - // This is the concise conversion to binary way - /*int rules (int a, int b, int c) { - String s = "" + a + b + c; - int index = Integer.parseInt(s, 2); - return ruleset[index]; - }*/ - // For JavaScript Mode - int rules (int a, int b, int c) { - if (a == 1 && b == 1 && c == 1) return ruleset[7]; - if (a == 1 && b == 1 && c == 0) return ruleset[6]; - if (a == 1 && b == 0 && c == 1) return ruleset[5]; - if (a == 1 && b == 0 && c == 0) return ruleset[4]; - if (a == 0 && b == 1 && c == 1) return ruleset[3]; - if (a == 0 && b == 1 && c == 0) return ruleset[2]; - if (a == 0 && b == 0 && c == 1) return ruleset[1]; - if (a == 0 && b == 0 && c == 0) return ruleset[0]; - return 0; - } - - // The CA is done if it reaches the bottom of the screen - boolean finished() { - if (generation > height/w) { - return true; - } - else { - return false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_222/Exercise_7_04_WolframCA_scrolling_222.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_222/Exercise_7_04_WolframCA_scrolling_222.pde deleted file mode 100644 index 69af02447..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_222/Exercise_7_04_WolframCA_scrolling_222.pde +++ /dev/null @@ -1,27 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// Simple demonstration of a Wolfram 1-dimensional cellular automata -// with the system scrolling by -// Also implements wrap around - -CA ca; // An object to describe a Wolfram elementary Cellular Automata - - -void setup() { - size(800, 100); - frameRate(30); - background(255); - int[] ruleset = {0,1,1,1,1,0,1,1}; // Rule 222 - //int[] ruleset = {0,1,1,1,1,1,0,1}; // Rule 190 - //int[] ruleset = {0,1,1,1,1,0,0,0}; // Rule 30 - //int[] ruleset = {0,1,1,1,0,1,1,0}; // Rule 110 - - ca = new CA(ruleset); // Initialize CA -} - -void draw() { - ca.display(); // Draw the CA - ca.generate(); -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_30/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_30/CA.pde deleted file mode 100644 index 0999f18b1..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_30/CA.pde +++ /dev/null @@ -1,103 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// A class to manage the CA - -class CA { - - int generation; // How many generations? - int[] ruleset; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1} - int w = 5; - int[][] matrix; // Store a history of generations in 2D array, not just one - - int cols; - int rows; - - - CA(int[] r) { - ruleset = r; - cols = width/w; - rows = height/w; - matrix = new int[cols][rows]; - restart(); - } - - // Make a random ruleset - void randomize() { - for (int i = 0; i < 8; i++) { - ruleset[i] = int(random(2)); - } - } - - // Reset to generation 0 - void restart() { - for (int i = 0; i < cols; i++) { - for (int j = 0; j < rows; j++) { - matrix[i][j] = 0; - } - } - matrix[cols/2][0] = 1; // We arbitrarily start with just the middle cell having a state of "1" - generation = 0; - } - - - // The process of creating the new generation - void generate() { - - // For every spot, determine new state by examing current state, and neighbor states - // Ignore edges that only have one neighor - for (int i = 0; i < cols; i++) { - int left = matrix[(i+cols-1)%cols][generation%rows]; // Left neighbor state - int me = matrix[i][generation%rows]; // Current state - int right = matrix[(i+1)%cols][generation%rows]; // Right neighbor state - matrix[i][(generation+1)%rows] = rules(left, me, right); // Compute next generation state based on ruleset - } - generation++; - } - - // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0' - void display() { - int offset = generation%rows; - - for (int i = 0; i < cols; i++) { - for (int j = 0; j < rows; j++) { - int y = j - offset; - if (y <= 0) y = rows + y; - if (matrix[i][j] == 1) fill(0); - else fill(255); - noStroke(); - rect(i*w, (y-1)*w, w, w); - } - } - } - // Implementing the Wolfram rules - // This is the concise conversion to binary way - /*int rules (int a, int b, int c) { - String s = "" + a + b + c; - int index = Integer.parseInt(s, 2); - return ruleset[index]; - }*/ - // For JavaScript Mode - int rules (int a, int b, int c) { - if (a == 1 && b == 1 && c == 1) return ruleset[7]; - if (a == 1 && b == 1 && c == 0) return ruleset[6]; - if (a == 1 && b == 0 && c == 1) return ruleset[5]; - if (a == 1 && b == 0 && c == 0) return ruleset[4]; - if (a == 0 && b == 1 && c == 1) return ruleset[3]; - if (a == 0 && b == 1 && c == 0) return ruleset[2]; - if (a == 0 && b == 0 && c == 1) return ruleset[1]; - if (a == 0 && b == 0 && c == 0) return ruleset[0]; - return 0; - } - - // The CA is done if it reaches the bottom of the screen - boolean finished() { - if (generation > height/w) { - return true; - } - else { - return false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_30/Exercise_7_04_WolframCA_scrolling_30.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_30/Exercise_7_04_WolframCA_scrolling_30.pde deleted file mode 100644 index 044451336..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_30/Exercise_7_04_WolframCA_scrolling_30.pde +++ /dev/null @@ -1,27 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// Simple demonstration of a Wolfram 1-dimensional cellular automata -// with the system scrolling by -// Also implements wrap around - -CA ca; // An object to describe a Wolfram elementary Cellular Automata - - -void setup() { - size(800, 100); - frameRate(30); - background(255); - //int[] ruleset = {0,1,1,1,1,0,1,1}; // Rule 222 - //int[] ruleset = {0,1,1,1,1,1,0,1}; // Rule 190 - int[] ruleset = {0,1,1,1,1,0,0,0}; // Rule 30 - //int[] ruleset = {0,1,1,1,0,1,1,0}; // Rule 110 - - ca = new CA(ruleset); // Initialize CA -} - -void draw() { - ca.display(); // Draw the CA - ca.generate(); -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/Figure_7_17_cells/Figure_7_17_cells.pde b/java/examples/Books/Nature of Code/chp7_CA/Figure_7_17_cells/Figure_7_17_cells.pde deleted file mode 100644 index 81ec31d42..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/Figure_7_17_cells/Figure_7_17_cells.pde +++ /dev/null @@ -1,28 +0,0 @@ - -size(1800,90); - -int w = 90; - -int total = width/w; - -int[] cells = {1,0,1,0,0,0,0,1,0,1,1,1,0,0,0,1,1,1,0,0}; - - -print("int[] cells = {"); -for (int i = 0; i < cells.length; i++) { - if (cells[i] == 0) fill(255); - else fill(64); - stroke(0); - rect(i*w,0,w-1,w-1); - print(cells[i] +","); -} - -saveFrame("cells.png"); - - - - - - - - diff --git a/java/examples/Books/Nature of Code/chp7_CA/Figure_7_17_cells/cells.tif b/java/examples/Books/Nature of Code/chp7_CA/Figure_7_17_cells/cells.tif deleted file mode 100644 index 38ef13501fddfbe9a3b66bc778d2b839a9253b66..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 486768 zcmeI!L5?0)6-427f=C!L0QSHt*g!VG5*RUN@jyE^(vhxShD_?~DDBd3Tb9l}RsDYX z<>Rj(A0Iz|{Ndx@AHVxdUq1i;`t8TBzx?#`=eIB4^2gsl^AEq~ufO-NFTel(`469; z|M7o+_s5SffBOFU=b!rW=ltEjeE%~){o|is|BcUo^Xq@U5I_I{1Q0*~0R#|0009IL zKmY**5I_I{1Q0;r|4HC)zJ4X}jro6k{Yu~)4QhNNz>U@d4KzxinH!ge6}6(Z;#>9; zw!J_DjS^_~Go|Z+1{x*MY(?*G^poYxjb7i1-reXY%UM%2<>fy&xbfR=ync7>b3b8w zaWpQCF3ED{1~*>*dvBBs8ka`9vz)DHuaCy1(e5l~E86R$acQ(W%h`(d`kJCC^`V&? z+^7%DRuqjAXy(SH(Ir{V+~CH`fA5WwLF3YBcb2mi?e)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 0) && (neighbors == 3)) next[x][y] = 1; // Reproduction - else next[x][y] = board[x][y]; // Stasis - } - } - - // Next is now our board - board = next; - } - - // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0' - void display() { - for ( int i = 0; i < columns;i++) { - for ( int j = 0; j < rows;j++) { - if ((board[i][j] == 1)) fill(0); - else fill(255); - stroke(0); - rect(i*w, j*w, w, w); - } - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/GameOfLifeWrapAround/GameOfLifeWrapAround.pde b/java/examples/Books/Nature of Code/chp7_CA/GameOfLifeWrapAround/GameOfLifeWrapAround.pde deleted file mode 100644 index 97d409a1c..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/GameOfLifeWrapAround/GameOfLifeWrapAround.pde +++ /dev/null @@ -1,31 +0,0 @@ -// Daniel Shiffman, Nature of Code -// - -// A basic implementation of John Conway's Game of Life CA -// how could this be improved to use object oriented programming? -// think of it as similar to our particle system, with a "cell" class -// to describe each individual cell and a "cellular automata" class -// to describe a collection of cells - -// Cells wrap around - -GOL gol; - -void setup() { - size(400, 400); - smooth(); - gol = new GOL(); -} - -void draw() { - background(255); - - gol.generate(); - gol.display(); -} - -// reset board when mouse is pressed -void mousePressed() { - gol.init(); -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/Cell.pde b/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/Cell.pde deleted file mode 100644 index 3f4a43fb5..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/Cell.pde +++ /dev/null @@ -1,38 +0,0 @@ -class Cell { - - float x, y; - float w; - float xoff; - float yoff; - - int state; - - Cell(float x_, float y_, float w_) { - x = x_; - y = y_; - w = w_; - xoff = w/2; - yoff = sin(radians(60))*w; - state = int(random(2)); - } - - - void display() { - - fill(state*255); - stroke(0); - pushMatrix(); - translate(x,y); - beginShape(); - vertex(0, yoff); - vertex(xoff, 0); - vertex(xoff+w, 0); - vertex(2*w, yoff); - vertex(xoff+w, 2*yoff); - vertex(xoff, 2*yoff); - vertex(0, yoff); - endShape(); - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/GOL.pde b/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/GOL.pde deleted file mode 100644 index c72710b1d..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/GOL.pde +++ /dev/null @@ -1,40 +0,0 @@ -class GOL { - - float w = 20; - float h = sin(radians(60))*w; - int columns, rows; - - // Game of life board - Cell[][] board; - - - GOL() { - // Initialize rows, columns and set-up arrays - columns = width/int(w*3); - rows = height/int(h); - board = new Cell[columns][rows]; - init(); - } - - void init() { - float h = sin(radians(60))*w; - for (int i = 0; i < columns; i++) { - for (int j = 0; j < rows; j++) { - if (j % 2 == 0) board[i][j] = new Cell(i*w*3, j*h,w); - else board[i][j] = new Cell(i*w*3+w+h/2, j*h, w); - } - } - } - - - - // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0' - void display() { - for ( int i = 0; i < columns;i++) { - for ( int j = 0; j < rows;j++) { - board[i][j].display(); - } - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/HexagonCells.pde b/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/HexagonCells.pde deleted file mode 100644 index 2a42cdc5b..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/HexagonCells.pde +++ /dev/null @@ -1,24 +0,0 @@ -// Daniel Shiffman, Nature of Code -// - -// Outline for game of life -// This is just a grid of hexagons right now - -GOL gol; - -void setup() { - size(600, 600); - smooth(); - gol = new GOL(); -} - -void draw() { - background(255); - gol.display(); -} - -// reset board when mouse is pressed -void mousePressed() { - gol.init(); -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_figures/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_figures/CA.pde deleted file mode 100644 index adb77ee3e..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_figures/CA.pde +++ /dev/null @@ -1,92 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// A class to manage the CA - -class CA { - - int[] cells; // An array of 0s and 1s - int generation; // How many generations? - - int[] ruleset; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1} - - CA(int[] r) { - ruleset = r; - cells = new int[width/scl]; - restart(); - } - - CA() { - scl = 1; - cells = new int[width/scl]; - randomize(); - restart(); - } - - // Set the rules of the CA - void setRules(int[] r) { - ruleset = r; - } - - // Make a random ruleset - void randomize() { - for (int i = 0; i < 8; i++) { - ruleset[i] = int(random(2)); - } - } - - // Reset to generation 0 - void restart() { - for (int i = 0; i < cells.length; i++) { - cells[i] = 0; - } - cells[cells.length/2] = 1; // We arbitrarily start with just the middle cell having a state of "1" - generation = 0; - } - - // The process of creating the new generation - void generate() { - // First we create an empty array for the new values - int[] nextgen = new int[cells.length]; - // For every spot, determine new state by examing current state, and neighbor states - // Ignore edges that only have one neighor - for (int i = 1; i < cells.length-1; i++) { - int left = cells[i-1]; // Left neighbor state - int me = cells[i]; // Current state - int right = cells[i+1]; // Right neighbor state - nextgen[i] = rules(left, me, right); // Compute next generation state based on ruleset - } - // The current generation is the new generation - cells = nextgen; - generation++; - } - - // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0' - void render() { - for (int i = 0; i < cells.length; i++) { - if (cells[i] == 1) fill(0); - else fill(255); - stroke(0); - rect(i*scl, generation*scl, scl, scl); - } - } - - // Implementing the Wolfram rules - // Could be improved and made more concise, but here we can explicitly see what is going on for each case - int rules (int a, int b, int c) { - String s = "" + a + b + c; - int index = Integer.parseInt(s,2); - return ruleset[index]; - } - - // The CA is done if it reaches the bottom of the screen - boolean finished() { - if (generation > height/scl) { - return true; - } - else { - return false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_figures/NOC_7_01_WolframCA_figures.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_figures/NOC_7_01_WolframCA_figures.pde deleted file mode 100644 index a824998f2..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_figures/NOC_7_01_WolframCA_figures.pde +++ /dev/null @@ -1,35 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// Simple demonstration of a Wolfram 1-dimensional cellular automata -// When the system reaches bottom of the window, it restarts with a new ruleset -// Mouse click restarts as well - - -CA ca; // An instance object to describe the Wolfram basic Cellular Automata - -int scl = 20; - -void setup() { - size(1800,600); - background(255); - //int[] ruleset = {0,1,0,1,1,0,1,0}; // 90 - int[] ruleset = {0,1,1,1,1,0,1,1}; // An initial rule system - ca = new CA(ruleset); // Initialize CA -} - -void draw() { - ca.render(); // Draw the CA - ca.generate(); // Generate the next level - - if (ca.finished()) { // If we're done, clear the screen, pick a new ruleset and restart - saveFrame("rule222.png"); - noLoop(); - } -} - -void mousePressed() { - background(255); - ca.randomize(); - ca.restart(); -} diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_simple/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_simple/CA.pde deleted file mode 100644 index 654b06645..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_simple/CA.pde +++ /dev/null @@ -1,65 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// A class to manage the CA - -class CA { - - int[] cells; // An array of 0s and 1s - int generation; // How many generations? - - int[] ruleset = {0, 1, 0, 1, 1, 0, 1, 0}; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1} - - int w = 10; - - CA() { - cells = new int[width/w]; - for (int i = 0; i < cells.length; i++) { - cells[i] = 0; - } - cells[cells.length/2] = 1; // We arbitrarily start with just the middle cell having a state of "1" - generation = 0; - } - - // The process of creating the new generation - void generate() { - // First we create an empty array for the new values - int[] nextgen = new int[cells.length]; - // For every spot, determine new state by examing current state, and neighbor states - // Ignore edges that only have one neighor - for (int i = 1; i < cells.length-1; i++) { - int left = cells[i-1]; // Left neighbor state - int me = cells[i]; // Current state - int right = cells[i+1]; // Right neighbor state - nextgen[i] = rules(left, me, right); // Compute next generation state based on ruleset - } - // The current generation is the new generation - cells = nextgen; - generation++; - } - - // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0' - void display() { - for (int i = 0; i < cells.length; i++) { - if (cells[i] == 1) fill(0); - else fill(255); - noStroke(); - rect(i*w, generation*w, w, w); - } - } - - // Implementing the Wolfram rules - // Could be improved and made more concise, but here we can explicitly see what is going on for each case - int rules (int a, int b, int c) { - if (a == 1 && b == 1 && c == 1) return ruleset[0]; - if (a == 1 && b == 1 && c == 0) return ruleset[1]; - if (a == 1 && b == 0 && c == 1) return ruleset[2]; - if (a == 1 && b == 0 && c == 0) return ruleset[3]; - if (a == 0 && b == 1 && c == 1) return ruleset[4]; - if (a == 0 && b == 1 && c == 0) return ruleset[5]; - if (a == 0 && b == 0 && c == 1) return ruleset[6]; - if (a == 0 && b == 0 && c == 0) return ruleset[7]; - return 0; - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_simple/NOC_7_01_WolframCA_simple.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_simple/NOC_7_01_WolframCA_simple.pde deleted file mode 100644 index 61020ce67..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_simple/NOC_7_01_WolframCA_simple.pde +++ /dev/null @@ -1,21 +0,0 @@ -// Wolfram Cellular Automata -// Daniel Shiffman - -// Simple demonstration of a Wolfram 1-dimensional cellular automata - -CA ca; // An instance object to describe the Wolfram basic Cellular Automata - - -void setup() { - size(800, 400); - background(255); - ca = new CA(); // Initialize CA -} - -void draw() { - ca.display(); // Draw the CA - if (ca.generation < height/ca.w) { - ca.generate(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeOOP/Cell.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeOOP/Cell.pde deleted file mode 100644 index 86ba100b6..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeOOP/Cell.pde +++ /dev/null @@ -1,36 +0,0 @@ -class Cell { - - float x, y; - float w; - - int state; - int previous; - - Cell(float x_, float y_, float w_) { - x = x_; - y = y_; - w = w_; - - state = int(random(2)); - previous = state; - } - - void savePrevious() { - previous = state; - } - - void newState(int s) { - state = s; - } - - void display() { - if (previous == 0 && state == 1) fill(0,0,255); - else if (state == 1) fill(0); - else if (previous == 1 && state == 0) fill(255,0,0); - else fill(255); - stroke(0); - rect(x, y, w, w); - } -} - - diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeOOP/GOL.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeOOP/GOL.pde deleted file mode 100644 index f7c13d486..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeOOP/GOL.pde +++ /dev/null @@ -1,69 +0,0 @@ -class GOL { - - int w = 8; - int columns, rows; - - // Game of life board - Cell[][] board; - - - GOL() { - // Initialize rows, columns and set-up arrays - columns = width/w; - rows = height/w; - board = new Cell[columns][rows]; - init(); - } - - void init() { - for (int i = 0; i < columns; i++) { - for (int j = 0; j < rows; j++) { - board[i][j] = new Cell(i*w, j*w, w); - } - } - } - - // The process of creating the new generation - void generate() { - for ( int i = 0; i < columns;i++) { - for ( int j = 0; j < rows;j++) { - board[i][j].savePrevious(); - } - } - - - // Loop through every spot in our 2D array and check spots neighbors - for (int x = 0; x < columns; x++) { - for (int y = 0; y < rows; y++) { - - // Add up all the states in a 3x3 surrounding grid - int neighbors = 0; - for (int i = -1; i <= 1; i++) { - for (int j = -1; j <= 1; j++) { - neighbors += board[(x+i+columns)%columns][(y+j+rows)%rows].previous; - } - } - - // A little trick to subtract the current cell's state since - // we added it in the above loop - neighbors -= board[x][y].previous; - - // Rules of Life - if ((board[x][y].state == 1) && (neighbors < 2)) board[x][y].newState(0); // Loneliness - else if ((board[x][y].state == 1) && (neighbors > 3)) board[x][y].newState(0); // Overpopulation - else if ((board[x][y].state == 0) && (neighbors == 3)) board[x][y].newState(1); // Reproduction - // else do nothing! - } - } - } - - // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0' - void display() { - for ( int i = 0; i < columns;i++) { - for ( int j = 0; j < rows;j++) { - board[i][j].display(); - } - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeOOP/NOC_7_02_GameOfLifeOOP.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeOOP/NOC_7_02_GameOfLifeOOP.pde deleted file mode 100644 index e10b32ef6..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeOOP/NOC_7_02_GameOfLifeOOP.pde +++ /dev/null @@ -1,27 +0,0 @@ -// Daniel Shiffman, Nature of Code -// - -// A basic implementation of John Conway's Game of Life CA - -// Each cell is now an object! - -GOL gol; - -void setup() { - size(400, 400); - smooth(); - gol = new GOL(); -} - -void draw() { - background(255); - - gol.generate(); - gol.display(); -} - -// reset board when mouse is pressed -void mousePressed() { - gol.init(); -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeSimple/GOL.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeSimple/GOL.pde deleted file mode 100644 index 981919ae4..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeSimple/GOL.pde +++ /dev/null @@ -1,73 +0,0 @@ -class GOL { - - int w = 8; - int columns, rows; - - // Game of life board - int[][] board; - - - GOL() { - // Initialize rows, columns and set-up arrays - columns = width/w; - rows = height/w; - board = new int[columns][rows]; - //next = new int[columns][rows]; - // Call function to fill array with random values 0 or 1 - init(); - } - - void init() { - for (int i =1;i < columns-1;i++) { - for (int j =1;j < rows-1;j++) { - board[i][j] = int(random(2)); - } - } - } - - // The process of creating the new generation - void generate() { - - int[][] next = new int[columns][rows]; - - // Loop through every spot in our 2D array and check spots neighbors - for (int x = 1; x < columns-1; x++) { - for (int y = 1; y < rows-1; y++) { - - // Add up all the states in a 3x3 surrounding grid - int neighbors = 0; - for (int i = -1; i <= 1; i++) { - for (int j = -1; j <= 1; j++) { - neighbors += board[x+i][y+j]; - } - } - - // A little trick to subtract the current cell's state since - // we added it in the above loop - neighbors -= board[x][y]; - - // Rules of Life - if ((board[x][y] == 1) && (neighbors < 2)) next[x][y] = 0; // Loneliness - else if ((board[x][y] == 1) && (neighbors > 3)) next[x][y] = 0; // Overpopulation - else if ((board[x][y] == 0) && (neighbors == 3)) next[x][y] = 1; // Reproduction - else next[x][y] = board[x][y]; // Stasis - } - } - - // Next is now our board - board = next; - } - - // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0' - void display() { - for ( int i = 0; i < columns;i++) { - for ( int j = 0; j < rows;j++) { - if ((board[i][j] == 1)) fill(0); - else fill(255); - stroke(0); - rect(i*w, j*w, w, w); - } - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeSimple/NOC_7_03_GameOfLifeSimple.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeSimple/NOC_7_03_GameOfLifeSimple.pde deleted file mode 100644 index 3ac6009ba..000000000 --- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeSimple/NOC_7_03_GameOfLifeSimple.pde +++ /dev/null @@ -1,29 +0,0 @@ -// Daniel Shiffman, Nature of Code -// - -// A basic implementation of John Conway's Game of Life CA -// how could this be improved to use object oriented programming? -// think of it as similar to our particle system, with a "cell" class -// to describe each individual cell and a "cellular automata" class -// to describe a collection of cells - -GOL gol; - -void setup() { - size(400, 400); - smooth(); - gol = new GOL(); -} - -void draw() { - background(255); - - gol.generate(); - gol.display(); -} - -// reset board when mouse is pressed -void mousePressed() { - gol.init(); -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/CantorSetArrayList/CantorSetArrayList.pde b/java/examples/Books/Nature of Code/chp8_fractals/CantorSetArrayList/CantorSetArrayList.pde deleted file mode 100644 index 48b2832de..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/CantorSetArrayList/CantorSetArrayList.pde +++ /dev/null @@ -1,47 +0,0 @@ -// Cantor Set -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Renders a simple fractal, the Cantor Set -// Uses an ArrayList to store list of objects -// Generates when mouse is pressed - -float h = 30; - -// List of line objects -ArrayList cantor; - -void setup() { - size(729, 200); - - // Start with one line - cantor = new ArrayList(); - cantor.add(new CantorLine(0, 100, width)); -} - -// Click the mouse to advance the sequence -void mousePressed() { - generate(); -} - -void draw() { - background(255); - // Always show all the lines - for (CantorLine cl : cantor) { - cl.display(); - } - - fill(0); - text("Click mouse to generate",10,height-20); -} - -void generate() { - // Generate the next set of lines - ArrayList next = new ArrayList(); - for (CantorLine cl : cantor) { - next.add(new CantorLine(cl.x,cl.y,cl.len/3)); - next.add(new CantorLine(cl.x+cl.len*2/3,cl.y,cl.len/3)); - } - cantor = next; -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/CantorSetArrayList/Line.pde b/java/examples/Books/Nature of Code/chp8_fractals/CantorSetArrayList/Line.pde deleted file mode 100644 index 7e5c9dffa..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/CantorSetArrayList/Line.pde +++ /dev/null @@ -1,23 +0,0 @@ -// Cantor Set -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Cantor line is a simple horizontal line with a starting point -// and length - -class CantorLine { - float x,y; - float len; - - CantorLine(float x_, float y_, float len_) { - x = x_; - y = y_; - len = len_; - } - - void display() { - stroke(0); - line(x,y,x+len,y); - } - -} diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_01_RecursionLines/Exercise_8_01_RecursionLines.pde b/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_01_RecursionLines/Exercise_8_01_RecursionLines.pde deleted file mode 100644 index 0c5f2790f..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_01_RecursionLines/Exercise_8_01_RecursionLines.pde +++ /dev/null @@ -1,35 +0,0 @@ -// Simple Recursion -// Daniel Shiffman -// Nature of Code, Chapter 8 - -void setup() { - size(800, 200); - smooth(); -} - -void draw() { - background(255); - drawLines(100,100,700,100); - noLoop(); -} - -void drawLines(float x1, float y1, float x2, float y2) { - - line(x1,y1,x2,y2); - - float dx = x2-x1; - float dy = y2-y1; - - //println(dx + " " + dy); - - if (dx == 0 && dy > 4) { - //println(dy); - drawLines(x1-dy/3,y1,x1+dy/3,y1); - drawLines(x1-dy/3,y2,x1+dy/3,y2); - } else if (dy == 0 && dx > 4) { - //println(dx); - drawLines(x1,y1-dx/3,x1,y1+dx/3); - drawLines(x2,y1-dx/3,x2,y1+dx/3); - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_02_KochSnowFlake/Exercise_8_02_KochSnowFlake.pde b/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_02_KochSnowFlake/Exercise_8_02_KochSnowFlake.pde deleted file mode 100644 index 8ab63f9c7..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_02_KochSnowFlake/Exercise_8_02_KochSnowFlake.pde +++ /dev/null @@ -1,54 +0,0 @@ -// Koch Snowflake -// Daniel Shiffman - -// Renders a simple fractal, the Koch snowflake -// Each recursive level drawn in sequence - -ArrayList lines ; // A list to keep track of all the lines - -void setup() { - size(600, 692); - background(255); - lines = new ArrayList(); - PVector a = new PVector(0, 173); - PVector b = new PVector(width, 173); - PVector c = new PVector(width/2, 173+width*cos(radians(30))); - - // Starting with additional lines - lines.add(new KochLine(a, b)); - lines.add(new KochLine(b, c)); - lines.add(new KochLine(c, a)); - - for (int i = 0; i < 5; i++) { - generate(); - } - - smooth(); -} - -void draw() { - background(255); - for (KochLine l : lines) { - l.display(); - } -} - -void generate() { - ArrayList next = new ArrayList(); // Create emtpy list - for (KochLine l : lines) { - // Calculate 5 koch PVectors (done for us by the line object) - PVector a = l.kochA(); - PVector b = l.kochB(); - PVector c = l.kochC(); - PVector d = l.kochD(); - PVector e = l.kochE(); - // Make line segments between all the PVectors and add them - next.add(new KochLine(a, b)); - next.add(new KochLine(b, c)); - next.add(new KochLine(c, d)); - next.add(new KochLine(d, e)); - } - lines = next; -} - - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_02_KochSnowFlake/KochLine.pde b/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_02_KochSnowFlake/KochLine.pde deleted file mode 100644 index a241afe1c..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_02_KochSnowFlake/KochLine.pde +++ /dev/null @@ -1,71 +0,0 @@ -// Koch Curve -// Daniel Shiffman - -// A class to describe one line segment in the fractal -// Includes methods to calculate midPVectors along the line according to the Koch algorithm - -class KochLine { - - // Two PVectors, - // a is the "left" PVector and - // b is the "right PVector - PVector start; - PVector end; - - KochLine(PVector a, PVector b) { - start = a.get(); - end = b.get(); - } - - void display() { - stroke(0); - line(start.x, start.y, end.x, end.y); - } - - PVector kochA() { - return start.get(); - } - - - // This is easy, just 1/3 of the way - PVector kochB() { - PVector v = PVector.sub(end, start); - v.div(3); - v.add(start); - return v; - } - - // More complicated, have to use a little trig to figure out where this PVector is! - PVector kochC() { - PVector a = start.get(); // Start at the beginning - - PVector v = PVector.sub(end, start); - v.div(3); - a.add(v); // Move to point B - - rotate(v, -radians(60)); // Rotate 60 degrees - a.add(v); // Move to point C - - return a; - } - - // Easy, just 2/3 of the way - PVector kochD() { - PVector v = PVector.sub(end, start); - v.mult(2/3.0); - v.add(start); - return v; - } - - PVector kochE() { - return end.get(); - } -} - -public void rotate(PVector v, float theta) { - float xTemp = v.x; - // Might need to check for rounding errors like with angleBetween function? - v.x = v.x*PApplet.cos(theta) - v.y*PApplet.sin(theta); - v.y = xTemp*PApplet.sin(theta) + v.y*PApplet.cos(theta); -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_06_Tree/Exercise_8_06_Tree.pde b/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_06_Tree/Exercise_8_06_Tree.pde deleted file mode 100644 index 456441db3..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_06_Tree/Exercise_8_06_Tree.pde +++ /dev/null @@ -1,56 +0,0 @@ -// Recursive Tree -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Renders a simple tree-like structure via recursion -// Branching angle calculated as a function of horizontal mouse location - -float theta; - -void setup() { - size(1800, 500); - smooth(); -} - -void draw() { - background(255); - // Let's pick an angle 0 to 90 degrees based on the mouse position - theta = PI/6;//map(mouseX,0,width,0,PI/2); - - // Start the tree from the bottom of the screen - translate(width/2, height); - stroke(0); - branch(200,0); - save("chapter08_exc06.png"); - noLoop(); -} - -void branch(float len, int level) { - // Each branch will be 2/3rds the size of the previous one - - //float sw = map(len,2,120,1,10); - //strokeWeight(sw); - strokeWeight(2); - - line(0, 0, 0, -len); - // Move to the end of that line - translate(0, -len); - - len *= 0.66; - level++; - // All recursive functions must have an exit condition!!!! - // Here, ours is when the length of the branch is 2 pixels or less - if (level < 5) { - pushMatrix(); // Save the current state of transformation (i.e. where are we now) - rotate(theta); // Rotate by theta - branch(len,level); // Ok, now call myself to draw two new branches!! - popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state - - // Repeat the same thing, only branch off to the "left" this time! - pushMatrix(); - rotate(-theta); - branch(len,level); - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_07_Tree/Exercise_8_07_Tree.pde b/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_07_Tree/Exercise_8_07_Tree.pde deleted file mode 100644 index 759570bf9..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_07_Tree/Exercise_8_07_Tree.pde +++ /dev/null @@ -1,51 +0,0 @@ -// Recursive Tree -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Renders a simple tree-like structure via recursion -// Branching angle calculated as a function of horizontal mouse location - -float theta; - -void setup() { - size(800, 200); - smooth(); -} - -void draw() { - background(255); - // Let's pick an angle 0 to 90 degrees based on the mouse position - theta = map(mouseX,0,width,0,PI/2); - - // Start the tree from the bottom of the screen - translate(width/2, height); - stroke(0); - branch(60); -} - -void branch(float len) { - // Each branch will be 2/3rds the size of the previous one - float sw = map(len,2,120,1,10); - strokeWeight(sw); - - line(0, 0, 0, -len); - // Move to the end of that line - translate(0, -len); - - len *= 0.66; - // All recursive functions must have an exit condition!!!! - // Here, ours is when the length of the branch is 2 pixels or less - if (len > 2) { - pushMatrix(); // Save the current state of transformation (i.e. where are we now) - rotate(theta); // Rotate by theta - branch(len); // Ok, now call myself to draw two new branches!! - popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state - - // Repeat the same thing, only branch off to the "left" this time! - pushMatrix(); - rotate(-theta); - branch(len); - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_02_Mandelbrot/Figure_8_02_Mandelbrot.pde b/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_02_Mandelbrot/Figure_8_02_Mandelbrot.pde deleted file mode 100644 index 5de2d26a6..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_02_Mandelbrot/Figure_8_02_Mandelbrot.pde +++ /dev/null @@ -1,79 +0,0 @@ -// The Mandelbrot Set -// Daniel Shiffman - -// Simple rendering of the Mandelbrot set -// c = a + bi -// Iterate z = z^2 + c, i.e. -// z(0) = 0 -// z(1) = 0*0 + c -// z(2) = c*c + c -// z(3) = (c*c + c) * (c*c + c) + c -// etc. - -// c*c = (a+bi) * (a+bi) = a^2 - b^2 + 2abi - -// Created 2 May 2005 - -// Establish a range of values on the complex plane -double xmin = -2.5; double ymin = -1; double w = 4; double h = 2; -// A different range will allow us to "zoom" in or out on the fractal -// double xmin = -1.5; double ymin = -.1; double wh = 0.15; - -void setup() { - size(863,863/2); -} - -void draw() { - - loadPixels(); - - // Maximum number of iterations for each point on the complex plane - int maxiterations = 200; - - // x goes from xmin to xmax - double xmax = xmin + w; - // y goes from ymin to ymax - double ymax = ymin + h; - - // Calculate amount we increment x,y for each pixel - double dx = (xmax - xmin) / (width); - double dy = (ymax - ymin) / (height); - - // Start y - double y = ymin; - for(int j = 0; j < height; j++) { - // Start x - double x = xmin; - for(int i = 0; i < width; i++) { - - // Now we test, as we iterate z = z^2 + cm does z tend towards infinity? - double a = x; - double b = y; - int n = 0; - while (n < maxiterations) { - double aa = a * a; - double bb = b * b; - double twoab = 2.0 * a * b; - a = aa - bb + x; - b = twoab + y; - // Infinty in our finite world is simple, let's just consider it 16 - if(aa + bb > 16.0f) { - break; // Bail - } - n++; - } - - // We color each pixel based on how long it takes to get to infinity - // If we never got there, let's pick the color black - if (n == maxiterations) pixels[i+j*width] = color(0); - else pixels[i+j*width] = color(n*16 % 255); // Gosh, we could make fancy colors here if we wanted - x += dx; - } - y += dy; - } - updatePixels(); - - save("chapter08_02.png"); - noLoop(); -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_14_Koch/Figure_8_14_Koch.pde b/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_14_Koch/Figure_8_14_Koch.pde deleted file mode 100644 index ea0ba890f..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_14_Koch/Figure_8_14_Koch.pde +++ /dev/null @@ -1,65 +0,0 @@ -// Koch Curve -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Renders a simple fractal, the Koch snowflake -// Each recursive level drawn in sequence - -ArrayList lines ; // A list to keep track of all the lines - -void setup() { - size(1820, 200); - - - smooth(); -} - - - -void draw() { - translate(10,0); - int spacing = 10; - int total = 5; - - background(255); - float w = (1800-spacing*(total-1))/5; - for (int n = 0; n < total; n++) { - lines = new ArrayList(); - PVector start = new PVector(0, height*2/3); - PVector end = new PVector(w, height*2/3); - lines.add(new KochLine(start, end)); - for (int i = 0; i < n; i++) { - generate(); - } - strokeWeight(2); - for (KochLine l : lines) { - l.display(); - } - noFill(); - strokeWeight(1); - stroke(127); - rect(0, 10, w,height-20); - translate(w+spacing, 0); - } - save("chapter08_14.png"); - noLoop(); -} - -void generate() { - ArrayList next = new ArrayList(); // Create emtpy list - for (KochLine l : lines) { - // Calculate 5 koch PVectors (done for us by the line object) - PVector a = l.kochA(); - PVector b = l.kochB(); - PVector c = l.kochC(); - PVector d = l.kochD(); - PVector e = l.kochE(); - // Make line segments between all the PVectors and add them - next.add(new KochLine(a, b)); - next.add(new KochLine(b, c)); - next.add(new KochLine(c, d)); - next.add(new KochLine(d, e)); - } - lines = next; -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_14_Koch/KochLine.pde b/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_14_Koch/KochLine.pde deleted file mode 100644 index a241afe1c..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_14_Koch/KochLine.pde +++ /dev/null @@ -1,71 +0,0 @@ -// Koch Curve -// Daniel Shiffman - -// A class to describe one line segment in the fractal -// Includes methods to calculate midPVectors along the line according to the Koch algorithm - -class KochLine { - - // Two PVectors, - // a is the "left" PVector and - // b is the "right PVector - PVector start; - PVector end; - - KochLine(PVector a, PVector b) { - start = a.get(); - end = b.get(); - } - - void display() { - stroke(0); - line(start.x, start.y, end.x, end.y); - } - - PVector kochA() { - return start.get(); - } - - - // This is easy, just 1/3 of the way - PVector kochB() { - PVector v = PVector.sub(end, start); - v.div(3); - v.add(start); - return v; - } - - // More complicated, have to use a little trig to figure out where this PVector is! - PVector kochC() { - PVector a = start.get(); // Start at the beginning - - PVector v = PVector.sub(end, start); - v.div(3); - a.add(v); // Move to point B - - rotate(v, -radians(60)); // Rotate 60 degrees - a.add(v); // Move to point C - - return a; - } - - // Easy, just 2/3 of the way - PVector kochD() { - PVector v = PVector.sub(end, start); - v.mult(2/3.0); - v.add(start); - return v; - } - - PVector kochE() { - return end.get(); - } -} - -public void rotate(PVector v, float theta) { - float xTemp = v.x; - // Might need to check for rounding errors like with angleBetween function? - v.x = v.x*PApplet.cos(theta) - v.y*PApplet.sin(theta); - v.y = xTemp*PApplet.sin(theta) + v.y*PApplet.cos(theta); -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_20_Tree/Figure_8_20_Tree.pde b/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_20_Tree/Figure_8_20_Tree.pde deleted file mode 100644 index b64c609fc..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_20_Tree/Figure_8_20_Tree.pde +++ /dev/null @@ -1,53 +0,0 @@ -// Recursive Tree -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Renders a simple tree-like structure via recursion -// Branching angle calculated as a function of horizontal mouse location - -float theta; - -void setup() { - size(800, 200); - smooth(); -} - -void draw() { - background(255); - // Let's pick an angle 0 to 90 degrees based on the mouse position - theta = map(mouseX,0,width,0,PI/2); - - // Start the tree from the bottom of the screen - translate(width/2, height); - stroke(0); - branch(60); -} - -void branch(float len) { - // Each branch will be 2/3rds the size of the previous one - - //float sw = map(len,2,120,1,10); - //strokeWeight(sw); - strokeWeight(2); - - line(0, 0, 0, -len); - // Move to the end of that line - translate(0, -len); - - len *= 0.66; - // All recursive functions must have an exit condition!!!! - // Here, ours is when the length of the branch is 2 pixels or less - if (len > 2) { - pushMatrix(); // Save the current state of transformation (i.e. where are we now) - rotate(theta); // Rotate by theta - branch(len); // Ok, now call myself to draw two new branches!! - popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state - - // Repeat the same thing, only branch off to the "left" this time! - pushMatrix(); - rotate(-theta); - branch(len); - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_CantorLine/Figure_8_CantorLine.pde b/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_CantorLine/Figure_8_CantorLine.pde deleted file mode 100644 index c79f11cc4..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_CantorLine/Figure_8_CantorLine.pde +++ /dev/null @@ -1,20 +0,0 @@ - -void setup() { - size(800, 60); - background(255); -} - -void cantor(float x, float y, float len) { - line(x, y, x+len, y); - - y += 20; - line(x,y,x+len/3,y); // [bold] - line(x+len*2/3,y,x+len,y); // [bold] -} - -void draw() { - cantor(10, 20, width-20); - save("chapter08_12.png"); - noLoop(); -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_01_Recursion/NOC_8_01_Recursion.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_01_Recursion/NOC_8_01_Recursion.pde deleted file mode 100644 index 13b5ff2f2..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_01_Recursion/NOC_8_01_Recursion.pde +++ /dev/null @@ -1,26 +0,0 @@ -// Simple Recursion -// Daniel Shiffman -// Nature of Code, Chapter 8 - -void setup() { - size(800,200); - smooth(); -} - -void draw() { - background(255); - drawCircle(width/2,height/2,width); - noLoop(); -} - -// Very simple function that draws one circle -// and recursively calls itself -void drawCircle(int x, int y, float r) { - ellipse(x, y, r, r); - // Exit condition, stop when radius is too small - if(r > 2) { - r *= 0.75f; - // Call the function inside the function! (recursion!) - drawCircle(x, y, r); - } -} diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_02_Recursion/NOC_8_02_Recursion.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_02_Recursion/NOC_8_02_Recursion.pde deleted file mode 100644 index 1a460ecba..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_02_Recursion/NOC_8_02_Recursion.pde +++ /dev/null @@ -1,27 +0,0 @@ -// Simple Recursion -// Daniel Shiffman -// Nature of Code, Chapter 8 - -void setup() { - size(800,200); - smooth(); -} - -void draw() { - background(255); - drawCircle(width/2,height/2,400); - noLoop(); -} - -// Recursive function -void drawCircle(float x, float y, float r) { - stroke(0); - noFill(); - ellipse(x, y, r, r); - if(r > 2) { - // Now we draw two more circles, one to the left - // and one to the right - drawCircle(x + r/2, y, r/2); - drawCircle(x - r/2, y, r/2); - } -} diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_03_KochSimple/KochLine.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_03_KochSimple/KochLine.pde deleted file mode 100644 index a241afe1c..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_03_KochSimple/KochLine.pde +++ /dev/null @@ -1,71 +0,0 @@ -// Koch Curve -// Daniel Shiffman - -// A class to describe one line segment in the fractal -// Includes methods to calculate midPVectors along the line according to the Koch algorithm - -class KochLine { - - // Two PVectors, - // a is the "left" PVector and - // b is the "right PVector - PVector start; - PVector end; - - KochLine(PVector a, PVector b) { - start = a.get(); - end = b.get(); - } - - void display() { - stroke(0); - line(start.x, start.y, end.x, end.y); - } - - PVector kochA() { - return start.get(); - } - - - // This is easy, just 1/3 of the way - PVector kochB() { - PVector v = PVector.sub(end, start); - v.div(3); - v.add(start); - return v; - } - - // More complicated, have to use a little trig to figure out where this PVector is! - PVector kochC() { - PVector a = start.get(); // Start at the beginning - - PVector v = PVector.sub(end, start); - v.div(3); - a.add(v); // Move to point B - - rotate(v, -radians(60)); // Rotate 60 degrees - a.add(v); // Move to point C - - return a; - } - - // Easy, just 2/3 of the way - PVector kochD() { - PVector v = PVector.sub(end, start); - v.mult(2/3.0); - v.add(start); - return v; - } - - PVector kochE() { - return end.get(); - } -} - -public void rotate(PVector v, float theta) { - float xTemp = v.x; - // Might need to check for rounding errors like with angleBetween function? - v.x = v.x*PApplet.cos(theta) - v.y*PApplet.sin(theta); - v.y = xTemp*PApplet.sin(theta) + v.y*PApplet.cos(theta); -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_03_KochSimple/NOC_8_03_KochSimple.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_03_KochSimple/NOC_8_03_KochSimple.pde deleted file mode 100644 index 0bfb84f6c..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_03_KochSimple/NOC_8_03_KochSimple.pde +++ /dev/null @@ -1,50 +0,0 @@ - // Koch Curve -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Renders a simple fractal, the Koch snowflake -// Each recursive level drawn in sequence - -ArrayList lines ; // A list to keep track of all the lines - -void setup() { - size(600, 300); - background(255); - lines = new ArrayList(); - PVector start = new PVector(0, 200); - PVector end = new PVector(width, 200); - lines.add(new KochLine(start, end)); - - for (int i = 0; i < 5; i++) { - generate(); - } - - smooth(); -} - -void draw() { - background(255); - for (KochLine l : lines) { - l.display(); - } -} - -void generate() { - ArrayList next = new ArrayList(); // Create emtpy list - for (KochLine l : lines) { - // Calculate 5 koch PVectors (done for us by the line object) - PVector a = l.kochA(); - PVector b = l.kochB(); - PVector c = l.kochC(); - PVector d = l.kochD(); - PVector e = l.kochE(); - // Make line segments between all the PVectors and add them - next.add(new KochLine(a, b)); - next.add(new KochLine(b, c)); - next.add(new KochLine(c, d)); - next.add(new KochLine(d, e)); - } - lines = next; -} - - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_03_Recursion/NOC_8_03_Recursion.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_03_Recursion/NOC_8_03_Recursion.pde deleted file mode 100644 index 55672e39f..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_03_Recursion/NOC_8_03_Recursion.pde +++ /dev/null @@ -1,28 +0,0 @@ -// Simple Recursion -// Daniel Shiffman -// Nature of Code, Chapter 8 - -void setup() { - size(800, 200); - smooth(); -} - -void draw() { - background(255); - drawCircle(width/2, height/2, 400); - noLoop(); -} - -void drawCircle(float x, float y, float radius) { - noFill(); - stroke(0); - ellipse(x, y, radius, radius); - if (radius > 8) { - // Four circles! left right, up and down - drawCircle(x + radius/2, y, radius/2); - drawCircle(x - radius/2, y, radius/2); - drawCircle(x, y + radius/2, radius/2); - drawCircle(x, y - radius/2, radius/2); - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_04_CantorSet/NOC_8_04_CantorSet.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_04_CantorSet/NOC_8_04_CantorSet.pde deleted file mode 100644 index 8bced0afb..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_04_CantorSet/NOC_8_04_CantorSet.pde +++ /dev/null @@ -1,38 +0,0 @@ -// Cantor Set -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Renders a simple fractal, the Cantor Set - -void setup() { - size(800, 200); - background(255); - - // Call the recursive function - cantor(35, 0, 730); -} - -void draw() { - // No need to loop - noLoop(); -} - - -void cantor(float x, float y, float len) { - - float h = 30; - - // recursive exit condition - if (len >= 1) { - // Draw line (as rectangle to make it easier to see) - noStroke(); - fill(0); - rect(x, y, len, h/3); - // Go down to next y position - y += h; - // Draw 2 more lines 1/3rd the length (without the middle section) - cantor(x, y, len/3); - cantor(x+len*2/3, y, len/3); - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_04_Tree/NOC_8_04_Tree.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_04_Tree/NOC_8_04_Tree.pde deleted file mode 100644 index 2cf4d38da..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_04_Tree/NOC_8_04_Tree.pde +++ /dev/null @@ -1,52 +0,0 @@ -// Recursive Tree -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Renders a simple tree-like structure via recursion -// Branching angle calculated as a function of horizontal mouse location - -float theta; - -void setup() { - size(300, 200); - smooth(); -} - -void draw() { - background(255); - // Let's pick an angle 0 to 90 degrees based on the mouse position - theta = map(mouseX,0,width,0,PI/2); - - // Start the tree from the bottom of the screen - translate(width/2, height); - stroke(0); - branch(60); -} - -void branch(float len) { - // Each branch will be 2/3rds the size of the previous one - - float sw = map(len,2,120,1,10); - strokeWeight(sw); - - line(0, 0, 0, -len); - // Move to the end of that line - translate(0, -len); - - len *= 0.66; - // All recursive functions must have an exit condition!!!! - // Here, ours is when the length of the branch is 2 pixels or less - if (len > 2) { - pushMatrix(); // Save the current state of transformation (i.e. where are we now) - rotate(theta); // Rotate by theta - branch(len); // Ok, now call myself to draw two new branches!! - popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state - - // Repeat the same thing, only branch off to the "left" this time! - pushMatrix(); - rotate(-theta); - branch(len); - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/KochFractal.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/KochFractal.pde deleted file mode 100644 index c045cdd9d..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/KochFractal.pde +++ /dev/null @@ -1,70 +0,0 @@ -// Koch Curve -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// A class to manage the list of line segments in the snowflake pattern - -class KochFractal { - PVector start; // A PVector for the start - PVector end; // A PVector for the end - ArrayList lines; // A list to keep track of all the lines - int count; - - public KochFractal() { - start = new PVector(0,height-20); - end = new PVector(width,height-20); - lines = new ArrayList(); - restart(); - } - - void nextLevel() { - // For every line that is in the arraylist - // create 4 more lines in a new arraylist - lines = iterate(lines); - count++; - } - - void restart() { - count = 0; // Reset count - lines.clear(); // Empty the array list - lines.add(new KochLine(start,end)); // Add the initial line (from one end PVector to the other) - } - - int getCount() { - return count; - } - - // This is easy, just draw all the lines - void render() { - for(KochLine l : lines) { - l.display(); - } - } - - // This is where the **MAGIC** happens - // Step 1: Create an empty arraylist - // Step 2: For every line currently in the arraylist - // - calculate 4 line segments based on Koch algorithm - // - add all 4 line segments into the new arraylist - // Step 3: Return the new arraylist and it becomes the list of line segments for the structure - - // As we do this over and over again, each line gets broken into 4 lines, which gets broken into 4 lines, and so on. . . - ArrayList iterate(ArrayList before) { - ArrayList now = new ArrayList(); // Create emtpy list - for(KochLine l : before) { - // Calculate 5 koch PVectors (done for us by the line object) - PVector a = l.start(); - PVector b = l.kochleft(); - PVector c = l.kochmiddle(); - PVector d = l.kochright(); - PVector e = l.end(); - // Make line segments between all the PVectors and add them - now.add(new KochLine(a,b)); - now.add(new KochLine(b,c)); - now.add(new KochLine(c,d)); - now.add(new KochLine(d,e)); - } - return now; - } - -} diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/KochLine.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/KochLine.pde deleted file mode 100644 index 9f4f59871..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/KochLine.pde +++ /dev/null @@ -1,73 +0,0 @@ -// Koch Curve -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// A class to describe one line segment in the fractal -// Includes methods to calculate midPVectors along the line according to the Koch algorithm - -class KochLine { - - // Two PVectors, - // a is the "left" PVector and - // b is the "right PVector - PVector a; - PVector b; - - KochLine(PVector start, PVector end) { - a = start.get(); - b = end.get(); - } - - void display() { - stroke(0); - line(a.x, a.y, b.x, b.y); - } - - PVector start() { - return a.get(); - } - - PVector end() { - return b.get(); - } - - // This is easy, just 1/3 of the way - PVector kochleft() { - PVector v = PVector.sub(b, a); - v.div(3); - v.add(a); - return v; - } - - // More complicated, have to use a little trig to figure out where this PVector is! - PVector kochmiddle() { - PVector v = PVector.sub(b, a); - v.div(3); - - PVector p = a.get(); - p.add(v); - - rotate(v,-radians(60)); - p.add(v); - - return p; - } - - - // Easy, just 2/3 of the way - PVector kochright() { - PVector v = PVector.sub(a, b); - v.div(3); - v.add(b); - return v; - } -} - - public void rotate(PVector v, float theta) { - float xTemp = v.x; - // Might need to check for rounding errors like with angleBetween function? - v.x = v.x*cos(theta) - v.y*sin(theta); - v.y = xTemp*sin(theta) + v.y*cos(theta); - } - - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/NOC_8_05_Koch.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/NOC_8_05_Koch.pde deleted file mode 100644 index 8d6fe3a35..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/NOC_8_05_Koch.pde +++ /dev/null @@ -1,29 +0,0 @@ -// Koch Curve -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Renders a simple fractal, the Koch snowflake -// Each recursive level drawn in sequence - -KochFractal k; - -void setup() { - size(800,250); - background(255); - frameRate(1); // Animate slowly - k = new KochFractal(); - smooth(); -} - -void draw() { - background(255); - // Draws the snowflake! - k.render(); - // Iterate - k.nextLevel(); - // Let's not do it more than 5 times. . . - if (k.getCount() > 5) { - k.restart(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/sketch.properties b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/sketch.properties deleted file mode 100644 index 140966b6e..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/sketch.properties +++ /dev/null @@ -1,2 +0,0 @@ -mode.id=processing.mode.javascript.JavaScriptMode -mode=JavaScript diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_KochSimple/KochLine.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_KochSimple/KochLine.pde deleted file mode 100644 index a241afe1c..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_KochSimple/KochLine.pde +++ /dev/null @@ -1,71 +0,0 @@ -// Koch Curve -// Daniel Shiffman - -// A class to describe one line segment in the fractal -// Includes methods to calculate midPVectors along the line according to the Koch algorithm - -class KochLine { - - // Two PVectors, - // a is the "left" PVector and - // b is the "right PVector - PVector start; - PVector end; - - KochLine(PVector a, PVector b) { - start = a.get(); - end = b.get(); - } - - void display() { - stroke(0); - line(start.x, start.y, end.x, end.y); - } - - PVector kochA() { - return start.get(); - } - - - // This is easy, just 1/3 of the way - PVector kochB() { - PVector v = PVector.sub(end, start); - v.div(3); - v.add(start); - return v; - } - - // More complicated, have to use a little trig to figure out where this PVector is! - PVector kochC() { - PVector a = start.get(); // Start at the beginning - - PVector v = PVector.sub(end, start); - v.div(3); - a.add(v); // Move to point B - - rotate(v, -radians(60)); // Rotate 60 degrees - a.add(v); // Move to point C - - return a; - } - - // Easy, just 2/3 of the way - PVector kochD() { - PVector v = PVector.sub(end, start); - v.mult(2/3.0); - v.add(start); - return v; - } - - PVector kochE() { - return end.get(); - } -} - -public void rotate(PVector v, float theta) { - float xTemp = v.x; - // Might need to check for rounding errors like with angleBetween function? - v.x = v.x*PApplet.cos(theta) - v.y*PApplet.sin(theta); - v.y = xTemp*PApplet.sin(theta) + v.y*PApplet.cos(theta); -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_KochSimple/NOC_8_05_KochSimple.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_KochSimple/NOC_8_05_KochSimple.pde deleted file mode 100644 index e387ed5c4..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_KochSimple/NOC_8_05_KochSimple.pde +++ /dev/null @@ -1,50 +0,0 @@ - // Koch Curve -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Renders a simple fractal, the Koch snowflake -// Each recursive level drawn in sequence - -ArrayList lines ; // A list to keep track of all the lines - -void setup() { - size(383, 200); - background(255); - lines = new ArrayList(); - PVector start = new PVector(0, 150); - PVector end = new PVector(width, 150); - lines.add(new KochLine(start, end)); - - for (int i = 0; i < 5; i++) { - generate(); - } - - smooth(); -} - -void draw() { - background(255); - for (KochLine l : lines) { - l.display(); - } -} - -void generate() { - ArrayList next = new ArrayList(); // Create emtpy list - for (KochLine l : lines) { - // Calculate 5 koch PVectors (done for us by the line object) - PVector a = l.kochA(); - PVector b = l.kochB(); - PVector c = l.kochC(); - PVector d = l.kochD(); - PVector e = l.kochE(); - // Make line segments between all the PVectors and add them - next.add(new KochLine(a, b)); - next.add(new KochLine(b, c)); - next.add(new KochLine(c, d)); - next.add(new KochLine(d, e)); - } - lines = next; -} - - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_TreeStochastic/NOC_8_05_TreeStochastic.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_TreeStochastic/NOC_8_05_TreeStochastic.pde deleted file mode 100644 index 17acd3e21..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_TreeStochastic/NOC_8_05_TreeStochastic.pde +++ /dev/null @@ -1,63 +0,0 @@ -// Stochastic Tree -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Renders a simple tree-like structure via recursion -// Angles and number of branches are random - -void setup() { - size(600, 400); - smooth(); - newTree(); -} - -void draw() { - -} - -void mousePressed() { - newTree(); -} - -void newTree() { - background(255); - fill(0); - text("Click mouse to generate a new tree", 10, height-20); - - stroke(0); - // Start the tree from the bottom of the screen - translate(width/2, height); - // Start the recursive branching! - branch(120); -} - - - -void branch(float h) { - // thickness of the branch is mapped to its length - float sw = map(h, 2, 120, 1, 5); - strokeWeight(sw); - // Draw the actual branch - line(0, 0, 0, -h); - // Move along to end - translate(0, -h); - - // Each branch will be 2/3rds the size of the previous one - h *= 0.66f; - - // All recursive functions must have an exit condition!!!! - // Here, ours is when the length of the branch is 2 pixels or less - if (h > 2) { - // A random number of branches - int n = int(random(1, 4)); - for (int i = 0; i < n; i++) { - // Picking a random angle - float theta = random(-PI/2, PI/2); - pushMatrix(); // Save the current state of transformation (i.e. where are we now) - rotate(theta); // Rotate by theta - branch(h); // Ok, now call myself to branch again - popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_SimpleLSystem/NOC_8_06_SimpleLSystem.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_SimpleLSystem/NOC_8_06_SimpleLSystem.pde deleted file mode 100644 index 14e10da7e..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_SimpleLSystem/NOC_8_06_SimpleLSystem.pde +++ /dev/null @@ -1,47 +0,0 @@ -// L-System -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Just demonstrating working with L-System strings -// No drawing - -// Start with "A" -String current = "A"; -// Number of generations -int count = 0; - -void setup() { - size(200, 200); - println("Generation " + count + ": " + current); -} - -void draw() { - background(255); - fill(0); - text("Click mouse to generate", 10, height-20); - noLoop(); -} - -void mousePressed() { - // A new StringBuffer for the next generation - StringBuffer next = new StringBuffer(); - - // Look through the current String to replace according to L-System rules - for (int i = 0; i < current.length(); i++) { - char c = current.charAt(i); - if (c == 'A') { - // If we find A replace with AB - next.append("AB"); - } else if (c == 'B') { - // If we find B replace with A - next.append("A"); - } - } - // The current String is now the next one - current = next.toString(); - count++; - // Print to message console - println("Generation " + count + ": " + current); - println(count + " " + current.length()); -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_Tree/NOC_8_06_Tree.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_Tree/NOC_8_06_Tree.pde deleted file mode 100644 index 4b415662d..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_Tree/NOC_8_06_Tree.pde +++ /dev/null @@ -1,53 +0,0 @@ -// Recursive Tree -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Renders a simple tree-like structure via recursion -// Branching angle calculated as a function of horizontal mouse location - -float theta; - -void setup() { - size(250, 200); - smooth(); -} - -void draw() { - background(255); - // Let's pick an angle 0 to 90 degrees based on the mouse position - theta = map(mouseX,0,width,0,PI/2); - - // Start the tree from the bottom of the screen - translate(width/2, height); - stroke(0); - branch(60); -} - -void branch(float len) { - // Each branch will be 2/3rds the size of the previous one - - //float sw = map(len,2,120,1,10); - //strokeWeight(sw); - strokeWeight(2); - - line(0, 0, 0, -len); - // Move to the end of that line - translate(0, -len); - - len *= 0.66; - // All recursive functions must have an exit condition!!!! - // Here, ours is when the length of the branch is 2 pixels or less - if (len > 2) { - pushMatrix(); // Save the current state of transformation (i.e. where are we now) - rotate(theta); // Rotate by theta - branch(len); // Ok, now call myself to draw two new branches!! - popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state - - // Repeat the same thing, only branch off to the "left" this time! - pushMatrix(); - rotate(-theta); - branch(len); - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_Tree_static/NOC_8_06_Tree_static.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_Tree_static/NOC_8_06_Tree_static.pde deleted file mode 100644 index 92805fdb4..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_Tree_static/NOC_8_06_Tree_static.pde +++ /dev/null @@ -1,45 +0,0 @@ -// Recursive Tree -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Renders a simple tree-like structure via recursion -// Branching angle calculated as a function of horizontal mouse location - -void setup() { - size(800, 200); - smooth(); -} - -void draw() { - background(255); - // Start the tree from the bottom of the screen - translate(width/2, height); - stroke(0); - branch(60); - noLoop(); -} - -void branch(float len) { - strokeWeight(2); - - line(0, 0, 0, -len); - // Move to the end of that line - translate(0, -len); - - len *= 0.66; - // All recursive functions must have an exit condition!!!! - // Here, ours is when the length of the branch is 2 pixels or less - if (len > 2) { - pushMatrix(); // Save the current state of transformation (i.e. where are we now) - rotate(PI/5); // Rotate by theta - branch(len); // Ok, now call myself to draw two new branches!! - popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state - - // Repeat the same thing, only branch off to the "left" this time! - pushMatrix(); - rotate(-PI/5); - branch(len); - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_07_TreeStochastic/NOC_8_07_TreeStochastic.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_07_TreeStochastic/NOC_8_07_TreeStochastic.pde deleted file mode 100644 index 9b6af0bc7..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_07_TreeStochastic/NOC_8_07_TreeStochastic.pde +++ /dev/null @@ -1,66 +0,0 @@ -// Stochastic Tree -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Renders a simple tree-like structure via recursion -// Angles and number of branches are random - -void setup() { - size(800, 200); - smooth(); - newTree(); -} - -void draw() { - noLoop(); -} - -void mousePressed() { - newTree(); - redraw(); -} - -void newTree() { - background(255); - fill(0); - text("Click mouse to generate a new tree", 10, height-10); - - stroke(0); - pushMatrix(); - // Start the tree from the bottom of the screen - translate(width/2, height); - // Start the recursive branching! - branch(80); - popMatrix(); -} - - - -void branch(float h) { - // thickness of the branch is mapped to its length - float sw = map(h, 2, 120, 1, 5); - strokeWeight(sw); - // Draw the actual branch - line(0, 0, 0, -h); - // Move along to end - translate(0, -h); - - // Each branch will be 2/3rds the size of the previous one - h *= 0.66f; - - // All recursive functions must have an exit condition!!!! - // Here, ours is when the length of the branch is 2 pixels or less - if (h > 2) { - // A random number of branches - int n = int(random(1, 4)); - for (int i = 0; i < n; i++) { - // Picking a random angle - float theta = random(-PI/2, PI/2); - pushMatrix(); // Save the current state of transformation (i.e. where are we now) - rotate(theta); // Rotate by theta - branch(h); // Ok, now call myself to branch again - popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_07_TreeStochastic_angleonly/NOC_8_07_TreeStochastic_angleonly.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_07_TreeStochastic_angleonly/NOC_8_07_TreeStochastic_angleonly.pde deleted file mode 100644 index ef4b2a41b..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_07_TreeStochastic_angleonly/NOC_8_07_TreeStochastic_angleonly.pde +++ /dev/null @@ -1,59 +0,0 @@ -// Stochastic Tree -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Renders a simple tree-like structure via recursion -// Angles and number of branches are random - -void setup() { - size(800, 200); - smooth(); - newTree(); -} - -void draw() { - noLoop(); -} - -void mousePressed() { - pushMatrix(); - newTree(); - popMatrix(); - redraw(); -} - -void newTree() { - background(255); - fill(0); - text("Click mouse to generate a new tree", 10, height-10); - - stroke(0); - // Start the tree from the bottom of the screen - translate(width/2, height); - // Start the recursive branching! - branch(60); -} - - - -void branch(float h) { - // thickness of the branch is mapped to its length - float sw = map(h, 2, 120, 1, 5); - strokeWeight(sw); - float theta = random(0,PI/3); - - line(0, 0, 0, -h); - translate(0, -h); - h *= 0.66; - if (h > 2) { - pushMatrix(); - rotate(theta); - branch(h); - popMatrix(); - pushMatrix(); - rotate(-theta); - branch(h); - popMatrix(); - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_08_SimpleLSystem/NOC_8_08_SimpleLSystem.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_08_SimpleLSystem/NOC_8_08_SimpleLSystem.pde deleted file mode 100644 index da65cab34..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_08_SimpleLSystem/NOC_8_08_SimpleLSystem.pde +++ /dev/null @@ -1,47 +0,0 @@ -// L-System -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Just demonstrating working with L-System strings -// No drawing - -// Start with "A" -String current = "A"; -// Number of generations -int count = 0; - -void setup() { - size(800, 200); - println("Generation " + count + ": " + current); -} - -void draw() { - background(255); - fill(0); - text("Click mouse to generate", 10, height-20); - noLoop(); -} - -void mousePressed() { - // A new StringBuffer for the next generation - StringBuffer next = new StringBuffer(); - - // Look through the current String to replace according to L-System rules - for (int i = 0; i < current.length(); i++) { - char c = current.charAt(i); - if (c == 'A') { - // If we find A replace with AB - next.append("AB"); - } else if (c == 'B') { - // If we find B replace with A - next.append("A"); - } - } - // The current String is now the next one - current = next.toString(); - count++; - // Print to message console - println("Generation " + count + ": " + current); - //println(count + " " + current.length()); -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/LSystem.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/LSystem.pde deleted file mode 100644 index 3d381bd82..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/LSystem.pde +++ /dev/null @@ -1,67 +0,0 @@ -/* Daniel Shiffman */ -/* Programming from A to Z */ -/* Spring 2006 */ -/* http://www.shiffman.net */ -/* daniel.shiffman@nyu.edu */ - -/* LSystem Class */ - -// An LSystem has a starting sentence -// An a ruleset -// Each generation recursively replaces characteres in the sentence -// Based on the rulset - -class LSystem { - - String sentence; // The sentence (a String) - Rule[] ruleset; // The ruleset (an array of Rule objects) - int generation; // Keeping track of the generation # - - // Construct an LSystem with a startin sentence and a ruleset - LSystem(String axiom, Rule[] r) { - sentence = axiom; - ruleset = r; - generation = 0; - } - - // Generate the next generation - void generate() { - // An empty StringBuffer that we will fill - StringBuffer nextgen = new StringBuffer(); - // For every character in the sentence - for (int i = 0; i < sentence.length(); i++) { - // What is the character - char curr = sentence.charAt(i); - // We will replace it with itself unless it matches one of our rules - String replace = "" + curr; - // Check every rule - for (int j = 0; j < ruleset.length; j++) { - char a = ruleset[j].getA(); - // if we match the Rule, get the replacement String out of the Rule - if (a == curr) { - replace = ruleset[j].getB(); - break; - } - } - // Append replacement String - nextgen.append(replace); - } - // Replace sentence - sentence = nextgen.toString(); - // Increment generation - generation++; - } - - String getSentence() { - return sentence; - } - - int getGeneration() { - return generation; - } - - -} - - - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/NOC_8_09_LSystem.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/NOC_8_09_LSystem.pde deleted file mode 100644 index 9d745a120..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/NOC_8_09_LSystem.pde +++ /dev/null @@ -1,63 +0,0 @@ -/* Daniel Shiffman */ -/* The Nature of Code */ -/* http://www.shiffman.net */ -/* daniel.shiffman@nyu.edu */ - -LSystem lsys; -Turtle turtle; - -void setup() { - size(800, 200); - /* - // Create an empty ruleset - Rule[] ruleset = new Rule[2]; - // Fill with two rules (These are rules for the Sierpinksi Gasket Triangle) - ruleset[0] = new Rule('F',"F--F--F--G"); - ruleset[1] = new Rule('G',"GG"); - // Create LSystem with axiom and ruleset - lsys = new LSystem("F--F--F",ruleset); - turtle = new Turtle(lsys.getSentence(),width*2,TWO_PI/3); - */ - - /*Rule[] ruleset = new Rule[1]; - //ruleset[0] = new Rule('F',"F[F]-F+F[--F]+F-F"); - ruleset[0] = new Rule['F',"FF+[+F-F-F]-[-F+F+F]"); - lsys = new LSystem("F-F-F-F",ruleset); - turtle = new Turtle(lsys.getSentence(),width-1,PI/2); - */ - - Rule[] ruleset = new Rule[1]; - ruleset[0] = new Rule('F', "FF+[+F-F-F]-[-F+F+F]"); - lsys = new LSystem("F", ruleset); - turtle = new Turtle(lsys.getSentence(), height/3, radians(25)); - - - - smooth(); -} - -void draw() { - background(255); - fill(0); - //text("Click mouse to generate", 10, height-10); - - translate(width/2, height); - rotate(-PI/2); - turtle.render(); - noLoop(); -} - -int counter = 0; - -void mousePressed() { - if (counter < 5) { - pushMatrix(); - lsys.generate(); - turtle.setToDo(lsys.getSentence()); - turtle.changeLen(0.5); - popMatrix(); - redraw(); - counter++; - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/Rule.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/Rule.pde deleted file mode 100644 index 43142063e..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/Rule.pde +++ /dev/null @@ -1,26 +0,0 @@ -/* Daniel Shiffman */ -/* http://www.shiffman.net */ - -/* A Class to describe an - LSystem Rule */ - -class Rule { - char a; - String b; - - Rule(char a_, String b_) { - a = a_; - b = b_; - } - - char getA() { - return a; - } - - String getB() { - return b; - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/Turtle.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/Turtle.pde deleted file mode 100644 index 0193562e2..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/Turtle.pde +++ /dev/null @@ -1,53 +0,0 @@ -/* Daniel Shiffman */ -/* http://www.shiffman.net */ - -class Turtle { - - String todo; - float len; - float theta; - - Turtle(String s, float l, float t) { - todo = s; - len = l; - theta = t; - } - - void render() { - stroke(0,175); - for (int i = 0; i < todo.length(); i++) { - char c = todo.charAt(i); - if (c == 'F' || c == 'G') { - line(0,0,len,0); - translate(len,0); - } - else if (c == '+') { - rotate(theta); - } - else if (c == '-') { - rotate(-theta); - } - else if (c == '[') { - pushMatrix(); - } - else if (c == ']') { - popMatrix(); - } - } - } - - void setLen(float l) { - len = l; - } - - void changeLen(float percent) { - len *= percent; - } - - void setToDo(String s) { - todo = s; - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/sketch.properties b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/sketch.properties deleted file mode 100644 index b3cbe600e..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/sketch.properties +++ /dev/null @@ -1,2 +0,0 @@ -mode.id=processing.mode.java.JavaMode -mode=Standard diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Tree2/Branch.pde b/java/examples/Books/Nature of Code/chp8_fractals/Tree2/Branch.pde deleted file mode 100644 index 67f073dcf..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/Tree2/Branch.pde +++ /dev/null @@ -1,59 +0,0 @@ -// Recursive Tree (w/ ArrayList) -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// A class for one branch in the system - -class Branch { - // Each has a location, velocity, and timer - // We could implement this same idea with different data - PVector loc; - PVector vel; - float timer; - float timerstart; - - Branch(PVector l, PVector v, float n) { - loc = l.get(); - vel = v.get(); - timerstart = n; - timer = timerstart; - } - - // Move location - void update() { - loc.add(vel); - } - - // Draw a dot at location - void render() { - fill(0); - noStroke(); - ellipseMode(CENTER); - ellipse(loc.x,loc.y,2,2); - } - - // Did the timer run out? - boolean timeToBranch() { - timer--; - if (timer < 0) { - return true; - } else { - return false; - } - } - - // Create a new branch at the current location, but change direction by a given angle - Branch branch(float angle) { - // What is my current heading - float theta = vel.heading2D(); - // What is my current speed - float mag = vel.mag(); - // Turn me - theta += radians(angle); - // Look, polar coordinates to cartesian!! - PVector newvel = new PVector(mag*cos(theta),mag*sin(theta)); - // Return a new Branch - return new Branch(loc,newvel,timerstart*0.66f); - } - -} diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Tree2/Tree2.pde b/java/examples/Books/Nature of Code/chp8_fractals/Tree2/Tree2.pde deleted file mode 100644 index 3d558d0d9..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/Tree2/Tree2.pde +++ /dev/null @@ -1,47 +0,0 @@ -// Recursive Tree (w/ ArrayList) -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Recursive branching "structure" without an explicitly recursive function -// Instead we have an ArrayList to hold onto N number of elements -// For every element in the ArrayList, we add 2 more elements, etc. (this is the recursion) - -// An arraylist that will keep track of all current branches -ArrayList tree; - -void setup() { - size(200,200); - background(255); - smooth(); - - // Setup the arraylist and add one branch to it - tree = new ArrayList(); - // A branch has a starting location, a starting "velocity", and a starting "timer" - Branch b = new Branch(new PVector(width/2,height),new PVector(0,-0.5),100); - // Add to arraylist - tree.add(b); -} - -void draw() { - // Try erasing the background to see how it works - // background(255); - - // Let's stop when the arraylist gets too big - if (tree.size() < 1024) { - // For every branch in the arraylist - for (int i = tree.size()-1; i >= 0; i--) { - // Get the branch, update and draw it - Branch b = tree.get(i); - b.update(); - b.render(); - // If it's ready to split - if (b.timeToBranch()) { - tree.remove(i); // Delete it - tree.add(b.branch( 30)); // Add one going right - tree.add(b.branch(-25)); // Add one going left - } - } - } -} - - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Tree3/Branch.pde b/java/examples/Books/Nature of Code/chp8_fractals/Tree3/Branch.pde deleted file mode 100644 index a6921813b..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/Tree3/Branch.pde +++ /dev/null @@ -1,66 +0,0 @@ -// Recursive Tree (w/ ArrayList) -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// A class for one branch in the system - -class Branch { - // Each has a location, velocity, and timer - // We could implement this same idea with different data - PVector start; - PVector end; - PVector vel; - float timer; - float timerstart; - - boolean growing = true; - - Branch(PVector l, PVector v, float n) { - start = l.get(); - end = l.get(); - vel = v.get(); - timerstart = n; - timer = timerstart; - } - - // Move location - void update() { - if (growing) { - end.add(vel); - } - } - - // Draw a dot at location - void render() { - stroke(0); - line(start.x,start.y,end.x,end.y); - } - - // Did the timer run out? - boolean timeToBranch() { - timer--; - if (timer < 0 && growing) { - growing = false; - return true; - } - else { - return false; - } - } - - // Create a new branch at the current location, but change direction by a given angle - Branch branch(float angle) { - // What is my current heading - float theta = vel.heading2D(); - // What is my current speed - float mag = vel.mag(); - // Turn me - theta += radians(angle); - // Look, polar coordinates to cartesian!! - PVector newvel = new PVector(mag*cos(theta),mag*sin(theta)); - // Return a new Branch - return new Branch(end,newvel,timerstart*0.66f); - } - -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Tree3/Leaf.pde b/java/examples/Books/Nature of Code/chp8_fractals/Tree3/Leaf.pde deleted file mode 100644 index 145e0d1ce..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/Tree3/Leaf.pde +++ /dev/null @@ -1,21 +0,0 @@ -// Recursive Tree (w/ ArrayList) -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// A class for a leaf that gets placed at the end of -// the last branches - -class Leaf { - PVector loc; - - Leaf(PVector l) { - loc = l.get(); - } - - void display() { - noStroke(); - fill(50,100); - ellipse(loc.x,loc.y,4,4); - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Tree3/Tree3.pde b/java/examples/Books/Nature of Code/chp8_fractals/Tree3/Tree3.pde deleted file mode 100644 index 612650d72..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/Tree3/Tree3.pde +++ /dev/null @@ -1,58 +0,0 @@ -// Recursive Tree (w/ ArrayList) -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Recursive branching "structure" without an explicitly recursive function -// Instead we have an ArrayList to hold onto N number of elements -// For every element in the ArrayList, we add 2 more elements, etc. (this is the recursion) - -// An arraylist that will keep track of all current branches -ArrayList tree; -ArrayList leaves; - -void setup() { - size(200,200); - background(255); - smooth(); - - // Setup the arraylist and add one branch to it - tree = new ArrayList(); - leaves = new ArrayList(); - // A branch has a starting location, a starting "velocity", and a starting "timer" - Branch b = new Branch(new PVector(width/2,height),new PVector(0,-0.5),100); - // Add to arraylist - tree.add(b); -} - -void draw() { - background(255); - - // Let's stop when the arraylist gets too big - // For every branch in the arraylist - for (int i = tree.size()-1; i >= 0; i--) { - // Get the branch, update and draw it - Branch b = tree.get(i); - b.update(); - b.render(); - // If it's ready to split - if (b.timeToBranch()) { - if (tree.size() < 1024) { - //tree.remove(i); // Delete it - tree.add(b.branch( 30)); // Add one going right - tree.add(b.branch(-25)); // Add one going left - } - else { - leaves.add(new Leaf(b.end)); - } - } - } - - for (Leaf leaf : leaves) { - leaf.display(); - } - -} - - - - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/TreeStochasticNoise/TreeStochasticNoise.pde b/java/examples/Books/Nature of Code/chp8_fractals/TreeStochasticNoise/TreeStochasticNoise.pde deleted file mode 100644 index 2a5544943..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/TreeStochasticNoise/TreeStochasticNoise.pde +++ /dev/null @@ -1,71 +0,0 @@ -// Stochastic Tree with angles fluctuating with Perlin noise -// Daniel Shiffman -// Nature of Code, Chapter 8 - -// Perlin noise offset -float yoff = 0; -// Random seed to control randomness while drawing the tree -int seed = 5; - - -void setup() { - size(800, 200); - smooth(); -} - -void draw() { - background(255); - fill(0); - //text("Click mouse to generate a new tree", 10, height-20); - - stroke(0); - // Start the tree from the bottom of the screen - translate(width/2, height); - // Move alogn through noise - yoff += 0.005; - randomSeed(seed); - // Start the recursive branching! - branch(60, 0); -} - - -void mousePressed() { - // New tree starts with new noise offset and new random seed - yoff = random(1000); - seed = millis(); -} - - -void branch(float h, float xoff) { - // thickness of the branch is mapped to its length - float sw = map(h, 2, 100, 1, 5); - strokeWeight(sw); - // Draw the branch - line(0, 0, 0, -h); - // Move along to end - translate(0, -h); - - // Each branch will be 2/3rds the size of the previous one - h *= 0.7f; - - // Move along through noise space - xoff += 0.1; - - if (h > 4) { - // Random number of branches - int n = int(random(0, 5)); - for (int i = 0; i < n; i++) { - - // Here the angle is controlled by perlin noise - // This is a totally arbitrary way to do it, try others! - float theta = map(noise(xoff+i, yoff), 0, 1, -PI/3, PI/3); - if (n%2==0) theta *= -1; - - pushMatrix(); // Save the current state of transformation (i.e. where are we now) - rotate(theta); // Rotate by theta - branch(h, xoff); // Ok, now call myself to branch again - popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/TreeStochasticNoise/sketch.properties b/java/examples/Books/Nature of Code/chp8_fractals/TreeStochasticNoise/sketch.properties deleted file mode 100644 index 28faa5897..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/TreeStochasticNoise/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=Standard diff --git a/java/examples/Books/Nature of Code/chp8_fractals/lsys/LSystem.pde b/java/examples/Books/Nature of Code/chp8_fractals/lsys/LSystem.pde deleted file mode 100644 index 3d381bd82..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/lsys/LSystem.pde +++ /dev/null @@ -1,67 +0,0 @@ -/* Daniel Shiffman */ -/* Programming from A to Z */ -/* Spring 2006 */ -/* http://www.shiffman.net */ -/* daniel.shiffman@nyu.edu */ - -/* LSystem Class */ - -// An LSystem has a starting sentence -// An a ruleset -// Each generation recursively replaces characteres in the sentence -// Based on the rulset - -class LSystem { - - String sentence; // The sentence (a String) - Rule[] ruleset; // The ruleset (an array of Rule objects) - int generation; // Keeping track of the generation # - - // Construct an LSystem with a startin sentence and a ruleset - LSystem(String axiom, Rule[] r) { - sentence = axiom; - ruleset = r; - generation = 0; - } - - // Generate the next generation - void generate() { - // An empty StringBuffer that we will fill - StringBuffer nextgen = new StringBuffer(); - // For every character in the sentence - for (int i = 0; i < sentence.length(); i++) { - // What is the character - char curr = sentence.charAt(i); - // We will replace it with itself unless it matches one of our rules - String replace = "" + curr; - // Check every rule - for (int j = 0; j < ruleset.length; j++) { - char a = ruleset[j].getA(); - // if we match the Rule, get the replacement String out of the Rule - if (a == curr) { - replace = ruleset[j].getB(); - break; - } - } - // Append replacement String - nextgen.append(replace); - } - // Replace sentence - sentence = nextgen.toString(); - // Increment generation - generation++; - } - - String getSentence() { - return sentence; - } - - int getGeneration() { - return generation; - } - - -} - - - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/lsys/Rule.pde b/java/examples/Books/Nature of Code/chp8_fractals/lsys/Rule.pde deleted file mode 100644 index 43142063e..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/lsys/Rule.pde +++ /dev/null @@ -1,26 +0,0 @@ -/* Daniel Shiffman */ -/* http://www.shiffman.net */ - -/* A Class to describe an - LSystem Rule */ - -class Rule { - char a; - String b; - - Rule(char a_, String b_) { - a = a_; - b = b_; - } - - char getA() { - return a; - } - - String getB() { - return b; - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/lsys/Turtle.pde b/java/examples/Books/Nature of Code/chp8_fractals/lsys/Turtle.pde deleted file mode 100644 index ac0ffa8d9..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/lsys/Turtle.pde +++ /dev/null @@ -1,53 +0,0 @@ -/* Daniel Shiffman */ -/* http://www.shiffman.net */ - -class Turtle { - - String todo; - float len; - float theta; - - Turtle(String s, float l, float t) { - todo = s; - len = l; - theta = t; - } - - void render() { - stroke(0); - for (int i = 0; i < todo.length(); i++) { - char c = todo.charAt(i); - if (c == 'F' || c == 'G') { - line(0,0,len,0); - translate(len,0); - } - else if (c == '+') { - rotate(theta); - } - else if (c == '-') { - rotate(-theta); - } - else if (c == '[') { - pushMatrix(); - } - else if (c == ']') { - popMatrix(); - } - } - } - - void setLen(float l) { - len = l; - } - - void changeLen(float percent) { - len *= percent; - } - - void setToDo(String s) { - todo = s; - } - -} - - diff --git a/java/examples/Books/Nature of Code/chp8_fractals/lsys/lsys.pde b/java/examples/Books/Nature of Code/chp8_fractals/lsys/lsys.pde deleted file mode 100644 index 8ed2d08bd..000000000 --- a/java/examples/Books/Nature of Code/chp8_fractals/lsys/lsys.pde +++ /dev/null @@ -1,56 +0,0 @@ -/* Daniel Shiffman */ -/* The Nature of Code */ -/* http://www.shiffman.net */ -/* daniel.shiffman@nyu.edu */ - -LSystem lsys; -Turtle turtle; - -void setup() { - size(600, 600); - /* - // Create an empty ruleset - Rule[] ruleset = new Rule[2]; - // Fill with two rules (These are rules for the Sierpinksi Gasket Triangle) - ruleset[0] = new Rule('F',"F--F--F--G"); - ruleset[1] = new Rule('G',"GG"); - // Create LSystem with axiom and ruleset - lsys = new LSystem("F--F--F",ruleset); - turtle = new Turtle(lsys.getSentence(),width*2,TWO_PI/3); - */ - - /*Rule[] ruleset = new Rule[1]; - //ruleset[0] = new Rule('F',"F[F]-F+F[--F]+F-F"); - ruleset[0] = new Rule['F',"FF+[+F-F-F]-[-F+F+F]"); - lsys = new LSystem("F-F-F-F",ruleset); - turtle = new Turtle(lsys.getSentence(),width-1,PI/2); - */ - - Rule[] ruleset = new Rule[1]; - ruleset[0] = new Rule('F', "FF+[+F-F-F]-[-F+F+F]"); - lsys = new LSystem("F", ruleset); - turtle = new Turtle(lsys.getSentence(), width/4, radians(25)); - - - - smooth(); -} - -void draw() { - background(255); - fill(0); - text("Click mouse to generate", 10, height-20); - - translate(width/2, height); - rotate(-PI/2); - turtle.render(); - noLoop(); -} - -void mousePressed() { - lsys.generate(); - turtle.setToDo(lsys.getSentence()); - turtle.changeLen(0.5); - redraw(); -} - diff --git a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/DNA.pde b/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/DNA.pde deleted file mode 100644 index 9e7ce4bc8..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/DNA.pde +++ /dev/null @@ -1,51 +0,0 @@ -// Pathfinding w/ Genetic Algorithms -// Daniel Shiffman - -// DNA is an array of vectors - -class DNA { - - // The genetic sequence - PVector[] genes; - - // Constructor (makes a DNA of random PVectors) - DNA(int num) { - genes = new PVector[num]; - for (int i = 0; i < genes.length; i++) { - float angle = random(TWO_PI); - genes[i] = new PVector(cos(angle),sin(angle)); - } - } - - // Constructor #2, creates the instance based on an existing array - DNA(PVector[] newgenes) { - // We could make a copy if necessary - // genes = (PVector []) newgenes.clone(); - genes = newgenes; - } - - // CROSSOVER - // Creates new DNA sequence from two (this & and a partner) - DNA crossover(DNA partner) { - PVector[] child = new PVector[genes.length]; - // Pick a midpoint - int crossover = int(random(genes.length)); - // Take "half" from one and "half" from the other - for (int i = 0; i < genes.length; i++) { - if (i > crossover) child[i] = genes[i]; - else child[i] = partner.genes[i]; - } - DNA newgenes = new DNA(child); - return newgenes; - } - - // Based on a mutation probability, picks a new random Vector - void mutate(float m) { - for (int i = 0; i < genes.length; i++) { - if (random(1) < m) { - float angle = random(TWO_PI); - genes[i] = new PVector(cos(angle),sin(angle)); - } - } - } -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/EvolveFlowField.pde b/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/EvolveFlowField.pde deleted file mode 100644 index ce43c9f67..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/EvolveFlowField.pde +++ /dev/null @@ -1,100 +0,0 @@ -// Pathfinding Flowfield w/ Genetic Algorithms -// Daniel Shiffman - -// This example produces an obstacle course with a start and finish -// Virtual "creatures" are rewarded for making it closer to the finish - -// Each creature's DNA is a "flowfield" of PVectors that -// determine steering vectors for each cell on the screen - -int gridscale = 24; // Scale of grid is 1/24 of screen size - -// DNA needs one vector for every spot on the grid -// (it's like a pixel array, but with vectors instead of colors) -int dnasize; - -int lifetime; // How long should each generation live - -// Global maxforce and maxspeed (hmmm, could make this part of DNA??) -float maxspeed = 4.0; -float maxforce = 1.0; - -Population population; // Population -int lifecycle; // Timer for cycle of generation -int recordtime; // Fastest time to target -Obstacle target; // Target location -Obstacle start; // Start location -int diam = 24; // Size of target - -ArrayList obstacles; //an array list to keep track of all the obstacles! - -void setup() { - size(640,480); - smooth(); - - dnasize = (width / gridscale) * (height / gridscale); - lifetime = width/2; - - // Initialize variables - lifecycle = 0; - recordtime = lifetime; - target = new Obstacle(width-diam-diam/2,height/2-diam/2,diam,diam); - start = new Obstacle(diam/2,height/2-diam/2,diam,diam); - - // Create a population with a mutation rate, and population max - int popmax = 1000; - float mutationRate = 0.05; - population = new Population(mutationRate,popmax); - - // Create the obstacle course - obstacles = new ArrayList(); - obstacles.add(new Obstacle(width/4,40,10,height-80)); - obstacles.add(new Obstacle(width/2,0,10,height/2-10)); - obstacles.add(new Obstacle(width/2,height-height/2+10,10,height/2-10)); - obstacles.add(new Obstacle(2*width/3,height/2-height/8,10,height/4)); -} - -void draw() { - background(255); - - // Draw the start and target locations - start.display(); - target.display(); - - // Draw the obstacles - for (Obstacle obs : obstacles) { - obs.display(); - } - - - // If the generation hasn't ended yet - if (lifecycle < lifetime) { - population.live(obstacles); - if ((population.targetReached()) && (lifecycle < recordtime)) { - recordtime = lifecycle; - } - lifecycle++; - // Otherwise a new generation - } else { - lifecycle = 0; - population.calcFitness(); - population.naturalSelection(); - population.generate(); - } - - // Display some info - textAlign(RIGHT); - fill(0); - text("Generation #:" + population.getGenerations(),width-10,18); - text("Cycles left:" + ((lifetime-lifecycle)/10),width-10,36); - text("Record cycles: " + recordtime,width-10,54); - -} - -// Move the target if the mouse is pressed -// System will adapt to new target -void mousePressed() { - target = new Obstacle(mouseX,mouseY,diam,diam); - recordtime = lifetime; -} - diff --git a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Obstacle.pde b/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Obstacle.pde deleted file mode 100644 index 250edc4cd..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Obstacle.pde +++ /dev/null @@ -1,34 +0,0 @@ -// Pathfinding w/ Genetic Algorithms -// Daniel Shiffman - -// A class for an obstacle, just a simple rectangle that is drawn -// and can check if a creature touches it - -// Also using this class for starting point and target location - -import java.awt.Rectangle; - -class Obstacle { - - Rectangle r; - - Obstacle(int x, int y, int w, int h) { - r = new Rectangle(x,y,w,h); - } - - void display() { - stroke(0); - fill(175); - rectMode(CORNER); - rect(r.x,r.y,r.width,r.height); - } - - boolean contains(PVector spot) { - if (r.contains((int)spot.x,(int)spot.y)) { - return true; - } else { - return false; - } - } - -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Population.pde b/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Population.pde deleted file mode 100644 index a5b283ea6..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Population.pde +++ /dev/null @@ -1,115 +0,0 @@ -// Pathfinding w/ Genetic Algorithms -// Daniel Shiffman - -// A class to describe a population of "creatures" - -class Population { - - float mutationRate; // Mutation rate - Rocket[] population; // Array to hold the current population - ArrayList darwin; // ArrayList which we will use for our "mating pool" - int generations; // Number of generations - - int order; // Keep track of the order of creature's finishing the maze - - // Initialize the population - Population(float m, int num) { - mutationRate = m; - population = new Rocket[num]; - darwin = new ArrayList(); - generations = 0; - //make a new set of creatures - for (int i = 0; i < population.length; i++) { - PVector location = new PVector(start.r.x+start.r.width/2,start.r.y+start.r.height/2); - population[i] = new Rocket(location, new DNA(dnasize)); - } - order = 1; // The first one to finish will be #1 - } - - void live (ArrayList o) { - // For every creature - for (int i = 0; i < population.length; i++) { - // If it finishes, mark it down as done! - if ((population[i].finished()) && (!population[i].stopped())) { - population[i].setFinish(order); - order++; - } - // Run it - population[i].run(o); - } - } - - // Did anything finish? - boolean targetReached() { - for (int i = 0; i < population.length; i++) { - if (population[i].finished()) return true; - } - return false; - } - - // Calculate fitness for each creature - void calcFitness() { - for (int i = 0; i < population.length; i++) { - population[i].calcFitness(); - } - order = 1; // Hmmm, awkward place for this, we have to reset this for the next generation - } - - // Generate a mating pool - void naturalSelection() { - // Clear the ArrayList - darwin.clear(); - - // Calculate total fitness of whole population - float totalFitness = getTotalFitness(); - - // Calculate normalized fitness for each member of the population - // Based on normalized fitness, each member will get added to the mating pool a certain number of times a la roulette wheel - // A higher fitness = more entries to mating pool = more likely to be picked as a parent - // A lower fitness = fewer entries to mating pool = less likely to be picked as a parent - for (int i = 0; i < population.length; i++) { - float fitnessNormal = population[i].getFitness() / totalFitness; - int n = (int) (fitnessNormal * 50000); // Arbitrary multiplier, consider mapping fix - for (int j = 0; j < n; j++) { - darwin.add(population[i]); - } - } - } - - // Making the next generation - void generate() { - // Refill the population with children from the mating pool - for (int i = 0; i < population.length; i++) { - int m = int(random(darwin.size())); - int d = int(random(darwin.size())); - // Pick two parents - Rocket mom = darwin.get(m); - Rocket dad = darwin.get(d); - // Get their genes - DNA momgenes = mom.getDNA(); - DNA dadgenes = dad.getDNA(); - // Mate their genes - DNA child = momgenes.crossover(dadgenes); - // Mutate their genes - child.mutate(mutationRate); - // Fill the new population with the new child - PVector location = new PVector(start.r.x+start.r.width/2,start.r.y+start.r.height/2); - population[i] = new Rocket(location, child); - } - generations++; - } - - int getGenerations() { - return generations; - } - - //compute total fitness for the population - float getTotalFitness() { - float total = 0; - for (int i = 0; i < population.length; i++) { - total += population[i].getFitness(); - } - return total; - } - -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Rocket.pde b/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Rocket.pde deleted file mode 100644 index 1327ee928..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Rocket.pde +++ /dev/null @@ -1,149 +0,0 @@ -// Pathfinding w/ Genetic Algorithms -// Daniel Shiffman - -// Rocket class -- this is just like our Boid / Particle class -// the only difference is that it has DNA & fitness - -class Rocket { - - // All of our physics stuff - PVector location; - PVector velocity; - PVector acceleration; - float r; - float recordDist; - - float fitness; - DNA dna; - - boolean stopped; // Am I stuck? - int finish; // What was my finish? (first, second, etc. . . ) - - //constructor - Rocket(PVector l, DNA dna_) { - acceleration = new PVector(); - velocity = new PVector(); - location = l.get(); - r = 2; - dna = dna_; - stopped = false; - finish = 100000; // Some high number to begin with - recordDist = width; - } - - // FITNESS FUNCTION - // distance = distance from target - // finish = what order did i finish (first, second, etc. . .) - // f(distance,finish) = (1.0f / finish^1.5) * (1.0f / distance^6); - // a lower finish is rewarded (exponentially) and/or shorter distance to target (exponetially) - void calcFitness() { - float d = recordDist; - if (d < diam/2) { - d = 1.0; - } - // Reward finishing faster and getting closer - fitness = (1.0f / pow(finish,1.5)) * (1 / (pow(d,6))); - } - - void setFinish(int f) { - finish = f; - } - - // Run in relation to all the obstacles - // If I'm stuck, don't bother updating or checking for intersection - void run(ArrayList o) { - if (!stopped) { - update(); - // If I hit an edge or an obstacle - if ((borders()) || (obstacles(o))) { - stopped = true; - } - } - // Draw me! - display(); - } - - // Did I hit an edge? - boolean borders() { - if ((location.x < 0) || (location.y < 0) || (location.x > width) || (location.y > height)) { - return true; - } else { - return false; - } - } - - // Did I make it to the target? - boolean finished() { - float d = dist(location.x,location.y,target.r.x,target.r.y); - if (d < recordDist) recordDist = d; - if (target.contains(location)) { - stopped = true; - return true; - } - return false; - } - - // Did I hit an obstacle? - boolean obstacles(ArrayList o) { - for (Obstacle obs : o) { - if (obs.contains(location)) { - return true; - } - } - return false; - } - - void update() { - if (!finished()) { - // Where are we? Our location will tell us what steering vector to look up in our DNA; - int x = (int) location.x/gridscale; - int y = (int) location.y/gridscale; - x = constrain(x,0,width/gridscale-1); // Make sure we are not off the edge - y = constrain(y,0,height/gridscale-1); // Make sure we are not off the edge - - // Get the steering vector out of our genes in the right spot - // We could do (desired - velocity) to be more in line with the Reynolds flow field following - acceleration.add(dna.genes[x+y*width/gridscale]); - - // This is all the same stuff we've done before - acceleration.mult(maxforce); - velocity.add(acceleration); - velocity.limit(maxspeed); - location.add(velocity); - acceleration.mult(0); - } - } - - void display() { - //fill(0,150); - //stroke(0); - //ellipse(location.x,location.y,r,r); - float theta = velocity.heading2D() + PI/2; - fill(200,100); - stroke(0); - pushMatrix(); - translate(location.x,location.y); - rotate(theta); - beginShape(TRIANGLES); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(); - popMatrix(); - - - } - - float getFitness() { - return fitness; - } - - DNA getDNA() { - return dna; - } - - boolean stopped() { - return stopped; - } - -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/DNA.pde b/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/DNA.pde deleted file mode 100644 index 516c3f98d..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/DNA.pde +++ /dev/null @@ -1,67 +0,0 @@ -// Genetic Algorithm, Evolving Shakespeare -// Daniel Shiffman - -// A class to describe a psuedo-DNA, i.e. genotype -// Here, a virtual organism's DNA is an array of character. -// Functionality: -// -- convert DNA into a string -// -- calculate DNA's "fitness" -// -- mate DNA with another set of DNA -// -- mutate DNA - - -class DNA { - - // The genetic sequence - char[] genes; - - float fitness; - - // Constructor (makes a random DNA) - DNA(int num) { - genes = new char[num]; - for (int i = 0; i < genes.length; i++) { - genes[i] = (char) random(32,128); // Pick from range of chars - } - } - - // Converts character array to a String - String getPhrase() { - return new String(genes); - } - - // Fitness function (returns floating point % of "correct" characters) - void fitness (String target) { - int score = 0; - for (int i = 0; i < genes.length; i++) { - if (genes[i] == target.charAt(i)) { - score++; - } - } - fitness = pow(2,score); - } - - // Crossover - DNA crossover(DNA partner) { - // A new child - DNA child = new DNA(genes.length); - - int midpoint = int(random(genes.length)); // Pick a midpoint - - // Half from one, half from the other - for (int i = 0; i < genes.length; i++) { - if (i > midpoint) child.genes[i] = genes[i]; - else child.genes[i] = partner.genes[i]; - } - return child; - } - - // Based on a mutation probability, picks a new random character - void mutate(float mutationRate) { - for (int i = 0; i < genes.length; i++) { - if (random(1) < mutationRate) { - genes[i] = (char) random(32,128); - } - } - } -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/GA_Shakespeare_fancyfitness.pde b/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/GA_Shakespeare_fancyfitness.pde deleted file mode 100644 index b739fa570..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/GA_Shakespeare_fancyfitness.pde +++ /dev/null @@ -1,86 +0,0 @@ -// Genetic Algorithm, Evolving Shakespeare -// Daniel Shiffman - -// Demonstration of using a genetic algorithm to perform a search - -// setup() -// # Step 1: The populationation -// # Create an empty populationation (an array or ArrayList) -// # Fill it with DNA encoded objects (pick random values to start) - -// draw() -// # Step 1: Selection -// # Create an empty mating pool (an empty ArrayList) -// # For every member of the populationation, evaluate its fitness based on some criteria / function, -// and add it to the mating pool in a manner consistant with its fitness, i.e. the more fit it -// is the more times it appears in the mating pool, in order to be more likely picked for reproduction. - -// # Step 2: Reproduction Create a new empty populationation -// # Fill the new populationation by executing the following steps: -// 1. Pick two "parent" objects from the mating pool. -// 2. Crossover -- create a "child" object by mating these two parents. -// 3. Mutation -- mutate the child's DNA based on a given probability. -// 4. Add the child object to the new populationation. -// # Replace the old populationation with the new populationation -// -// # Rinse and repeat - - -PFont f; -String target; -int popmax; -float mutationRate; -Population population; - -void setup() { - size(600, 200); - f = createFont("Courier", 32, true); - target = "To be or not to be."; - popmax = 150; - mutationRate = 0.01; - - // Create a populationation with a target phrase, mutation rate, and populationation max - population = new Population(target, mutationRate, popmax); -} - -void draw() { - // Generate mating pool - population.naturalSelection(); - //Create next generation - population.generate(); - // Calculate fitness - population.calcFitness(); - displayInfo(); - - // If we found the target phrase, stop - if (population.finished()) { - println(millis()/1000.0); - noLoop(); - } -} - -void displayInfo() { - background(255); - // Display current status of populationation - String answer = population.getBest(); - textFont(f); - textAlign(LEFT); - fill(0); - - - textSize(16); - text("Best phrase:",20,30); - textSize(32); - text(answer, 20, 75); - - textSize(12); - text("total generations: " + population.getGenerations(), 20, 140); - text("average fitness: " + nf(population.getAverageFitness(), 0, 2), 20, 155); - text("total populationation: " + popmax, 20, 170); - text("mutation rate: " + int(mutationRate * 100) + "%", 20, 185); - - textSize(10); - text("All phrases:\n" + population.allPhrases(), 450, 10); -} - - diff --git a/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/Population.pde b/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/Population.pde deleted file mode 100644 index e8dbe67cd..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/Population.pde +++ /dev/null @@ -1,127 +0,0 @@ -// Genetic Algorithm, Evolving Shakespeare -// Daniel Shiffman - -// A class to describe a population of virtual organisms -// In this case, each organism is just an instance of a DNA object - - - - -class Population { - - float mutationRate; // Mutation rate - DNA[] population; // Array to hold the current population - ArrayList matingPool; // ArrayList which we will use for our "mating pool" - String target; // Target phrase - int generations; // Number of generations - boolean finished; // Are we finished evolving? -int perfectScore; - - Population(String p, float m, int num) { - target = p; - mutationRate = m; - population = new DNA[num]; - for (int i = 0; i < population.length; i++) { - population[i] = new DNA(target.length()); - } - calcFitness(); - matingPool = new ArrayList(); - finished = false; - generations = 0; - - perfectScore = int(pow(2,target.length())); - } - - // Fill our fitness array with a value for every member of the population - void calcFitness() { - for (int i = 0; i < population.length; i++) { - population[i].fitness(target); - } - } - - // Generate a mating pool - void naturalSelection() { - // Clear the ArrayList - matingPool.clear(); - - float maxFitness = 0; - for (int i = 0; i < population.length; i++) { - if (population[i].fitness > maxFitness) { - maxFitness = population[i].fitness; - } - } - - // Based on fitness, each member will get added to the mating pool a certain number of times - // a higher fitness = more entries to mating pool = more likely to be picked as a parent - // a lower fitness = fewer entries to mating pool = less likely to be picked as a parent - for (int i = 0; i < population.length; i++) { - - float fitness = map(population[i].fitness,0,maxFitness,0,1); - int n = int(fitness * 100); // Arbitrary multiplier, we can also use monte carlo method - for (int j = 0; j < n; j++) { // and pick two random numbers - matingPool.add(population[i]); - } - } - } - - // Create a new generation - void generate() { - // Refill the population with children from the mating pool - for (int i = 0; i < population.length; i++) { - int a = int(random(matingPool.size())); - int b = int(random(matingPool.size())); - DNA partnerA = matingPool.get(a); - DNA partnerB = matingPool.get(b); - DNA child = partnerA.crossover(partnerB); - child.mutate(mutationRate); - population[i] = child; - } - generations++; - } - - - // Compute the current "most fit" member of the population - String getBest() { - float worldrecord = 0.0f; - int index = 0; - for (int i = 0; i < population.length; i++) { - if (population[i].fitness > worldrecord) { - index = i; - worldrecord = population[i].fitness; - } - } - - if (worldrecord == perfectScore ) finished = true; - return population[index].getPhrase(); - } - - boolean finished() { - return finished; - } - - int getGenerations() { - return generations; - } - - // Compute average fitness for the population - float getAverageFitness() { - float total = 0; - for (int i = 0; i < population.length; i++) { - total += population[i].fitness; - } - return total / (population.length); - } - - String allPhrases() { - String everything = ""; - - int displayLimit = min(population.length,50); - - - for (int i = 0; i < displayLimit; i++) { - everything += population[i].getPhrase() + "\n"; - } - return everything; - } -} - diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/DNA.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/DNA.pde deleted file mode 100644 index dd3e31563..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/DNA.pde +++ /dev/null @@ -1,67 +0,0 @@ -// Genetic Algorithm, Evolving Shakespeare -// Daniel Shiffman - -// A class to describe a psuedo-DNA, i.e. genotype -// Here, a virtual organism's DNA is an array of character. -// Functionality: -// -- convert DNA into a string -// -- calculate DNA's "fitness" -// -- mate DNA with another set of DNA -// -- mutate DNA - - -class DNA { - - // The genetic sequence - char[] genes; - - float fitness; - - // Constructor (makes a random DNA) - DNA(int num) { - genes = new char[num]; - for (int i = 0; i < genes.length; i++) { - genes[i] = (char) random(32,128); // Pick from range of chars - } - } - - // Converts character array to a String - String getPhrase() { - return new String(genes); - } - - // Fitness function (returns floating point % of "correct" characters) - void fitness (String target) { - int score = 0; - for (int i = 0; i < genes.length; i++) { - if (genes[i] == target.charAt(i)) { - score++; - } - } - fitness = (float)score / (float)target.length(); - } - - // Crossover - DNA crossover(DNA partner) { - // A new child - DNA child = new DNA(genes.length); - - int midpoint = int(random(genes.length)); // Pick a midpoint - - // Half from one, half from the other - for (int i = 0; i < genes.length; i++) { - if (i > midpoint) child.genes[i] = genes[i]; - else child.genes[i] = partner.genes[i]; - } - return child; - } - - // Based on a mutation probability, picks a new random character - void mutate(float mutationRate) { - for (int i = 0; i < genes.length; i++) { - if (random(1) < mutationRate) { - genes[i] = (char) random(32,128); - } - } - } -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/NOC_9_01_GA_Shakespeare.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/NOC_9_01_GA_Shakespeare.pde deleted file mode 100644 index b8831e6c8..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/NOC_9_01_GA_Shakespeare.pde +++ /dev/null @@ -1,87 +0,0 @@ -// Genetic Algorithm, Evolving Shakespeare -// Daniel Shiffman - -// Demonstration of using a genetic algorithm to perform a search - -// setup() -// # Step 1: The Population -// # Create an empty population (an array or ArrayList) -// # Fill it with DNA encoded objects (pick random values to start) - -// draw() -// # Step 1: Selection -// # Create an empty mating pool (an empty ArrayList) -// # For every member of the population, evaluate its fitness based on some criteria / function, -// and add it to the mating pool in a manner consistant with its fitness, i.e. the more fit it -// is the more times it appears in the mating pool, in order to be more likely picked for reproduction. - -// # Step 2: Reproduction Create a new empty population -// # Fill the new population by executing the following steps: -// 1. Pick two "parent" objects from the mating pool. -// 2. Crossover -- create a "child" object by mating these two parents. -// 3. Mutation -- mutate the child's DNA based on a given probability. -// 4. Add the child object to the new population. -// # Replace the old population with the new population -// -// # Rinse and repeat - - -PFont f; -String target; -int popmax; -float mutationRate; -Population population; - -void setup() { - size(800, 200); - f = createFont("Courier", 32, true); - target = "To be or not to be."; - popmax = 150; - mutationRate = 0.01; - - // Create a populationation with a target phrase, mutation rate, and populationation max - population = new Population(target, mutationRate, popmax); -} - -void draw() { - // Generate mating pool - population.naturalSelection(); - //Create next generation - population.generate(); - // Calculate fitness - population.calcFitness(); - displayInfo(); - - // If we found the target phrase, stop - if (population.finished()) { - println(millis()/1000.0); - noLoop(); - } -} - -void displayInfo() { - background(255); - // Display current status of populationation - String answer = population.getBest(); - textFont(f); - textAlign(LEFT); - fill(0); - - - textSize(16); - text("Best phrase:",20,30); - textSize(32); - text(answer, 20, 75); - - textSize(12); - text("total generations: " + population.getGenerations(), 20, 140); - text("average fitness: " + nf(population.getAverageFitness(), 0, 2), 20, 155); - text("total populationation: " + popmax, 20, 170); - text("mutation rate: " + int(mutationRate * 100) + "%", 20, 185); - - textSize(10); - text("All phrases:\n" + population.allPhrases(), 650, 10); -} - - - diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/Population.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/Population.pde deleted file mode 100644 index e8dbe67cd..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/Population.pde +++ /dev/null @@ -1,127 +0,0 @@ -// Genetic Algorithm, Evolving Shakespeare -// Daniel Shiffman - -// A class to describe a population of virtual organisms -// In this case, each organism is just an instance of a DNA object - - - - -class Population { - - float mutationRate; // Mutation rate - DNA[] population; // Array to hold the current population - ArrayList matingPool; // ArrayList which we will use for our "mating pool" - String target; // Target phrase - int generations; // Number of generations - boolean finished; // Are we finished evolving? -int perfectScore; - - Population(String p, float m, int num) { - target = p; - mutationRate = m; - population = new DNA[num]; - for (int i = 0; i < population.length; i++) { - population[i] = new DNA(target.length()); - } - calcFitness(); - matingPool = new ArrayList(); - finished = false; - generations = 0; - - perfectScore = int(pow(2,target.length())); - } - - // Fill our fitness array with a value for every member of the population - void calcFitness() { - for (int i = 0; i < population.length; i++) { - population[i].fitness(target); - } - } - - // Generate a mating pool - void naturalSelection() { - // Clear the ArrayList - matingPool.clear(); - - float maxFitness = 0; - for (int i = 0; i < population.length; i++) { - if (population[i].fitness > maxFitness) { - maxFitness = population[i].fitness; - } - } - - // Based on fitness, each member will get added to the mating pool a certain number of times - // a higher fitness = more entries to mating pool = more likely to be picked as a parent - // a lower fitness = fewer entries to mating pool = less likely to be picked as a parent - for (int i = 0; i < population.length; i++) { - - float fitness = map(population[i].fitness,0,maxFitness,0,1); - int n = int(fitness * 100); // Arbitrary multiplier, we can also use monte carlo method - for (int j = 0; j < n; j++) { // and pick two random numbers - matingPool.add(population[i]); - } - } - } - - // Create a new generation - void generate() { - // Refill the population with children from the mating pool - for (int i = 0; i < population.length; i++) { - int a = int(random(matingPool.size())); - int b = int(random(matingPool.size())); - DNA partnerA = matingPool.get(a); - DNA partnerB = matingPool.get(b); - DNA child = partnerA.crossover(partnerB); - child.mutate(mutationRate); - population[i] = child; - } - generations++; - } - - - // Compute the current "most fit" member of the population - String getBest() { - float worldrecord = 0.0f; - int index = 0; - for (int i = 0; i < population.length; i++) { - if (population[i].fitness > worldrecord) { - index = i; - worldrecord = population[i].fitness; - } - } - - if (worldrecord == perfectScore ) finished = true; - return population[index].getPhrase(); - } - - boolean finished() { - return finished; - } - - int getGenerations() { - return generations; - } - - // Compute average fitness for the population - float getAverageFitness() { - float total = 0; - for (int i = 0; i < population.length; i++) { - total += population[i].fitness; - } - return total / (population.length); - } - - String allPhrases() { - String everything = ""; - - int displayLimit = min(population.length,50); - - - for (int i = 0; i < displayLimit; i++) { - everything += population[i].getPhrase() + "\n"; - } - return everything; - } -} - diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/sketch.properties b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/sketch.properties deleted file mode 100644 index b3cbe600e..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/sketch.properties +++ /dev/null @@ -1,2 +0,0 @@ -mode.id=processing.mode.java.JavaMode -mode=Standard diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare_simplified/DNA.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare_simplified/DNA.pde deleted file mode 100644 index faa7c3ebf..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare_simplified/DNA.pde +++ /dev/null @@ -1,67 +0,0 @@ -// Genetic Algorithm, Evolving Shakespeare -// Daniel Shiffman - -// A class to describe a psuedo-DNA, i.e. genotype -// Here, a virtual organism's DNA is an array of character. -// Functionality: -// -- convert DNA into a string -// -- calculate DNA's "fitness" -// -- mate DNA with another set of DNA -// -- mutate DNA - - -class DNA { - - // The genetic sequence - char[] genes; - - float fitness; - - // Constructor (makes a random DNA) - DNA(int num) { - genes = new char[num]; - for (int i = 0; i < genes.length; i++) { - genes[i] = (char) random(32,128); // Pick from range of chars - } - } - - // Converts character array to a String - String getPhrase() { - return new String(genes); - } - - // Fitness function (returns floating point % of "correct" characters) - void calcFitness (String target) { - int score = 0; - for (int i = 0; i < genes.length; i++) { - if (genes[i] == target.charAt(i)) { - score++; - } - } - fitness = (float)score / (float)target.length(); - } - - // Crossover - DNA crossover(DNA partner) { - // A new child - DNA child = new DNA(genes.length); - - int midpoint = int(random(genes.length)); // Pick a midpoint - - // Half from one, half from the other - for (int i = 0; i < genes.length; i++) { - if (i > midpoint) child.genes[i] = genes[i]; - else child.genes[i] = partner.genes[i]; - } - return child; - } - - // Based on a mutation probability, picks a new random character - void mutate(float mutationRate) { - for (int i = 0; i < genes.length; i++) { - if (random(1) < mutationRate) { - genes[i] = (char) random(32,128); - } - } - } -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare_simplified/NOC_9_01_GA_Shakespeare_simplified.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare_simplified/NOC_9_01_GA_Shakespeare_simplified.pde deleted file mode 100644 index f78e8237a..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare_simplified/NOC_9_01_GA_Shakespeare_simplified.pde +++ /dev/null @@ -1,86 +0,0 @@ -// Genetic Algorithm, Evolving Shakespeare -// Daniel Shiffman - -// Demonstration of using a genetic algorithm to perform a search - -// setup() -// # Step 1: The Population -// # Create an empty population (an array or ArrayList) -// # Fill it with DNA encoded objects (pick random values to start) - -// draw() -// # Step 1: Selection -// # Create an empty mating pool (an empty ArrayList) -// # For every member of the population, evaluate its fitness based on some criteria / function, -// and add it to the mating pool in a manner consistant with its fitness, i.e. the more fit it -// is the more times it appears in the mating pool, in order to be more likely picked for reproduction. - -// # Step 2: Reproduction Create a new empty population -// # Fill the new population by executing the following steps: -// 1. Pick two "parent" objects from the mating pool. -// 2. Crossover -- create a "child" object by mating these two parents. -// 3. Mutation -- mutate the child's DNA based on a given probability. -// 4. Add the child object to the new population. -// # Replace the old population with the new population -// -// # Rinse and repeat - - -float mutationRate = 0.01; // Mutation rate -int totalPopulation = 150; // Total Population - -DNA[] population; // Array to hold the current population -ArrayList matingPool; // ArrayList which we will use for our "mating pool" -String target; // Target phrase - -PFont f; - -void setup() { - size(800, 200); - target = "To be or not to be."; - - population = new DNA[totalPopulation]; - - for (int i = 0; i < population.length; i++) { - population[i] = new DNA(target.length()); - } - - f = createFont("Courier",12,true); -} - -void draw() { - for (int i = 0; i < population.length; i++) { - population[i].calcFitness(target); - } - - ArrayList matingPool = new ArrayList(); // ArrayList which we will use for our "mating pool" - - for (int i = 0; i < population.length; i++) { - int nnnn = int(population[i].fitness * 100); // Arbitrary multiplier, we can also use monte carlo method - for (int j = 0; j - -// DNA is an array of vectors - -class DNA { - - // The genetic sequence - PVector[] genes; - - // The maximum strength of the forces - float maxforce = 0.1; - - // Constructor (makes a DNA of random PVectors) - DNA() { - genes = new PVector[lifetime]; - for (int i = 0; i < genes.length; i++) { - float angle = random(TWO_PI); - genes[i] = new PVector(cos(angle), sin(angle)); - genes[i].mult(random(0, maxforce)); - } - } - - // Constructor #2, creates the instance based on an existing array - DNA(PVector[] newgenes) { - // We could make a copy if necessary - // genes = (PVector []) newgenes.clone(); - genes = newgenes; - } - - // CROSSOVER - // Creates new DNA sequence from two (this & and a partner) - DNA crossover(DNA partner) { - PVector[] child = new PVector[genes.length]; - // Pick a midpoint - int crossover = int(random(genes.length)); - // Take "half" from one and "half" from the other - for (int i = 0; i < genes.length; i++) { - if (i > crossover) child[i] = genes[i]; - else child[i] = partner.genes[i]; - } - DNA newgenes = new DNA(child); - return newgenes; - } - - // Based on a mutation probability, picks a new random Vector - void mutate(float m) { - for (int i = 0; i < genes.length; i++) { - if (random(1) < m) { - float angle = random(TWO_PI); - genes[i] = new PVector(cos(angle), sin(angle)); - genes[i].mult(random(0, maxforce)); - } - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/NOC_9_02_SmartRockets_superbasic.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/NOC_9_02_SmartRockets_superbasic.pde deleted file mode 100644 index 5271ef73b..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/NOC_9_02_SmartRockets_superbasic.pde +++ /dev/null @@ -1,73 +0,0 @@ -// Smart Rockets w/ Genetic Algorithms -// Daniel Shiffman - -// Each Rocket's DNA is an array of PVectors -// Each PVector acts as a force for each frame of animation -// Imagine an booster on the end of the rocket that can point in any direction -// and fire at any strength every frame - -// The Rocket's fitness is a function of how close it gets to the target as well as how fast it gets there - -// This example is inspired by Jer Thorp's Smart Rockets -// http://www.blprnt.com/smartrockets/ - -int lifetime; // How long should each generation live - -Population population; // Population - -int lifeCounter; // Timer for cycle of generation - -PVector target; // Target location - -void setup() { - size(800, 200); - smooth(); - - // The number of cycles we will allow a generation to live - lifetime = 200; - - // Initialize variables - lifeCounter = 0; - - target = new PVector(width/2, 24); - - // Create a population with a mutation rate, and population max - float mutationRate = 0.01; - population = new Population(mutationRate, 50); - -} - -void draw() { - background(255); - - // Draw the start and target locations - fill(0); - ellipse(target.x,target.y,24,24); - - - // If the generation hasn't ended yet - if (lifeCounter < lifetime) { - population.live(); - lifeCounter++; - // Otherwise a new generation - } - else { - lifeCounter = 0; - population.fitness(); - population.selection(); - population.reproduction(); - } - - // Display some info - fill(0); - text("Generation #: " + population.getGenerations(), 10, 18); - text("Cycles left: " + (lifetime-lifeCounter), 10, 36); -} - -// Move the target if the mouse is pressed -// System will adapt to new target -void mousePressed() { - target.x = mouseX; - target.y = mouseY; -} - diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/Population.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/Population.pde deleted file mode 100644 index 3a1cce530..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/Population.pde +++ /dev/null @@ -1,100 +0,0 @@ -// Pathfinding w/ Genetic Algorithms -// Daniel Shiffman - -// A class to describe a population of "creatures" - -class Population { - - float mutationRate; // Mutation rate - Rocket[] population; // Array to hold the current population - ArrayList matingPool; // ArrayList which we will use for our "mating pool" - int generations; // Number of generations - - // Initialize the population - Population(float m, int num) { - mutationRate = m; - population = new Rocket[num]; - matingPool = new ArrayList(); - generations = 0; - //make a new set of creatures - for (int i = 0; i < population.length; i++) { - PVector location = new PVector(width/2,height+20); - population[i] = new Rocket(location, new DNA()); - } - } - - void live () { - // Run every rocket - for (int i = 0; i < population.length; i++) { - population[i].run(); - } - } - - // Calculate fitness for each creature - void fitness() { - for (int i = 0; i < population.length; i++) { - population[i].fitness(); - } - } - - // Generate a mating pool - void selection() { - // Clear the ArrayList - matingPool.clear(); - - // Calculate total fitness of whole population - float maxFitness = getMaxFitness(); - - // Calculate fitness for each member of the population (scaled to value between 0 and 1) - // Based on fitness, each member will get added to the mating pool a certain number of times - // A higher fitness = more entries to mating pool = more likely to be picked as a parent - // A lower fitness = fewer entries to mating pool = less likely to be picked as a parent - for (int i = 0; i < population.length; i++) { - float fitnessNormal = map(population[i].getFitness(),0,maxFitness,0,1); - int n = (int) (fitnessNormal * 100); // Arbitrary multiplier - for (int j = 0; j < n; j++) { - matingPool.add(population[i]); - } - } - } - - // Making the next generation - void reproduction() { - // Refill the population with children from the mating pool - for (int i = 0; i < population.length; i++) { - // Sping the wheel of fortune to pick two parents - int m = int(random(matingPool.size())); - int d = int(random(matingPool.size())); - // Pick two parents - Rocket mom = matingPool.get(m); - Rocket dad = matingPool.get(d); - // Get their genes - DNA momgenes = mom.getDNA(); - DNA dadgenes = dad.getDNA(); - // Mate their genes - DNA child = momgenes.crossover(dadgenes); - // Mutate their genes - child.mutate(mutationRate); - // Fill the new population with the new child - PVector location = new PVector(width/2,height+20); - population[i] = new Rocket(location, child); - } - generations++; - } - - int getGenerations() { - return generations; - } - - // Find highest fintess for the population - float getMaxFitness() { - float record = 0; - for (int i = 0; i < population.length; i++) { - if(population[i].getFitness() > record) { - record = population[i].getFitness(); - } - } - return record; - } - -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/Rocket.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/Rocket.pde deleted file mode 100644 index e9a77323a..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/Rocket.pde +++ /dev/null @@ -1,105 +0,0 @@ -// Pathfinding w/ Genetic Algorithms -// Daniel Shiffman - -// Rocket class -- this is just like our Boid / Particle class -// the only difference is that it has DNA & fitness - -class Rocket { - - // All of our physics stuff - PVector location; - PVector velocity; - PVector acceleration; - - // Size - float r; - - // Fitness and DNA - float fitness; - DNA dna; - // To count which force we're on in the genes - int geneCounter = 0; - - boolean hitTarget = false; // Did I reach the target - - //constructor - Rocket(PVector l, DNA dna_) { - acceleration = new PVector(); - velocity = new PVector(); - location = l.get(); - r = 4; - dna = dna_; - } - - // Fitness function - // fitness = one divided by distance squared - void fitness() { - float d = dist(location.x, location.y, target.x, target.y); - fitness = pow(1/d, 2); - } - - // Run in relation to all the obstacles - // If I'm stuck, don't bother updating or checking for intersection - void run() { - checkTarget(); // Check to see if we've reached the target - if (!hitTarget) { - applyForce(dna.genes[geneCounter]); - geneCounter = (geneCounter + 1) % dna.genes.length; - update(); - } - display(); - } - - // Did I make it to the target? - void checkTarget() { - float d = dist(location.x, location.y, target.x, target.y); - if (d < 12) { - hitTarget = true; - } - } - - void applyForce(PVector f) { - acceleration.add(f); - } - - void update() { - velocity.add(acceleration); - location.add(velocity); - acceleration.mult(0); - } - - void display() { - float theta = velocity.heading2D() + PI/2; - fill(200, 100); - stroke(0); - pushMatrix(); - translate(location.x, location.y); - rotate(theta); - - // Thrusters - rectMode(CENTER); - fill(0); - rect(-r/2, r*2, r/2, r); - rect(r/2, r*2, r/2, r); - - // Rocket body - fill(175); - beginShape(TRIANGLES); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(); - - popMatrix(); - } - - float getFitness() { - return fitness; - } - - DNA getDNA() { - return dna; - } - -} - diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/DNA.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/DNA.pde deleted file mode 100644 index 6243526f1..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/DNA.pde +++ /dev/null @@ -1,65 +0,0 @@ -// Pathfinding w/ Genetic Algorithms -// Daniel Shiffman - -// DNA is an array of vectors - -class DNA { - - // The genetic sequence - PVector[] genes; - - // The maximum strength of the forces - float maxforce = 0.1; - - // Constructor (makes a DNA of random PVectors) - DNA() { - genes = new PVector[lifetime]; - for (int i = 0; i < genes.length; i++) { - float angle = random(TWO_PI); - genes[i] = new PVector(cos(angle), sin(angle)); - genes[i].mult(random(0, maxforce)); - } - - // Let's give each Rocket an extra boost of strength for its first frame - genes[0].normalize(); - } - - // Constructor #2, creates the instance based on an existing array - DNA(PVector[] newgenes) { - // We could make a copy if necessary - // genes = (PVector []) newgenes.clone(); - genes = newgenes; - } - - // CROSSOVER - // Creates new DNA sequence from two (this & and a partner) - DNA crossover(DNA partner) { - PVector[] child = new PVector[genes.length]; - // Pick a midpoint - int crossover = int(random(genes.length)); - // Take "half" from one and "half" from the other - for (int i = 0; i < genes.length; i++) { - if (i > crossover) child[i] = genes[i]; - else child[i] = partner.genes[i]; - } - DNA newgenes = new DNA(child); - return newgenes; - } - - // Based on a mutation probability, picks a new random Vector - void mutate(float m) { - for (int i = 0; i < genes.length; i++) { - if (random(1) < m) { - float angle = random(TWO_PI); - genes[i] = new PVector(cos(angle), sin(angle)); - genes[i].mult(random(0, maxforce)); - // float angle = random(-0.1,0.1); - // genes[i].rotate(angle); - // float factor = random(0.9,1.1); - // genes[i].mult(factor); - if (i ==0) genes[i].normalize(); - } - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/NOC_9_03_SmartRockets.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/NOC_9_03_SmartRockets.pde deleted file mode 100644 index 46f7d6df4..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/NOC_9_03_SmartRockets.pde +++ /dev/null @@ -1,93 +0,0 @@ -// Smart Rockets w/ Genetic Algorithms -// Daniel Shiffman - -// Each Rocket's DNA is an array of PVectors -// Each PVector acts as a force for each frame of animation -// Imagine an booster on the end of the rocket that can point in any direction -// and fire at any strength every frame - -// The Rocket's fitness is a function of how close it gets to the target as well as how fast it gets there - -// This example is inspired by Jer Thorp's Smart Rockets -// http://www.blprnt.com/smartrockets/ - -int lifetime; // How long should each generation live - -Population population; // Population - -int lifecycle; // Timer for cycle of generation -int recordtime; // Fastest time to target - -Obstacle target; // Target location - -//int diam = 24; // Size of target - -ArrayList obstacles; //an array list to keep track of all the obstacles! - -void setup() { - size(800, 200); - smooth(); - - // The number of cycles we will allow a generation to live - lifetime = 300; - - // Initialize variables - lifecycle = 0; - recordtime = lifetime; - - target = new Obstacle(width/2-12, 24, 24, 24); - - // Create a population with a mutation rate, and population max - float mutationRate = 0.01; - population = new Population(mutationRate, 50); - - // Create the obstacle course - obstacles = new ArrayList(); - obstacles.add(new Obstacle(300, height/2, width-600, 10)); -} - -void draw() { - background(255); - - // Draw the start and target locations - target.display(); - - - // If the generation hasn't ended yet - if (lifecycle < lifetime) { - population.live(obstacles); - if ((population.targetReached()) && (lifecycle < recordtime)) { - recordtime = lifecycle; - } - lifecycle++; - // Otherwise a new generation - } - else { - lifecycle = 0; - population.fitness(); - population.selection(); - population.reproduction(); - } - - // Draw the obstacles - for (Obstacle obs : obstacles) { - obs.display(); - } - - // Display some info - fill(0); - text("Generation #: " + population.getGenerations(), 10, 18); - text("Cycles left: " + (lifetime-lifecycle), 10, 36); - text("Record cycles: " + recordtime, 10, 54); - - -} - -// Move the target if the mouse is pressed -// System will adapt to new target -void mousePressed() { - target.location.x = mouseX; - target.location.y = mouseY; - recordtime = lifetime; -} - diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Obstacle.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Obstacle.pde deleted file mode 100644 index e8d4207b6..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Obstacle.pde +++ /dev/null @@ -1,37 +0,0 @@ -// Pathfinding w/ Genetic Algorithms -// Daniel Shiffman - -// A class for an obstacle, just a simple rectangle that is drawn -// and can check if a Rocket touches it - -// Also using this class for target location - - -class Obstacle { - - PVector location; - float w,h; - - Obstacle(float x, float y, float w_, float h_) { - location = new PVector(x,y); - w = w_; - h = h_; - } - - void display() { - stroke(0); - fill(175); - strokeWeight(2); - rectMode(CORNER); - rect(location.x,location.y,w,h); - } - - boolean contains(PVector spot) { - if (spot.x > location.x && spot.x < location.x + w && spot.y > location.y && spot.y < location.y + h) { - return true; - } else { - return false; - } - } - -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Population.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Population.pde deleted file mode 100644 index b5a8ccbed..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Population.pde +++ /dev/null @@ -1,110 +0,0 @@ -// Pathfinding w/ Genetic Algorithms -// Daniel Shiffman - -// A class to describe a population of "creatures" - -class Population { - - float mutationRate; // Mutation rate - Rocket[] population; // Array to hold the current population - ArrayList matingPool; // ArrayList which we will use for our "mating pool" - int generations; // Number of generations - - // Initialize the population - Population(float m, int num) { - mutationRate = m; - population = new Rocket[num]; - matingPool = new ArrayList(); - generations = 0; - //make a new set of creatures - for (int i = 0; i < population.length; i++) { - PVector location = new PVector(width/2,height+20); - population[i] = new Rocket(location, new DNA(),population.length); - } - } - - void live (ArrayList os) { - // For every creature - for (int i = 0; i < population.length; i++) { - // If it finishes, mark it down as done! - population[i].checkTarget(); - population[i].run(os); - } - } - - // Did anything finish? - boolean targetReached() { - for (int i = 0; i < population.length; i++) { - if (population[i].hitTarget) return true; - } - return false; - } - - // Calculate fitness for each creature - void fitness() { - for (int i = 0; i < population.length; i++) { - population[i].fitness(); - } - } - - // Generate a mating pool - void selection() { - // Clear the ArrayList - matingPool.clear(); - - // Calculate total fitness of whole population - float maxFitness = getMaxFitness(); - - // Calculate fitness for each member of the population (scaled to value between 0 and 1) - // Based on fitness, each member will get added to the mating pool a certain number of times - // A higher fitness = more entries to mating pool = more likely to be picked as a parent - // A lower fitness = fewer entries to mating pool = less likely to be picked as a parent - for (int i = 0; i < population.length; i++) { - float fitnessNormal = map(population[i].getFitness(),0,maxFitness,0,1); - int n = (int) (fitnessNormal * 100); // Arbitrary multiplier - for (int j = 0; j < n; j++) { - matingPool.add(population[i]); - } - } - } - - // Making the next generation - void reproduction() { - // Refill the population with children from the mating pool - for (int i = 0; i < population.length; i++) { - // Sping the wheel of fortune to pick two parents - int m = int(random(matingPool.size())); - int d = int(random(matingPool.size())); - // Pick two parents - Rocket mom = matingPool.get(m); - Rocket dad = matingPool.get(d); - // Get their genes - DNA momgenes = mom.getDNA(); - DNA dadgenes = dad.getDNA(); - // Mate their genes - DNA child = momgenes.crossover(dadgenes); - // Mutate their genes - child.mutate(mutationRate); - // Fill the new population with the new child - PVector location = new PVector(width/2,height+20); - population[i] = new Rocket(location, child,population.length); - } - generations++; - } - - int getGenerations() { - return generations; - } - - // Find highest fintess for the population - float getMaxFitness() { - float record = 0; - for (int i = 0; i < population.length; i++) { - if(population[i].getFitness() > record) { - record = population[i].getFitness(); - } - } - return record; - } - -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Rocket.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Rocket.pde deleted file mode 100644 index 488b9ea9e..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Rocket.pde +++ /dev/null @@ -1,147 +0,0 @@ -// Pathfinding w/ Genetic Algorithms -// Daniel Shiffman - -// Rocket class -- this is just like our Boid / Particle class -// the only difference is that it has DNA & fitness - -class Rocket { - - // All of our physics stuff - PVector location; - PVector velocity; - PVector acceleration; - - // Size - float r; - - // How close did it get to the target - float recordDist; - - // Fitness and DNA - float fitness; - DNA dna; - // To count which force we're on in the genes - int geneCounter = 0; - - boolean hitObstacle = false; // Am I stuck on an obstacle? - boolean hitTarget = false; // Did I reach the target - int finishTime; // What was my finish time? - - //constructor - Rocket(PVector l, DNA dna_, int totalRockets) { - acceleration = new PVector(); - velocity = new PVector(); - location = l.get(); - r = 4; - dna = dna_; - finishTime = 0; // We're going to count how long it takes to reach target - recordDist = 10000; // Some high number that will be beat instantly - } - - // FITNESS FUNCTION - // distance = distance from target - // finish = what order did i finish (first, second, etc. . .) - // f(distance,finish) = (1.0f / finish^1.5) * (1.0f / distance^6); - // a lower finish is rewarded (exponentially) and/or shorter distance to target (exponetially) - void fitness() { - if (recordDist < 1) recordDist = 1; - - // Reward finishing faster and getting close - fitness = (1/(finishTime*recordDist)); - - // Make the function exponential - fitness = pow(fitness, 4); - - if (hitObstacle) fitness *= 0.1; // lose 90% of fitness hitting an obstacle - if (hitTarget) fitness *= 2; // twice the fitness for finishing! - } - - // Run in relation to all the obstacles - // If I'm stuck, don't bother updating or checking for intersection - void run(ArrayList os) { - if (!hitObstacle && !hitTarget) { - applyForce(dna.genes[geneCounter]); - geneCounter = (geneCounter + 1) % dna.genes.length; - update(); - // If I hit an edge or an obstacle - obstacles(os); - } - // Draw me! - if (!hitObstacle) { - display(); - } - } - - // Did I make it to the target? - void checkTarget() { - float d = dist(location.x, location.y, target.location.x, target.location.y); - if (d < recordDist) recordDist = d; - - if (target.contains(location) && !hitTarget) { - hitTarget = true; - } - else if (!hitTarget) { - finishTime++; - } - } - - // Did I hit an obstacle? - void obstacles(ArrayList os) { - for (Obstacle obs : os) { - if (obs.contains(location)) { - hitObstacle = true; - } - } - } - - void applyForce(PVector f) { - acceleration.add(f); - } - - - void update() { - velocity.add(acceleration); - location.add(velocity); - acceleration.mult(0); - } - - void display() { - //background(255,0,0); - float theta = velocity.heading2D() + PI/2; - fill(200, 100); - stroke(0); - strokeWeight(1); - pushMatrix(); - translate(location.x, location.y); - rotate(theta); - - // Thrusters - rectMode(CENTER); - fill(0); - rect(-r/2, r*2, r/2, r); - rect(r/2, r*2, r/2, r); - - // Rocket body - fill(175); - beginShape(TRIANGLES); - vertex(0, -r*2); - vertex(-r, r*2); - vertex(r, r*2); - endShape(); - - popMatrix(); - } - - float getFitness() { - return fitness; - } - - DNA getDNA() { - return dna; - } - - boolean stopped() { - return hitObstacle; - } -} - diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/sketch.properties b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/sketch.properties deleted file mode 100644 index 28faa5897..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=Standard diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Button.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Button.pde deleted file mode 100644 index c7747749a..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Button.pde +++ /dev/null @@ -1,53 +0,0 @@ -// Interactive Selection -// http://www.genarts.com/karl/papers/siggraph91.html -// Daniel Shiffman - -//import java.awt.Rectangle; - -class Button { - Rectangle r; // Button's rectangle - String txt; // Button's text - boolean clickedOn; // Did i click on it? - boolean rolloverOn; // Did i rollover it? - - Button(int x, int y, int w, int h, String s) { - r = new Rectangle(x,y,w,h); - txt = s; - } - - void display() { - // Draw rectangle and text based on whether rollover or clicked - rectMode(CORNER); - stroke(0); noFill(); - if (rolloverOn) fill(0.5); - if (clickedOn) fill(0); - rect(r.x,r.y,r.width,r.height); - float b = 0.0; - if (clickedOn) b = 1; - else if (rolloverOn) b = 0.2; - else b = 0; - fill(b); - textAlign(LEFT); - text(txt,r.x+10,r.y+14); - - } - - - // Methods to check rollover, clicked, or released (must be called from appropriate - // Places in draw, mousePressed, mouseReleased - boolean rollover(int mx, int my) { - if (r.contains(mx,my)) rolloverOn = true; - else rolloverOn = false; - return rolloverOn; - } - - boolean clicked(int mx, int my) { - if (r.contains(mx,my)) clickedOn = true; - return clickedOn; - } - - void released() { - clickedOn = false; - } - -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/DNA.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/DNA.pde deleted file mode 100644 index f5f986159..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/DNA.pde +++ /dev/null @@ -1,46 +0,0 @@ -// Interactive Selection -// http://www.genarts.com/karl/papers/siggraph91.html -// Daniel Shiffman - -class DNA { - - // The genetic sequence - float[] genes; - int len = 20; // Arbitrary length - - //Constructor (makes a random DNA) - DNA() { - // DNA is random floating point values between 0 and 1 (!!) - genes = new float[len]; - for (int i = 0; i < genes.length; i++) { - genes[i] = random(0,1); - } - } - - DNA(float[] newgenes) { - genes = newgenes; - } - - - // Crossover - // Creates new DNA sequence from two (this & - DNA crossover(DNA partner) { - float[] child = new float[genes.length]; - int crossover = int(random(genes.length)); - for (int i = 0; i < genes.length; i++) { - if (i > crossover) child[i] = genes[i]; - else child[i] = partner.genes[i]; - } - DNA newgenes = new DNA(child); - return newgenes; - } - - // Based on a mutation probability, picks a new random character in array spots - void mutate(float m) { - for (int i = 0; i < genes.length; i++) { - if (random(1) < m) { - genes[i] = random(0,1); - } - } - } -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Face.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Face.pde deleted file mode 100644 index d95dbc7c2..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Face.pde +++ /dev/null @@ -1,101 +0,0 @@ -// Interactive Selection -// http://www.genarts.com/karl/papers/siggraph91.html -// Daniel Shiffman - -// The class for our "face", contains DNA sequence, fitness value, position on screen - -// Fitness Function f(t) = t (where t is "time" mouse rolls over face) - -class Face { - - DNA dna; // Face's DNA - float fitness; // How good is this face? - float x, y; // Position on screen - int wh = 70; // Size of square enclosing face - boolean rolloverOn; // Are we rolling over this face? - - Rectangle r; - - // Create a new face - Face(DNA dna_, float x_, float y_) { - dna = dna_; - x = x_; - y = y_; - fitness = 1; - // Using java.awt.Rectangle (see: http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Rectangle.html) - r = new Rectangle(int(x-wh/2), int(y-wh/2), int(wh), int(wh)); - } - - // Display the face - void display() { - // We are using the face's DNA to pick properties for this face - // such as: head size, color, eye position, etc. - // Now, since every gene is a floating point between 0 and 1, we map the values - float r = map(dna.genes[0],0,1,0,70); - color c = color(dna.genes[1],dna.genes[2],dna.genes[3]); - float eye_y = map(dna.genes[4],0,1,0,5); - float eye_x = map(dna.genes[5],0,1,0,10); - float eye_size = map(dna.genes[5],0,1,0,10); - color eyecolor = color(dna.genes[4],dna.genes[5],dna.genes[6]); - color mouthColor = color(dna.genes[7],dna.genes[8],dna.genes[9]); - float mouth_y = map(dna.genes[5],0,1,0,25); - float mouth_x = map(dna.genes[5],0,1,-25,25); - float mouthw = map(dna.genes[5],0,1,0,50); - float mouthh = map(dna.genes[5],0,1,0,10); - - // Once we calculate all the above properties, we use those variables to draw rects, ellipses, etc. - pushMatrix(); - translate(x, y); - noStroke(); - - // Draw the head - smooth(); - fill(c); - ellipseMode(CENTER); - ellipse(0, 0, r, r); - - // Draw the eyes - fill(eyecolor); - rectMode(CENTER); - rect(-eye_x, -eye_y, eye_size, eye_size); - rect( eye_x, -eye_y, eye_size, eye_size); - - // Draw the mouth - fill(mouthColor); - rectMode(CENTER); - rect(mouth_x, mouth_y, mouthw, mouthh); - - // Draw the bounding box - stroke(0.25); - if (rolloverOn) fill(0, 0.25); - else noFill(); - rectMode(CENTER); - rect(0, 0, wh, wh); - popMatrix(); - - // Display fitness value - textAlign(CENTER); - if (rolloverOn) fill(0); - else fill(0.25); - text(int(fitness), x, y+55); - } - - float getFitness() { - return fitness; - } - - DNA getDNA() { - return dna; - } - - // Increment fitness if mouse is rolling over face - void rollover(int mx, int my) { - if (r.contains(mx, my)) { - rolloverOn = true; - fitness += 0.25; - } else { - rolloverOn = false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/NOC_9_04_Faces_interactiveselection.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/NOC_9_04_Faces_interactiveselection.pde deleted file mode 100644 index 77a1e5af9..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/NOC_9_04_Faces_interactiveselection.pde +++ /dev/null @@ -1,46 +0,0 @@ -// Interactive Selection -// http://www.genarts.com/karl/papers/siggraph91.html -// Daniel Shiffman - -Population population; -Button button; - -void setup() { - size(800,200); - colorMode(RGB,1.0); - smooth(); - int popmax = 10; - float mutationRate = 0.05; // A pretty high mutation rate here, our population is rather small we need to enforce variety - // Create a population with a target phrase, mutation rate, and population max - population = new Population(mutationRate,popmax); - // A simple button class - button = new Button(15,150,160,20, "evolve new generation"); -} - -void draw() { - background(1.0); - // Display the faces - population.display(); - population.rollover(mouseX,mouseY); - // Display some text - textAlign(LEFT); - fill(0); - text("Generation #:" + population.getGenerations(),15,190); - - // Display the button - button.display(); - button.rollover(mouseX,mouseY); - -} - -// If the button is clicked, evolve next generation -void mousePressed() { - if (button.clicked(mouseX,mouseY)) { - population.selection(); - population.reproduction(); - } -} - -void mouseReleased() { - button.released(); -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Population.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Population.pde deleted file mode 100644 index f4df91d2a..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Population.pde +++ /dev/null @@ -1,99 +0,0 @@ -// Interactive Selection -// http://www.genarts.com/karl/papers/siggraph91.html -// Daniel Shiffman - -// A class to describe a population of faces -// this hasn't changed very much from example to example - -class Population { - - float mutationRate; // Mutation rate - Face[] population; // array to hold the current population - ArrayList matingPool; // ArrayList which we will use for our "mating pool" - int generations; // Number of generations - - // Create the population - Population(float m, int num) { - mutationRate = m; - population = new Face[num]; - matingPool = new ArrayList(); - generations = 0; - for (int i = 0; i < population.length; i++) { - population[i] = new Face(new DNA(), 50+i*75, 60); - } - } - - // Display all faces - void display() { - for (int i = 0; i < population.length; i++) { - population[i].display(); - } - } - - // Are we rolling over any of the faces? - void rollover(int mx, int my) { - for (int i = 0; i < population.length; i++) { - population[i].rollover(mx, my); - } - } - - // Generate a mating pool - void selection() { - // Clear the ArrayList - matingPool.clear(); - - // Calculate total fitness of whole population - float maxFitness = getMaxFitness(); - - // Calculate fitness for each member of the population (scaled to value between 0 and 1) - // Based on fitness, each member will get added to the mating pool a certain number of times - // A higher fitness = more entries to mating pool = more likely to be picked as a parent - // A lower fitness = fewer entries to mating pool = less likely to be picked as a parent - for (int i = 0; i < population.length; i++) { - float fitnessNormal = map(population[i].getFitness(), 0, maxFitness, 0, 1); - int n = (int) (fitnessNormal * 100); // Arbitrary multiplier - for (int j = 0; j < n; j++) { - matingPool.add(population[i]); - } - } - } - - // Making the next generation - void reproduction() { - // Refill the population with children from the mating pool - for (int i = 0; i < population.length; i++) { - // Sping the wheel of fortune to pick two parents - int m = int(random(matingPool.size())); - int d = int(random(matingPool.size())); - // Pick two parents - Face mom = matingPool.get(m); - Face dad = matingPool.get(d); - // Get their genes - DNA momgenes = mom.getDNA(); - DNA dadgenes = dad.getDNA(); - // Mate their genes - DNA child = momgenes.crossover(dadgenes); - // Mutate their genes - child.mutate(mutationRate); - // Fill the new population with the new child - population[i] = new Face(child, 50+i*75, 60); - } - generations++; - } - - int getGenerations() { - return generations; - } - - // Find highest fintess for the population - float getMaxFitness() { - float record = 0; - for (int i = 0; i < population.length; i++) { - if (population[i].getFitness() > record) { - record = population[i].getFitness(); - } - } - return record; - } -} - diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Rectangle.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Rectangle.pde deleted file mode 100644 index 7f6ad9691..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_04_Faces_interactiveselection/Rectangle.pde +++ /dev/null @@ -1,21 +0,0 @@ -// Re-implementing java.awt.Rectangle -// so JS mode works - -class Rectangle { - int x; - int y; - int width; - int height; - - Rectangle(int x_, int y_, int w, int h) { - x = x_; - y = y_; - width = w; - height = h; - } - - boolean contains(int px, int py) { - return (px > x && px < x + width && py > y && py < y + height); - } - -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/Bloop.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/Bloop.pde deleted file mode 100644 index a7f11cfd3..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/Bloop.pde +++ /dev/null @@ -1,105 +0,0 @@ -// Evolution EcoSystem -// Daniel Shiffman - -// Creature class - -class Bloop { - PVector location; // Location - DNA dna; // DNA - float health; // Life timer - float xoff; // For perlin noise - float yoff; - // DNA will determine size and maxspeed - float r; - float maxspeed; - - // Create a "bloop" creature - Bloop(PVector l, DNA dna_) { - location = l.get(); - health = 200; - xoff = random(1000); - yoff = random(1000); - dna = dna_; - // Gene 0 determines maxspeed and r - // The bigger the bloop, the slower it is - maxspeed = map(dna.genes[0], 0, 1, 15, 0); - r = map(dna.genes[0], 0, 1, 0, 50); - } - - void run() { - update(); - borders(); - display(); - } - - // A bloop can find food and eat it - void eat(Food f) { - ArrayList food = f.getFood(); - // Are we touching any food objects? - for (int i = food.size()-1; i >= 0; i--) { - PVector foodLocation = food.get(i); - float d = PVector.dist(location, foodLocation); - // If we are, juice up our strength! - if (d < r/2) { - health += 100; - food.remove(i); - } - } - } - - // At any moment there is a teeny, tiny chance a bloop will reproduce - Bloop reproduce() { - // asexual reproduction - if (random(1) < 0.0005) { - // Child is exact copy of single parent - DNA childDNA = dna.copy(); - // Child DNA can mutate - childDNA.mutate(0.01); - return new Bloop(location, childDNA); - } - else { - return null; - } - } - - // Method to update location - void update() { - // Simple movement based on perlin noise - float vx = map(noise(xoff),0,1,-maxspeed,maxspeed); - float vy = map(noise(yoff),0,1,-maxspeed,maxspeed); - PVector velocity = new PVector(vx,vy); - xoff += 0.01; - yoff += 0.01; - - location.add(velocity); - // Death always looming - health -= 0.2; - } - - // Wraparound - void borders() { - if (location.x < -r) location.x = width+r; - if (location.y < -r) location.y = height+r; - if (location.x > width+r) location.x = -r; - if (location.y > height+r) location.y = -r; - } - - // Method to display - void display() { - ellipseMode(CENTER); - stroke(0,health); - fill(0, health); - ellipse(location.x, location.y, r, r); - } - - // Death - boolean dead() { - if (health < 0.0) { - return true; - } - else { - return false; - } - } -} - diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/DNA.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/DNA.pde deleted file mode 100644 index 807e776a7..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/DNA.pde +++ /dev/null @@ -1,44 +0,0 @@ -// Evolution EcoSystem -// Daniel Shiffman - -// Class to describe DNA -// Has more features for two parent mating (not used in this example) - -class DNA { - - // The genetic sequence - float[] genes; - - // Constructor (makes a random DNA) - DNA() { - // DNA is random floating point values between 0 and 1 (!!) - genes = new float[1]; - for (int i = 0; i < genes.length; i++) { - genes[i] = random(0,1); - } - } - - DNA(float[] newgenes) { - genes = newgenes; - } - - DNA copy() { - float[] newgenes = new float[genes.length]; - //arraycopy(genes,newgenes); - // JS mode not supporting arraycopy - for (int i = 0; i < newgenes.length; i++) { - newgenes[i] = genes[i]; - } - - return new DNA(newgenes); - } - - // Based on a mutation probability, picks a new random character in array spots - void mutate(float m) { - for (int i = 0; i < genes.length; i++) { - if (random(1) < m) { - genes[i] = random(0,1); - } - } - } -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/Food.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/Food.pde deleted file mode 100644 index e94bd5a0a..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/Food.pde +++ /dev/null @@ -1,41 +0,0 @@ -// Evolution EcoSystem -// Daniel Shiffman - -// A collection of food in the world - -class Food { - ArrayList food; - - Food(int num) { - // Start with some food - food = new ArrayList(); - for (int i = 0; i < num; i++) { - food.add(new PVector(random(width),random(height))); - } - } - - // Add some food at a location - void add(PVector l) { - food.add(l.get()); - } - - // Display the food - void run() { - for (PVector f : food) { - rectMode(CENTER); - stroke(0); - fill(175); - rect(f.x,f.y,8,8); - } - - // There's a small chance food will appear randomly - if (random(1) < 0.001) { - food.add(new PVector(random(width),random(height))); - } - } - - // Return the list of food - ArrayList getFood() { - return food; - } -} diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/NOC_9_05_EvolutionEcosystem.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/NOC_9_05_EvolutionEcosystem.pde deleted file mode 100644 index f92a22e37..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/NOC_9_05_EvolutionEcosystem.pde +++ /dev/null @@ -1,33 +0,0 @@ -// Evolution EcoSystem -// Daniel Shiffman -// The Nature of Code - -// A World of creatures that eat food -// The more they eat, the longer they survive -// The longer they survive, the more likely they are to reproduce -// The bigger they are, the easier it is to land on food -// The bigger they are, the slower they are to find food -// When the creatures die, food is left behind - - -World world; - -void setup() { - size(800, 200); - // World starts with 20 creatures - // and 20 pieces of food - world = new World(20); - smooth(); -} - -void draw() { - background(255); - world.run(); -} - -// We can add a creature manually if we so desire -void mousePressed() { - world.born(mouseX,mouseY); -} - - diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/World.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/World.pde deleted file mode 100644 index d3edc5dd8..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/World.pde +++ /dev/null @@ -1,56 +0,0 @@ -// Evolution EcoSystem -// Daniel Shiffman -// Spring 2007, The Nature of Code - -// The World we live in -// Has bloops and food - -class World { - - ArrayList bloops; // An arraylist for all the creatures - Food food; - - // Constructor - World(int num) { - // Start with initial food and creatures - food = new Food(num); - bloops = new ArrayList(); // Initialize the arraylist - for (int i = 0; i < num; i++) { - PVector l = new PVector(random(width),random(height)); - DNA dna = new DNA(); - bloops.add(new Bloop(l,dna)); - } - } - - // Make a new creature - void born(float x, float y) { - PVector l = new PVector(x,y); - DNA dna = new DNA(); - bloops.add(new Bloop(l,dna)); - } - - // Run the world - void run() { - // Deal with food - food.run(); - - // Cycle through the ArrayList backwards b/c we are deleting - for (int i = bloops.size()-1; i >= 0; i--) { - // All bloops run and eat - Bloop b = bloops.get(i); - b.run(); - b.eat(food); - // If it's dead, kill it and make food - if (b.dead()) { - bloops.remove(i); - food.add(b.location); - } - // Perhaps this bloop would like to make a baby? - Bloop child = b.reproduce(); - if (child != null) bloops.add(child); - } - } -} - - - diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/sketch.properties b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/sketch.properties deleted file mode 100644 index 28faa5897..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_05_EvolutionEcosystem/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -mode=Standard diff --git a/java/examples/Books/Nature of Code/chp9_ga/bruteforce/bruteforce.pde b/java/examples/Books/Nature of Code/chp9_ga/bruteforce/bruteforce.pde deleted file mode 100644 index c8a00ce51..000000000 --- a/java/examples/Books/Nature of Code/chp9_ga/bruteforce/bruteforce.pde +++ /dev/null @@ -1,16 +0,0 @@ - - -int now = millis(); - -int passedTime = millis() - now; -int count = 0; -while (passedTime < 1000) { - for (int i = 0; i < 33; i++) { - float r = random(27); - } - count++; - passedTime = millis() - now; -} -println(count); - - diff --git a/java/examples/Books/Nature of Code/introduction/Exc_I_10_NoiseLandscape/Exc_I_10_NoiseLandscape.pde b/java/examples/Books/Nature of Code/introduction/Exc_I_10_NoiseLandscape/Exc_I_10_NoiseLandscape.pde deleted file mode 100644 index ffef4e6ab..000000000 --- a/java/examples/Books/Nature of Code/introduction/Exc_I_10_NoiseLandscape/Exc_I_10_NoiseLandscape.pde +++ /dev/null @@ -1,32 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/teaching/nature - -// Landscape with height values according to Perlin noise - -Landscape land; -float theta = 0.0; - -void setup() { - - size(800,200,P3D); - - // Create a landscape object - land = new Landscape(20,800,400); -} - -void draw() { - - // Ok, visualize the landscape space - background(255); - pushMatrix(); - translate(width/2,height/2+20,-160); - rotateX(PI/3); - rotateZ(theta); - land.render(); - popMatrix(); - - land.calculate(); - - theta += 0.0025; -} diff --git a/java/examples/Books/Nature of Code/introduction/Exc_I_10_NoiseLandscape/Landscape.pde b/java/examples/Books/Nature of Code/introduction/Exc_I_10_NoiseLandscape/Landscape.pde deleted file mode 100644 index 7d1114ac5..000000000 --- a/java/examples/Books/Nature of Code/introduction/Exc_I_10_NoiseLandscape/Landscape.pde +++ /dev/null @@ -1,65 +0,0 @@ -// Daniel Shiffman -// -// "Landscape" example - -class Landscape { - - int scl; // size of each cell - int w, h; // width and height of thingie - int rows, cols; // number of rows and columns - float zoff = 0.0; // perlin noise argument - float[][] z; // using an array to store all the height values - - Landscape(int scl_, int w_, int h_) { - scl = scl_; - w = w_; - h = h_; - cols = w/scl; - rows = h/scl; - z = new float[cols][rows]; - } - - - // Calculate height values (based off a neural netork) - void calculate() { - float xoff = 0; - for (int i = 0; i < cols; i++) - { - float yoff = 0; - for (int j = 0; j < rows; j++) - { - z[i][j] = map(noise(xoff, yoff,zoff), 0, 1, -120, 120); - yoff += 0.1; - } - xoff += 0.1; - } - zoff+=0.01; - } - - // Render landscape as grid of quads - void render() { - // Every cell is an individual quad - // (could use quad_strip here, but produces funny results, investigate this) - for (int x = 0; x < z.length-1; x++) - { - for (int y = 0; y < z[x].length-1; y++) - { - // one quad at a time - // each quad's color is determined by the height value at each vertex - // (clean this part up) - stroke(0); - fill(100, 100); - pushMatrix(); - beginShape(QUADS); - translate(x*scl-w/2, y*scl-h/2, 0); - vertex(0, 0, z[x][y]); - vertex(scl, 0, z[x+1][y]); - vertex(scl, scl, z[x+1][y+1]); - vertex(0, scl, z[x][y+1]); - endShape(); - popMatrix(); - } - } - } -} - diff --git a/java/examples/Books/Nature of Code/introduction/Exc_I_9_Noise3D/Exc_I_9_Noise3D.pde b/java/examples/Books/Nature of Code/introduction/Exc_I_9_Noise3D/Exc_I_9_Noise3D.pde deleted file mode 100644 index 125f77be9..000000000 --- a/java/examples/Books/Nature of Code/introduction/Exc_I_9_Noise3D/Exc_I_9_Noise3D.pde +++ /dev/null @@ -1,47 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/ - -float increment = 0.01; -// The noise function's 3rd argument, a global variable that increments once per cycle -float zoff = 0.0; -// We will increment zoff differently than xoff and yoff -float zincrement = 0.02; - -void setup() { - size(200,200); -} - -void draw() { - background(0); - - // Optional: adjust noise detail here - // noiseDetail(8,0.65f); - - loadPixels(); - - float xoff = 0.0; // Start xoff at 0 - - // For every x,y coordinate in a 2D space, calculate a noise value and produce a brightness value - for (int x = 0; x < width; x++) { - xoff += increment; // Increment xoff - float yoff = 0.0; // For every xoff, start yoff at 0 - for (int y = 0; y < height; y++) { - yoff += increment; // Increment yoff - - // Calculate noise and scale by 255 - float bright = noise(xoff,yoff,zoff)*255; - - // Try using this line instead - //float bright = random(0,255); - - // Set each pixel onscreen to a grayscale value - pixels[x+y*width] = color(bright,bright,bright); - } - } - updatePixels(); - - zoff += zincrement; // Increment zoff - - -} diff --git a/java/examples/Books/Nature of Code/introduction/Figure_I_2_BellCurve/Figure_I_2_BellCurve.pde b/java/examples/Books/Nature of Code/introduction/Figure_I_2_BellCurve/Figure_I_2_BellCurve.pde deleted file mode 100644 index 72dc64e22..000000000 --- a/java/examples/Books/Nature of Code/introduction/Figure_I_2_BellCurve/Figure_I_2_BellCurve.pde +++ /dev/null @@ -1,38 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/ - -float[] heights; - -void setup() { - size(400, 200); - smooth(); -} - -void draw() { - background(255); - float e = 2.71828183; //"e", see http://mathforum.org/dr.math/faq/faq.e.html for more info - float[] heights = new float[width]; //use an array to store all the "y" values - float m = 0; //default mean of 0 - float sd = map(mouseX,0,width,0.4,2); //standard deviation based on mouseX - for (int i = 0; i < heights.length; i++) { - float xcoord = map(i,0,width,-3,3); - float sq2pi = sqrt(2*PI); //square root of 2 * PI - float xmsq = -1*(xcoord-m)*(xcoord-m); //-(x - mu)^2 - float sdsq = sd*sd; //variance (standard deviation squared) - heights[i] = (1 / (sd * sq2pi)) * (pow(e, (xmsq/sdsq))); //P(x) function - } - - // a little for loop that draws a line between each point on the graph - stroke(0); - strokeWeight(2); - noFill(); - beginShape(); - for (int i = 0; i < heights.length-1; i++) { - float x = i; - float y = map(heights[i], 0, 1, height-2, 2); - vertex(x, y); - } - endShape(); -} - diff --git a/java/examples/Books/Nature of Code/introduction/Figure_I_5_Noise1DGraph/Figure_I_5_Noise1DGraph.pde b/java/examples/Books/Nature of Code/introduction/Figure_I_5_Noise1DGraph/Figure_I_5_Noise1DGraph.pde deleted file mode 100644 index af4efc566..000000000 --- a/java/examples/Books/Nature of Code/introduction/Figure_I_5_Noise1DGraph/Figure_I_5_Noise1DGraph.pde +++ /dev/null @@ -1,27 +0,0 @@ -// The Nature of Code -// http://www.shiffman.net/ - -// TIME -float t = 0.0; - -void setup() { - size(400,200); - smooth(); -} - - -void draw() { - background(255); - float xoff = t; - noFill(); - stroke(0); - strokeWeight(2); - beginShape(); - for (int i = 0; i < width; i++) { - float y = noise(xoff)*height; - xoff += 0.01; - vertex(i,y); - } - endShape(); - t+= 0.01; -} diff --git a/java/examples/Books/Nature of Code/introduction/Figure_I_6_RandomGraph/Figure_I_6_RandomGraph.pde b/java/examples/Books/Nature of Code/introduction/Figure_I_6_RandomGraph/Figure_I_6_RandomGraph.pde deleted file mode 100644 index d1d4bd4fd..000000000 --- a/java/examples/Books/Nature of Code/introduction/Figure_I_6_RandomGraph/Figure_I_6_RandomGraph.pde +++ /dev/null @@ -1,22 +0,0 @@ -// The Nature of Code -// http://www.shiffman.net/ - -void setup() { - size(400,200); - smooth(); -} - - -void draw() { - background(255); - noFill(); - stroke(0); - strokeWeight(2); - beginShape(); - for (int i = 0; i < width; i++) { - float y = random(height); - vertex(i,y); - } - endShape(); - noLoop(); -} diff --git a/java/examples/Books/Nature of Code/introduction/Gaussian2/Gaussian2.pde b/java/examples/Books/Nature of Code/introduction/Gaussian2/Gaussian2.pde deleted file mode 100644 index 43992d4c6..000000000 --- a/java/examples/Books/Nature of Code/introduction/Gaussian2/Gaussian2.pde +++ /dev/null @@ -1,49 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/ - -Random generator; - -void setup() { - size(200,200); - background(0); - smooth(); - generator = new Random(); -} - -void draw() { - //create an alpha blended background - fill(0,1); - rect(0,0,width,height); - - //get 3 gaussian random numbers w/ mean of 0 and standard deviation of 1.0 - float r = (float) generator.nextGaussian(); - float g = (float) generator.nextGaussian(); - float b = (float) generator.nextGaussian(); - - //define standard deviation and mean - float sd = 100; float mean = 100; - //scale by standard deviation and mean - //also constrain to between (0,255) since we are dealing with color - r = constrain((r * sd) + mean,0,255); - - //repeat for g & b - sd = 20; mean = 200; - g = constrain((g * sd) + mean,0,255); - sd = 50; mean = 0; - b = constrain((b * sd) + mean,0,255); - - //get more gaussian numbers, this time for location - float xloc = (float) generator.nextGaussian(); - float yloc = (float) generator.nextGaussian(); - sd = width/10; - mean = width/2; - xloc = ( xloc * sd ) + mean; - yloc = ( yloc * sd ) + mean; - - //draw an ellipse with gaussian generated color and location - noStroke(); - fill(r,g,b); - ellipse(xloc,yloc,8,8); -} - diff --git a/java/examples/Books/Nature of Code/introduction/MonteCarloDistribution/MonteCarlo.pde b/java/examples/Books/Nature of Code/introduction/MonteCarloDistribution/MonteCarlo.pde deleted file mode 100644 index bc7cfab1a..000000000 --- a/java/examples/Books/Nature of Code/introduction/MonteCarloDistribution/MonteCarlo.pde +++ /dev/null @@ -1,66 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/ - -float[] vals; // Array to count how often a random # is picked -float[] norms; // Normalized version of above - -void setup() { - size(200, 200); - smooth(); - vals = new float[width]; - norms = new float[width]; -} - -void draw() { - background(100); - - // Pick a random number between 0 and 1 based on custom probability function - float n = montecarlo(); - - // What spot in the array did we pick - int index = int(n*width); - vals[index]++; - stroke(255); - - boolean normalization = false; - float maxy = 0.0; - - // Draw graph based on values in norms array - // If a value is greater than the height, set normalization to true - for (int x = 0; x < vals.length; x++) { - line(x, height, x, height-norms[x]); - if (vals[x] > height) normalization = true; - if (vals[x] > maxy) maxy = vals[x]; - } - - // If normalization is true then normalize to height - // Otherwise, just copy the info - for (int x = 0; x < vals.length; x++) { - if (normalization) norms[x] = (vals[x] / maxy) * (height); - else norms[x] = vals[x]; - } -} - -// An algorithm for picking a random number based on monte carlo method -// Here probability is determined by formula y = x -float montecarlo() { - // Have we found one yet - boolean foundone = false; - int hack = 0; // let's count just so we don't get stuck in an infinite loop by accident - while (!foundone && hack < 10000) { - // Pick two random numbers - float r1 = (float) random(1); - float r2 = (float) random(1); - float y = r1*r1; // y = x*x (change for different results) - // If r2 is valid, we'll use this one - if (r2 < y) { - foundone = true; - return r1; - } - hack++; - } - // Hack in case we run into a problem (need to improve this) - return 0; -} - diff --git a/java/examples/Books/Nature of Code/introduction/MultipleProbability/MultipleProbability.pde b/java/examples/Books/Nature of Code/introduction/MultipleProbability/MultipleProbability.pde deleted file mode 100644 index 74144ce1c..000000000 --- a/java/examples/Books/Nature of Code/introduction/MultipleProbability/MultipleProbability.pde +++ /dev/null @@ -1,39 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// ITP, Spring 2006 -// http://www.shiffman.net/ - -int x,y; - -void setup() { - size(200,200); - background(0); - smooth(); -} - -void draw() { - //create an alpha blended background - fill(0,1); - rect(0,0,width,height); - - //probabilities for 3 different cases (these need to add up to 100% since something always occurs here!) - float p1 = 0.05; // 5% chance of pure white occurring - float p2 = 0.80 + p1; // 80% chance of gray occuring - //float p3 = 1.0 - p2 ; // 15% chance of black (we don't actually need this line since it is - // by definit n, the "in all other cases" part of our else - float num = random(1); // pick a random number between 0 and 1 - if (num -// The Nature of Code - -Walker w; - -void setup() { - size(800, 200); - smooth(); - frameRate(30); - - // Create a walker object - w = new Walker(); -} - -void draw() { - background(255); - // Run the walker object - w.walk(); - w.display(); -} - - diff --git a/java/examples/Books/Nature of Code/introduction/NOC_I_5_NoiseWalk/Walker.pde b/java/examples/Books/Nature of Code/introduction/NOC_I_5_NoiseWalk/Walker.pde deleted file mode 100644 index dd11e252b..000000000 --- a/java/examples/Books/Nature of Code/introduction/NOC_I_5_NoiseWalk/Walker.pde +++ /dev/null @@ -1,33 +0,0 @@ -// Random Walker (No Vectors) -// Daniel Shiffman -// The Nature of Code - -// A random walker class! - -class Walker { - PVector location; - - PVector noff; - - Walker() { - location = new PVector(width/2, height/2); - noff = new PVector(random(1000),random(1000)); - } - - void display() { - strokeWeight(2); - fill(127); - stroke(0); - ellipse(location.x, location.y, 48, 48); - } - - // Randomly move up, down, left, right, or stay in one place - void walk() { - - location.x = map(noise(noff.x),0,1,0,width); - location.y = map(noise(noff.y),0,1,0,height); - - noff.add(0.01,0.01,0); - } -} - diff --git a/java/examples/Books/Nature of Code/introduction/Noise1D/Noise1D.pde b/java/examples/Books/Nature of Code/introduction/Noise1D/Noise1D.pde deleted file mode 100644 index a1be010e8..000000000 --- a/java/examples/Books/Nature of Code/introduction/Noise1D/Noise1D.pde +++ /dev/null @@ -1,31 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/ - -float xoff = 0.0; -float xincrement = 0.01; - -void setup() { - size(200,200); - background(0); - smooth(); - noStroke(); -} - -void draw() { - // Create an alpha blended background - fill(0, 10); - rect(0,0,width,height); - - //float n = random(0,width); // Try this line instead of noise - - // Get a noise value based on xoff and scale it according to the window's width - float n = noise(xoff)*width; - - // With each cycle, increment xoff - xoff += xincrement; - - // Draw the ellipse at the value produced by perlin noise - fill(200); - ellipse(n,height/2,16,16); -} diff --git a/java/examples/Books/Nature of Code/introduction/Noise2D/Noise2D.pde b/java/examples/Books/Nature of Code/introduction/Noise2D/Noise2D.pde deleted file mode 100644 index dc231badc..000000000 --- a/java/examples/Books/Nature of Code/introduction/Noise2D/Noise2D.pde +++ /dev/null @@ -1,41 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/ - -float increment = 0.02; - -void setup() { - size(800,200); - noLoop(); -} - -void draw() { - background(0); - - // Optional: adjust noise detail here - // noiseDetail(8,0.65f); - - loadPixels(); - - float xoff = 0.0; // Start xoff at 0 - - // For every x,y coordinate in a 2D space, calculate a noise value and produce a brightness value - for (int x = 0; x < width; x++) { - xoff += increment; // Increment xoff - float yoff = 0.0; // For every xoff, start yoff at 0 - for (int y = 0; y < height; y++) { - yoff += increment; // Increment yoff - - // Calculate noise and scale by 255 - float bright = noise(xoff,yoff)*255; - - // Try using this line instead - //float bright = random(0,255); - - // Set each pixel onscreen to a grayscale value - pixels[x+y*width] = color(bright); - } - } - - updatePixels(); -} diff --git a/java/examples/Books/Nature of Code/introduction/NoiseDistribution/NoiseDistribution.pde b/java/examples/Books/Nature of Code/introduction/NoiseDistribution/NoiseDistribution.pde deleted file mode 100644 index 56af3a708..000000000 --- a/java/examples/Books/Nature of Code/introduction/NoiseDistribution/NoiseDistribution.pde +++ /dev/null @@ -1,33 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// Testing Distribution of Perlin Noise generated #'s vs. Randoms - -float[] vals; -float[] norms; -float xoff = 0.0f; - -void setup() { - size(300,200); - vals = new float[width]; - norms = new float[width]; -} - -void draw() { - background(100); - float n = noise(xoff); - int index = int(n*width); - vals[index]++; - xoff += 0.01; - stroke(255); - boolean normalization = false; - float maxy = 0.0; - for (int x = 0; x < vals.length; x++) { - line(x,height,x,height-norms[x]); - if (vals[x] > height) normalization = true; - if(vals[x] > maxy) maxy = vals[x]; - } - for (int x = 0; x < vals.length; x++) { - if (normalization) norms[x] = (vals[x] / maxy) * (height); - else norms[x] = vals[x]; - } -} diff --git a/java/examples/Books/Nature of Code/introduction/NoiseWalkAcceleration/NoiseWalkAcceleration.pde b/java/examples/Books/Nature of Code/introduction/NoiseWalkAcceleration/NoiseWalkAcceleration.pde deleted file mode 100644 index e762a22e2..000000000 --- a/java/examples/Books/Nature of Code/introduction/NoiseWalkAcceleration/NoiseWalkAcceleration.pde +++ /dev/null @@ -1,24 +0,0 @@ -// Noise Walker -// Daniel Shiffman -// The Nature of Code - -Walker w; - -void setup() { - size(640,360); - smooth(); - - // Create a walker object - w = new Walker(); - -} - -void draw() { - background(255); - // Run the walker object - w.walk(); - w.display(); -} - - - diff --git a/java/examples/Books/Nature of Code/introduction/NoiseWalkAcceleration/Walker.pde b/java/examples/Books/Nature of Code/introduction/NoiseWalkAcceleration/Walker.pde deleted file mode 100644 index 78190295a..000000000 --- a/java/examples/Books/Nature of Code/introduction/NoiseWalkAcceleration/Walker.pde +++ /dev/null @@ -1,65 +0,0 @@ -// Random Walker -// Daniel Shiffman -// The Nature of Code - -// A random walker class! - -class Walker { - PVector location; - PVector velocity; - PVector acceleration; - - ArrayList history; - - PVector noff; - - - Walker() { - location = new PVector(width/2, height/2); - history = new ArrayList(); - noff = new PVector(random(1000), random(1000)); - velocity = new PVector(); - acceleration = new PVector(); - } - - void display() { - stroke(0); - fill(175); - rectMode(CENTER); - rect(location.x, location.y, 16, 16); - - beginShape(); - stroke(0); - noFill(); - for (PVector v: history) { - vertex(v.x, v.y); - } - endShape(); - } - - // Randomly move up, down, left, right, or stay in one place - void walk() { - - - acceleration.x = map(noise(noff.x), 0, 1, -1, 1); - acceleration.y = map(noise(noff.y), 0, 1, -1, 1); - acceleration.mult(0.1); - - noff.add(0.01, 0.01, 0); - - velocity.add(acceleration); - velocity.limit(1); - location.add(velocity); - - - history.add(location.get()); - if (history.size() > 1000) { - history.remove(0); - } - - // Stay on the screen - location.x = constrain(location.x, 0, width-1); - location.y = constrain(location.y, 0, height-1); - } -} - diff --git a/java/examples/Books/Nature of Code/introduction/NoiseWalkVelocity/NoiseWalkVelocity.pde b/java/examples/Books/Nature of Code/introduction/NoiseWalkVelocity/NoiseWalkVelocity.pde deleted file mode 100644 index f656f8073..000000000 --- a/java/examples/Books/Nature of Code/introduction/NoiseWalkVelocity/NoiseWalkVelocity.pde +++ /dev/null @@ -1,25 +0,0 @@ -// Noise Walker -// Daniel Shiffman -// The Nature of Code - -Walker w; - -void setup() { - size(400,400); - smooth(); - frameRate(30); - - // Create a walker object - w = new Walker(); - -} - -void draw() { - background(255); - // Run the walker object - w.walk(); - w.display(); -} - - - diff --git a/java/examples/Books/Nature of Code/introduction/NoiseWalkVelocity/Walker.pde b/java/examples/Books/Nature of Code/introduction/NoiseWalkVelocity/Walker.pde deleted file mode 100644 index adcd64b17..000000000 --- a/java/examples/Books/Nature of Code/introduction/NoiseWalkVelocity/Walker.pde +++ /dev/null @@ -1,60 +0,0 @@ -// Random Walker (No Vectors) -// Daniel Shiffman -// The Nature of Code - -// A random walker class! - -class Walker { - PVector location; - PVector velocity; - - ArrayList history; - - PVector noff; - - - Walker() { - location = new PVector(width/2, height/2); - history = new ArrayList(); - noff = new PVector(random(1000), random(1000)); - velocity = new PVector(); - } - - void display() { - stroke(0); - fill(175); - rectMode(CENTER); - rect(location.x, location.y, 16, 16); - - beginShape(); - stroke(0); - noFill(); - for (PVector v: history) { - vertex(v.x, v.y); - } - endShape(); - } - - // Randomly move up, down, left, right, or stay in one place - void walk() { - - - velocity.x = map(noise(noff.x), 0, 1, -1, 1); - velocity.y = map(noise(noff.y), 0, 1, -1, 1); - velocity.mult(5); - - noff.add(0.01, 0.01, 0); - - location.add(velocity); - - history.add(location.get()); - if (history.size() > 1000) { - history.remove(0); - } - - // Stay on the screen - location.x = constrain(location.x, 0, width-1); - location.y = constrain(location.y, 0, height-1); - } -} - diff --git a/java/examples/Books/Nature of Code/introduction/RandomWalk/RandomWalk.pde b/java/examples/Books/Nature of Code/introduction/RandomWalk/RandomWalk.pde deleted file mode 100644 index 7e0c65aa6..000000000 --- a/java/examples/Books/Nature of Code/introduction/RandomWalk/RandomWalk.pde +++ /dev/null @@ -1,24 +0,0 @@ -// Random Walker (No Vectors) -// Daniel Shiffman -// The Nature of Code - -Walker w; - -void setup() { - size(400,400); - frameRate(30); - - // Create a walker object - w = new Walker(); - -} - -void draw() { - background(255); - // Run the walker object - w.walk(); - w.render(); -} - - - diff --git a/java/examples/Books/Nature of Code/introduction/RandomWalk/Walker.pde b/java/examples/Books/Nature of Code/introduction/RandomWalk/Walker.pde deleted file mode 100644 index b0d26d6b1..000000000 --- a/java/examples/Books/Nature of Code/introduction/RandomWalk/Walker.pde +++ /dev/null @@ -1,34 +0,0 @@ -// Random Walker (No Vectors) -// Daniel Shiffman -// The Nature of Code - -// A random walker class! - -class Walker { - float x, y; - - Walker() { - x = width/2; - y = height/2; - } - - void render() { - stroke(0); - fill(175); - rectMode(CENTER); - rect(x, y, 40, 40); - } - - // Randomly move up, down, left, right, or stay in one place - void walk() { - float vx = random(-2, 2); - float vy = random(-2, 2); - x += vx; - y += vy; - - // Stay on the screen - x = constrain(x, 0, width-1); - y = constrain(y, 0, height-1); - } -} - diff --git a/java/examples/Books/Nature of Code/introduction/RandomWalkLevy/RandomWalkLevy.pde b/java/examples/Books/Nature of Code/introduction/RandomWalkLevy/RandomWalkLevy.pde deleted file mode 100644 index 6c9507216..000000000 --- a/java/examples/Books/Nature of Code/introduction/RandomWalkLevy/RandomWalkLevy.pde +++ /dev/null @@ -1,20 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/ - -Walker w; - -void setup() { - size(640,480); - // Create a walker object - w = new Walker(); - background(0); -} - -void draw() { - // Run the walker object - w.step(); - w.render(); -} - - diff --git a/java/examples/Books/Nature of Code/introduction/RandomWalkLevy/Walker.pde b/java/examples/Books/Nature of Code/introduction/RandomWalkLevy/Walker.pde deleted file mode 100644 index 147040bbe..000000000 --- a/java/examples/Books/Nature of Code/introduction/RandomWalkLevy/Walker.pde +++ /dev/null @@ -1,54 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/ - -// A random walker object! - -class Walker { - float x, y; - - float prevX, prevY; - - Walker() { - x = width/2; - y = height/2; - } - - void render() { - stroke(255); - line(prevX,prevY,x, y); - } - - // Randomly move according to floating point values - void step() { - prevX = x; - prevY = y; - - float stepx = random(-1, 1); - float stepy = random(-1, 1); - - float stepsize = montecarlo()*50; - stepx *= stepsize; - stepy *= stepsize; - - x += stepx; - y += stepy; - x = constrain(x, 0, width-1); - y = constrain(y, 0, height-1); - } -} - - -float montecarlo() { - while (true) { - - float r1 = random(1); - float probability = pow(1.0 - r1,8); - - float r2 = random(1); - if (r2 < probability) { - return r1; - } - } -} - diff --git a/java/examples/Books/Nature of Code/introduction/RandomWalkNoise/RandomWalkNoise.pde b/java/examples/Books/Nature of Code/introduction/RandomWalkNoise/RandomWalkNoise.pde deleted file mode 100644 index 7b85201cb..000000000 --- a/java/examples/Books/Nature of Code/introduction/RandomWalkNoise/RandomWalkNoise.pde +++ /dev/null @@ -1,20 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/ - -Walker w; - -void setup() { - size(640,360); - smooth(); - w = new Walker(); - background(0); -} - -void draw() { - // Run the walker object - w.step(); - w.render(); -} - - diff --git a/java/examples/Books/Nature of Code/introduction/RandomWalkNoise/Walker.pde b/java/examples/Books/Nature of Code/introduction/RandomWalkNoise/Walker.pde deleted file mode 100644 index 4bf77fbdd..000000000 --- a/java/examples/Books/Nature of Code/introduction/RandomWalkNoise/Walker.pde +++ /dev/null @@ -1,39 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/ - -// A random walker object! - -class Walker { - float x, y; - float tx, ty; - - float prevX, prevY; - - Walker() { - tx = 0; - ty = 10000; - x = map(noise(tx), 0, 1, 0, width); - y = map(noise(ty), 0, 1, 0, height); - } - - void render() { - stroke(255); - line(prevX, prevY, x, y); - } - - // Randomly move according to floating point values - void step() { - - prevX = x; - prevY = y; - - x = map(noise(tx), 0, 1, 0, width); - y = map(noise(ty), 0, 1, 0, height); - - tx += 0.01; - ty += 0.01; - - } -} - diff --git a/java/examples/Books/Nature of Code/introduction/RandomWalkPVector/RandomWalkPVector.pde b/java/examples/Books/Nature of Code/introduction/RandomWalkPVector/RandomWalkPVector.pde deleted file mode 100644 index 7e0c65aa6..000000000 --- a/java/examples/Books/Nature of Code/introduction/RandomWalkPVector/RandomWalkPVector.pde +++ /dev/null @@ -1,24 +0,0 @@ -// Random Walker (No Vectors) -// Daniel Shiffman -// The Nature of Code - -Walker w; - -void setup() { - size(400,400); - frameRate(30); - - // Create a walker object - w = new Walker(); - -} - -void draw() { - background(255); - // Run the walker object - w.walk(); - w.render(); -} - - - diff --git a/java/examples/Books/Nature of Code/introduction/RandomWalkPVector/Walker.pde b/java/examples/Books/Nature of Code/introduction/RandomWalkPVector/Walker.pde deleted file mode 100644 index 161db0a23..000000000 --- a/java/examples/Books/Nature of Code/introduction/RandomWalkPVector/Walker.pde +++ /dev/null @@ -1,30 +0,0 @@ -// Random Walker (No Vectors) -// Daniel Shiffman -// The Nature of Code -// A random walker class! - -class Walker { - PVector loc; - - Walker() { - loc = new PVector(width/2,height/2); - } - - void render() { - stroke(0); - fill(175); - rectMode(CENTER); - rect(loc.x,loc.y,40,40); - } - - // Randomly move up, down, left, right, or stay in one place - void walk() { - PVector vel = new PVector(random(-2,2),random(-2,2)); - loc.add(vel); - - // Stay on the screen - loc.x = constrain(loc.x,0,width-1); - loc.y = constrain(loc.y,0,height-1); - } -} - diff --git a/java/examples/Books/Nature of Code/introduction/RandomWalkTraditional2/RandomWalkTraditional2.pde b/java/examples/Books/Nature of Code/introduction/RandomWalkTraditional2/RandomWalkTraditional2.pde deleted file mode 100644 index d45577c28..000000000 --- a/java/examples/Books/Nature of Code/introduction/RandomWalkTraditional2/RandomWalkTraditional2.pde +++ /dev/null @@ -1,20 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/ - -Walker w; - -void setup() { - size(200,200); - // Create a walker object - w = new Walker(); - background(0); -} - -void draw() { - // Run the walker object - w.step(); - w.render(); -} - - diff --git a/java/examples/Books/Nature of Code/introduction/RandomWalkTraditional2/Walker.pde b/java/examples/Books/Nature of Code/introduction/RandomWalkTraditional2/Walker.pde deleted file mode 100644 index a73abfb93..000000000 --- a/java/examples/Books/Nature of Code/introduction/RandomWalkTraditional2/Walker.pde +++ /dev/null @@ -1,29 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/ - -// A random walker object! - -class Walker { - int x,y; - - Walker() { - x = width/2; - y = height/2; - } - - void render() { - stroke(255); - point(x,y); - } - - // Randomly move to any neighboring pixel (or stay in the same spot) - void step() { - int stepx = int(random(3))-1; - int stepy = int(random(3))-1; - x += stepx; - y += stepy; - x = constrain(x,0,width-1); - y = constrain(y,0,height-1); - } -} diff --git a/java/examples/Books/Nature of Code/introduction/RandomWalkTraditional3/RandomWalkTraditional3.pde b/java/examples/Books/Nature of Code/introduction/RandomWalkTraditional3/RandomWalkTraditional3.pde deleted file mode 100644 index d45577c28..000000000 --- a/java/examples/Books/Nature of Code/introduction/RandomWalkTraditional3/RandomWalkTraditional3.pde +++ /dev/null @@ -1,20 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/ - -Walker w; - -void setup() { - size(200,200); - // Create a walker object - w = new Walker(); - background(0); -} - -void draw() { - // Run the walker object - w.step(); - w.render(); -} - - diff --git a/java/examples/Books/Nature of Code/introduction/RandomWalkTraditional3/Walker.pde b/java/examples/Books/Nature of Code/introduction/RandomWalkTraditional3/Walker.pde deleted file mode 100644 index a3991d367..000000000 --- a/java/examples/Books/Nature of Code/introduction/RandomWalkTraditional3/Walker.pde +++ /dev/null @@ -1,30 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/ - -// A random walker object! - -class Walker { - float x, y; - - Walker() { - x = width/2; - y = height/2; - } - - void render() { - stroke(255); - point(x, y); - } - - // Randomly move according to floating point values - void step() { - float stepx = random(-1, 1); - float stepy = random(-1, 1); - x += stepx; - y += stepy; - x = constrain(x, 0, width-1); - y = constrain(y, 0, height-1); - } -} - diff --git a/java/examples/Books/Nature of Code/introduction/RandomWalkTrail/RandomWalkTrail.pde b/java/examples/Books/Nature of Code/introduction/RandomWalkTrail/RandomWalkTrail.pde deleted file mode 100644 index 829dd5a6a..000000000 --- a/java/examples/Books/Nature of Code/introduction/RandomWalkTrail/RandomWalkTrail.pde +++ /dev/null @@ -1,24 +0,0 @@ -// Random Walker (No Vectors) -// Daniel Shiffman -// The Nature of Code - -Walker w; - -void setup() { - size(400,400); - frameRate(30); - - // Create a walker object - w = new Walker(); - -} - -void draw() { - background(255); - // Run the walker object - w.walk(); - w.display(); -} - - - diff --git a/java/examples/Books/Nature of Code/introduction/RandomWalkTrail/Walker.pde b/java/examples/Books/Nature of Code/introduction/RandomWalkTrail/Walker.pde deleted file mode 100644 index 4fbab1eb1..000000000 --- a/java/examples/Books/Nature of Code/introduction/RandomWalkTrail/Walker.pde +++ /dev/null @@ -1,49 +0,0 @@ -// Random Walker (No Vectors) -// Daniel Shiffman -// The Nature of Code - -// A random walker class! - -class Walker { - PVector location; - - ArrayList history; - - - Walker() { - location = new PVector(width/2, height/2); - history = new ArrayList(); - } - - void display() { - stroke(0); - fill(175); - rectMode(CENTER); - rect(location.x, location.y, 16, 16); - - beginShape(); - stroke(0); - noFill(); - for (PVector v: history) { - vertex(v.x, v.y); - } - endShape(); - } - - // Randomly move up, down, left, right, or stay in one place - void walk() { - PVector vel = new PVector(random(-2, 2), random(-2, 2)); - location.add(vel); - - // Stay on the screen - location.x = constrain(location.x, 0, width-1); - location.y = constrain(location.y, 0, height-1); - - - history.add(location.get()); - if (history.size() > 1000) { - history.remove(0); - } - } -} - diff --git a/java/examples/Books/Nature of Code/introduction/SimpleProbablility/SimpleProbablility.pde b/java/examples/Books/Nature of Code/introduction/SimpleProbablility/SimpleProbablility.pde deleted file mode 100644 index 8843f1581..000000000 --- a/java/examples/Books/Nature of Code/introduction/SimpleProbablility/SimpleProbablility.pde +++ /dev/null @@ -1,34 +0,0 @@ -// Daniel Shiffman -// The Nature of Code -// http://www.shiffman.net/ - -int x,y; - -void setup() { - size(200,200); - background(0); - smooth(); -} - -void draw() { - //create an alpha blended background - fill(0,1); - rect(0,0,width,height); - - //calculate a probability between 0 and 100% based on mouseX location - float prob = (mouseX / (float) width); - - //get a random floating point value between 0 and 1 - float r = random(1); - - //test the random value against the probability and trigger an event - if (r < prob) { - noStroke(); - fill(255); - ellipse(x,y,10,10); - } - - // X and Y walk through a grid - x = (x + 10) % width; - if (x == 0) y = (y + 10) % width; -}

Force directed graph, - * heavily based on: fid.gen
- * The Nature of Code
- * Spring 2010