Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
claylake
claylake's Profile
1
Posts
0
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Javascript trouble...
[3 Replies]
27-Jun-2013 09:55 AM
Forum:
Processing with Other Languages
I have this bad excuse for code here, and I can't seem to get it to run in Javascript. I think its the wacky way Im mixing 2d and 3d, any ideas or solutions?
float ext = 5;
int siz = 700;
double trans = (double)siz/2;
float def = 100.0;
float spa = 10;
float rotation = 0;
float xpos=0;
float zpos=0;
float ypos=0;
float an=0;
int c = 0;
float dconv = 1.67;
void setup() {
// size(siz, siz, P3D);
size(700, 700, P3D);
strokeWeight(2);
stroke(255);
noFill();
smooth(8);
}
void draw() {
float orbitRadius = 5;
an= HALF_PI*0.5;
xpos = sin(radians(rotation))*orbitRadius;
ypos = cos(radians(rotation))*orbitRadius;
zpos = 120;
xpos /= ext;
ypos /= ext;
xpos *= trans;
ypos *= trans;
camera((float)(xpos + trans), (float)(ypos + trans), (float)(-zpos+trans), (float)trans, (float)trans, (float)trans, 0, 0, 1);
background(0);
earth();
sat();
rotation += 1;
}
void earth() {
hint(ENABLE_DEPTH_TEST);
fill(0);
noStroke();
sph(0, 0, 0, 70);
noFill();
stroke(255);
for (float j = 1.0/spa; j <= 1; j = j + 1.0/spa) {
beginShape();
for (float i = 0; i < 1.1; i = i + 1.0/def) {
vert(sin(j*TWO_PI)*cos(i*TWO_PI), sin(j*TWO_PI)*sin(i*TWO_PI), cos(j*TWO_PI));
}
endShape();
}
for (float j = 1.0/spa; j <= 1; j = j + 1.0/spa) {
beginShape();
for (float i = 0; i < 1.1; i = i + 1.0/def) {
vert(cos(j*TWO_PI)*sin(i*TWO_PI), sin(j*TWO_PI)*sin(i*TWO_PI), cos(i*TWO_PI));
}
endShape();
//rotateY(j*TWO_PI);
}
camera();
hint(DISABLE_DEPTH_TEST);
strokeWeight(3.5);
beginShape();
for (float i = 0; i < 1.1; i = i + 1.0/def) {
vert2d(dconv*sin(i*TWO_PI), dconv*cos(i*TWO_PI));
}
endShape();
beginShape();
vert2d(4, -4);
vert2d(4-cos(radians(rotation))*0.5, -4 - sin(radians(rotation))*0.5);
endShape();
c=0;
for (float i = 0; i < 1.1; i = i + 1.0/12) {
beginShape();
vert2d(4-cos(i*TWO_PI)*0.55, -4 - sin(i*TWO_PI)*0.55);
if(c%3==0)
vert2d(4-cos(i*TWO_PI)*0.65, -4 - sin(i*TWO_PI)*0.65);
else
vert2d(4-cos(i*TWO_PI)*0.6, -4 - sin(i*TWO_PI)*0.6);
endShape();
c++;
}
strokeWeight(2);
}
void sat() {
float orbitRadius = 2;
an= HALF_PI*0.5;
xpos = sin(radians(rotation))*orbitRadius;
ypos = cos(radians(rotation))*orbitRadius;
zpos = 120;
xpos /= ext;
ypos /= ext;
xpos *= trans;
ypos *= trans;
translate((float)(xpos + trans), (float)(ypos + trans), (float)(-zpos+trans));
rotate(radians(rotation), 0, 0.5, -0.5);
hint(ENABLE_DEPTH_TEST);
fill(0);
box(25, 12, 8);
noFill();
translate(-(float)(xpos + trans), -(float)(ypos + trans), -(float)(-zpos+trans));
}
void vert(float x, float y, float z) {
x /= ext;
y /= ext;
z /= ext;
// println(x);
// println(y);
// println(z);
x *= trans;
y *= trans;
z *= trans;
//beginShape(POINTS);
vertex((float)(x + trans), (float)(y + trans), (float)(z + trans));
//endShape();
}
void vert2d(float x, float y) {
x /= ext;
y /= ext;
// println(x);
// println(y);
// println(z);
x *= trans;
y *= trans;
//beginShape(POINTS);
vertex((float)(x + trans), (float)(y + trans));
//endShape();
}
void sph(float x, float y, float z, float s) {
x /= ext;
y /= ext;
z /= ext;
// println(x);
// println(y);
// println(z);
x *= trans;
y *= trans;
z *= trans;
translate((float)(x + trans), (float)(y + trans), (float)(z + trans));
sphere(s);
translate((float)-(x + trans), (float)-(y + trans), (float)-(z + trans));
}
Any help to greatly appreciated!
«Prev
Next »
Moderate user : claylake
Forum