Guest User

Untitled

a guest
Dec 16th, 2019
83
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package lab7;
  2.  
  3. import java.util.Random;
  4. import javax.microedition.lcdui.Canvas;
  5. import javax.microedition.lcdui.Graphics;
  6.  
  7. public class PadajacySnieg extends Canvas{
  8.  
  9. int height;
  10. int width;
  11. int snieg[];
  12. int warstwaSniegu[];
  13. Random generator = new Random();
  14. boolean painting = false;
  15.  
  16. public PadajacySnieg() {
  17. height = getHeight();
  18. width = getWidth();
  19. snieg = new int[height];
  20. warstwaSniegu = new int[width];
  21. for ( int i = 0; i < width; i++) {
  22. warstwaSniegu[i] = 0;
  23. }
  24. for (int i = 0; i < height; ++i) {
  25. snieg[i] = -1;
  26. }
  27. }
  28.  
  29. public void scroll() {
  30. if (painting) {
  31. return;
  32. }
  33. for (int i = height - 1; i > 0; --i) {
  34. snieg[i] = snieg[i - 1];
  35. }
  36. snieg[0] = Math.abs((generator.nextInt() % (2 * width)) / 2);
  37. repaint();
  38. }
  39.  
  40. protected void paint(Graphics g) {
  41. painting = true;
  42. g.setColor(128, 128, 128);
  43. g.fillRect(0, 0, width, height);
  44. g.setColor(255, 255, 255);
  45. for (int y = 0; y < height; ++y) {
  46. int x = snieg[y];
  47. if (x == -1) {
  48. continue;
  49. }
  50. g.drawLine(x, y, x, y);
  51. if(y == height - 1) {
  52. warstwaSniegu[x]++;
  53. }
  54. }
  55. for (int i = 0; i < warstwaSniegu.length; i++) {
  56. if(warstwaSniegu[i] != 0) {
  57. g.drawLine(i, height - warstwaSniegu[i], i, height);
  58.  
  59. }
  60. }
  61. painting = false;
  62. }
  63.  
  64. }
RAW Paste Data