We are about to switch to a new forum software. Until then we have removed the registration on this forum.
There might be some relevant previous discussion on the forum of solar system / planet modeling specifically:
When you say "I can's seem to do the final step and I think it has to do with the vectors" could you say more about what specifically you mean?
Example vector sketch:
Your class Planet's constructor got 5 parameters: L-)constructor(radius, distance, orbitspeed, angle, mass) {
However, when you instantiate it, you only pass 4 arguments to it: #-osun = new Planet(20, 0, 0, random(TWO_PI));
Which means Planet::mass property is assigned w/ undefined
: :-SSthis.mass = mass;
And inside Planet::orbit() method: this.angle += this.orbitspeed/this.mass;
The expression this.orbitspeed/this.mass
is evaluated as NaN
.
Which also makes Planet::angle property NaN
as well! :-&
Hey everyone, I am doing this sketch which is following up dan's shiffman tutorial in processing, however I am doing it in p5.js for some reason I can's seem to do the final step and I think it has to do with the vectors. If anyone can help me, I would really appreciate it. Here is the code in processing:
import peasy.*;
Planet sun;
PeasyCam cam;
void setup() {
size(600, 600, P3D);
cam = new PeasyCam(this, 500);
sun = new Planet(50, 0, 0);
sun.spawnMoons(4, 1);
}
void draw() {
background(0);
lights();
sun.show();
sun.orbit();
}
// planet class
class Planet {
float radius;
float distance;
Planet[] planets;
float angle;
float orbitspeed;
PVector v;
PShape globe;
Planet(float r, float d, float o) {
v = PVector.random3D();
radius = r;
distance = d;
v.mult(distance);
angle = random(TWO_PI);
orbitspeed = o;
}
void orbit() {
angle = angle + orbitspeed;
if (planets != null) {
for (int i = 0; i < planets.length; i++) {
planets[i].orbit();
}
}
}
void spawnMoons(int total, int level) {
planets = new Planet[total];
for (int i = 0; i < planets.length; i++) {
float r = radius/(level*2);
float d = random((radius + r), (radius+r)*2);
float o = random(-0.1, 0.1);
planets[i] = new Planet(r, d, o);
if (level < 2) {
int num = int(random(0, 3));
planets[i].spawnMoons(num, level+1);
}
}
}
void show() {
pushMatrix();
noStroke();
PVector v2 = new PVector(1, 0, 1);
PVector p = v.cross(v2);
rotate(angle, p.x, p.y, p.z);
stroke(255);
//line(0, 0, 0, v.x, v.y, v.z);
//line(0, 0, 0, p.x, p.y, p.z);
translate(v.x, v.y, v.z);
noStroke();
fill(255);
sphere(radius);
//ellipse(0, 0, radius*2, radius*2);
if (planets != null) {
for (int i = 0; i < planets.length; i++) {
planets[i].show();
}
}
popMatrix();
}
}
And this is the p5.js code
var easycam;
function setup() {
createCanvas(windowWidth,windowHeight,WEBGL);
easycam = createEasyCam();
sun = new Planet(20, 0, 0, random(TWO_PI));
sun.spawnMoons(2, 1);
}
function draw() {
background(0);
cursor(HAND);
sun.show();
sun.orbit();
}
//planet class
class Planet {
constructor(radius, distance, orbitspeed, angle,mass) {
this.radius = radius;
this.distance = distance;
this.orbitspeed = orbitspeed;
this.angle = angle;
this.planets = [];
this.mass=mass;
// this should be correct
// this is the vector coming out of the planet itself.
this.v = createVector();
this.v = p5.Vector.random3D();
this.v. mult(this.distance);
// park this for now.
// this.v = createVector();
// this.v = p5.Vector.random3D();
// this.v.mult(this.distance);
// var v = new p5.Vector.random3D();
// v. mult(this.distance);
}
orbit() {
this.angle += this.orbitspeed/this.mass;
for (let i in this.planets) {
this.planets[i].orbit();
}
}
spawnMoons(total, level) {
for (let i = 0; i < total; i++) {
let r = this.radius/(level*2);
let d = random(50, 150);
let o = random(-0.1, 0.1);
let a = random(TWO_PI);
this.planets.push(new Planet(r, d/level, o, a));
if (level < 1) {
let num = Math.floor(random(0, 4));
this.planets[i].spawnMoons(num, level+1);
}
}
}
show() {
push();
noStroke(0)
// fill(255);
// let v2 = createVector(1,0,1);
// let p = createVector(v.cross);
// this.v2 = createVector(0, 0, 1);
// this. p = this.v.cross(this.v2);
// rotateY(this.angel);
// translate(v.x,v.y,v.z);
this.v2= createVector(1,0,1);
this.p= this.v.cross(this.v2);
rotate(this.angel,this.p.x,this.p.y,this.p.z);
translate(this.v.x,this.v.y,this.v.z);
//lights
ambientLight(5,100);
directionalLight(255, 255, 255, 0.2, 0.2, 0.7);
specularMaterial(255);
sphere(this.radius);
for (let i in this.planets) {
this.planets[i].show();
}
pop();
}
}
I would really really appreciate some help, its quite difficult to find references on vectors in p5.js.
Thanks loads in advance
Hello. I have some objects call Planets. Each planet have a array call Labels, fill with a different information for each object. What i need is a way to find for every obj if that array have some value in common.
For example; Planet01 labels: "investigation", "love" Planet02 labels: "investigation", "hate", return true becouse "investigation"
in the case that different Obj array have the same value, return true and connected with a line. Im a little bit lost and is my first time programming in p5.js. How can compare the arrays of each object? here is my code:
let planet = [];
var postsIndex;
var labels = [];
var title;
var posts= [];
var r=400;;
function setup() {
createCanvas(windowWidth, windowHeight);
background(25);
loadJSON('https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts?key=AIzaSyDljSVan2cU0a0kq0iqF0cglFUzXnWgRP8', gotData);
smooth();
}
function gotData(data){
// console.log(data.items.length);
postsIndex = data.items.length;
posts = data.items;
fill(255);
textSize(25);
text("posts: " + postsIndex, 100, 100);
for(var i = 0; i < postsIndex; i++){
labels = data.items[i].labels;
title = data.items[i].title;
var radius = random(r);
var a = random(TWO_PI);
var x = width/2+ cos(a)*radius;
var y = height/2+ sin(a)*radius;
let p = new Planet(x,y, 10, labels,title, i);
var overlapping = false;
for(var j = 0; j < planet.length; j++){
var other = planet[j];
var d = dist(p.x, p.y, other.x, other.y);
if(d < p.r + other.r){
overlapping = true;
break;
}
}
if(!overlapping){
planet.push(p);
}
}
}
function draw() {
background(25);
connected();
// console.log(frameRate());
fill(255);
textSize(15);
text("postCount: " + postsIndex, 100, 100);
push();
translate(width/2, height/2);
noFill();
stroke(255);
ellipse(0,0, r*2, r*2);
pop();
for(let p of planet){
p.display();
}
}
function mousePressed(){
for(var i = 0; i < planet.length; i++){
planet[i].clicked(mouseX, mouseY);
planet[i].checking();
}
}
function connected(){
for(let p of planet){
let conectado = false;
for(let other of planet){
if(p!==other && p.isConnected(other)){
conectado = true;
}
if(conectado){
line(p.x, p.y, other.x, other.y);
}
}
}
}
class Planet{
constructor(x, y, r, labels, title, id){
this.x = x;
this.y = y;
this.r = r;
this.labels = labels;
this.title = title;
this.over = false;
this.brightness = 255;
this.id = id;
}
display(){
noStroke();
strokeWeight(1);
fill(this.brightness);
stroke(255);
ellipseMode(CENTER);
ellipse(this.x, this.y, this.r*2, this.r*2);
// console.log(this.over);
}
checking(){
if(this.over){
console.log(this.id,this.title, this.labels);
this.brightness = 0;
}else{
this.brightness = 255;
}
}
isConnected(other){ //this is the problematic function
for(var i =0; i<labels.length;i++){
if(this.labels[i] == other.labels){
return true;
}else{
return false;
}
return false;
}
}
clicked(px, py) {
let d = dist(px, py, this.x, this.y);
if(d < this.r){
this.over = true;
}else{
this.over = false;
}
}
}
Hey everyone, I created this sketch for a bunch of emojis orbiting around one emoji and I am trying to make them bounce off each other when they touch, can someone please help me on how to do that? Here is the code I am using:
// importing the Peasy Cam library
import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;
// declaring the main emoji
Planet sun;
//declairing the Peasy Cam
PeasyCam cam;
// declaring the PImage function
PImage img;
// declairing the the texture
PImage[] textures = new PImage[7];
// declaring the particle system
void setup() {
size(displayWidth, displayHeight, P3D);
img = loadImage("1.jpg");
textures[0]= loadImage("2.jpg");
textures[1]= loadImage("3.jpg");
textures[2]= loadImage("4.jpg");
textures[3]= loadImage("5.jpg");
textures[4]= loadImage("6.jpg");
textures[5]= loadImage("7.jpg");
cam = new PeasyCam(this, 500);
sun = new Planet (100, 0, 0, img);
sun.spawnMoons(10, 4);
}
void draw() {
background(0);
lights();
ambientLight(129, 62, 0);
//translate(displayWidth, displayHeight);
noFill();
stroke(255);
strokeWeight(1);
//rotateY(frameCount/200.0);
box(4000);
lights();
ambientLight(129, 62, 0);
directionalLight(51, 102, 126, 0, -1, 0);
spotLight(255, 0, 0, width/2, height/2, 400, 0, 0, -1, PI/4, 2);
sun.show();
sun.orbit();
}
class Planet {
float radius;
float angle;
float distance;
Planet [] planets;
float orbitSpeed;
PVector v;
PShape globe;
float mass=1;
Planet(float r, float d, float o, PImage img ) {
v = PVector. random3D();
radius = r;
angle = random(20);
distance= d;
v.mult(distance);
orbitSpeed = o;
noStroke();
noFill();
globe = createShape(SPHERE, radius);
globe.setTexture(img);
}
void spawnMoons(int total, int level) {
planets = new Planet[total];
for (int i = 0; i<planets.length; i++) {
float r= random(level*10);
float d = random(100, 1000);
float o = random (-0.01, 0.02);
int index = int(random (textures.length));
planets[i]= new Planet (r, d, o, textures[index]);
if (level<1) {
int num = int(random(0, 5));
planets[i].spawnMoons(num, level+1);
}
}
}
void orbit() {
angle = angle + orbitSpeed/mass;
if (planets !=null) {
for (int i = 0; i<planets.length; i++) {
planets[i].orbit();
}
}
}
void show() {
pushMatrix();
noStroke();
PVector v2 = new PVector(1, 0, 1);
PVector p = v.cross(v2);
rotate (angle, p.x, p.y, p.z);
translate(v.x, v.y, v.z);
shape(globe);
if (planets !=null) {
for (int i = 0; i<planets.length; i++) {
planets[i].show();
}
}
popMatrix();
}
void bounce() {
}
}
I would really appreciate your help Thanks
The key question here is what interface you are producing your image for. For example, map interfaces like Google Maps have progressive tile loading and zooming mechanism -- this is a common way of interacting with an extremely large image (like the surface of the planet). In general, the way you populate an interface like that is through writing tile images, so you would set up your visualizer accordingly -- walk through the space in a grid and saveFrame each tile.
https://forum.processing.org/two/discussion/20910/slippy-maps-on-p5-js
https://github.com/cvalenzuela/Mappa
For very large image file formats, a great classic is pyramid TIFF format / bigTIFF. Like a zoomable tile map, it saves different resolutions in a pyramid of sub-files -- one image on top, many zoomed in images below. If you are planning on printing a poster the size of a building this might make sense.
https://www.loc.gov/preservation/digital/formats/fdd/fdd000237.shtml
There are also other scientific image formats designed for astronomy / medicine... the question is, what do you want to do with your big picture?
Hi everybody !
I'm having big problems to understand the maths behind camera rotation for short animations of terrain or planet flight by (like a kind of spatial vessel)
Following Daniel Shifman's lessons about vector I use vectors for position, velocity, acceleration and lookAt (and later implement applyForce to velocity to create some nice camera movements) I use the Processing camera() method
It's very basic but it works, except concerning rotations. I want my camera to rotate on Z axis and I really don't know how to do. It's not as simple as calling rotateZ(rad_angle)
I don't rotate on X or Y axis because I presume I should be able to achieve rotations by computing a new lookAt vector correctly.
Is the solution to play_with/compute/tweak the up vector ? And how ? I'm totally at loss...
Note : I've digged into quesycam, peasycam, OCD but that not helped me that much - and frankly I really want to code my own Camera class from a learning point of view.
Note 2 : sorry if this post is not very clear, that's very hard to formulate questions about a confusing subject ;-)
Yeah, I've experimented with constraining either the distance or limit() the acceleration. While it "works" to damp the effect, it's kind of more like a hack. I think OP in that thread was right as to the cause that it's due to frame rates as we are approximating the motion to gravity. When acceleration throws a large value the next frame will be too far away from the center to get another huge value in the opposite direction. so it ends up being random which frame lands closest. There's got to be a better way, or some way to mitigate it besides clamping values. I also wonder if the wandering phenomenon is due to clamping values or the slingshot effect.
Gravity assist for satellites uses the relative motion of the planet body. So it's more like grabbing onto the back of a truck and then letting go and less of a gravity cannon like we're seeing in this kind of frame based simulation.
it's not just a problem when they are equal, it's a problem when they get close because then 1 / sq dist gets enormous and things tend to shoot off. (slingshot effect, used to accelerate satellites)
the way around this is to add a constant to the denominator so that it cannot be 0 (or small).
but, more realistic perhaps, is to implement a collision in the code, because if that satellite is closer to the centre of the planet than the planet is wide then that's crashed into the surface.
btw, to indent code, paste it, highlight it and press ctrl-o. the button or backticks are meant for single lines, or snippets
, not whole blocks of code.
also, try adding some spaces to your code, it'll be easier to read and not the dense mass it currently is
if (x>=0) {g=-1/sq(dist(0,0,x,y));}
speedx=speedx+30*g*cos(atan(y/x)); // my eyes!
vs
if (x >= 0) {
g = -1 / sq(dist(0, 0, x, y));
}
speedx += 30 * g * cos(atan(y / x));
(also, atan2 is prefered - what if x is 0?)
Why not use dist()? And make the gravity correspond to the distance to the planet?
oh sorry ,I forgot to put this,it's a multiple lines.I posted the text here and need to copy it to txt file.
I WOULD LIKE TO LEAVE THIS CITY THIS OLD TOWN DON'T SMELL TOO PRETTY AND
I CAN FEEL THE WARNING SIGNS RUNNING AROUND MY MIND AND WHEN I LEAVE THIS ISLAND I'LL BOOK MYSELF INTO A SOUL ASYLUM
'CAUSE I CAN FEEL THE WARNING SIGNS RUNNING AROUND MY MIND
SO HERE I GO, I'M STILL SCRATCHING AROUND IN THE SAME OLD HOLE
MY BODY FEELS YOUNG BUT MY MIND IS VERY OLD SO WHAT DO YOU SAY?
YOU CAN'T GIVE ME THE DREAMS THAT ARE MINE ANYWAY HALF THE WORLD AWAY, HALF THE WORLD AWAY
HALF THE WORLD AWAY I'VE BEEN LOST, I'VE BEEN FOUND BUT I DON'T FEEL DOWN AND WHEN I LEAVE THIS PLANET
YOU KNOW I'D STAY BUT I JUST CAN'T STAND IT AND I CAN FEEL THE WARNING SIGNS RUNNING AROUND MY MIND
AND IF I COULD LEAVE THIS SPIRIT I'LL FIND ME A HOLE AND I WILL LIVE IN IT AND I CAN…
I WOULD LIKE TO LEAVE THIS CITY THIS OLD TOWN DON'T SMELL TOO PRETTY AND
I CAN FEEL THE WARNING SIGNS RUNNING AROUND MY MIND
AND WHEN I LEAVE THIS ISLAND I'LL BOOK MYSELF INTO A SOUL ASYLUM 'CAUSE I CAN FEEL THE WARNING SIGNS RUNNING AROUND MY MIND SO HERE I GO, I'M STILL SCRATCHING AROUND IN THE SAME OLD HOLE
MY BODY FEELS YOUNG BUT MY MIND IS VERY OLD SO WHAT DO YOU SAY?
YOU CAN'T GIVE ME THE DREAMS THAT ARE MINE ANYWAY HALF THE WORLD AWAY, HALF THE WORLD AWAY
HALF THE WORLD AWAY I'VE BEEN LOST, I'VE BEEN FOUND BUT I DON'T FEEL DOWN
AND WHEN I LEAVE THIS PLANET YOU KNOW I'D STAY BUT I JUST CAN'T STAND IT AND
I CAN FEEL THE WARNING SIGNS RUNNING AROUND MY MIND AND IF I COULD LEAVE THIS SPIRIT
I'LL FIND ME A HOLE AND I WILL LIVE IN IT AND I CAN…
I WOULD LIKE TO LEAVE THIS CITY THIS OLD TOWN DON'T SMELL TOO PRETTY AND
I CAN FEEL THE WARNING SIGNS RUNNING AROUND MY MIND AND WHEN I LEAVE THIS ISLAND I'LL BOOK MYSELF INTO A SOUL ASYLUM
'CAUSE I CAN FEEL THE WARNING SIGNS RUNNING AROUND MY MIND
SO HERE I GO, I'M STILL SCRATCHING AROUND IN THE SAME OLD HOLE
MY BODY FEELS YOUNG BUT MY MIND IS VERY OLD SO WHAT DO YOU SAY?
YOU CAN'T GIVE ME THE DREAMS THAT ARE MINE ANYWAY HALF THE WORLD AWAY, HALF THE WORLD AWAY
HALF THE WORLD AWAY I'VE BEEN LOST, I'VE BEEN FOUND BUT I DON'T FEEL DOWN AND WHEN I LEAVE THIS PLANET
YOU KNOW I'D STAY BUT I JUST CAN'T STAND IT AND
I CAN FEEL THE WARNING SIGNS RUNNING AROUND MY MIND AND IF I COULD LEAVE THIS SPIRIT
I'LL FIND ME A HOLE AND I WILL LIVE IN IT AND I CAN…
PFont font1;
import ddf.minim.*;
Minim minim;
//Astronaut
float X=390;
float Y=285;
int leven=0;
float j = 30;
float k = 50;
float l = 40;
float t = 50;
float o = 30;
float p = 40;
//MUZIEK//
AudioPlayer bm; //TOE III -Domyeah
AudioPlayer bm2; // TOE III v2016 -Domyeah
//SFX//
AudioPlayer biep;
AudioPlayer krak;
float bwg=1000;
float xx=200;
float yy=200;
//Grote steen
float c=random (0,1000);
float b=random(-200,-400);
//Middel steen
float D=random (0,1000);
float A=random(-200,-400);
//Kleine steen
float I=random (0,1000);
float U=random(-200,-400);
//
///
//////
//////////
///////////////////
int lifes=3;/////////////////////
///////////////////
///////////
///////
///
//
//Grote steen
float C=random (0,1000);
float B=random(800,950);
//Middel steen
float d=random (0,1000);
float a=random(800,950);
//Kleine steen
float i=random (0,1000);
float u=random(800,950);
////////////
//plaatjes//
////////////
PImage Meteor;
PImage Asteroid;
PImage Koekje;
/////////////
PImage Meteor2;
PImage Asteroid2;
PImage Koekje2;
/////////////
PImage Astronaut;
PImage Astronaut2;
PImage Astronaut3;
PImage wallpaper;
PImage dood;
//planeentie ding
PImage PLANET;
//grootte scherm
void setup(){
size(1000,750);
minim = new Minim(this);
bm = minim.loadFile("bm.wav");
bm.loop();
bm.skip(38600);
minim = new Minim(this);
bm2 = minim.loadFile("bm2.wav");
bm2.loop();
bm2.skip(38550);
font1=loadFont("font1.vlw");
textFont(font1);
}
void draw(){
if(leven>25){
j+=0.3;
k+=0.3;
l+=0.3;
}
t+=0.4;
o+=0.4;
p+=0.4;
textSize(49);
fill(#3491EA);
text("SCORE: "+leven,10,50);
wallpaper=loadImage("achtergrond.jpg");
wallpaper.resize(1000,750);
if(leven>10){
bwg-=1;
}
if (lifes==0){
bm.pause();
}
/////////////////
//CONTROLS DING//
if(keyPressed==true){
if(key=='a'){
X-=40;
}}
if(keyPressed==true){
if(key=='d'){
X+=40;
}}
if(keyPressed==true){
if(key=='w'){
Y-=40;
}}
if(keyPressed==true){
if(key=='s'){
Y+=40;
}}
//////////////////////////////////////////////
//////o m a e w a m o u s h i n d e i r u//////
//////////////////////////////////////////////
if(X>890){
X=-110;
}
if(X<-110){
X=890;
}
if(lifes>0){
image(wallpaper,0,0);
Astronaut=loadImage("Astronaut.png");
Astronaut.resize(220,180);}
image(Astronaut,X,Y);
//boven
if(leven>25){
B-=j;
a-=k;
u-=l;
}
//onder
b+=t;
A+=o;
U+=p;
////////////////////////////////
////////////////////////////////
if(dist(X+110,Y+90,c+100,b+100)<175){
minim = new Minim(this);
krak = minim.loadFile("krak.wav");
krak.play();
krak.skip(1000);
b=random(-200,-400);
c=random(0,1000);
if(lifes>0){
lifes-=1;
}}
////////////////////////////////
////////////////////////////////
////////////////////////////////
////////////////////////////////
if(dist(X+110,Y+90,I+35,U+35)<110){
minim = new Minim(this);
krak = minim.loadFile("krak.wav");
krak.play();
krak.skip(1000);
U=random(-200,-400);
I=random(0,1000);
if(lifes>0){
lifes-=1;
}}
////////////////////////////////
////////////////////////////////
////////////////////////////////
////////////////////////////////
if(dist(X+110,Y+90,D+63,A+63)<130){
minim = new Minim(this);
krak = minim.loadFile("krak.wav");
krak.play();
krak.skip(1000);
A=random(-200,-400);
D=random(0,1000);
if(lifes>0){
lifes-=1;
}}
////////////////////////////////
////////////////////////////////
/////////////////////////////////
Koekje2=loadImage("Koekje2.png");
Koekje2.resize(110,110);
image(Koekje2,d,a);
Asteroid2=loadImage("Asteroid2.png");
Asteroid2.resize(84,84);
image(Asteroid2,i,u);
Meteor2=loadImage("Meteor2.png");
Meteor2.resize(185,185);
image(Meteor2,C,B);
/////////////////////////////////
/////////////////////////////////
Koekje=loadImage("Koekje.png");
Koekje.resize(125,125);
image(Koekje,D,A);
Asteroid=loadImage("Asteroid.png");
Asteroid.resize(80,80);
image(Asteroid,I,U);
Meteor=loadImage("Meteor.png");
Meteor.resize(200,200);
image(Meteor,c,b);
/////////////////////////////////
///////////////////
//bovenste stenen//
///////////////////
if(A>750){
A=-400;
D=random(0,1000);
leven+=1;
}
if(b>750){
b=-400;
c=random(0,1000);
leven+=1;
}
if(U>750){
U=-400;
I=random(0,1000);
leven+=1;
}
textSize(49);
fill(#3491EA);
text("SCORE: "+leven,10,50);
//death screen
if(lifes<1){
dood=loadImage("dood.jpg");
dood.resize(1000,750);
image(dood,0,0);
fill(#81A0F5);
text("GAME OVER",325,325);
text("PRESS _ TO RESTART",310,425);
b=-400;
U=-400;
A=-400;
B=1150;
u=1150;
a=1150;
biep = minim.loadFile("biep.wav");
biep.play();
bm2.pause();
bm.pause();
//////////////////////////////////
if(keyPressed==true){
if(key==' '){
lifes=3;
biep.pause();
leven=0;
bwg=1000;
////////////////////////////
//DING DAT ZE LAAT STIJGEN//
////////////////////////////////
if(leven>25){ ////
B-=j; ////////////////
a-=k; ////////////////
u-=j;
///////////////////////////
// sry hier is niks :( //
///////////////////////////
b+=t;
A+=o; //////////////
U+=p; //
///////////////////////////////
//DING DAT ZE LAAT VALLEN//////
///////////////////////////
bm = minim.loadFile("bm.wav");
bm.loop();
bm.skip(38500);
bm2= minim.loadFile("bm2.wav");
bm2.loop();
bm2.skip(38500);
}}}}
//////////////////////////////////////////
if(lifes==1){
Astronaut3=loadImage("Astronaut3.png");
Astronaut3.resize(220,180);
image(Astronaut3,X,Y);
}
if(lifes==2){
Astronaut2=loadImage("Astronaut2.png");
Astronaut2.resize(220,180);
image(Astronaut2,X,Y);
}
///////////////////
//bovenste stenen//
///////////////////
if(u<-150){
u=random(800,950);;
i=random(0,1000);
}
if(B<-150){
B=random(800,950);;
C=random(0,1000);
}
if(a<-150){
a=random(800,950);;
d=random(0,1000);
}
////////////////////////////////
////////////////////////////////
if(dist(X+110,Y+90,C+100,B+100)<175){
minim = new Minim(this);
krak = minim.loadFile("krak.wav");
krak.play();
krak.skip(1000);
B=random(800,950);
C=random(0,1000);
if(lifes>0){
lifes-=1;
}}
////////////////////////////////
////////////////////////////////
////////////////////////////////
////////////////////////////////
if(dist(X+110,Y+90,I+35,U+35)<110){
minim = new Minim(this);
krak = minim.loadFile("krak.wav");
krak.play();
krak.skip(1000);
u=random(800,950);
i=random(0,1000);
if(lifes>0){
lifes-=1;
}}
////////////////////////////////
////////////////////////////////
////////////////////////////////
////////////////////////////////
if(dist(X+110,Y+90,D+63,A+63)<130){
minim = new Minim(this);
krak = minim.loadFile("krak.wav");
krak.play();
krak.skip(1000);
a=random(800,950);
d=random(0,1000);
if(lifes>0){
lifes-=1;
}}
////////////////////////////////
////////////////////////////////
}
//i don't know what im doing
How to manipulate the string
Manipulate in what way? Change its color? Combined fields under the same text element? Something similar to: https://processing.org/reference/concat_.html
although there are other options:
int ctr=100;
float number=100.0;
String msg="A message from other planet";
textAlign(CENTER,CENTER);
text("This is my text ctr: " + ctr+
"\n Here is my number: "+number+
"\n Here is my msg: "+msg,0,0,width,height);
Kf
It is hard to start with your previous code as it has some aspects that could be used in your assignment but some other parts must be re-written to fit you (future/current) design based on the given instructions.
Do you have an idea of your final outcome? Do you have a feeling of what needs to be accomplished?
Before you start coding, you need to think as a programmer architect and consider what pieces do you need for your program to run and HOW they will come together. For example, consider creating an object that receives both arrival time and departure time and this object outputs the total cost (This is for milestone 2). I can see this object to be a class by itself, and it will need to be instantiated once in the life of your program. It could potentially be owned by another class (potentially the ParkingLot object that you will instantiate during your program)
Back to your question:
You were giving a set of instructions. Note that what you implement in your first milestone won't be set on stone. It might change in the next two milestones, so don't be surprised if anything changes.
You need to create the ParkingLotSimulator first. This is one tab in your Processing IDE. In this tab you have a setup() and draw() methods.
Create a class called ParkingLot and it should look like this:
class ParkingLot {
//Constructor next...
}
Do the same for ParkingStallSection (aka. do its class definition). Now based only on those two classes and the descriptions given in your assignment, you should start putting everything together. I give you a idea:
final int N_SECTIONS=6;
final int ROW_N_IN_SECTION=5;
final int COL_N_IN_SECTION=5;
final int N_STALL_PER_SECTION=ROW_N_IN_SECTION*COL_N_IN_SECTION;
final int SIZE_W=50; //Width
final int SIZE_H=70;
ParkingLot mainLot;
void setup() {
size(520, 520);
mainLot = new ParkingLot(N_SECTIONS);
}
void draw(){
background(0);
mainLot.draw();
}
//ooooooooooo----------oooooooooooooo
class ParkingLot {
//Constructor next...
// Here you should think what to take as input and what to create next
// For instance, a parking lot has many sections. Here you need to
// simplify your design: All parking lots on this planet are made of n given
// sections and each section has the same number of stalls organized
// in n rows by n columns. It is a very simplified model but that is what
// it was given to you.
// QUESTION: How do you keep track of n number of sections?
//This function draws each section.
void draw(){
//To be implemented
//Here you iterate through your section objects and call the *draw* function
//of each section so for them to be drawn.
}
}
//ooooooooooo----------oooooooooooooo
class ParkingStallSection{
//TBI (To be implemented):
//Contructor, member variables and associated functions
//For instance: Next draws te section, which is made of row x col number
//of stalls
void draw(){
}
}
//ooooooooooo----------oooooooooooooo
class ParkingStall{
//.......
}
Notice your last class is already implemented (or given to you) so you just need to reuse that code.
For handling multiple objects, you should consider using arrays or arrayList (https://processing.org/reference/ArrayList.html). There are pros and cons of which one to use but not relevant at this point. Either one will work in your case.
I hope this gives you some direction....
Kf
hast du scale und peasycam korrigiert?
vllt. ist der zweite Planet ausserhalb vom bildschirm?
this
PVector pos; PVector vel; PVector acc; float mas; float deltaT; float far;
belongs probably into the class
so it is individually for each planet and not global variables
Hey guys, I´m Theresa, student of Visual Communication in Germany, so English is not my native language and I am new in processing but I will try my best, so here is my question. I try to simulate a moving solar system in processing with all physics components like gravitation, forces, velocity, acceleration, positions etc. the coordinates I got from the nasa website. I have two mainly problems. the first is the physic, I don't know, if the calculating methods are right and the second problem is that only one planet is visible but I defined two. Ah, and it must be ready till Monday :-P please, could anyone help me? Here is my code:
/////// SONNE zum 1.1. 2000
/////// X = -7.139143380212697E-03 Y = -2.792019770161695E-03 Z = 2.061838852554664E-04
/////// VX= 5.374260940168566E-06 VY=-7.410965396701423E-06 VZ=-2.522925180072137E-03
/////// MERKUR zum 1.1. 2000
/////// X =-1.478672233442572E-01 Y =-4.466929775364947E-01 Z =-2.313937582786785E-02
/////// VX= 2.117424563261189E-02 VY=-7.105386404267509E-03 VZ=-2.522925180072137E-03
/////// VENUS zum 1.1. 2000
/////// X =-7.257693602841776E-01 Y =-2.529582082587794E-02 Z = 4.137802526208009E-02
/////// VX= 5.189070188671265E-04 VY=-2.031355258779472E-02 VZ=-3.072687386494688E-04
/////// ERDE zum 1.1. 2000
/////// X =-1.756637922977122E-01 Y = 9.659912850526895E-01 Z = 2.020629118443605E-04
/////// VX=-1.722857156974862E-02 VY=-3.015071224668472E-03 VZ=-5.859931223618532E-08
/////// MARS zum 1.1. 2000
/////// X = 1.383221922520998E+00 Y =-2.380174081741852E-02 Z =-3.441183028447500E-02
/////// VX= 7.533013850513376E-04 VY= 1.517888771209419E-02 VZ= 2.996589710207392E-04
/////// https://rechneronline.de/planeten/masse.php
import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;
PVector pos;
PVector vel;
PVector acc;
float mas;
float deltaT;
float far;
Boid Erde = new Boid(
new PVector(-1.756637922977122E-01, 9.659912850526895E-01, 2.020629118443605E-04),
new PVector(-1.722857156974862E-02, -3.015071224668472E-03, -5.859931223618532E-08),
new PVector(0, 0, 0),
0.000002988,
0.999,
255);
Boid Venus = new Boid(
new PVector(-7.257693602841776E-01, -2.529582082587794E-02, 4.137802526208009E-02),
new PVector(5.189070188671265E-04, -2.031355258779472E-02, -3.072687386494688E-04),
new PVector(0, 0, 0),
0.000002448,
0.999,
155);
PeasyCam cam;
void setup() {
size(1600, 1200, P3D);
background(150);
frameRate(10);
cam = new PeasyCam(this, 10000);
}
void draw() {
lights();
translate(width / 2, height / 2);
scale(2000);
Erde.bewegDich();
Erde.zeichneDich();
Venus.bewegDich();
Venus.zeichneDich();
}
and than a second tab called "boid"
class Boid {
Boid(PVector position, PVector velocity, PVector acceleration, float masse, float deltaZeit, float farbe) {
pos = position;
vel = velocity;
acc = acceleration;
mas = masse;
deltaT = deltaZeit;
far = farbe;
}
void bewegDich() {
PVector posS = new PVector();
float masS = 1; // Sonne in Sonnenmassen
float G_SI = 6.674E-11; // m^3 kg^-1 s^-2
float sekundenTag;
float kiloSonnenmassen;
float meterAE;
float Grav;
float r = PVector.dist(posS, pos); //muss in AE umgerechnet werden
sekundenTag = (24 * 60 * 60);
kiloSonnenmassen = 1.98892E+30;
meterAE = (1 / (1.49597E+11));
Grav = (G_SI * (sekundenTag * sekundenTag) * kiloSonnenmassen * (meterAE * meterAE * meterAE)); // 0.017204072^2
PVector Anziehungskraft = (PVector.sub(posS, pos)).mult(Grav * mas * masS * (1 / (r * r * r))); // anziehungskraft der sonne
acc = PVector.div(Anziehungskraft, mas);
vel = PVector.add(vel, (acc.mult(deltaT)));
pos = PVector.add(pos, vel); // DIE GESCHWINDIGKEIT WIRD AUF DIE POSITION AUFADDIERT
acc = PVector.mult(acc, 0);
}
void zeichneDich() {
background(0);
println(pos);
pushMatrix(); // ändert die koordinaten innerhalb von push/pop matrix
translate(pos.x, pos.y, pos.z);
fill(far);
noStroke();
sphere(0.1);
popMatrix();
}
}
I'm making a fairly simple sketch with 1 class and a planet (which I got a picture from online) but I want to know how to make that image have an outlining kind of flashing glow.
Hopefully someone can help me :)
This is my main sketch:
PImage img;
PImage sun;
int numberOfplanets = 0; //this variable controls how many planets
planets[] big = new planets[numberOfplanets]; //this creates an array of planets
//make an array list with a flexible number of objects in it
ArrayList<planets> biglist = new ArrayList<planets>();
void setup()
{
size(700, 393);
noStroke();
frameRate(30);
ellipseMode(RADIUS);
for ( int i=0; i<numberOfplanets; i=i+1) {
big[i] = new planets(width/2, height/2); //this creates Ball object in the array spaces from 0 to 1 to 2 to....numberOfBalls
}
}
void draw()
{
background(img = loadImage("background.jpg"));
tint(255);
sun = loadImage("sun.png");
image(sun, 255, 100, 200, 180);
tint(300);
for ( int i=0; i<numberOfplanets; i=i+1) {
big[i].move(); //this will move each Ball object in the array
big[i].display(); //this will display each Ball object
}
// move and display all the Balls in the balls list
for ( int i=0; i<biglist.size(); i=i+1) {
planets temp = biglist.get(i); //this gets the ith object in the array list
temp.display();
temp.move();
for ( int j=0; j<biglist.size(); j=j+1) {
if (i != j ) { //avoid when i==j
planets temp2 = biglist.get(j); //gets the other ball
if (temp.checkCollide(temp2)) {
; //check if the ball collides with another one
if ( temp2.getRad()>temp.getRad()) {
//temp2 is bigger than temp
biglist.remove(temp);
temp2.setRad(temp2.getRad()+temp.getRad()); //adds the two values
} else {
biglist.remove(temp2);
temp.setRad(temp2.getRad()+temp.getRad()); //adds the two values
}
}
}
}
}
}
//this method runs every time the mouse is clicked
void mousePressed() {
//add one ball object to the bobslist arraylist
biglist.add(new planets (mouseX, mouseY)); //.add means run the add method for arraylists
}
and this is my class:
public class planets {
//all the code in here defines the planets
//first, declare any class variables
int rad; // Width of the shape
float xpos, ypos; // Starting position of shape
float xspeed; // Speed of the shape
float yspeed; // Speed of the shape
int xdirection; // Left or Right
int ydirection; // Top to Bottom
PImage earth; //this makes a PImage object
//a constructor: code that runs when we make an object
public planets() {
earth = loadImage("earth.png"); //this image is in data folder
rad = (int)random(100); //This is to randomize the size of the balls without the balls flickering
xspeed = random(10); //random speed for balls
yspeed = random(10);
xdirection = 1;
ydirection = 1;
xpos = random(rad, 400-rad);
ypos = random(rad, 200-rad);
}
//an overload constructor with width and height
public planets(int w, int h) { //w=width, h=height
earth = loadImage("earth.png"); //this image is in data folder
rad = (int)random(100); //This is to randomize the size of the balls without the balls flickering
xspeed = random(10); //random speed for balls
yspeed = random(10);
xdirection = 1;
ydirection = 1;
xpos = random(rad, w-rad);
ypos = random(rad, h-rad);
}
//overload constructor
public planets(int w, int h, int s) { //w=width, h=height
earth = loadImage("earth.png"); //this image is in data folder
rad = (int)random(100); //This is to randomize the size of the balls without the balls flickering
xspeed = random(10); //random speed for balls
yspeed = random(10);
xdirection = 1;
ydirection = 1;
xpos = random(rad, w-rad);
ypos = random(rad, h-rad);
}
//a overloaded constructor: takes 2 location values
public planets(int xposition, int yposition, int w, int h) { //parameters
earth = loadImage("earth.png"); //this image is in data folder
rad = (int)random(100); //This is to randomize the size of the balls without the balls flickering
xspeed = random(10); //random speed for balls
yspeed = random(10);
float change = random(-100, 100);
if (change < 0) {
xdirection = -1;
} else {
xdirection = 1;
}
change = random(-100, 100);
if (change < 0) {
ydirection = -1;
} else {
ydirection = 1;
}
xpos = xposition; //object will start in the parameter location
ypos = yposition;
}
//methods to control the Ball objects
public void move() {
// Update the position of the shape
xpos = xpos + ( xspeed * xdirection );
ypos = ypos + ( yspeed * ydirection );
bounce();
}
public void bounce() {
// Test to see if the shape exceeds the boundaries of the screen
// If it does, reverse its direction by multiplying by -1
if (xpos > width-rad || xpos < rad) {
xdirection *= -1;
}
if (ypos > height-rad || ypos < rad) {
ydirection *= -1;
}
}
public void display() {
image(earth, xpos, ypos, 90, 90);
}
//METHOD
//this method checks if the ball object hits another one
public boolean checkCollide(planets other) {
if ( dist(xpos, ypos, other.xpos, other.ypos) <= rad + other.rad) {
println("bounce");
return true;
} else {
return false;
}
}
public int getRad() {
return rad; //this will send the NUMBER back
}
//a "setter" to change the size of the ball
public void setRad(float newSize ) {
rad = (int) newSize;
}
}
here is an example where there are countries (your planets) with their earthquakes shown as circles. The data is stored in parallel arrays
Here you have one array for each property so that the data for one country/planet would be distributed over all arrays (and for each planet in the same slot number in each array, country[0] and magnis[0] belonging to the same country number 0).
see
https://github.com/Kango/Processing-snippets/wiki/Variables,-Arrays-and-object-oriented-programming
// parallel arrays
String[] headlines = {"Indonesia", "Australia", "Japan", "Mexico", "USA", "Germany"};
float[] magnis = { 12, 44, 32, 24, 12, 8.3 };
String[] date = { "12/10.", "9/3.", "3/2", "2/4", "1/2", "12/27" };
color[] colorBall = new color [headlines.length]; // { 122, 255, 0, color(255, 2, 2), color(255, 2, 2), 122 };
float[] diameter = new float [headlines.length];
// the length of the arrays
int numBalls = headlines.length; // headlines is in the lead here: We want as many balls as we have countries
// ------------------------------------------------------------
void setup() {
size(1275, 700);
textSize(20);
// control check : length of the arrays
if (headlines.length == magnis.length &&
headlines.length == date.length &&
headlines.length == colorBall.length &&
headlines.length == diameter.length) {
// OK
println("the lengths match");
} else
{
// Error
println("the lengths don't match +++++++++++++");
}//else
// init some fields
for (int i = 0; i < numBalls; i++) {
//define fill col and diameter
colorBall[i] = color(random(255), random(255), random(255));
diameter[i] = random (12, 63);
}//for
} // function
void draw() {
background(255, 255, 255);
noStroke();
for (int i = 0; i < numBalls; i++) {
//fill ellipse
fill(colorBall[i]); // the ellipses own color
ellipse(i*23+88, i*66+55, diameter[i], diameter[i]);
//show text
fill(0); // black
text(headlines[i]+ " /"+magnis[i], i*23+88+diameter[i], i*66+55);
}//for
//
}//function
//
Also you have an array for each planet now
it would also be possible to have one array for each property so that the data for one planet would be distributed over all arrays (and for each planet in the same slot number in each array): sizes, weights, ages....
Best way would be to have a class Planet and an array of that type but that's for later