Scratch to Python Dictionary
Motion Blocks
- move (10) steps → x += 10 * cos(radians(direction)); y += 10 * sin(radians(direction)) Lib: math
- turn clockwise (15) degrees → direction += 15 Lib: None
- turn counterclockwise (15) degrees → direction -= 15 Lib: None
- go to x:(0) y:(0) → x = 0; y = 0 Lib: None
- glide (1) secs to x:(0) y:(0) → smooth_move(x, y, 1) Lib: time
- point in direction (90) → direction = 90 Lib: None
- change x by (10) → x += 10 Lib: None
- set x to (0) → x = 0 Lib: None
- change y by (10) → y += 10 Lib: None
- set y to (0) → y = 0 Lib: None
- if on edge, bounce → bounce_if_edge() Lib: Custom
- set rotation style [left-right, don't rotate, all around] → rotation_style = "left-right" Lib: None
Looks Blocks
- say [Hello!] for (2) seconds → print("Hello!"); time.sleep(2) Lib: time
- say [Hello!] → print("Hello!") Lib: None
- think [Hmm...] for (2) seconds → print("(thinking) Hmm..."); time.sleep(2) Lib: time
- switch costume to [costume2] → costume = "costume2" Lib: None
- next costume → costume_index = (costume_index + 1) % len(costumes) Lib: None
- change size by (10) → size += 10 Lib: None
- set size to (100)% → size = 100 Lib: None
- show → visible = True Lib: None
- hide → visible = False Lib: None
- go to front layer → layer = "front" Lib: None
- go back (1) layers → layer -= 1 Lib: None
Sound Blocks
- play sound [meow] → playsound("meow.wav") Lib: playsound
- play sound [meow] until done → playsound("meow.wav", block=True) Lib: playsound
- stop all sounds → pygame.mixer.stop() Lib: pygame
- change pitch effect by (10) → sound_pitch += 10 Lib: pydub or custom
- set volume to (100)% → volume = 100 Lib: pygame
Events Blocks
- when green flag clicked → def on_start(): Lib: None
- when [space] key pressed → on_key("space") Lib: keyboard
- when this sprite clicked → on_click() Lib: Custom
- broadcast [message1] → send("message1") Lib: Custom
- broadcast [message1] and wait → send_and_wait("message1") Lib: Custom
- when I receive [message1] → on_message("message1") Lib: Custom
Control Blocks
NOTE: Replace condition with the condition or equation you want (e.g. if i = 10: )
- wait (1) seconds → time.sleep(1) Lib: time
- repeat (10) → for i in range(10): Lib: None
- forever → while True: Lib: None
- if then → if condition: Lib: None
- if then else → if condition: else: Lib: None
- wait until → while not condition: pass Lib: None
- repeat until → while not condition: Lib: None
- stop [all, this script, other scripts] → sys.exit() or return Lib: sys
- create clone of [myself] → clone_object(self) Lib: Custom
- when I start as a clone → on_clone_start() Lib: Custom
- delete this clone → delete(self) Lib: Custom
Sensing Blocks
- touching [sprite1]? → touching("sprite1") Lib: Custom
- mouse down? → mouse.is_pressed() Lib: pygame
- mouse x → mouse.x Lib: pygame
- mouse y → mouse.y Lib: pygame
- key [space] pressed? → keyboard.is_pressed("space") Lib: keyboard
- loudness → get_microphone_level() Lib: sounddevice or pyaudio
- timer → time.time() - timer_start Lib: time
- reset timer → timer_start = time.time() Lib: time
- current [year/month/date/hour/minute/second] → datetime.now().year etc. Lib: datetime
Operators
- Arithmetic, comparison, logic, and string operations: use built-in Python; no additional libraries.
- Random: pick random (1) to (10) → random.randint(1,10) Lib: random
Variables & Lists
- set [score] to (0) → score = 0 Lib: None
- change [score] by (1) → score += 1 Lib: None
- add [thing] to [list] → list.append("thing") Lib: None
- delete (1) of [list] → del list[0] Lib: None
- length of [list] → len(list) Lib: None
- contains? → "thing" in list Lib: None
TurboWarp Extensions (with Libraries)
Animated Text
- animated text ["Hello"] at x:(0) y:(0) → display_text("Hello", 0, 0) Lib: Custom
- animate text ["Hello"] by [wave] → animate_text("Hello", style="wave") Lib: Custom
Face Sensing
- face detected? → detect_face() != None Lib: opencv-python
- face x position → face_coords[0] Lib: opencv-python
- face y position → face_coords[1] Lib: opencv-python
- face size → face_size Lib: opencv-python
Stretch
- set stretch x to (1.5) → scale_x = 1.5 Lib: Custom
- set stretch y to (0.5) → scale_y = 0.5 Lib: Custom
- reset stretch → scale_x = 1; scale_y = 1 Lib: Custom
Gamepad
- when gamepad button [0] pressed → on_gamepad_press(0) Lib: pygame
- gamepad button [0] down? → gamepad.is_pressed(0) Lib: pygame
- gamepad axis [0] value → gamepad.get_axis(0) Lib: pygame
Box2D Physics
- set gravity to (0, -9.8) → world.gravity = (0, -9.8) Lib: pymunk or pybox2d
- create physics sprite → physics_body = create_body() Lib: pymunk
- apply force (10, 0) to sprite → body.apply_force((10,0)) Lib: pymunk
- set restitution (0.5) → body.restitution = 0.5 Lib: pymunk
Files
- read file ["data.json"] → open("data.json").read() Lib: None
- write file ["log.txt"] contents ["hello"] → open("log.txt","w").write("hello") Lib: None
Pointer Lock / Mouse
- enable pointer lock → enable_pointer_lock() Lib: Custom
- pointer movement x change → mouse.dx Lib: pygame
- pointer movement y change → mouse.dy Lib: pygame
Mouse Cursor
- hide cursor → hide_cursor() Lib: pygame
- show cursor → show_cursor() Lib: pygame
- set cursor to costume [cursor1] → set_cursor("cursor1.png") Lib: pygame
Runtime Options
- set framerate to (60) → clock.tick(60) Lib: pygame
- get framerate → clock.get_fps() Lib: pygame
- set stage width to (800) height to (600) → set_screen_size(800,600) Lib: pygame
- enable turbo mode → turbo = True Lib: Custom
Fetch / Networking
- fetch ["https://..."] → requests.get("https://...").text Lib: requests
- fetch JSON ["https://..."] → requests.get("https://...").json() Lib: requests
- post to ["url"] with data [dict] → requests.post("url", json=data).json() Lib: requests
Text Utilities
- text length of ["hello"] → len("hello") Lib: None
- uppercase ["hello"] → "hello".upper() Lib: None
- lowercase ["Hello"] → "Hello".lower() Lib: None
- replace ["hello world"] "world" with "there" → "hello world".replace("world","there") Lib: None
- reverse ["hello"] → "hello"[::-1] Lib: None
- substring of ["hello"] from (1) to (3) → "hello"[0:3] Lib: None
- index of ["lo"] in ["hello"] → "hello".find("lo") + 1 Lib: None
Local Storage
- set [score] to [100] in storage → local["score"] = "100" Lib: json or pickle
- get [score] from storage → local.get("score", "") Lib: json or pickle
- delete [score] from storage → del local["score"] Lib: json or pickle
- delete storage → local.clear() Lib: json or pickle
User Interface (UI) Reference — Scratch → Python Equivalents (with Libraries)
Stage & Screen
- set stage size to (width) (height) → screen = pygame.display.set_mode((width, height)) Lib: pygame
- set stage color to [color] → screen.fill((r, g, b)) Lib: pygame
- set background to [backdrop1] → background = load_image("backdrop1.png"); screen.blit(background, (0, 0)) Lib: pygame + PIL or pygame.image
- switch backdrop to [next backdrop] → backdrop_index = (backdrop_index + 1) % len(backdrops); background = load_image(backdrops[backdrop_index]) Lib: pygame
- show backdrop [name] → background = load_image(f"{name}.png") Lib: pygame
- hide backdrop → background = None Lib: pygame
Sprites
- create sprite [sprite1] from ["sprite.png"] → sprite1 = Sprite("sprite.png", x=0, y=0) Lib: pygame
- show sprite [sprite1] → sprite1.visible = True Lib: pygame
- hide sprite [sprite1] → sprite1.visible = False Lib: pygame
- set sprite [sprite1] position to x:(0) y:(0) → sprite1.x, sprite1.y = 0, 0 Lib: pygame
- change sprite [sprite1] costume to [costume2] → sprite1.set_costume("costume2.png") Lib: pygame
- set sprite [sprite1] rotation to (90) → sprite1.angle = 90 Lib: pygame
- scale sprite [sprite1] by (1.5) → sprite1.scale = 1.5 Lib: pygame
- set sprite [sprite1] opacity to (80)% → sprite1.opacity = 0.8 Lib: pygame
Buttons
- create button ["Click me"] at x:(100) y:(50) → button = UIButton("Click me", (100, 50)) Lib: tkinter or pygame_gui
- when button ["Click me"] clicked → button.on_click = lambda: print("Clicked!") Lib: tkinter or pygame_gui
- set button color to [gold] → button.color = (255, 215, 0) Lib: tkinter or pygame_gui
- hide button ["Click me"] → button.visible = False Lib: tkinter or pygame_gui
- disable button ["Click me"] → button.enabled = False Lib: tkinter or pygame_gui
Labels & Text
- create label ["Score:"] at x:(0) y:(0) → label = UILabel("Score:", (0, 0)) Lib: tkinter or pygame_gui
- set label ["Score:"] text to ["Score: 10"] → label.text = "Score: 10" Lib: tkinter or pygame_gui
- set label color to [white] → label.color = (255, 255, 255) Lib: tkinter or pygame_gui
- show label ["Score:"] → label.visible = True Lib: tkinter or pygame_gui
- hide label ["Score:"] → label.visible = False Lib: tkinter or pygame_gui
Input Fields
- create input ["Enter name"] at x:(100) y:(200) → input_box = UITextInput("Enter name", (100, 200)) Lib: tkinter or pygame_gui
- get input ["Enter name"] value → name = input_box.text Lib: tkinter or pygame_gui
- clear input ["Enter name"] → input_box.text = "" Lib: tkinter or pygame_gui
- disable input ["Enter name"] → input_box.enabled = False Lib: tkinter or pygame_gui
Sliders
- create slider [volume] from (0) to (100) default (50) at x:(150) y:(300) → slider = UISlider(0, 100, 50, (150, 300)) Lib: tkinter or pygame_gui
- get slider [volume] value → value = slider.value Lib: tkinter or pygame_gui
- set slider [volume] to (75) → slider.value = 75 Lib: tkinter or pygame_gui
- when slider [volume] changed → slider.on_change = lambda val: print(val) Lib: tkinter or pygame_gui
Checkboxes & Toggles
- create checkbox ["Enable Sound"] default (true) at x:(200) y:(350) → checkbox = UICheckbox("Enable Sound", True, (200, 350)) Lib: tkinter or pygame_gui
- get checkbox ["Enable Sound"] state → state = checkbox.checked Lib: tkinter or pygame_gui
- set checkbox ["Enable Sound"] to (false) → checkbox.checked = False Lib: tkinter or pygame_gui
Messages / Alerts
- show alert ["You Win!"] → show_message("You Win!") Lib: tkinter or pygame_gui
- show confirm ["Are you sure?"] → confirmed = confirm_dialog("Are you sure?") Lib: tkinter or pygame_gui
- show prompt ["Enter your name"] → name = prompt_dialog("Enter your name") Lib: tkinter or pygame_gui
Menus
- create dropdown ["Difficulty"] options ["Easy", "Medium", "Hard"] at x:(200) y:(400) → menu = UIDropdown(["Easy", "Medium", "Hard"], (200, 400)) Lib: tkinter or pygame_gui
- get dropdown ["Difficulty"] selected option → difficulty = menu.selected Lib: tkinter or pygame_gui
- set dropdown ["Difficulty"] to ["Medium"] → menu.selected = "Medium" Lib: tkinter or pygame_gui
Progress Bars
- create progress bar [loading] max (100) at x:(100) y:(450) → progress = UIProgressBar(0, 100, (100, 450)) Lib: tkinter or pygame_gui
- set progress bar [loading] to (50) → progress.value = 50 Lib: tkinter or pygame_gui
- increase progress bar [loading] by (10) → progress.value += 10 Lib: tkinter or pygame_gui
Dialog Windows
- open window ["Settings"] size (400x300) → settings_window = UIWindow("Settings", (400, 300)) Lib: tkinter or pygame_gui
- close window ["Settings"] → settings_window.close() Lib: tkinter or pygame_gui
- show window ["Settings"] → settings_window.show() Lib: tkinter or pygame_gui
Mouse Interaction
- mouse over [sprite1]? → sprite1.collides_with(mouse) Lib: pygame
- mouse clicked on [sprite1]? → mouse.is_pressed() and sprite1.collides_with(mouse) Lib: pygame
UI Animations
- fade in [sprite1] over (1) sec → sprite1.fade_in(1) Lib: pygame or pygame_gui
- fade out [sprite1] over (1) sec → sprite1.fade_out(1) Lib: pygame or pygame_gui
- move [sprite1] to x:(100) y:(100) over (1) sec → sprite1.move_to((100,100), duration=1) Lib: pygame
- rotate [sprite1] by (90) over (1) sec → sprite1.rotate_by(90, duration=1) Lib: pygame
Perfect! Here’s the Stage Camera / 3D Effects, Particles, and Advanced Visual Effects section rewritten with explicit library references for every block.
Stage Camera & 3D UI / Visual Effects — Scratch → Python Equivalents (with Libraries)
Camera Position & Movement
- set camera x to (0) y to (0) → camera.x, camera.y = 0, 0 Lib: pygame or arcade
- move camera by x:(10) y:(5) → camera.x += 10; camera.y += 5 Lib: pygame or arcade
- center camera on [sprite1] → camera.center_on(sprite1) Lib: pygame or arcade
- pan camera to x:(100) y:(200) over (1) sec → camera.pan_to((100, 200), duration=1) Lib: pygame or arcade
- zoom camera to (1.5) → camera.zoom = 1.5 Lib: pygame or arcade
- zoom camera by (0.2) → camera.zoom += 0.2 Lib: pygame or arcade
- rotate camera by (30) degrees → camera.rotation += 30 Lib: pygame or arcade
Parallax Background
- set parallax layer [1] speed (0.5) → background_layers[1].parallax_speed = 0.5 Lib: pygame
- move parallax layer [2] x by (10) y by (0) → background_layers[2].x += 10 * background_layers[2].parallax_speed Lib: pygame
Filters / Effects
- apply color filter [red] to stage → stage.add_filter(ColorFilter("red")) Lib: pygame or arcade
- apply blur filter (5 px) to stage → stage.add_filter(BlurFilter(5)) Lib: pygame or arcade
- clear all stage filters → stage.clear_filters() Lib: pygame or arcade
- apply sprite [sprite1] brightness (20) → sprite1.add_filter(BrightnessFilter(20)) Lib: pygame or arcade
- apply sprite [sprite1] contrast (-10) → sprite1.add_filter(ContrastFilter(-10)) Lib: pygame or arcade
- apply sprite [sprite1] custom shader [shader_name] → sprite1.add_shader(load_shader("shader_name")) Lib: pygame or moderngl
Screen Shake / Camera Effects
- shake camera intensity (5) duration (0.5 sec) → camera.shake(intensity=5, duration=0.5) Lib: pygame or arcade
- screen flash color [white] duration (0.3 sec) → stage.flash(color=(255,255,255), duration=0.3) Lib: pygame or arcade
- fade screen to color [black] over (1 sec) → stage.fade_to_color((0,0,0), duration=1) Lib: pygame or arcade
3D Transformations (Optional / TurboWarp Advanced)
- rotate stage around x:(30) y:(0) z:(0) → stage.rotate_3d(x=30, y=0, z=0) Lib: moderngl or pyglet
- zoom stage in 3D by (1.2) → stage.zoom_3d(1.2) Lib: moderngl or pyglet
- tilt stage by (15) degrees → stage.tilt(15) Lib: moderngl or pyglet
- apply 3D perspective effect → stage.set_perspective(fov=60, near=0.1, far=1000) Lib: moderngl or pyglet
Sprite Depth & Layering
- set sprite [sprite1] z-index to (5) → sprite1.z = 5 Lib: pygame or arcade
- bring sprite [sprite1] to front → sprite1.z = max_z_index + 1 Lib: pygame or arcade
- send sprite [sprite1] to back → sprite1.z = 0 Lib: pygame or arcade
Motion Trails & Afterimages
- enable motion trail for sprite [sprite1] length (10) → sprite1.enable_trail(length=10) Lib: pygame or arcade
- disable motion trail for sprite [sprite1] → sprite1.disable_trail() Lib: pygame or arcade
- clear all trails → stage.clear_trails() Lib: pygame or arcade
Lighting & Shadows
- set light direction to x:(0) y:(0) z:(-1) → stage.light_direction = (0,0,-1) Lib: pygame or moderngl
- set shadow intensity to (0.5) → stage.shadow_intensity = 0.5 Lib: pygame or moderngl
- enable dynamic shadows → stage.dynamic_shadows = True Lib: pygame or moderngl
Particle Systems & Advanced Visual Effects — Scratch → Python Equivalents (with Libraries)
Creating Particles
- create particle at x:(0) y:(0) → particle = Particle(position=(0,0)) Lib: pygame or arcade
- create particle at sprite [sprite1] → particle = Particle(position=sprite1.position) Lib: pygame or arcade
- set particle color to [red] → particle.color = (255,0,0) Lib: pygame or arcade
- set particle size to (5) → particle.size = 5 Lib: pygame or arcade
- set particle lifetime to (2) seconds → particle.lifetime = 2 Lib: pygame or arcade
Emission
- emit particle every (0.1) sec → particle_emitter.emit_interval = 0.1 Lib: pygame or arcade
- emit (10) particles at once → particle_emitter.emit(count=10) Lib: pygame or arcade
- set emission direction to (90) degrees → particle_emitter.direction = 90 Lib: pygame or arcade
- set emission speed to (5) → particle_emitter.speed = 5 Lib: pygame or arcade
- set emission spread to (30) degrees → particle_emitter.spread = 30 Lib: pygame or arcade
Particle Behavior
- apply gravity to particles (0, -9.8) → particle.gravity = (0, -9.8) Lib: pygame or arcade
- apply wind to particles x:(1) y:(0) → particle.force = (1,0) Lib: pygame or arcade
- fade particles over (2) sec → particle.fade(duration=2) Lib: pygame or arcade
- shrink particles over (2) sec → particle.shrink(duration=2) Lib: pygame or arcade
- rotate particles by (30) deg/sec → particle.rotation_speed = 30 Lib: pygame or arcade
Particle Colors & Effects
- randomize particle color → particle.color = random_color() Lib: random + pygame or arcade
- cycle particle colors [red, green, blue] → particle.cycle_colors(["red","green","blue"]) Lib: pygame or arcade
- apply glow effect to particles → particle.add_effect(GlowEffect()) Lib: pygame or arcade
- add trail to particle → particle.enable_trail(length=5) Lib: pygame or arcade
Particle Systems (Emitters)
- create emitter at x:(0) y:(0) → emitter = ParticleEmitter(position=(0,0)) Lib: pygame or arcade
- set emitter shape to [circle, square, line] → emitter.shape = "circle" Lib: pygame or arcade
- start emitter → emitter.start() Lib: pygame or arcade
- stop emitter → emitter.stop() Lib: pygame or arcade
- clear all particles → emitter.clear() Lib: pygame or arcade
Sparkle / Glitter Effects
- create sparkle at x:(100) y:(200) count (20) → for _ in range(20): Particle(position=(100,200), color=random_color(), size=random.randint(2,5)) Lib: pygame + random
- sparkle follow sprite [sprite1] → emitter.position = sprite1.position; emitter.start() Lib: pygame
Smoke / Fire Effects
- create smoke at x:(0) y:(0) color [gray] → particle = Particle(position=(0,0), color=(128,128,128)); particle.behavior = "smoke" Lib: pygame
- create fire at x:(0) y:(0) → particle = Particle(position=(0,0), color=(255,100,0)); particle.behavior = "fire" Lib: pygame
Snow / Rain / Weather
- create snow particle at top of screen → particle = Particle(position=(random_x(),0), color=(255,255,255)) Lib: pygame + random
- create rain particle at top of screen → particle = Particle(position=(random_x(),0), color=(100,100,255)) Lib: pygame + random
- apply wind (x=1) → particle.force = (1,0) Lib: pygame
Collision / Interactions
- particles collide with sprite [sprite1]? → particle.collides_with(sprite1) Lib: pygame
- bounce particles off edges → particle.bounce_if_edge() Lib: pygame
- particles destroy on collision with [sprite2] → if particle.collides_with(sprite2): particle.destroy() Lib: pygame
Performance / Advanced Options
- limit particle count to (500) → particle_system.max_particles = 500 Lib: pygame or arcade
- update particles every frame → particle_system.update(dt) Lib: pygame or arcade
- render particles on layer [foreground] → particle_system.render(layer="foreground") Lib: pygame or arcade
Perfect! Here’s the Audio & Sound Extensions section rewritten with explicit library references for every block, fully integrated into your Scratch → Python dictionary.
Audio & Sound Extensions — Scratch → Python Equivalents (with Libraries)
Playing Sounds
- play sound [meow] → playsound("meow.wav") Lib: playsound or pygame.mixer
- play sound [meow] until done → playsound("meow.wav", block=True) Lib: playsound or pygame.mixer
- stop all sounds → pygame.mixer.stop() Lib: pygame.mixer
- set volume to (50)% → pygame.mixer.music.set_volume(0.5) Lib: pygame.mixer
- change pitch by (10) → sound.set_pitch(10) Lib: pydub or aubio or pygame.sndarray
Synthesizers
- play note (60) for (1) beat → synth.play(note=60, duration=1) Lib: pyo or pygame.midi
- stop all notes → synth.stop_all() Lib: pyo
- change instrument to [piano] → synth.set_instrument("piano") Lib: pyo
Audio Effects
- apply reverb to sound → sound = apply_reverb(sound) Lib: pydub or scipy
- apply echo to sound → sound = apply_echo(sound, delay=0.3, decay=0.5) Lib: pydub
- apply filter [lowpass] cutoff (1000 Hz) → sound = lowpass_filter(sound, cutoff=1000) Lib: pydub
- apply filter [highpass] cutoff (500 Hz) → sound = highpass_filter(sound, cutoff=500) Lib: pydub
URL / Streaming Audio
- play sound from URL ["https://..."] → download_file("https://...", "temp.wav"); playsound("temp.wav") Lib: requests + playsound or pygame.mixer
- fetch audio from URL and analyze → audio_data = requests.get(url).content; process(audio_data) Lib: requests + pydub + numpy
Audio Analysis
- loudness → get_microphone_level() Lib: sounddevice or pyaudio
- FFT / frequency spectrum → spectrum = np.fft.fft(audio_signal) Lib: numpy + scipy
- beat detection → beats = detect_beats(audio_signal) Lib: librosa or pyo
Microphone Input
- start microphone → mic = Microphone(); mic.start() Lib: sounddevice or pyaudio
- stop microphone → mic.stop() Lib: sounddevice or pyaudio
- get microphone level → mic.get_level() Lib: sounddevice or pyaudio
Sound Utilities
- fade in sound (2 sec) → sound.fade_in(2) Lib: pydub
- fade out sound (2 sec) → sound.fade_out(2) Lib: pydub
- change playback speed by (1.5x) → sound = speed_change(sound, 1.5) Lib: pydub
- loop sound indefinitely → sound.loop = True; sound.play() Lib: pygame.mixer or pyo