Add files via upload

This commit is contained in:
Daniel
2024-01-17 21:53:56 +02:00
committed by GitHub
parent 1c39199cc3
commit 7e04c3a9ef
8 changed files with 101 additions and 25 deletions

View File

@@ -7,11 +7,13 @@ class Balloon {
PVector velocity; PVector velocity;
PVector acceleration; PVector acceleration;
float lastWindChangeTime; float lastWindChangeTime;
PShape s;
Balloon(float x, float y, float z) { Balloon(float x, float y, float z, PShape s) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.s = s;
this.radius = 50; this.radius = 50;
this.velocity = new PVector(0, 0, 0); this.velocity = new PVector(0, 0, 0);
this.acceleration = new PVector(0, 0, 0); this.acceleration = new PVector(0, 0, 0);
@@ -46,19 +48,23 @@ class Balloon {
z += 2; z += 2;
translate(x, y, z); translate(x, y, z);
rotateY(PI);
scale(4);
fill(255, 0, 0); //fill(255, 0, 0);
noStroke(); //noStroke();
sphere(radius); //sphere(radius);
stroke(1); //stroke(1);
drawLeg(-radius / 2, -radius / 2); //drawLeg(-radius / 2, -radius / 2);
drawLeg(radius / 2, -radius / 2); //drawLeg(radius / 2, -radius / 2);
drawLeg(-radius / 2, radius / 2); //drawLeg(-radius / 2, radius / 2);
drawLeg(radius / 2, radius / 2); //drawLeg(radius / 2, radius / 2);
translate(0, 0, -75); //translate(0, 0, -75);
box(70, 70, 25); //box(70, 70, 25);
shape(s);
applyBuoyancy(); applyBuoyancy();
applyDamping(); applyDamping();

View File

@@ -6,11 +6,20 @@ class Block {
boolean isFlower; boolean isFlower;
int treeSize; int treeSize;
color treeColor; color treeColor;
ArrayList<Particle> particles = new ArrayList<>();
Block(int x, int y, float h, color treeColor, int treeSize) { Block(int x, int y, float h, color treeColor, int treeSize) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.h = h; this.h = h;
this.treeColor = treeColor; this.treeColor = treeColor;
this.treeSize = treeSize; this.treeSize = treeSize;
for (int i = 0; i < 4; i++) {
float angleInRadians = map(i, 0, 10, 0, TWO_PI);
particles.add(new Particle(cubeWidth * cos(angleInRadians), cubeWidth * sin(angleInRadians), 0, this, random(0.5, 1), h/2));
}
}
void drawParticles(float posZ) {
particles.forEach(particle -> particle.display(posZ));
} }
} }

View File

@@ -23,7 +23,7 @@ class Butterfly {
void draw() { void draw() {
pushMatrix(); pushMatrix();
rotateX(HALF_PI); rotateX(HALF_PI);
// (terrainLength / 10)
z = map(noise(perlinOffsetX, millis() * 0.0002), 0, 1, 400, 600); z = map(noise(perlinOffsetX, millis() * 0.0002), 0, 1, 400, 600);
x = map(noise(perlinOffsetY, millis() * 0.0001), 0, 1, 0, terrainLength * cubeWidth); x = map(noise(perlinOffsetY, millis() * 0.0001), 0, 1, 0, terrainLength * cubeWidth);
y = map(noise(perlinOffsetZ, millis() * 0.0001), 0, 1, 0, terrainWidth * cubeWidth); y = map(noise(perlinOffsetZ, millis() * 0.0001), 0, 1, 0, terrainWidth * cubeWidth);

View File

@@ -1,13 +1,13 @@
int terrainLength = 1000; int terrainLength = 100;
int terrainWidth = 1000; int terrainWidth = 100;
int minTreeHeight = 20; int minTreeHeight = 20;
int maxTreeHeight = 70; int maxTreeHeight = 70;
float noiseStep = 0.02; float noiseStep = 0.02;
float noiseScale = 5; float noiseScale = 5;
long randomSeedValue = 55; long randomSeedValue = 45;
long noiseSeedValue = 254; long noiseSeedValue = 2544;
int noiseOctaves = 4; int noiseOctaves = 4;
float noiseFalloff = 0.5; float noiseFalloff = 0.5;

View File

@@ -1,8 +1,9 @@
PVector camPosition = new PVector(1000, -700, 700); PVector camPosition = new PVector(1000, -700, 700);
PVector camPosition1 = new PVector(1000, -700, 700);
PVector lookAt = new PVector(0, 0, -1); PVector lookAt = new PVector(0, 0, -1);
PVector wind = new PVector(5, -8, 0); PVector wind = new PVector(5, -8, 0);
Terrain terra = new Terrain(); Terrain terra = new Terrain();
Balloon balloon = new Balloon(50 * 20, 50 * 20, 20 * 20); PImage skyboxImage;
void setup() { void setup() {
fullScreen(P3D); fullScreen(P3D);
@@ -13,6 +14,8 @@ void setup() {
noiseSeed(noiseSeedValue); noiseSeed(noiseSeedValue);
noiseDetail(noiseOctaves, noiseFalloff); noiseDetail(noiseOctaves, noiseFalloff);
skyboxImage = loadImage("hot.jpg");
terra.setup(); terra.setup();
terra.reloadTrees(); terra.reloadTrees();
} }
@@ -62,8 +65,8 @@ void draw() {
camPosition.sub(PVector.mult(right, camSpeed)); camPosition.sub(PVector.mult(right, camSpeed));
} }
if (key == 'r') terra.blocks.get(0).x += 1; if (key == 'r') terra.blocks.get(0).x += 1;
if (key == 'f') terra.blocks.get(0).y += 1; if (key == 'f') terra.blocks.get(0).y += 1;
} }
camera(camPosition.x, camPosition.y, camPosition.z, camPosition.x + lookAt.x, camPosition.y + lookAt.y, camPosition.z + lookAt.z, 0, 1, 0); camera(camPosition.x, camPosition.y, camPosition.z, camPosition.x + lookAt.x, camPosition.y + lookAt.y, camPosition.z + lookAt.z, 0, 1, 0);
@@ -71,7 +74,16 @@ void draw() {
terra.drawTerrain(camPosition); terra.drawTerrain(camPosition);
PVector windForce = wind.copy().mult(0.1); // Draw the skybox
balloon.applyForce(windForce); //drawSkySphere(500);
balloon.draw(); }
void drawSkySphere(float radius) {
pushMatrix();
noStroke();
translate(camPosition1.x, camPosition1.y, camPosition1.z);
textureMode(NORMAL);
texture(skyboxImage);
sphere(radius);
popMatrix();
} }

33
Particle.pde Normal file
View File

@@ -0,0 +1,33 @@
class Particle {
float x, y, z;
float speed;
color col;
float permOffset;
float offset = 0;
Block block;
Particle(float x, float y, float z, Block block, float speed, float treeSize) {
this.x = x;
this.y = y;
this.z = z;
this.block = block;
this.speed = speed;
this.permOffset = -150 - treeSize;
}
void update() {
offset -= speed;
if (offset < -100) offset = 0;
}
void display(float posZ) {
pushMatrix();
translate(x, y, posZ + permOffset + offset);
fill(block.treeColor);
float scaleDown = map(offset, 0, -150, 1, 10);
box(10/scaleDown, 8/scaleDown, 8/scaleDown);
scale(offset);
popMatrix();
update();
}
}

View File

@@ -3,6 +3,7 @@ class Terrain {
ArrayList < Bird > birds = new ArrayList < > (); ArrayList < Bird > birds = new ArrayList < > ();
ArrayList < Butterfly > butterflies = new ArrayList < > (); ArrayList < Butterfly > butterflies = new ArrayList < > ();
float blue = 100; float blue = 100;
float particleOffset;
float bluedirection = -0.25; float bluedirection = -0.25;
void addButterfly() { void addButterfly() {
@@ -24,6 +25,8 @@ class Terrain {
if (random(0, 1) < 0.001) addButterfly(); if (random(0, 1) < 0.001) addButterfly();
} }
} }
} }
void reloadTrees() { void reloadTrees() {
@@ -76,7 +79,7 @@ class Terrain {
float posY = block.y * cubeLength; float posY = block.y * cubeLength;
float posZ = blockHeight / 2.0; float posZ = blockHeight / 2.0;
if (dist(posX, 0.0, posY, position.x, 0.0, position.z) > 1500) return; if (dist(posX, 0.0, posY, position.x, 0.0, position.z) > 2000) return;
pushMatrix(); pushMatrix();
@@ -84,7 +87,10 @@ class Terrain {
translate(posX, posY, posZ); translate(posX, posY, posZ);
box(cubeWidth, cubeLength, blockHeight); box(cubeWidth, cubeLength, blockHeight);
if (block.isTree && blockHeight < 350) drawNormalTree(block, posZ); if (block.isTree && blockHeight < 350) {
drawNormalTree(block, posZ);
block.drawParticles(posZ);
}
else if (block.isTree) drawPineTree(block, posZ); else if (block.isTree) drawPineTree(block, posZ);
else if (block.isFlower && blockHeight < 350) drawFlower(block, posZ); else if (block.isFlower && blockHeight < 350) drawFlower(block, posZ);
@@ -139,4 +145,13 @@ else if (block.isFlower && blockHeight < 350) drawFlower(block, posZ);
sphere(10); sphere(10);
stroke(1); stroke(1);
} }
void drawParticle(float x, float y, float z, color col) {
pushMatrix();
translate(x, y, particleOffset);
particleOffset -= random(0, 0.001);
fill(col);
box(10, 10, 10);
popMatrix();
}
} }

1
sketch.properties Normal file
View File

@@ -0,0 +1 @@
main=Main.pde