# ๐งฉ Scratch-like Block Designer for HRIStudio
## Overview
The HRIStudio Block Designer provides an authentic MIT Scratch-inspired visual programming interface for creating experiment protocols. This approach offers structured creativity with intuitive block-based programming that prevents logic errors while enabling complex experimental workflows.
## ๐ฏ Design Philosophy
### **Why Scratch-like Design?**
- **Intuitive Learning**: Visual blocks are immediately understandable to researchers
- **Structured Creativity**: Prevents syntax errors while enabling complex logic
- **Linear Flow**: Natural top-to-bottom execution with clear visual sequence
- **Block Categories**: Organized by function (wizard, robot, control, sensing)
- **Magnetic Connections**: Blocks naturally want to connect when brought close together
### **Advantages Over Alternatives**
| Feature | Scratch Blocks | React Flow | Traditional Forms |
|---------|---------------|------------|-------------------|
| **Learning Curve** | โ
Minimal | โ ๏ธ Moderate | โ
Familiar |
| **Error Prevention** | โ
Built-in | โ User dependent | โ ๏ธ Validation needed |
| **Visual Clarity** | โ
Excellent | โ
Good | โ Poor |
| **Structured Flow** | โ
Enforced | โ ๏ธ Optional | โ
Enforced |
| **Complex Logic** | โ
Supported | โ
Flexible | โ Limited |
| **Creativity** | โ
High | โ
Maximum | โ Constrained |
| **Connection Logic** | โ
Magnetic | โ ๏ธ Manual | โ None |
## ๐งฉ Block Categories
### ๐ฃ **Wizard Actions** (Purple #9966FF)
Human-operated actions performed by the experiment wizard.
#### **Say Block**
```
[๐ฌ say "Hello, welcome to our study!"]
```
- **Purpose**: Wizard speaks to participant
- **Parameters**: Message text (inline editing)
- **Size**: 120px ร 32px
- **Use Case**: Instructions, questions, responses
#### **Gesture Block**
```
[๐ gesture wave]
```
- **Purpose**: Wizard performs physical gesture
- **Parameters**: Gesture type (wave, point, nod, thumbs up)
- **Size**: 100px ร 32px
- **Use Case**: Non-verbal communication, emphasis
### ๐ต **Robot Actions** (Blue #4C97FF)
Automated behaviors performed by the robot system.
#### **Robot Say Block**
```
[๐ค say "I'm ready to help you!"]
```
- **Purpose**: Robot text-to-speech output
- **Parameters**: Message text with voice settings
- **Size**: 120px ร 32px
- **Use Case**: Greetings, instructions, responses
#### **Move Block**
```
[โก๏ธ move forward 10 steps]
```
- **Purpose**: Robot movement commands
- **Parameters**: Direction (forward/backward/left/right), distance
- **Size**: 140px ร 32px
- **Use Case**: Navigation, positioning, demonstrations
#### **Look At Block**
```
[๐๏ธ look at participant]
```
- **Purpose**: Robot gaze/camera orientation
- **Parameters**: Target (participant, object, door)
- **Size**: 110px ร 32px
- **Use Case**: Attention direction, social cues
### ๐ **Control Flow** (Orange #FFAB19)
Programming logic and control structures.
#### **Wait Block**
```
[โฐ wait 3 seconds]
```
- **Purpose**: Pause execution for specified time
- **Parameters**: Duration in seconds
- **Size**: 100px ร 32px
- **Use Case**: Timing, pacing, delays
#### **If Block** (C-shaped)
```
[๐ if participant speaks]
[๐ฌ say "I heard you!"]
[๐ gesture wave]
```
- **Purpose**: Conditional execution based on events
- **Parameters**: Condition type (participant speaks, time elapsed, object detected)
- **Size**: 150px ร 60px + nested content
- **Nesting**: Contains child blocks in drop zone
- **Use Case**: Reactive behaviors, branching scenarios
#### **Repeat Block** (C-shaped)
```
[๐ repeat 3 times]
[๐ค say "Hello!"]
[โฐ wait 1 seconds]
```
- **Purpose**: Execute child blocks multiple times
- **Parameters**: Number of repetitions
- **Size**: 120px ร 60px + nested content
- **Nesting**: Contains child blocks in drop zone
- **Use Case**: Repeated actions, demonstrations
### ๐ข **Sensing** (Green #59C059)
Research data capture and observation tools.
#### **Observe Block**
```
[๐๏ธ observe "engagement"]
```
- **Purpose**: Record observations during experiment
- **Parameters**: Behavior to observe (engagement, attention, etc.)
- **Size**: 120px ร 32px
- **Use Case**: Behavioral coding, data collection
## ๐จ Visual Design System
### **Block Anatomy**
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Connection Tab โ โ Top connection point
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ [๐ค] say "Hello!" for 2 seconds โ โ Icon + action + parameters
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Connection Tab โ โ Bottom connection point
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
### **Color System**
- **Wizard Purple**: `#9966FF` - Human-operated actions
- **Robot Blue**: `#4C97FF` - Automated robot behaviors
- **Control Orange**: `#FFAB19` - Logic and flow control
- **Sensing Green**: `#59C059` - Data collection and observation
### **Shape Types**
- **Round Blocks**: Standard action blocks with rounded corners
- **C-Shaped Blocks**: Control blocks with nested drop zones
- **Connection Tabs**: 4px ร 16px tabs for magnetic connections
- **Parameter Bubbles**: Inline parameter display with `bg-white/20`
### **Size Standards**
- **Small Actions**: 100px width for simple actions (wait, gesture)
- **Medium Actions**: 120px width for text-based actions (say, observe)
- **Large Actions**: 140px width for complex actions (move with parameters)
- **Control Blocks**: 150px width with variable height based on content
- **Height**: 32px for round blocks, 60px+ for control blocks
## ๐ฎ User Interactions
### **Drag & Drop Workflow**
1. **Browse Palette**: Categories organize blocks by function
2. **Drag to Canvas**: Click and drag blocks from palette to freeform canvas
3. **Magnetic Connections**: Blocks automatically snap together when within 30px
4. **Visual Feedback**: Blue rings and snap previews guide connections
5. **Parameter Editing**: Click any block to open parameter editor panel
### **Magnetic Connection System**
- **Snap Distance**: 30px proximity triggers magnetic attraction
- **Visual Indicators**: Blue ring around target block, dashed snap preview
- **Automatic Alignment**: Blocks perfectly align when snapped together
- **Connection Storage**: Relationships stored in block metadata
- **Connection Feedback**: Toast notification confirms successful connections
### **Freeform Canvas**
- **Unlimited Positioning**: Blocks can be placed anywhere on infinite canvas
- **Grid Background**: Subtle dot pattern provides visual reference
- **Smooth Dragging**: Real-time position updates with zero lag
- **Canvas Scrolling**: Automatically expands to accommodate block placement
- **Random Placement**: New blocks from palette appear in available space
### **Parameter Configuration**
- **Inline Display**: Parameters show directly in block (say "Hello!")
- **Click to Edit**: Single click opens slide-out parameter editor
- **Type-Safe Inputs**: Text fields, number inputs, dropdown selectors
- **Live Preview**: Parameter changes update block display immediately
- **Validation**: Built-in validation prevents invalid parameter values
## ๐ Connection & Flow Logic
### **Block Sequencing**
```
โโโโโโโโโโโโโโโโโโโ
โ [๐ค] say "Hi!" โ โ Block 1
โโโโโโโโโโโฌโโโโโโโโ
โ Connection
โโโโโโโโโโโผโโโโโโโโ
โ [โฐ] wait 2 sec โ โ Block 2
โโโโโโโโโโโฌโโโโโโโโ
โ Connection
โโโโโโโโโโโผโโโโโโโโ
โ [๐] gesture โ โ Block 3
โโโโโโโโโโโโโโโโโโโ
```
### **Control Flow Nesting**
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ [๐] if participant speaks โ โ Control block
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ Nested area
โ โ [๐ฌ] say "I heard you!" โ โ โ Child block 1
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ [๐๏ธ] look at participantโ โ โ Child block 2
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
### **Connection Data Structure**
```typescript
interface ExperimentBlock {
id: string;
type: "action" | "control";
subtype: string; // wizard_speak, robot_move, etc.
name: string; // Display name
color: string; // Scratch color (#9966FF, #4C97FF, etc.)
shape: "round" | "control"; // Visual shape type
parameters: BlockParameter[]; // Configurable values
position: { x: number; y: number }; // Canvas position
connections?: { // Connection relationships
top?: string; // Connected block above
bottom?: string; // Connected block below
};
children?: ExperimentBlock[]; // Nested blocks (for control types)
}
```
## ๐๏ธ Technical Implementation
### **Component Architecture**
```typescript
// Main designer container