Bemerkenswertes vom Blick auf Walter Giers' "Kleiner Stern" (1990) https://www.victorgiers.com/stern/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stern.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. var img_unten,img_links,img_rechts,img_hinten;
  2. let unten,links,rechts;
  3. var rate = 1000;
  4. var imgW, imgH;
  5. let tempo = "medium"; //slow, medium or fast
  6. function preload(){
  7. img_unten = loadImage("img/unten.min.png");
  8. img_links = loadImage("img/links.min.png");
  9. img_rechts = loadImage("img/rechts.min.png");
  10. img_hinten = loadImage("img/bg.jpg");
  11. }
  12. function setImageSize(){
  13. imgW = windowWidth / windowHeight > img_hinten.width / img_hinten.height ? windowWidth : windowHeight/9*16;
  14. imgH = windowWidth / windowHeight > img_hinten.width / img_hinten.height ? windowWidth/16*9: windowHeight;
  15. }
  16. function setup() {
  17. createCanvas(windowWidth,windowHeight);
  18. setImageSize();
  19. imageMode(CENTER);
  20. frameRate(120);
  21. if(tempo == "medium"){
  22. unten = new Kammer(img_unten, 7, 3, 7);
  23. links = new Kammer(img_links, 12, 3, 15);
  24. rechts = new Kammer(img_rechts, 17, 3, 20);
  25. } else if (tempo == "fast"){
  26. unten = new Kammer(img_unten, 2, 1, 3);
  27. links = new Kammer(img_links, 3, 1, 4);
  28. rechts = new Kammer(img_rechts, 4, 2, 5);
  29. } else { // slow - standard - beschde
  30. unten = new Kammer(img_unten, 15, 7, 16);
  31. links = new Kammer(img_links, 25, 5, 30);
  32. rechts = new Kammer(img_rechts, 35, 5, 40);
  33. }
  34. console.log("......................:W*...=@...-WW@...*WW+..........:#-...*WW*...*WW+...*WW+.\n" +
  35. "....:@W@-:@W@-.......:W+...#@...-WW@....*WW+......:#WWWW-...*WW*...*WW+...*WW+.\n"+
  36. "....WWWWWWWWW@......:W+...#@...-WW#.....*WW+..-=WWW@*.......*WW*...*WW+...*WW+.\n"+
  37. ".....=WWWWWW*......:W+...#@...-WW#......*WW+..WWW=-.........*WW*...*WW+...*WW+.\n"+
  38. ".......-@@-.......+W+...#@...:WW#.......*WW+...-=WWWW=-.....*WW*...*WW+...*WW+.\n"+
  39. ".................+W:...@@...:WW=........*WW+.......-=WWW-...*WW*...*WW+...*WW+.\n"+
  40. "................-+-...:+....+++.........:++-...........-....-++:...:++-...:++-."
  41. );
  42. }
  43. function windowResized() {
  44. setImageSize();
  45. resizeCanvas(windowWidth, windowHeight);
  46. }
  47. function draw() {
  48. clear();
  49. //tint(255);
  50. image(img_hinten,windowWidth/2,windowHeight/2,imgW,imgH);
  51. unten.do();
  52. links.do();
  53. rechts.do();
  54. ///
  55. /*let fps = frameRate();///
  56. fill(255);
  57. stroke(0);
  58. text("FPS: " + fps.toFixed(2), 10, height - 10);*/
  59. }
  60. class Kammer {
  61. constructor(img, a, s, r) {
  62. this.img = img;
  63. this.attack = a * 1000;
  64. this.sustain = s * 1000;
  65. this.release = r * 1000;
  66. this.direction = Math.random() < 0.5 ? -1 : 1; // -1 = wird dunkler, 1 = wird heller
  67. this.nextBrightness = this.direction == 1 ? 1 : random(0.05,0.1);
  68. this.lastBrightness = Math.random();
  69. this.brightness = this.lastBrightness;
  70. this.lastSwitchTime = millis();
  71. }
  72. do() {
  73. this.brightness = constrain(this.brightness, this.nextBrightness, this.lastBrightness);
  74. if(this.direction == 1 && millis() < this.lastSwitchTime + this.attack){
  75. this.brightness = map(millis(), this.lastSwitchTime, this.lastSwitchTime + this.attack, this.lastBrightness, this.nextBrightness);
  76. }
  77. if(this.direction == 1 && millis() - this.lastSwitchTime > this.attack + this.sustain){
  78. this.direction = -1;
  79. this.lastBrightness = this.brightness;
  80. this.nextBrightness = random(0.05,0.1);
  81. this.lastSwitchTime = millis();
  82. }
  83. if(this.direction == -1){
  84. this.brightness = map(millis(), this.lastSwitchTime, this.lastSwitchTime + this.release, this.lastBrightness, this.nextBrightness);
  85. }
  86. if(this.direction == -1 && millis() - this.lastSwitchTime > this.release){
  87. this.direction = 1;
  88. this.lastBrightness = this.brightness;
  89. this.nextBrightness = 1;
  90. this.lastSwitchTime = millis();
  91. }
  92. this.img.loadPixels();
  93. for (let i = 0; i < this.img.width*this.img.height*4; i += 4) {
  94. if(this.img.pixels[i] > 0){ //has color; not a fully transparent pixel
  95. this.img.pixels[i + 3] = this.brightness*255;
  96. }
  97. }
  98. this.img.updatePixels();
  99. //tint(255,this.brightness*255);
  100. image(this.img,windowWidth/2,windowHeight/2,imgW,imgH);
  101. }
  102. }