Advertisement
Nojus_Globys

5 | face

Nov 15th, 2022 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.62 KB | Software | 0 0
  1. int
  2.   midH, // height / 2 (vidurio horizontali linija)
  3.   midW, // width / 2 (vidurio vertikali linija)
  4.  
  5.   left,
  6.   right,
  7.   above,
  8.   below,
  9.  
  10.   diameter, // akies dydis (atitinkamai prie jo pririšti ir kiti dydžiai)
  11.   weight; // plonų stačiakampių storis
  12.  
  13. void setup () {
  14.   size (1280, 700);
  15.   // width = 1280
  16.   // height = 700
  17.   background (255);
  18.   rectMode (CENTER); // nurodau, kad noriu visų stačiakampių (tame tarpe ir kvadrato) pradžia bus
  19.   // ne viršutinis kairys kampas, bet pats stačiakampio centras
  20.  
  21.   midH = height/2;
  22.   midW = width/2;
  23.  
  24.   diameter = height/5; // pririšu prie aukščio, nes jis dažniausiai būna mažesnis nei plotis
  25.   weight = height/50;
  26.  
  27.   left = midW - diameter;
  28.   right = midW + diameter;
  29.   above = midH - diameter;
  30.   below = midH + diameter;
  31. }
  32.  
  33. void draw () {
  34.   // face
  35.   fill (0, 255, 0);
  36.     circle (midW, midH, diameter*4);
  37.  
  38.   // eyebrows (antakiai)
  39.   fill (0);
  40.     rect (left, above, diameter, weight);
  41.     rect (right, above, diameter, weight);
  42.  
  43.   // nose
  44.     rect (midW, midH, weight, diameter/2);
  45.  
  46.   // eyes
  47.   // spalvą pasirenku priklausomai nuo to, ar pelė paspausta, ar ne
  48.   if (mousePressed)
  49.     fill (0, 0, 255);
  50.   else
  51.     fill (255); // tik šis sakinys galioja prie "else"
  52.     // (kadangi neapskliaudėme riestiniais skliaustais {})
  53.  
  54.   circle (left, midH, diameter);
  55.   circle (right, midH, diameter);
  56.  
  57.   // pupils (vyzdžiai)
  58.   fill (0);
  59.   circle (left, midH, diameter/3);
  60.   circle (right, midH, diameter/3);  
  61.  
  62.   // mouth
  63.   int mouthH; // burnos aukštis
  64.  
  65.   // burnos aukščio pasirinkimas
  66.   if (mouseY < below) // jei pelė yra aukščiau nei burna
  67.     mouthH = 0;
  68.   else if (mouseY > below + diameter) // jei pelė yra žemiau nei maksimalus burnos aukštis
  69.     mouthH = diameter;
  70.   else // jei pelė žemiau nei burna (bet ne per daug žemai)
  71.     mouthH = mouseY - below;
  72.    
  73.   fill (255, 0, 0); // red
  74.   rect (midW, below, diameter, mouthH); // pati burna
  75.  
  76.   lines ();
  77. }
  78.  
  79. void lines () {
  80.     strokeWeight (5);
  81.     // main
  82.         stroke (255, 0, 0); // red
  83.         line (0, midH, width, midH);
  84.         line (midW, 0, midW, height);
  85.     // vertical
  86.         stroke (0); // green
  87.         line (left, 0, left, height);
  88.         line (right, 0, right, height);      
  89.     // horizontal
  90.         stroke (0, 0, 255); // blue
  91.         line (0, above, width, above);
  92.         line (0, below, width, below);
  93.    
  94.     // to reset everything (I know it should not be a part of the function)
  95.     // only that in this case it is more appropriate for me to do that
  96.     strokeWeight (1);
  97.     stroke (0);
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement