Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.61 KB | None | 0 0
  1. //*BASIC VARIABLES*
  2. int x;
  3. int y;
  4. int z =0;
  5. int lastx=1;
  6. int lasty=1;
  7. int lastz=1;
  8. int xPos;
  9. int yPos;
  10. int zPos;
  11.  
  12. //*COLOUR VARIABLES*
  13. Float ColourR = (random(256));
  14. Float ColourG = (random(256));
  15. Float ColourB = (random(256));
  16.  
  17. //*CAMERA VARIABLES*
  18. int mousey;
  19. int mouseynow;
  20. float xmag, ymag = 0;
  21. float newXmag, newYmag = 0;
  22. int cameramove= 0;
  23. int camposz;
  24. int tdmode=1;
  25. int zoom =-30;
  26. int xnew;
  27. int ynew;
  28. int znew;
  29. int change;
  30. int lastxnew;
  31. int lastynew;
  32. int lastznew;
  33. int nlines=5000;
  34. int drawmode=0;
  35. int mousedrag;
  36. class Line3D { // class
  37. float x1,y1,z1,x2,y2,z2; //float variables which are basically x, y, z, lastx, lasty, lastz.
  38. public Line3D(float x1, float y1, float z1, float x2, float y2, float z2) {
  39. this.x1=x1; // all this is so the line knowz what variables it uses to draw the next line
  40. this.y1=y1;
  41. this.z1=z1;
  42. this.x2=x2;
  43. this.y2=y2;
  44. this.z2=z2;
  45. }
  46. void drawLine() {
  47.  
  48. //*VIEW MODE COMMANDS*
  49. if(keyPressed) {
  50. if(key == 'y'){ //Draw Mode
  51. drawmode=0;
  52. }
  53. if(key == 't'){ //Pan/Zoom Mode
  54. drawmode+=1;
  55. }
  56. if(key == 'o'){ //3D Mode
  57. z2=0;
  58. tdmode=0;
  59. }
  60. if(key == 'p'){ //2D Mode
  61. z2=100;
  62. tdmode=1;
  63. }
  64. }
  65.  
  66. if(tdmode==1){
  67. z2=0;
  68. }else{
  69. z2=100;
  70. }
  71. line(x1,y1,z1,x2,y2,z2); // draws the next line
  72. }
  73. }
  74. Line3D[] lines=new Line3D[nlines]; // uses the array to draw next line using variables contained in it
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. void mouseMoved() {
  84.  
  85. //background(255);
  86. //cameramove+=1;
  87. }
  88.  
  89.  
  90.  
  91. void setup() {
  92. size(1000,600, P3D);
  93. // background(255);
  94. frameRate(60);
  95. }
  96.  
  97. void draw() {
  98.  
  99. //*ENVIRONMENT SETTINGS*
  100. stroke(ColourR,ColourG,ColourB); //Line Colour Assignment
  101. lights(); // lights up the 3d images/objects
  102.  
  103. //*BORDER SETTINGS*
  104. background(255);
  105. beginShape(QUADS);
  106. fill(ColourR,ColourG,ColourB);
  107. vertex(10, 10);
  108. vertex(990, 10);
  109. vertex(990, 0);
  110. vertex(10, 0);
  111.  
  112. vertex(10,0);
  113. vertex(10,600);
  114. vertex(0,600);
  115. vertex(0,0);
  116.  
  117. vertex(990,0);
  118. vertex(990,590);
  119. vertex(1000,590);
  120. vertex(1000,0);
  121.  
  122. vertex(10, 590);
  123. vertex(1000, 590);
  124. vertex(1000, 600);
  125. vertex(10, 600);
  126. endShape(CLOSE);
  127.  
  128. if(keyPressed){
  129. if(change==0){
  130. if(key == 'c' || key == 'C'){
  131. ColourR = (random(256));
  132. ColourG = (random(256));
  133. ColourB = (random(256));
  134. change=1;
  135. }
  136. }
  137. }else{
  138. change=0;
  139. }
  140.  
  141. //*ZOOM COMMAND*
  142. if(keyPressed) {
  143. if(key == 'z' || key == 'Z'){
  144. zoom++;
  145. }
  146. if(key == 'x' || key == 'X'){
  147. zoom--;
  148. }
  149. }
  150.  
  151.  
  152. //*PAN COMMAND*
  153. if(drawmode>=1){
  154. translate(width/2, height/2, zoom);
  155.  
  156. newXmag = mouseX/float(width) * TWO_PI;
  157. newYmag = mouseY/float(height) * TWO_PI;
  158.  
  159. float diff = xmag-newXmag;
  160. if (abs(diff) > 0.01) { xmag -= diff/4.0; }
  161.  
  162. diff = ymag-newYmag;
  163. if (abs(diff) > 0.01) { ymag -= diff/4.0; }
  164.  
  165. rotateX(-ymag);
  166. rotateY(-xmag);
  167. }else
  168. translate(500, 300, 0);
  169. {
  170. }
  171.  
  172. //*RESET COMMAND*
  173. if(keyPressed) {
  174. if(key == 'r' || key == 'R') {
  175.  
  176. x = 0;
  177. y = 0;
  178. lastx = 0;
  179. lasty = 0;
  180.  
  181. lastp=0;
  182.  
  183. }
  184. }
  185.  
  186. //*MOVEMENT COMMANDS*
  187. if(keyPressed) {
  188. if(key == CODED) {
  189. if(keyCode == RIGHT) {
  190. x++;
  191. lastx++;
  192. myLine(lastx, lasty, lastz, x, y, z); //changes the variables required for drawing a line
  193. } // essentially allows us to create our line but does not actually "draw them
  194. }
  195. if(key == CODED) {
  196. if(keyCode == DOWN) { //Movement Down
  197. y++;
  198. lasty++;
  199. myLine(lastx, lasty, lastz, x, y, z);
  200. }
  201. }
  202. if(key == CODED) {
  203. if(keyCode == LEFT) { //Movement Left
  204. x--;
  205. lastx--;
  206. myLine(lastx, lasty, lastz, x, y, z);
  207. }
  208. }
  209. if(key == CODED) {
  210. if(keyCode == UP) { //Movement Up
  211. y--;
  212. lasty--;
  213. myLine(lastx, lasty, lastz, x, y, z);
  214. }
  215. }
  216. if(key == 'd' || key == 'D') { //Movement Down-Right
  217. x++;
  218. y++;
  219. lastx++;
  220. lasty++;
  221. myLine(lastx, lasty, lastz, x, y, z);
  222. }
  223. if(key == 'w'|| key == 'W') { //Movement Up-Right
  224. x++;
  225. y--;
  226. lastx++;
  227. lasty--;
  228. myLine(lastx, lasty, lastz, x, y, z);
  229. }
  230. if(key == 's' || key == 'S') { //Movement Down-Left
  231. x--;
  232. y++;
  233. lastx--;
  234. lasty++;
  235. myLine(lastx, lasty, lastz, x, y, z);
  236. }
  237. if(key == 'a' || key == 'A') { //Movement Up-Left
  238. x--;
  239. y--;
  240. lastx--;
  241. lasty--;
  242. myLine(lastx, lasty, lastz, x, y, z);
  243. }
  244. }
  245.  
  246. for(int i=0; i<nlines; i++){ //checks to see if lines have already been drawn
  247. if(lines[i]!=null)
  248. lines[i].drawLine(); // tells the line to begin drawing
  249. }
  250. }
  251. void update() {
  252. }
  253. int lastp=0;
  254. void myLine(float x1, float y1, float z1, float x2, float y2, float z2) { // gathers all variables for use with drawing the line
  255. //line(x1,y1,z1,x2,y2,z2);
  256. Line3D l= new Line3D(x1,y1,z1,x2,y2,z2); //prepares a new line using new variables
  257.  
  258. lines[ lastp]=l;
  259. lastp=lastp+1;
  260. if(lastp>=nlines) //checks to see if too many lines have been drawn
  261. lastp=0; // if too many lines begins to remove the earliest lines
  262. }
  263.  
  264.  
  265. //*JUNK CODE/NOTES*
  266. //
  267. //
  268. //
  269. // _██_ _██_
  270. // (ಠ_ృ) ¯\(º_o)/¯
  271. // What else were you expecting?
  272. //
  273. //
  274. //~ROSS WAS HERE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement