Dark Matter Gravitational Lensing

📅 April 15, 2026 🏷️ art
dark matter gravitational lensing space cosmic mysterious
Generated by GridFlow AI | Tags: dark matter, gravitational, lensing, space, cosmic, mysterious

📊 视觉感受量化评分

0
0
0
0

💡 AI 提示词

Create a generative art piece inspired by dark matter gravitational lensing. Use a dark cosmic background with stars that appear to bend around a central gravitational point. The lens effect should follow the mouse cursor. Make it mysterious and scientifically inspired.

🧠 核心算法要点

  • 500 stars with random positions, sizes, and colors
  • Distance calculation from each star to lens center
  • Gravitational distortion formula: distortion = lensStrength / (distance * 0.5)
  • Mouse position tracking with smooth lerp animation
  • Semi-transparent background trail for motion blur
  • Lens center glow with radial gradient

💻 原始 p5.js 代码

var sketch = function(p) {
  let stars = [];
  let lensCenter;
  let lensStrength = 300;
  
  p.setup = function() {
    let container = document.getElementById('p5-wrapper'); let canvas = p.createCanvas(container.offsetWidth, container.offsetHeight);
    canvas.parent('p5-wrapper');
    p.background(0);
    
    lensCenter = p.createVector(p.width / 2, p.height / 2);
    
    for (let i = 0; i < 500; i++) {
      stars.push({
        x: p.random(p.width),
        y: p.random(p.height),
        originalX: 0,
        originalY: 0,
        size: p.random(1, 3),
        brightness: p.random(100, 255),
        color: p.color(p.random(200, 255), p.random(200, 255), p.random(220, 255))
      });
      stars[i].originalX = stars[i].x;
      stars[i].originalY = stars[i].y;
    }
  };
  
  p.draw = function() {
    p.background(0, 50);
    
    if (p.mouseX > 0 && p.mouseX < p.width && p.mouseY > 0 && p.mouseY < p.height) {
      lensCenter.x = p.lerp(lensCenter.x, p.mouseX, 0.05);
      lensCenter.y = p.lerp(lensCenter.y, p.mouseY, 0.05);
    }
    
    for (let star of stars) {
      let dx = star.originalX - lensCenter.x;
      let dy = star.originalY - lensCenter.y;
      let dist = p.sqrt(dx * dx + dy * dy);
      
      if (dist > 10) {
        let angle = p.atan2(dy, dx);
        let distortion = lensStrength / (dist * 0.5);
        
        star.x = star.originalX + p.cos(angle) * distortion;
        star.y = star.originalY + p.sin(angle) * distortion;
      }
      
      let alpha = p.map(dist, 0, 400, 255, 50);
      p.fill(star.color.levels[0], star.color.levels[1], star.color.levels[2], alpha);
      p.noStroke();
      p.ellipse(star.x, star.y, star.size);
    }
    
    for (let r = 0; r < 100; r += 5) {
      let alpha = p.map(r, 0, 100, 100, 0);
      p.fill(100, 100, 255, alpha);
      p.noStroke();
      p.ellipse(lensCenter.x, lensCenter.y, r);
    }
  };
  
  p.windowResized = function() {
    let container = document.getElementById('p5-wrapper'); p.resizeCanvas(container.offsetWidth, container.offsetHeight);
    lensCenter = p.createVector(p.width / 2, p.height / 2);
    for (let star of stars) {
      star.originalX = p.random(p.width);
      star.originalY = p.random(p.height);
      star.x = star.originalX;
      star.y = star.originalY;
    }
  };
};

new p5(sketch);

🎨 AI 艺术解读

This piece explores the invisible force of dark matter through the phenomenon of gravitational lensing. The stars represent distant galaxies, their paths warped by an unseen mass at the center. As you move your cursor, you become the dark matter - invisible yet powerful, bending light and shaping the universe. The cosmic color palette evokes the mystery of the unknown, while the smooth animations mirror the elegance of astrophysical phenomena.

📝 补充说明

  • The lens strength can be adjusted by changing the lensStrength variable (current: 300)
  • Motion blur is created using semi-transparent background overlay (alpha: 50)
  • Stars are reinitialized on window resize for optimal distribution
  • The lens center glow uses radial gradient with decreasing alpha