Skip to content
TheChatArchiveThe Chat Archive
chatgpt-4o-latest-20250326· OpenAIHugging Face LMArena Human Preference 140K

why i see grey background? code: /** GlowingBlob.tsx — Apple-style organic blob…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with o4-mini-2025-04-16’s answer.
  1. User

    why i see grey background? code: /**

    GlowingBlob.tsx — Apple-style organic blob controlled via external slider */ import React, { useEffect } from 'react'; import { View, StyleSheet } from 'react-native'; import { Canvas, Path, Group, vec, RadialGradient, BlurMask, Image, Skia } from '@shopify/react-native-skia'; import Animated, { useSharedValue, withTiming, withRepeat, useDerivedValue } from 'react-native-reanimated'; import { Spacing, getClarityGradient } from '@/constants/Colors'; import { CognitionLevel } from '@/types'; // ---------- constants ---------- const SPEED: Record<CognitionLevel, number> = { 1: 8000, 2: 7000, 3: 6000, 4: 5000, 5: 4500, };

    // ---------- alpha helper ---------- const addAlpha = (hex: string, alpha: number) => { const a = Math.round(alpha * 255) .toString(16) .padStart(2, '0') .toUpperCase(); return #a{a}{hex.replace('#', '')}; };

    // ---------- noise bitmap (cached once) ---------- const createNoiseBitmap = () => { const surface = Skia.Surface.MakeOffscreen(512, 512); if (!surface) { console.warn('Skia offscreen surface failed; using transparent fallback'); return null; } const canvas = surface.getCanvas(); const paint = Skia.Paint(); paint.setAntiAlias(true); for (let x = 0; x < 512; x += 4) { for (let y = 0; y < 512; y += 4) { paint.setColor(Skia.Color(rgba(255,255,255,${Math.random() * 0.3 + 0.1}))); canvas.drawRect(Skia.XYWHRect(x, y, 4, 4), paint); } } return surface.makeImageSnapshot(); }; const noiseImage = createNoiseBitmap();

    // ---------- organic blob path ---------- const makeBlobPath = (R: number, t: number, clarity: CognitionLevel) => { 'worklet'; const pts = 48; const ampl = Math.min(0.08, Math.max(0.05, 0.18 - clarity * 0.02)); const p: [number, number][] = []; for (let i = 0; i < pts; ++i) { const a = (i / pts) * Math.PI * 2; const n = Math.sin(a * 3 + t * 2) * 0.6 + Math.sin(a * 7 + t) * 0.4; const r = R * (1 + ampl * n); p.push([Math.cos(a) * r, Math.sin(a) * r]); } const path = Skia.Path.Make(); for (let i = 0; i < pts; ++i) { const p0 = p[(i - 1 + pts) % pts], p1 = p[i], p2 = p[(i + 1) % pts], p3 = p[(i + 2) % pts]; if (i === 0) path.moveTo(...p1); path.cubicTo( p1[0] + (p2[0] - p0[0]) / 6, p1[1] + (p2[1] - p0[1]) / 6, p2[0] - (p3[0] - p1[0]) / 6, p2[1] - (p3[1] - p1[1]) / 6, ...p2 ); } path.close(); return path; };

    // ---------- component ---------- export default function GlowingBlob({ clarity = 3, size = 300, }: { clarity?: CognitionLevel; size?: number; }) { const level = clarity;

    const prog = useSharedValue(0); useEffect(() => { prog.value = withRepeat(withTiming(1, { duration: SPEED[level] }), -1, false); }, [level, prog]);

    // geometry const σ = 50; const pad = σ * 3; const canvasDim = size + pad * 2; const R = size * 0.35;

    // transforms const baseScale = 0.9 + level * 0.03; const transform = useDerivedValue(() => { const breath = 0.04 * Math.sin(prog.value * 2 * Math.PI); return [ { translateX: canvasDim / 2 }, { translateY: canvasDim / 2 }, { scale: baseScale + breath }, ]; });

    // dynamic colors from code2 const [light, mid, deep = mid] = getClarityGradient(level); const rimTint = addAlpha(light, 0); const bloomTint = addAlpha(mid, 0.8);

    // blob path const blobPath = useDerivedValue(() => makeBlobPath(R, prog.value * 2 * Math.PI, level), [ prog, level, ]);

    return ( <View style={[styles.container, { width: size, height: size }]}> <Canvas style={{ width: canvasDim, height: canvasDim, margin: -pad, backgroundColor: 'white', }} > <Group origin={vec(canvasDim / 2, canvasDim / 2)} transform={transform}> {/* bloom /} <RadialGradient c={vec(0, 0)} r={R} colors={[bloomTint, rimTint]} /> {/ core /} <RadialGradient c={vec(0, 0)} r={R} colors={[deep, mid, light]} positions={[0, 0.6, 1]} /> {/ rim highlight /} {/ noise */} {noiseImage && ( )} ); }

    const styles = StyleSheet.create({ container: { alignItems: 'center', justifyContent: 'center', marginVertical: Spacing.lg, backgroundColor: 'white', // ensure the container itself is white }, });

  2. Assistant

    You're seeing a grey background in your GlowingBlob component likely because of how <Canvas> is styled, and its blendModes and transparency are interacting with the colors and background. Based on your code, here are some likely causes — and how to fix them.


    🕵️‍♂️ Root Cause Diagnosis

    1. ✅ You Explicitly Set a White Background!

    In both the component and styles:

    <Canvas
      style={{
        width: canvasDim,
        height: canvasDim,
        margin: -pad,
        backgroundColor: 'white',  // <- this!
      }}
    

    And:

    const styles = StyleSheet.create({
      container: {
        ...
        backgroundColor: 'white', // <- this!
      },
    });
    

    So, it should appear white, not grey. But you might still see it looking gray because of:


    2. 🔄 Alpha Transparency / Blending Modes

    color blending + semi-transparent overlays = perceived gray

    You're using blendMode="screen", semi-transparent fills, and radial gradients:

    <RadialGradient c={vec(0, 0)} r={R} colors={[bloomTint, rimTint]} />
    

    But:

    const bloomTint = addAlpha(mid, 0.8);
    const rimTint = addAlpha(light, 0); // alpha = 0!
    

    And you're applying this in a grouped screen blend mode.

    💡 screen blend mode with transparency → can make background look washed-out or greyish, depending on the visual combination.


    3. 🟨 The Noise Layer May Also Be A Factor

    <Image
      image={noiseImage}
      x={0}
      y={0}
      width={canvasDim}
      height={canvasDim}
      blendMode="softLight"
      opacity={0.05}
    />
    

    Even with a low opacity of 0.05, the softLight blend mode can subtly shift the perceived background color — especially if your screen has varying gamma or color management.

    💡 Low-opacity white noise on white = could become slightly gray depending on render engine.


    ✅ How to Fix or Test

    🧪 Option 1: Force Canvas to White Layer — Solid Background Check

    Temporarily remove or comment out the blendMode, gradients, and noise image.

    Just render a white background layer at the bottom:

    <Canvas style={{ width: canvasDim, height: canvasDim, margin: -pad }}>
      <Path
        path={Skia.Path.MakeFromSVGString(`M0,0 H${canvasDim} V${canvasDim} H0 Z`) as any}
        color="white"
      />
    </Canvas>
    

    Does it still appear grey? If not, the cause is visual blending.


    🎯 Option 2: Add Solid Background Layer Behind All Content

    Just like above, add a solid white base layer inside the canvas, before any other drawing:

    <Group>
      <Path
        path={Skia.Path.MakeFromSVGString(`M0,0 H${canvasDim} V${canvasDim} H0 Z`)!}
        color="white"
      />
      {/* all other content here */}
    </Group>
    

    🎯 Option 3: Remove or tweak the noise layer

    Try commenting this out:

    {/* <Image image={noiseImage} ... /> */}
    

    Or increase opacity={0} temporarily. If background turns pure white, noise is the issue.


    🎯 Option 4: Debug Blend Modes / Alpha

    Try replacing:

    <RadialGradient c={vec(0, 0)} r={R} colors={[bloomTint, rimTint]} />
    

    With full opacity colors like:

    <RadialGradient c={vec(0, 0)} r={R} colors={['#FF0000', '#00FF00']} />
    

    Just to see how overlays affect appearance.


    Bonus: rgba() in Skia.Color() May Be Buggy

    You're calling:

    Skia.Color(`rgba(255,255,255,${Math.random() * 0.3 + 0.1})`)
    

    But Skia.Color from @shopify/react-native-skia may not reliably parse rgba() strings — especially dynamic ones. This might lead to unexpected alpha/gray visual effect.

    ✅ Use numeric Skia.Color values or hex strings:

    paint.setColor(Skia.Color(`#FFFFFF${Math.floor(255 * Math.random() * 0.3 + 0.1).toString(16).padStart(2, '0')}`));
    

    ❗ Final Notes

    • The gray appearance is likely a mix of transparency, blend modes, and subtle overlays like noise.
    • Canvas compositing may not visually match expected RGB values due to post-processing.
    • Mobile display gamma also affects how white vs. gray appears — test on physical device with max brightness & compare with backgroundColor: '#fff'.

    ✅ Suggestion (Minimal Fix):

    Force white base inside Canvas:

    <Canvas style={{ width: canvasDim, height: canvasDim, margin: -pad }}>
      <Path path={Skia.Path.MakeFromSVGString(`M0,0 H${canvasDim} V${canvasDim} H0 Z`)!} color="white" />
      {/* Group containing glow, blob, noise */}
    </Canvas>
    

    Let me know if you'd like help visually debugging with screenshots or tweaking blend behavior.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.