Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. /*
  2. @Author: Jan-David Schulz
  3.  Aufgabe 4: 3DCG - WS 2019/2020
  4.  
  5.  Mit den Maustasten kann man sich im Canvas bewegen, um die Formen zu betrachten
  6.  
  7.  Keys to use: / Q-A           / S-X           / R-F     / H-N   / UP-DOWN / LEFT
  8.  / BaseSegmente  / SideSegmente  / Radius  / Höhe  / Größe   / toggle Fill
  9.  
  10.  
  11.  */
  12.  
  13. import peasy.*;
  14. PeasyCam cam;
  15.  
  16. //Farbe für die Formen festlegen
  17. private color c1 = color(100, 13, 190);
  18. private color c2 = color(200, 60, 100);
  19.  
  20. //Formen
  21. private Kegel kegel;
  22. private Zylinder zylinder;
  23.  
  24. private int radius = 5;
  25. private int hoehe = 15;
  26.  
  27. private int baseSegmente = 10;
  28. private int sideSegmente= 5;
  29.  
  30. private int size = 20;
  31.  
  32. private boolean fill = true;
  33.  
  34. private float drehen = 0.0f;
  35.  
  36.  
  37.  
  38.  
  39.  
  40. void setup() {
  41.   size(1000, 1000, P3D);
  42.   cam = new PeasyCam(this, 100);
  43.   cam.setMinimumDistance(800);
  44.   cam.setMaximumDistance(2000);
  45.   kegel=new Kegel();
  46.   zylinder=new Zylinder();
  47. }
  48.  
  49. public void draw() {
  50.   lights();
  51.   background(0);
  52.  
  53.   pushMatrix();
  54.  
  55.   //Mittelpunkt des Canvas
  56.   translate(width/2, height/2);
  57.   //kontinuierliche Drehung der Elemente im Canvas
  58.   drehen +=0.05f;
  59.  
  60.   //Push Kegel
  61.   pushMatrix();
  62.   strokeWeight(0.03);
  63.   stroke(255);
  64.   //translate(-200, 0, 0);
  65.   kegel.draw(hoehe, radius, baseSegmente, c1, size, 90, 0, drehen, fill);
  66.   popMatrix();
  67.  
  68.   //Push Zylinder    ----------------------------------------------------------------------------------------------------------------------
  69.   pushMatrix();
  70.   strokeWeight(0.05);
  71.   stroke(255);
  72.   //translate(-200, 0, 0);
  73.   zylinder.draw(hoehe, radius, baseSegmente,sideSegmente, c1, size, 90, 0, drehen, fill);
  74.   popMatrix();
  75.   popMatrix();
  76. }
  77.  
  78. public void keyPressed() {
  79.   if (keyPressed) {
  80.  
  81.     if (key == 'r') {
  82.       radius++;
  83.     }
  84.     if (key == 'f') {
  85.       radius--;
  86.     }
  87.     if (key == 'h') {
  88.       hoehe++;
  89.     }
  90.     if (key == 'n') {
  91.       hoehe--;
  92.     }
  93.     if (key == 's') {
  94.       sideSegmente++;
  95.     }
  96.     if (key == 'x') {
  97.       sideSegmente--;
  98.     }
  99.     if (key == 'q') {
  100.       baseSegmente++;
  101.     }
  102.     if (key == 'a' && baseSegmente > 1) {
  103.       baseSegmente--;
  104.     }
  105.     if (keyCode == UP) {
  106.       size += 5;
  107.     }
  108.     if (keyCode == DOWN) {
  109.       size -= 5;
  110.     }
  111.     if (keyCode == LEFT) {
  112.       fill=!fill;
  113.     }
  114.   }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement