AP CSP: Snap! Learning Hub
Master block-based programming with interactive tutorials and pro tips
🚀 Getting Started with Snap!
Snap! is a visual, block-based programming language perfect for learning computational thinking. It's like Scratch but more powerful, preparing you for text-based languages.
🎮 Motion & Sprites
Key Blocks:
💡 Pro Tips:
- Coordinate System: Center is (0,0). X goes left (-) to right (+), Y goes down (-) to up (+)
- Degrees: 0° = up, 90° = right, 180° = down, 270° = left
- Smooth Movement: Use smaller step values in forever loops for smoother motion
- Boundaries: Use IF statements with x/y position to keep sprites on stage
🎨 Looks & Costumes
Key Blocks:
💡 Pro Tips:
- Animation: Switch costumes rapidly in a loop for smooth animation
- Visual Feedback: Use "say" blocks to display variable values during debugging
- Size Matters: Use set size vs change size depending on if you want absolute or relative sizing
- Effects: Combine color, brightness, and ghost effects for cool visuals
📊 Variables & Lists
Key Concepts:
💡 Pro Tips:
- Naming: Use descriptive names like "playerScore" not "x" or "temp"
- Scope: Make variables "for all sprites" only when multiple sprites need them
- Lists vs Variables: Use lists for collections (inventory, leaderboard), variables for single values
- Initialize: Always set variables to starting values at the beginning of your program
- List Length: Use "length of list" to avoid index errors when accessing items
🔄 Control Structures
Key Blocks:
💡 Pro Tips:
- Forever Loops: Great for constant checking (like game loops), but be careful of infinite loops that freeze
- Repeat vs Forever: Use "repeat" when you know how many times, "forever" for continuous action
- If vs If-Else: Use if-else when you have two specific outcomes, just if for one action
- Wait Blocks: Add small waits in forever loops to prevent lag (0.01-0.1 seconds)
- Nested Loops: You can put loops inside loops for complex patterns (like drawing grids)
🔢 Operators & Logic
Key Blocks:
💡 Pro Tips:
- Math Operations: Use +, -, *, / for arithmetic. Remember order of operations!
- Comparisons: < less than, > greater than, = equals. Useful in if statements
- AND/OR Logic: "AND" requires both true, "OR" needs just one true
- Random Numbers: Great for games! Random (1) to (10) gives 1,2,3...10
- Join Blocks: Combine text with "join" - useful for creating sentences with variables
🛠️ Custom Blocks (Functions)
Why Use Custom Blocks?
Custom blocks let you create your own reusable commands - like functions in other languages!
💡 Pro Tips:
- DRY Principle: "Don't Repeat Yourself" - if you use the same code twice, make a custom block!
- Input Parameters: Add input slots to make blocks flexible (like "drawSquare (size)")
- Naming: Use clear, action-based names like "drawHouse" or "checkCollision"
- Organization: Group related custom blocks together (all drawing blocks, all game logic blocks, etc.)
- Testing: Test custom blocks separately before using them in your main program
Example Custom Block Ideas:
- drawPolygon (sides) (size): Draw any regular polygon
- resetGame: Put all the game reset code in one block
- checkWin: Check if player has won the game
- enemyMove (speed): Control enemy behavior with parameters
🐛 Debugging Tips
Common Problems & Solutions:
Solution: Adjust step size or add wait blocks in forever loops
Solution: Check if variable is initialized, verify you're using "set" vs "change" correctly
Solution: Make sure the script starts with the correct "when" block (green flag, key pressed, sprite clicked)
Solution: Use "forever" loop for continuous checking, not just sequential blocks
💡 Debugging Strategies:
- Use Say Blocks: Display variable values to see what's happening
- Test in Steps: Build small pieces, test each one, then combine
- Check Conditions: Make sure IF statements are checking the right things
- Reset Between Tests: Click stop, then green flag to reset everything
- Simplify: Comment out code or remove blocks to isolate the problem
🎮 Project Ideas for AP CSP
🎯 Beginner: Catch Game
Create a game where falling objects must be caught. Use variables for score, forever loops for falling motion, and collision detection.
🎨 Intermediate: Drawing App
Build a program that lets users draw by moving the mouse. Use pen blocks, mouse position, and keyboard controls for colors.
🧮 Intermediate: Quiz Game
Create an interactive quiz with multiple questions. Use lists for questions/answers, variables for score, and custom blocks for asking questions.
🚀 Advanced: Platformer Game
Build a side-scrolling platformer with gravity, jumping, and obstacles. Uses complex collision detection and game physics.
🤖 Advanced: AI Chatbot
Create a chatbot that responds to user input with different answers. Use lists for responses and string operations for pattern matching.
📋 Quick Reference Cheat Sheet
Essential Shortcuts
- Ctrl + Shift + Click: Edit block
- Right-click block: Duplicate or delete
- Shift + Click green flag: Turbo mode
- Drag block to palette: Delete it
Best Practices
- ✅ Name variables clearly
- ✅ Use custom blocks for repeated code
- ✅ Comment complex sections
- ✅ Save frequently
- ✅ Test often