Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //*BASIC VARIABLES*
- int x;
- int y;
- int z =0;
- int lastx=1;
- int lasty=1;
- int lastz=1;
- int xPos;
- int yPos;
- int zPos;
- //*COLOUR VARIABLES*
- Float ColourR = (random(256));
- Float ColourG = (random(256));
- Float ColourB = (random(256));
- //*CAMERA VARIABLES*
- int mousey;
- int mouseynow;
- float xmag, ymag = 0;
- float newXmag, newYmag = 0;
- int cameramove= 0;
- int camposz;
- int tdmode=1;
- int zoom =-30;
- int xnew;
- int ynew;
- int znew;
- int change;
- int lastxnew;
- int lastynew;
- int lastznew;
- int nlines=5000;
- int drawmode=0;
- int mousedrag;
- class Line3D { // class
- float x1,y1,z1,x2,y2,z2; //float variables which are basically x, y, z, lastx, lasty, lastz.
- public Line3D(float x1, float y1, float z1, float x2, float y2, float z2) {
- this.x1=x1; // all this is so the line knowz what variables it uses to draw the next line
- this.y1=y1;
- this.z1=z1;
- this.x2=x2;
- this.y2=y2;
- this.z2=z2;
- }
- void drawLine() {
- //*VIEW MODE COMMANDS*
- if(keyPressed) {
- if(key == 'y'){ //Draw Mode
- drawmode=0;
- }
- if(key == 't'){ //Pan/Zoom Mode
- drawmode+=1;
- }
- if(key == 'o'){ //3D Mode
- z2=0;
- tdmode=0;
- }
- if(key == 'p'){ //2D Mode
- z2=100;
- tdmode=1;
- }
- }
- if(tdmode==1){
- z2=0;
- }else{
- z2=100;
- }
- line(x1,y1,z1,x2,y2,z2); // draws the next line
- }
- }
- Line3D[] lines=new Line3D[nlines]; // uses the array to draw next line using variables contained in it
- void mouseMoved() {
- //background(255);
- //cameramove+=1;
- }
- void setup() {
- size(1000,600, P3D);
- // background(255);
- frameRate(60);
- }
- void draw() {
- //*ENVIRONMENT SETTINGS*
- stroke(ColourR,ColourG,ColourB); //Line Colour Assignment
- lights(); // lights up the 3d images/objects
- //*BORDER SETTINGS*
- background(255);
- beginShape(QUADS);
- fill(ColourR,ColourG,ColourB);
- vertex(10, 10);
- vertex(990, 10);
- vertex(990, 0);
- vertex(10, 0);
- vertex(10,0);
- vertex(10,600);
- vertex(0,600);
- vertex(0,0);
- vertex(990,0);
- vertex(990,590);
- vertex(1000,590);
- vertex(1000,0);
- vertex(10, 590);
- vertex(1000, 590);
- vertex(1000, 600);
- vertex(10, 600);
- endShape(CLOSE);
- if(keyPressed){
- if(change==0){
- if(key == 'c' || key == 'C'){
- ColourR = (random(256));
- ColourG = (random(256));
- ColourB = (random(256));
- change=1;
- }
- }
- }else{
- change=0;
- }
- //*ZOOM COMMAND*
- if(keyPressed) {
- if(key == 'z' || key == 'Z'){
- zoom++;
- }
- if(key == 'x' || key == 'X'){
- zoom--;
- }
- }
- //*PAN COMMAND*
- if(drawmode>=1){
- translate(width/2, height/2, zoom);
- newXmag = mouseX/float(width) * TWO_PI;
- newYmag = mouseY/float(height) * TWO_PI;
- float diff = xmag-newXmag;
- if (abs(diff) > 0.01) { xmag -= diff/4.0; }
- diff = ymag-newYmag;
- if (abs(diff) > 0.01) { ymag -= diff/4.0; }
- rotateX(-ymag);
- rotateY(-xmag);
- }else
- translate(500, 300, 0);
- {
- }
- //*RESET COMMAND*
- if(keyPressed) {
- if(key == 'r' || key == 'R') {
- x = 0;
- y = 0;
- lastx = 0;
- lasty = 0;
- lastp=0;
- }
- }
- //*MOVEMENT COMMANDS*
- if(keyPressed) {
- if(key == CODED) {
- if(keyCode == RIGHT) {
- x++;
- lastx++;
- myLine(lastx, lasty, lastz, x, y, z); //changes the variables required for drawing a line
- } // essentially allows us to create our line but does not actually "draw them
- }
- if(key == CODED) {
- if(keyCode == DOWN) { //Movement Down
- y++;
- lasty++;
- myLine(lastx, lasty, lastz, x, y, z);
- }
- }
- if(key == CODED) {
- if(keyCode == LEFT) { //Movement Left
- x--;
- lastx--;
- myLine(lastx, lasty, lastz, x, y, z);
- }
- }
- if(key == CODED) {
- if(keyCode == UP) { //Movement Up
- y--;
- lasty--;
- myLine(lastx, lasty, lastz, x, y, z);
- }
- }
- if(key == 'd' || key == 'D') { //Movement Down-Right
- x++;
- y++;
- lastx++;
- lasty++;
- myLine(lastx, lasty, lastz, x, y, z);
- }
- if(key == 'w'|| key == 'W') { //Movement Up-Right
- x++;
- y--;
- lastx++;
- lasty--;
- myLine(lastx, lasty, lastz, x, y, z);
- }
- if(key == 's' || key == 'S') { //Movement Down-Left
- x--;
- y++;
- lastx--;
- lasty++;
- myLine(lastx, lasty, lastz, x, y, z);
- }
- if(key == 'a' || key == 'A') { //Movement Up-Left
- x--;
- y--;
- lastx--;
- lasty--;
- myLine(lastx, lasty, lastz, x, y, z);
- }
- }
- for(int i=0; i<nlines; i++){ //checks to see if lines have already been drawn
- if(lines[i]!=null)
- lines[i].drawLine(); // tells the line to begin drawing
- }
- }
- void update() {
- }
- int lastp=0;
- void myLine(float x1, float y1, float z1, float x2, float y2, float z2) { // gathers all variables for use with drawing the line
- //line(x1,y1,z1,x2,y2,z2);
- Line3D l= new Line3D(x1,y1,z1,x2,y2,z2); //prepares a new line using new variables
- lines[ lastp]=l;
- lastp=lastp+1;
- if(lastp>=nlines) //checks to see if too many lines have been drawn
- lastp=0; // if too many lines begins to remove the earliest lines
- }
- //*JUNK CODE/NOTES*
- //
- //
- //
- // _██_ _██_
- // (ಠ_ృ) ¯\(º_o)/¯
- // What else were you expecting?
- //
- //
- //~ROSS WAS HERE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement