horizon.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. class Drop {
  3. protected $x;
  4. protected $y;
  5. protected $length;
  6. protected $color;
  7. function __construct($x, $y) {
  8. $this->x = $x;
  9. $this->y = $y;
  10. $this->length = rand(5, 10);
  11. $r = dechex(20+(sin($this->x)*235));
  12. $g = $r; //dechex(rand(0, 255));
  13. $b = $r; //dechex(rand(0, 255));
  14. $r = strlen($r == 1) ? $r."0" : $r;
  15. $g = strlen($g == 1) ? $r."0" : $g;
  16. $b = strlen($b == 1) ? $r."0" : $b;
  17. $this->color = $r.$g.$b;
  18. $this->x +=1;
  19. }
  20. public function draw() {
  21. //echo("px ".($this->x-10)." ".(pow((sin($this->y)-10),2)%500)." 000000\n");
  22. echo("px ".$this->x." ".(int)(500*abs(pow(2,cos($this->y))))." ".$this->color."\n");
  23. }
  24. public function update() {
  25. $this->outOfCanvas();
  26. $this->y += 1;
  27. if ($this->y % 5 == 0)
  28. $this->x += 1;
  29. }
  30. public function outOfCanvas() {
  31. if($this->y > 500) {
  32. $this->x = rand(0, 800);
  33. $this->y = rand(0, 1000);
  34. }
  35. }
  36. }
  37. $drops = [];
  38. for($i=0;$i<1;$i++) {
  39. $drops[] = new Drop(rand(0, 800), rand(0, 1000));
  40. }
  41. while(true) {
  42. foreach($drops as $drop) {
  43. $drop->update();
  44. $drop->draw();
  45. }
  46. }