
No title available

JVL
Jules of Nature
todays bird
Sweet Seals For You, Always
sheepfilms
we're not kids anymore.
Game of Thrones Daily

Love Begins
Not today Justin
RMH

祝日 / Permanent Vacation
occasionally subtle

⁂

@theartofmadeline
will byers stan first human second

izzy's playlists!
One Nice Bug Per Day
hello vonnie
Aqua Utopia|海の底で記憶を紡ぐ
seen from United States
seen from Denmark
seen from United States
seen from United States
seen from Vietnam
seen from United States

seen from Germany
seen from United States

seen from Malaysia

seen from Latvia

seen from United States
seen from United States
seen from Brazil
seen from Brazil
seen from United States

seen from United States
seen from United States

seen from United States
seen from United States
seen from United States
@ibcs3
We made a working ecosystem, with fishes, jellyfishes, and Squidward, who acts as a predator. He pursues the fish, until they all die and disappear.
Here’s the code:
PImage burguer; PImage fish; PImage jellyfish2; PImage squidward2; PImage bg;
int total =0;
gusanito gusanito; jellyfish2 [] j; Crawler[] crawlers = new Crawler[4]; evil e;
Attractor a;
void setup() {
fish=loadImage("fish.png"); burguer=loadImage("burguer.png"); squidward2 = loadImage("squidward2.png"); jellyfish2 = loadImage("jellyfish2.gif"); bg= loadImage ("SkyFlower.jpg"); e= new evil();
j =new jellyfish2[12]; for (int v=0; v< j.length; v++){ j[v] = new jellyfish2(); }
gusanito = new gusanito (new PVector (150,250), 70,10,110);
size(1000,500); // 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(bg);
gusanito.calculate(); gusanito.display();
e.walk (crawlers [0].loc.x, crawlers [0].loc.y); e.display();
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();
} if (frameCount %30 ==0){ total =total+1; if (total >j.length-1){ total=j.length-1; } }
for (int v=0; v< total; v++){ j[v].walk(); j[v].display();
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); }
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; }
}
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();
loc.x = constrain (loc.x,0-5,width-10); loc.y = constrain (loc.y,0-5,height-10);
pushMatrix(); translate(loc.x,loc.y); rotate(angle); ellipseMode(CENTER); stroke(0); fill(175,100); pushMatrix(); scale(0.2,0.2); image(fish,mass*2,mass*2); popMatrix();
// osc.display(loc); popMatrix();
} }
class gusanito {
int xspacing = 9; // 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;
gusanito(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.08;
// 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;
float r= random (2); if(r==0){ origin.x++; }if (r==1){ origin.x++; }else{ origin.x++; }}
}
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(); } } }
class jellyfish2{
PVector location;
PVector noff; float lifespan;
jellyfish2(){ location = new PVector (width/2, height/2); noff = new PVector (random(1000), random(1000)); lifespan =1500.0; }
void display(){ pushMatrix(); tint(255,lifespan); image(jellyfish2,location.x,location.y); popMatrix(); }
void walk(){
location.x = map(noise (noff.x),0,1,0,width); location.y = map (noise (noff.y),0,1,0,height);
noff.x +=0.01; noff.y +=0.01; lifespan -=2.0; }
boolean isDead(){ if (lifespan <0.0){ return true; } else{ return false; } }
}
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); }*/ }
WTF is this? Is the game we made. It is a Flappy Bird-type game, starring Mario and Bowser(s), a lot of Bowsers. I think we made a really good job. The only thing we missed is that the Bowsers show up in a random order.
Here’s the code:
mario b = new mario(); object[] o= new object[3]; int x,y; boolean end=false; boolean intro=true; int score=0; PImage img, img2,img3; PImage bg;
void setup() { size(500, 500);
img=loadImage("Mario2.png"); img2= loadImage("bowser.png");
bg= loadImage("BgMario.jpg"); bg.resize(600, 500);
for (int i = 0; i<3; i++) { o[i]=new object(i);
}
}
void draw() { x= constrain(x,0,bg.width); y= constrain(y,0,bg.height);
image(bg,-x,0); x= frameCount % 600; image(bg,-x+600,0); frameRate(60); if (end) { b.move(); } b.drawmario(); if (end) { b.drag(); } b.checkCollisions(); for (int i = 0; i<3; i++) { o[i].drawobject(); o[i].checkPosition(); }
fill(0); stroke(255); textSize(32); if (end) { rect(20, 20, 100, 50); fill(255); text(score, 30, 58); } else { rect(150, 100, 200, 50); rect(150, 200, 200, 50); fill(255); if (intro) { text("WTF is this?", 155, 140); text("Press W", 155, 240); } else { text("game over", 170, 140); text("score", 180, 240); text(score, 280, 240); } } } class mario { float xPos, yPos, ySpeed; mario() { xPos = 50; yPos = 420; } void drawmario() {
image(img, xPos, yPos, 50, 50); //piso if (yPos>=420) { yPos=420; ySpeed=0; } } void jump() { ySpeed=-10; } void drag() { ySpeed+=0.4; } void move() { yPos+=ySpeed; for (int i = 0; i<3; i++) { o[i].xPos-=3; } }
//COLLISIONS WITH OBJECTS void checkCollisions() { if (yPos>800) { end=false; } for (int i = 0; i<3; i++) { if ((xPos<o[i].xPos+10 && yPos<o[i].yPos+20) && (xPos>o[i].xPos-10 && yPos>o[i].yPos-20)) { end=false; } } } }
//Enemies code class object { float xPos, yPos; boolean cashed = false; object(int o) { xPos = 100+(o*200); yPos=100+(o*200);
} void drawobject() { image(img2, xPos, yPos, 75, 75); //img2=random(600)+100; } //Position void checkPosition() { if (xPos<0) { xPos+=(200*3); cashed=false; } if (xPos<50&&cashed==false) { cashed=true; score++; } } } void reset() { end=true; score=0; b.yPos=400; for (int i = 0; i<3; i++) { o[i].xPos+=550; o[i].cashed = false; } } void keyPressed() { b.jump(); intro=false; if (end==false) { reset(); } }
Runner. Exercise 1.5.
Application of Vectors:
class Ball{ PVector location; PVector velocity; PVector acceleration; Ball(){ location=new PVector(width/2,height/2); velocity=new PVector(10,0); acceleration=new PVector(1,0); } void accel(){ velocity.mult(2); } void brake(){ velocity.div(2); }
void update(){ 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; } } void display(){ stroke(10); fill(42,42,42); image(img,location.x,location.y,300,300); } }
Ball b; PImage img; PImage bg;
void setup(){ b=new Ball(); img=loadImage("Runner.png"); bg=loadImage("Track2.jpg"); } void settings(){ size(1024,686); } void draw(){ background(bg); b.update(); b.display(); } void keyPressed(){ if(key==CODED){ if(keyCode==UP){ b.accel(); } else if(keyCode==DOWN){ b.brake(); }
} }
Generally, it wasn’t hard to build the code. The only difficulty that I found was how to prevent the runner from disappear when he reached the border. However, I successfully managed to fix it.
Example of Vector Basics:
void setup(){ size(700,700); }
void draw(){ background(255,255,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); }