Understanding Addiction & Anxiety: A Neurological Cycle Simulation

A visual simulation exploring how anxiety and addiction interact in the brain

The Connection Between Anxiety and Addiction

Have you ever wondered how anxiety and addiction interact in our brains? These two challenges often feed into each other, creating cycles that can be difficult to break free from. This recursive loop resembles what philosophers call a "strange loop" – a self-referential system where cause and effect become blurred. The ancient symbol of the ouroboros, the snake eating its own tail, perfectly captures the self-perpetuating nature of these conditions. In such cycles, we often cannot identify where anxiety ends and addiction begins – they become two faces of the same underlying system.

Ouroboros - Snake eating its own tail
The ouroboros: an ancient symbol representing cycles of self-reference and recursive patterns, visually depicting the self-perpetuating nature of anxiety and addiction.

To better understand this relationship, I created a simulation that visualizes how anxiety and addiction levels change over time, how they influence each other, and how recovery can happen. This approach draws inspiration from systems theory, which teaches us that complex behaviors emerge from the interactions between simple components. Just as ecologists model forest growth or physicists model particle interactions, I believe we can model the dynamics of psychological states. There's a profound beauty in seeing abstract internal experiences represented visually – making the invisible visible and the intangible tangible.


This creative modeling approach offers a new lens for understanding human suffering. Rather than viewing addiction or anxiety as character flaws or simple medical conditions, we can see them as emergent properties of complex systems – patterns that arise from the interplay of biology, psychology, and environment. The philosopher Martin Heidegger spoke of "being-in-the-world" – the idea that we cannot separate our existence from our context. Similarly, this simulation shows how mental states cannot be separated from their dynamic interactions with life events, neurochemistry, and each other.


When someone experiences anxiety, they often seek relief. Sometimes that relief comes through substances or behaviors that temporarily reduce anxiety but may lead to addiction. Then, as addiction develops, it often creates more anxiety - forming a difficult cycle. This dance between temporary comfort and long-term suffering mirrors what Buddhist philosophy calls the cycle of samsara – the wheel of suffering that turns through attachment and aversion. The simulation attempts to reveal both the mechanics of this cycle and, crucially, the points where intervention can break it.

The Wheel of Samsara - Buddhist cycle of suffering
The Wheel of Samsara from Buddhist tradition: a visual representation of the cycle of suffering perpetuated by attachment and aversion, conceptually similar to the cyclic relationship between anxiety and addiction.

What makes this simulation special is that it doesn't just show static statistics - it demonstrates the dynamic relationship between these mental states as they evolve over time, including how positive events, negative life circumstances, and deliberate coping strategies can change someone's trajectory. There's something deeply hopeful in visualizing recovery as an actual path – seeing graphically how even entrenched patterns can shift with the right inputs at the right time. This aligns with existentialist thinking about human freedom: despite the powerful forces that shape us, we maintain some capacity to redirect our course.

The simulation in action: showing anxiety levels, addiction trends, and recovery phases over time.

How the Simulation Works

The simulation creates a visual representation of five key metrics that interact in complex ways: anxiety, addiction, dopamine (pleasure), serotonin (wellbeing), and tolerance. Each of these values influences the others through time, creating patterns that mirror real psychological experiences.

Setting Up the Core Psychological Variables

First, I needed to establish the main metrics and their relationships:

# Simulation parameters
addiction_level = 30
anxiety_level = 20
dopamine = 50
serotonin = 50
tolerance = 10
max_level = 100
min_level = 0

# Chart setup
chart_length = 100  # number of data points to track
anxiety_history = collections.deque([20] * chart_length, maxlen=chart_length)
addiction_history = collections.deque([30] * chart_length, maxlen=chart_length)
dopamine_history = collections.deque([50] * chart_length, maxlen=chart_length)
serotonin_history = collections.deque([50] * chart_length, maxlen=chart_length)
tolerance_history = collections.deque([10] * chart_length, maxlen=chart_length)

This code establishes:

  • Starting values for each psychological metric
  • Upper and lower bounds for all metrics (0-100)
  • Data structures to track each metric's history over time

This creates a starting point for someone who has moderate anxiety and addiction levels. The collections.deque objects store the history of each metric, allowing us to track changes over time and visualize trends.

Modeling Life Events and Their Impact

One of the most important aspects of anxiety and addiction is how they're affected by real-life circumstances. I created a set of life events that can either trigger anxiety/addiction or promote healing:

# Life events with their impacts
life_events = [
    {"name": "Job loss", "anxiety": 25, "addiction": 15, "dopamine": -10, "serotonin": -15, "type": "negative"},
    {"name": "Relationship breakup", "anxiety": 30, "addiction": 20, "dopamine": -15, "serotonin": -20, "type": "negative"},
    {"name": "Financial problems", "anxiety": 20, "addiction": 10, "dopamine": -5, "serotonin": -10, "type": "negative"},
    {"name": "Social rejection", "anxiety": 15, "addiction": 12, "dopamine": -8, "serotonin": -10, "type": "negative"},
    {"name": "Health issue diagnosis", "anxiety": 25, "addiction": 15, "dopamine": -10, "serotonin": -15, "type": "negative"},
    {"name": "Exercise routine", "anxiety": -15, "addiction": -10, "dopamine": 10, "serotonin": 15, "type": "positive"},
    {"name": "Meditation practice", "anxiety": -20, "addiction": -8, "dopamine": 5, "serotonin": 20, "type": "positive"},
    {"name": "Social connection", "anxiety": -15, "addiction": -12, "dopamine": 15, "serotonin": 18, "type": "positive"},
    {"name": "Therapy session", "anxiety": -25, "addiction": -15, "dopamine": 5, "serotonin": 15, "type": "positive"},
    {"name": "New hobby enjoyment", "anxiety": -10, "addiction": -15, "dopamine": 20, "serotonin": 12, "type": "positive"},
]

# Special recovery events
recovery_events = [
    {"name": "Breaking point: Seeking help", "anxiety": -30, "addiction": -25, "dopamine": 5, "serotonin": 25, "type": "recovery"},
    {"name": "Breaking point: Lifestyle change", "anxiety": -35, "addiction": -30, "dopamine": 10, "serotonin": 30, "type": "recovery"},
    {"name": "Breaking point: Support system", "anxiety": -25, "addiction": -20, "dopamine": 15, "serotonin": 35, "type": "recovery"}
]

Each life event affects multiple psychological metrics simultaneously:

  • Negative events (like job loss) increase anxiety and addiction while decreasing wellbeing
  • Positive events (like exercise) decrease anxiety and addiction while increasing wellbeing
  • Special recovery events occur at breaking points and have powerful healing effects

This mirrors how real-life stressors and positive experiences affect us on multiple psychological levels simultaneously.

The Breaking Point and Recovery Process

One of the most meaningful aspects of the simulation is how it models hitting "rock bottom" and the recovery process:

def trigger_life_event(forced_event=None, forced_type=None):
    # ...existing code...
    
    # Determine event probabilities based on anxiety level
    if anxiety_level > anxiety_threshold and not in_recovery_phase:
        # Trigger a recovery event at breaking point
        event = random.choice(recovery_events)
        enter_recovery_phase()
    else:
        # Probability of negative event increases with anxiety
        neg_prob = min(0.8, 0.3 + (anxiety_level / 100) * 0.5)
        
        # In recovery phase, bias toward positive events
        if in_recovery_phase:
            neg_prob = max(0.1, neg_prob - 0.4)
            
        # Select based on calculated probability
        if forced_type == "negative" or (forced_type is None and random.random() < neg_prob):
            event = random.choice([e for e in life_events if e["type"] == "negative"])
        else:
            event = random.choice([e for e in life_events if e["type"] == "positive"])

This code demonstrates several important psychological patterns:

  • When anxiety reaches a threshold, a "breaking point" occurs that triggers recovery
  • Higher anxiety levels make negative events more likely (creating a downward spiral)
  • Being in recovery reduces the probability of negative events by 40%
  • This models how seeking help creates a more supportive environment

The cycle of breakdown and recovery mirrors real-life experiences where hitting "rock bottom" often precedes significant positive change.

The Natural Dynamics of Anxiety and Addiction

What makes this simulation especially realistic is how it models the natural interplay between anxiety and addiction:

# Natural dynamics
if step_count % 3 == 0:
    # Addiction tends to increase anxiety over time
    if addiction_level > 50:
        anxiety_level += (addiction_level - 50) / 20
    
    # Anxiety can trigger addiction behaviors as coping
    if anxiety_level > 60 and random.random() < 0.3:
        addiction_level += random.randint(5, 10)
        dopamine += random.randint(10, 20)
        anxiety_level -= random.randint(5, 10)  # temporary relief
    
    # Tolerance build-up reduces dopamine effectiveness
    dopamine = max(min_level, dopamine - tolerance / 10)
    
    # Serotonin helps reduce anxiety
    if serotonin > 60:
        anxiety_level = max(min_level, anxiety_level - random.uniform(0, 2))
    
    # Tolerance increases with addiction level
    if addiction_level > 70:
        tolerance = min(30, tolerance + 0.5)
    
    # Prolonged high anxiety reduces serotonin
    if anxiety_level > 70:
        serotonin = max(min_level, serotonin - random.uniform(0.5, 1.5))

This code demonstrates several important psychological realities:

  • Higher addiction levels gradually increase anxiety over time
  • High anxiety can trigger addiction behaviors as a coping mechanism
  • Using addictive behaviors provides temporary anxiety relief but builds tolerance
  • Higher serotonin (wellbeing) naturally reduces anxiety
  • Prolonged anxiety depletes serotonin, creating a downward spiral

These interactions create the self-reinforcing cycles often seen in real cases of anxiety and addiction.

What the Simulation Reveals

Running this simulation shows several insights about addiction and anxiety:

  1. Self-reinforcing cycles - Anxiety and addiction form feedback loops that can intensify over time if not interrupted.
  2. The importance of positive events - Regular positive events like exercise, meditation, and social connection help maintain low anxiety levels and reduce addiction potential.
  3. Breaking points as opportunities - While hitting a "breaking point" feels terrible, it often serves as the catalyst for seeking help and beginning recovery.
  4. Recovery phases - During recovery, the chance of positive events increases while negative events have less impact, showing how proper support creates a protective effect.
  5. The neurochemical balance - The simulation shows how serotonin and dopamine levels influence anxiety and addiction, highlighting the biological basis of these conditions.

The Visualization

The GUI displays several key elements:

  • Multi-line chart - Shows all five metrics evolving over time with distinct colors
  • Recovery phases - Green shaded areas on the chart indicate periods of active recovery
  • Breaking point threshold - A red dashed line showing when someone is approaching crisis
  • Event markers - Colored dots showing when significant life events occurred
  • Current status indicators - Text and color-coding showing the person's psychological state
  • Control elements - Buttons and sliders to adjust speed, trigger events, or simulate coping strategies

The visualization makes abstract psychological concepts tangible and helps you see patterns that might otherwise be invisible.

Why This Matters

Understanding the relationship between anxiety and addiction isn't just an academic exercise - it's crucial for helping real people. This simulation shows how:

  • Addiction isn't simply a matter of willpower but is influenced by anxiety, life events, and neurochemistry
  • Recovery isn't linear but follows patterns of improvement and setbacks over time
  • Small positive interventions can accumulate and change someone's trajectory
  • Breaking points, while painful, often create the conditions necessary for lasting change

For anyone supporting loved ones with addiction or anxiety issues, this perspective can foster compassion. It shows that these conditions involve complex feedback loops rather than simple choices, and that recovery requires changing multiple aspects of someone's internal and external environment.

Try It Yourself

If you'd like to run this simulation:

  1. Make sure you have Python with tkinter installed
  2. Install required packages: pip install numpy matplotlib
  3. Download the code from GitHub
  4. Run python addiction_anxiety_simulation.py

You can experiment by:

  • Triggering different life events to see their impact
  • Using coping strategies at different times to see how they help
  • Adjusting the simulation parameters to model different starting conditions
  • Watching how recovery unfolds after hitting a breaking point

Hope Through Understanding

What I find most meaningful about this simulation is that it shows a path forward. Even in cases where anxiety and addiction have reinforced each other for a long time, the system can change. With the right interventions - a combination of positive events, coping strategies, and sometimes reaching a breaking point that leads to seeking help - recovery is possible.

The fact that our brains and psyches operate according to these patterns doesn't mean we're trapped by them. Rather, understanding these patterns gives us the power to interrupt them at critical points and gradually shift them toward healing.

Kim Pham - 01.11.2024