Giter VIP home page Giter VIP logo

noc-examples-processing's People

Contributors

abhikpal avatar andrei-dracea avatar arastogi1997 avatar carla-de-beer avatar dead-horse avatar hamoid avatar hardmaru avatar hysysk avatar jakejscott avatar javl avatar jesuino avatar liam-middlebrook avatar makio135 avatar markubu avatar millilux avatar monkstone avatar mvcrft avatar nkint avatar noosphere2 avatar overbk avatar owenroberts avatar playgrdstar avatar redek91 avatar scotthmurray avatar shiffman avatar ssouzawallace avatar takocheung avatar tsulej avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

noc-examples-processing's Issues

Strange behaviour in Example NOC_2_5_fluidresistance.pde

Hi Dan, i found a strange behaviour while making the exercises in the book. I could reproduce the problem in the example NOC_2_5_fluidresistance.pde.
Try to set
movers[i] = new Mover(random(0.1, 0.2), 40+i*70, 0);
at line 62 instead of
movers[i] = new Mover(random(0.5, 3), 40+i*70, 0);
You'll see that the small objects are actually bouncing off the liquid and going up at "speed of light".

Why is this happening? Is it to the low precision of the float data type or am I missing something?

expecting EOF, found 'import'

In Processing example ch_9ga/EvolveFlowField/EvolveFlowField.pde using Processing 2.0b6, I get the following error when trying to run the sketch.

Expecting EOF, found 'import'

This occurred in line 9 of Obstacle.pde, the line that reads import java.awt.Rectangle;

I was able to remedy this by moving this library import line to the main file (EvolveFlowField.pde) at the top of the file, in which I could then run the sketch. Thanks.

Exercise 5.16

Create an object that both attracts and repels. What if it attracts any particle that is far away but repels those particles at a short distance?

Variation of NOC_02forces_many_mutual_boundaries

Hi Daniel,

First of all, thanks for the wonderful work on code / videos / and your books.

Just wanted to post an enhancement for a variation for one of the exercises.

I'll call it Big-Bang.
It consists of exactly the same exercise (NOC_02forces_many_mutual_boundaries), but change the start position of all particles to the center of the screen.

Next generate a starting force and on each particle iteration, rotate the force so that each particle starts moving to a different angle simulating an explosion.

void setup() {
  size(1500,1000);
  for (int i = 0; i < movers.length; i++) {
    movers[i] = new Mover(random(1,2),width/2,height/2);

    // Determine an angle so that all particles get a force in a unique direction ( 360 / amount of particles )
    float angle = 360/movers.length;    

    // Create a force with a random X 
    PVector some_force = new PVector(random(0,10),0);

    // Rotate the force according to particle i
    PVector force = some_force.rotate(radians(angle*(i+1)));

    // Apply the force to the particle so that when the program starts, each one is moving in a direction
    movers[i].applyForce(force);

  }
}

pjs preloads

check them, specifically image particle systems

exercise 2.7 solution

"Fluid resistance does not only work opposite to the velocity vector, but also perpendicular to it. This is known as “lift-induced drag” and will cause an airplane with an angled wing to rise in altitude. Try creating a simulation of lift."

Iterator

Need to decide whether to use Iterator in the examples or not. It needs an explicit import now. It seems to be supported by Processing.js but maybe less risk to iterate with i.

Iterator<Particle> it = particles.iterator();
while (it.hasNext()) {
  Particle p = it.next();
  p.run();
  if (p.isDead()) {
     it.remove(); 
   }
}

vs.

for (int i = particles.size()-1; i >=0; i--) {
  Particle p = particles.get(i);
  p.run();
  if (p.isDead()) {
    particles.remove(i);
  }
}

pbox2d comment error

from reader:

This is just a note on the PBox2D example code that came with Processing 2.0b6:

ApplyForceSimpleWind and ApplyForceAttractMouse around line 48

// 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);
}

I guess the comment should read something like "add a new Box object about 10% of the time"

TimeTable Generator with Genetic Algorithm

I have been trying to develop an application for timetable generation for universities/schools using Genetic Algorithm. It would be great if you could give a some guidance!!!!!!

Exercise_8_08_09_TreeArrayListLeaves 'pos' and 'loc' names

The-Nature-of-Code-Examples-master\chp08_fractals\Exercise_8_08_09_TreeArrayListLeaves\Leaf.pde

This:

class Leaf {
  PVector pos;

  Leaf(PVector l) {
    loc = l.get();
  }

Should be this:

class Leaf {
  PVector pos;

  Leaf(PVector l) {
    pos = l.get();
 }

or this:

class Leaf {
  PVector loc;

  Leaf(PVector l) {
    loc = l.get();
 }

exercise 2.1 balloons

Below is my solution for exercise 2.1, balloons.

//code by Densou
//email: [email protected]

Balloon[] balloons= new Balloon[10];

void setup(){
size(600,400);
smooth();
for(int i=0; i<balloons.length;i++){
balloons[i]= new Balloon(i);
}

}

void draw(){
background(200,40,60);

for(int i=0; i<balloons.length;i++){
balloons[i].render();
balloons[i].update();
balloons[i].checkCollision();
}

}

class Balloon{
//v for velocity
//f for acceleration of flotage
//r for acceleration of resistance
//l for location
//a for total acceleration
//wind force
PVector v, f, l, a, wind;
//w,h:size of this balloon
//stringl:string length
//sw: string swing range
//maxV stands for the max velocity a balloon can reach--
//when gracity and flotage get balance
float w,h, maxV,stringl,sw;
//covenient for array
int array;
//color of each balloon
color c;

Balloon(int array_){
v= new PVector(0,0);
//f= new PVector(0,-0.02);
//f minus 0.01, in case acceleration too small
f= new PVector(0,random(0.02)-1-0.01);
maxV= 2.5;
w=random(15)+30;
h=random(10)+w
1.2;
//l= new PVector(width/2,height);
l = new PVector(random(width),random(height/2)+height*.5);
stringl=80.0;
sw=40;
array=array_;
c=color(random(150)+100,random(150)+100,random(150)+100);
//c=color(array%3150,(array+2)%3150,(array+1)%3*150);
}

void update(){
wind= new PVector((noise(1,frameCount/200)-0.5)*0.04,(noise(2,frameCount/200)-0.5)*0.01);
a=PVector.add(f,wind);//use static function here, otherwise a increases.
//println(a.x,a.y);
v.add(a);
l.add(v);
//println(v.y);
v.limit(2.2);
//if(v.y>maxV ){
// v.y=maxV;
//}else if(v.y<-maxV){
// v.y=-maxV;
//}
}

void render(){
pushMatrix();
translate(l.x,l.y+h/2);
//swinging string
stroke(242,192,86);
strokeWeight(1);
noFill();
float t=frameCount/500.0;
bezier(
0,0,
0,noise(1,array,t)*stringl-stringl/2,
noise(2,array,t)*sw-sw/2,noise(3,array,t)stringl0.6,
noise(4,array,t)*sw-sw/2,noise(5,array,t)*stringl
);

//balloon ball
//fill(220,30,100);
fill(c);
noStroke();
//ellipse(l.x,l.y,w,h);
ellipse(0,-h/2,w,h);
popMatrix();

}

void checkCollision(){
if(l.y<h/2){
v.y=v.y*-0.8;
f.y=f.y0.8;
if(v.y<0.02 && -0.02<v.y){
v.y=0;
f.y=0;
l.y=h/2;
}
}
//println(v.y);
if(l.x<w/2 || l.x>width-w/2){
v.x=v.x
-0.6;
}
}
}

MousePressed in "NOC_5_1_box2d_exercise_solved.pde"

I think line 31 should read something like this or the boxes just keep appearing regardless if you click your mouse or not.

// When the mouse is clicked, add a new Box object
if (mousePressed) {
Box p = new Box(mouseX, mouseY);
boxes.add(p);
}

Pull request guidelines

"pull request guidelines? would think a lang specific readme with requirements and dependencies would be a good start."

examples with p5.js

Hey Daniel, just starting your book, really looking forward to getting into it!

I was just curious to see if you had any plans of creating a set of javascript examples - so that we can follow along using p5.js?

A simple question about the path following code

I have a question about NOC_6_05_PathFollowingSimple

In the Vehicle class you calculate the target position outside the if (distance > p.radius), but actually you apply seek(target) only if in that condition is true, could you save some calculation by moving the logic for finding the target within the if (distance > p.radius) block?

Why did you choose to put that logic outside the conditional? Just for debugging reasons or there's something else useful you can do with that?

Missing mouse interaction

The example Exercise_6_08_FlowField3DNoise says: "click mouse to generate a new flow field", but this is not implemented in the code. Could be copy pasted from NOC_6_04_Flowfield maybe?

How to add an example?

I'm sorry this is surely not the way to go but I'm not sure how to do it otherwise ...

Here's the code for example 1.3 from the book:

/* built with Studio Sketchpad:

// Nature of Code - EXERCISE 1.3 - 3D Bouncing Ball
// Extend the bouncing ball with vectors example into 3D.
// Can you get a sphere to bounce around a box?

// https://forum.processing.org/topic/
// the-nature-of-code-code-solutions-of-the-examples

// studio.processingtogether.com/sp/pad/export/ro.9o1T5z1ghf2s7/latest

final PVector location = new PVector();
final PVector velocity = new PVector(3, 2, 4);

final static int BALL_DIM = 30;
final static int CUBE_DIM = 450, CUBE_RAD = CUBE_DIM >> 1;

int cx, cy;

void setup() {
size(400, 400, P3D);
strokeWeight(2);

cx = width >> 1;
cy = height >> 1;
}

void draw() {
background(-1);

drawCube();
moveSphere();
drawSphere();
}

void drawCube() {
//move cube and ball to center:
translate(cx, cy, -CUBE_DIM);

//rotate cube and ball so it's 3D-ness can be appreciated:
rotateX(-QUARTER_PI);
rotateY(QUARTER_PI);
rotateZ(QUARTER_PI/2);

//draw cube:
noFill();
stroke(0);

box(CUBE_DIM);
}

void moveSphere() {
//move ball:
location.add(velocity);

//detect edges with center at 0,0 and edge minus width of ball:
if ( checkBounce(location.x) ) velocity.x *= -1;
if ( checkBounce(location.y) ) velocity.y *= -1;
if ( checkBounce(location.z) ) velocity.z *= -1;
}

void drawSphere() {
//draw ball, and lights for definition:
translate(location.x, location.y, location.z);

fill(0300);
noStroke();
lights();

sphere(BALL_DIM);
}

static final boolean checkBounce(float coord) {
return coord > CUBE_RAD - BALL_DIM | coord < BALL_DIM - CUBE_RAD;
}

Genetic Faces example mispells "fitness"

My incorrectly-placed issue - this is from the pre-loaded Processing examples, which I would guess are cloned from here:

In NOC_9_04_Faces_interactiveselection, in the Population class, in the comment above the function getMaxFitness(), the word "fitness" is spelled "fintess".

Trivial, but FWIW.

openFrameworks port of the examples

Hey,

the structure of this repo lets me assume, that it is planned to add ports of the examples in different languages.

I just took care of porting chapter 4 to openFrameworks yesterday and would like to share my findings. So i was wondering, if a PR would be appreciated here.

Doing a bit of research, i found that @firmread and @emmanuelgeoffray have already started rewriting chapter 1, 2, 3 and 6 in openFrameworks. Maybe they would contribute their code too.

best,
/m

Braitenberg Vehilces

I would really like to find the time to make a set of examples for chapter 6 that implement the braitenberg vehicles.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.