AI wrote it with prompting for Processing code

I was building a circuit that used some 4051N multiplexers and a 74HCT595N shift register to scan a sensor array I made from Velostat. The idea was to send the data through serial and display it as a pressure map. My soldering is awful and the project stalled when I put in the storage unit.

I decided I would try to simulate what I was trying to build using Processing and AI. I was careful with my prompts and had to go through several iterations to fine tune it but it works. Here’s the code:

```processing

```processing 
int cols = 16;
int rows = 16;
int pixelSize = 40;
int totalPixels = cols * rows; 

void setup() {
  size(640, 640); 
}

void draw() {
  background(0);
  noStroke();

  float time = frameCount * 0.03; 
  
  // 1. Calculate a moving center anchor
  float centerIdx = (cols - 1) / 2.0;
  float movingCenterX = centerIdx + cos(time) * 2.0;
  float movingCenterY = centerIdx + sin(time * 1.3) * 2.0; 

  // 2. REDUCED CORE SIZE: Now varies from 1/20 (5%) to 1/4 (25%) of the total area
  float sizeNoise = noise(frameCount * 0.01); 
  float targetAreaFraction = map(sizeNoise, 0, 1, 0.05, 0.25); 
  float targetPixelCount = totalPixels * targetAreaFraction; 
  float highPressureRadius = sqrt(targetPixelCount / PI);

  for (int x = 0; x < cols; x++) {
    for (int y = 0; y < rows; y++) {
      
      // 3. Evolving Perlin noise for internal variance
      float noiseVal = noise(x * 0.35, y * 0.35, frameCount * 0.02); 
      
      // 4. Calculate distance from the moving peak
      float distanceToPeak = dist(x, y, movingCenterX, movingCenterY);
      
      // 5. Secondary noise creates the organic, irregular edge shape
      float shapeNoise = noise(x * 0.4 + 100, y * 0.4 + 100, frameCount * 0.015);
      
      // Dynamic boundary adjusted by the shape roughness
      float dynamicRadius = highPressureRadius * (0.8 + shapeNoise * 0.4);
      
      // 6. ADJUSTED FALLOFF MATH
      float pressure = 0;
      if (distanceToPeak <= dynamicRadius) {
        // Inside the core: High pressure (Red zone)
        pressure = map(noiseVal, 0, 1, 0.75, 1.0);
      } else {
        // Outside the core: Calculate falloff relative to the edge of the screen
        float maxFalloffDist = dist(0, 0, centerIdx, centerIdx) - dynamicRadius;
        float distPastCore = distanceToPeak - dynamicRadius;
        
        float falloffRatio = constrain(distPastCore / maxFalloffDist, 0, 1);
        
        // Squashing the falloff slightly using pow() so it dips into low pressure quicker,
        // leaving the outer edges completely dominated by blue.
        float transitionCurve = pow(1.0 - falloffRatio, 1.5);
        
        pressure = map(transitionCurve, 0, 1, 0.0, 0.75);
        
        // Add subtle noise texture to the transition bands
        pressure += (noiseVal - 0.5) * 0.12; 
      }
      
      pressure = constrain(pressure, 0, 1);
      
      // 7. Weather Radar Color Scale
      color pixelColor;
      if (pressure < 0.30) {
        // Broad low pressure zone (Dominant Blue)
        float segmentPressure = map(pressure, 0, 0.30, 0, 1);
        pixelColor = lerpColor(color(0, 0, 255), color(0, 220, 50), segmentPressure);
      } else if (pressure < 0.65) {
        // Tight Green to Bright Yellow transition ring
        float segmentPressure = map(pressure, 0.30, 0.65, 0, 1);
        pixelColor = lerpColor(color(0, 220, 50), color(255, 255, 0), segmentPressure);
      } else if (pressure < 0.85) {
        // Yellow to Orange transition ring
        float segmentPressure = map(pressure, 0.65, 0.85, 0, 1);
        pixelColor = lerpColor(color(255, 255, 0), color(255, 120, 0), segmentPressure);
      } else {
        // Peak Core: Small, concentrated Red mass
        float segmentPressure = map(pressure, 0.85, 1.0, 0, 1);
        pixelColor = lerpColor(color(255, 120, 0), color(200, 0, 0), segmentPressure);
      }
      
      // Draw grid unit
      fill(pixelColor);
      rect(x * pixelSize, y * pixelSize, pixelSize, pixelSize);
    }
  }
}```