├── example ├── ios │ ├── Runner │ │ ├── Runner-Bridging-Header.h │ │ ├── Assets.xcassets │ │ │ ├── LaunchImage.imageset │ │ │ │ ├── LaunchImage.png │ │ │ │ ├── LaunchImage@2x.png │ │ │ │ ├── LaunchImage@3x.png │ │ │ │ ├── README.md │ │ │ │ └── Contents.json │ │ │ └── AppIcon.appiconset │ │ │ │ ├── Icon-App-20x20@1x.png │ │ │ │ ├── Icon-App-20x20@2x.png │ │ │ │ ├── Icon-App-20x20@3x.png │ │ │ │ ├── Icon-App-29x29@1x.png │ │ │ │ ├── Icon-App-29x29@2x.png │ │ │ │ ├── Icon-App-29x29@3x.png │ │ │ │ ├── Icon-App-40x40@1x.png │ │ │ │ ├── Icon-App-40x40@2x.png │ │ │ │ ├── Icon-App-40x40@3x.png │ │ │ │ ├── Icon-App-60x60@2x.png │ │ │ │ ├── Icon-App-60x60@3x.png │ │ │ │ ├── Icon-App-76x76@1x.png │ │ │ │ ├── Icon-App-76x76@2x.png │ │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ │ ├── Icon-App-83.5x83.5@2x.png │ │ │ │ └── Contents.json │ │ ├── AppDelegate.swift │ │ ├── Base.lproj │ │ │ ├── Main.storyboard │ │ │ └── LaunchScreen.storyboard │ │ └── Info.plist │ ├── Flutter │ │ ├── Debug.xcconfig │ │ ├── Release.xcconfig │ │ └── AppFrameworkInfo.plist │ ├── Runner.xcodeproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ │ ├── WorkspaceSettings.xcsettings │ │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── WorkspaceSettings.xcsettings │ │ │ └── IDEWorkspaceChecks.plist │ ├── Podfile.lock │ ├── .gitignore │ └── Podfile ├── assets │ ├── mask.jpg │ ├── coffee.png │ ├── gradient.png │ ├── logo_128.png │ ├── audio-mixer.png │ └── coding-train │ │ ├── flutter-text.png │ │ └── 031_flappy_bird │ │ ├── dash.png │ │ ├── pipe_top.png │ │ ├── pipe_bottom.png │ │ └── flappy-bird_bk.png ├── README.md ├── android │ ├── gradle.properties │ ├── app │ │ ├── src │ │ │ ├── main │ │ │ │ ├── res │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── drawable │ │ │ │ │ │ └── launch_background.xml │ │ │ │ │ ├── drawable-v21 │ │ │ │ │ │ └── launch_background.xml │ │ │ │ │ ├── values │ │ │ │ │ │ └── styles.xml │ │ │ │ │ └── values-night │ │ │ │ │ │ └── styles.xml │ │ │ │ ├── kotlin │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── example │ │ │ │ │ │ └── MainActivity.kt │ │ │ │ └── AndroidManifest.xml │ │ │ ├── debug │ │ │ │ └── AndroidManifest.xml │ │ │ └── profile │ │ │ │ └── AndroidManifest.xml │ │ └── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ ├── .gitignore │ ├── settings.gradle │ └── build.gradle ├── macos │ ├── Runner │ │ ├── Configs │ │ │ ├── Debug.xcconfig │ │ │ ├── Release.xcconfig │ │ │ ├── Warnings.xcconfig │ │ │ └── AppInfo.xcconfig │ │ ├── Assets.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ ├── app_icon_16.png │ │ │ │ ├── app_icon_32.png │ │ │ │ ├── app_icon_64.png │ │ │ │ ├── app_icon_1024.png │ │ │ │ ├── app_icon_128.png │ │ │ │ ├── app_icon_256.png │ │ │ │ ├── app_icon_512.png │ │ │ │ └── Contents.json │ │ ├── AppDelegate.swift │ │ ├── Release.entitlements │ │ ├── DebugProfile.entitlements │ │ ├── MainFlutterWindow.swift │ │ └── Info.plist │ ├── .gitignore │ ├── Flutter │ │ ├── Flutter-Debug.xcconfig │ │ ├── Flutter-Release.xcconfig │ │ └── GeneratedPluginRegistrant.swift │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── Runner.xcodeproj │ │ ├── project.xcworkspace │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Podfile.lock │ └── Podfile ├── analysis_options.yaml ├── .metadata ├── lib │ ├── io │ │ └── _files.dart │ ├── the_coding_train │ │ └── coding_challenges │ │ │ ├── 030_phyllotaxis.dart │ │ │ ├── 103_fire_effect.dart │ │ │ ├── 052_random_walker.dart │ │ │ ├── 004_purple-rain.dart │ │ │ ├── 036_blobby.dart │ │ │ ├── 028_metaballs.dart │ │ │ ├── 006_mitosis_simulation.dart │ │ │ ├── 001_starfield.dart │ │ │ ├── 050_circle-packing.dart │ │ │ └── 085_game_of_life.dart │ ├── demos │ │ ├── _empty_sketch.dart │ │ ├── perlin_noise_demo.dart │ │ ├── _hacking.dart │ │ ├── _filters_sketch.dart │ │ └── _hacking_demo.dart │ ├── verify_behaviors │ │ └── _mouse_and_touch.dart │ ├── generative_art │ │ ├── liquid_gels.dart │ │ ├── colored_circles.dart │ │ ├── dot_field.dart │ │ ├── wobbly_swarm.dart │ │ ├── solar_storm.dart │ │ └── network.dart │ └── api_demos │ │ ├── _image_mask_sketch.dart │ │ ├── _image_resize_sketch.dart │ │ └── _image_blending_sketch.dart ├── pubspec.yaml └── .gitignore ├── lib ├── src │ ├── input │ │ ├── mouse_buttons.dart │ │ ├── _keyboard.dart │ │ ├── _time_and_date.dart │ │ └── _mouse.dart │ ├── rendering │ │ └── _rendering.dart │ ├── constants │ │ └── _constants.dart │ ├── shape │ │ ├── _attributes.dart │ │ └── shapes.dart │ ├── structure │ │ └── _structure.dart │ ├── transform │ │ └── _transform.dart │ ├── output │ │ └── image_file_formats.dart │ ├── math │ │ ├── _trigonometry.dart │ │ ├── _calculations.dart │ │ ├── _random.dart │ │ └── _pvector.dart │ ├── color │ │ ├── _setting.dart │ │ └── _color.dart │ ├── environment │ │ └── _environment.dart │ ├── image │ │ └── _loading_and_displaying.dart │ ├── _core.dart │ └── data │ │ └── conversion.dart └── flutter_processing.dart ├── test ├── assets │ ├── space_100x.png │ └── audio-mixer_100x.png ├── constants │ ├── goldens │ │ └── constants.png │ └── constants_test.dart ├── goldens │ ├── complex-shapes_stars.png │ └── complex-shapes_triangle-strip-circle.png ├── math │ ├── goldens │ │ ├── math_trigonometry_cos.png │ │ ├── math_trigonometry_sin.png │ │ └── math_trigonometry_tan.png │ └── trigonometry_test.dart ├── random │ ├── goldens │ │ ├── random_gaussian_example-1.png │ │ └── random_gaussian_example-2.png │ └── random_test.dart ├── shape │ ├── goldens │ │ ├── shape_vertex_begin-shape_1.png │ │ ├── shape_vertex_begin-shape_2.png │ │ ├── shape_vertex_begin-shape_3.png │ │ ├── shape_vertex_begin-shape_4.png │ │ ├── shape_vertex_begin-shape_5.png │ │ ├── shape_vertex_begin-shape_6.png │ │ ├── shape_vertex_begin-shape_7.png │ │ ├── shape_vertex_begin-shape_8.png │ │ ├── shape_vertex_begin-shape_9.png │ │ ├── shape_vertex_end-shape_1.png │ │ ├── shape_vertex_begin-shape_10.png │ │ ├── shape_vertex_begin-shape_11.png │ │ ├── shape_vertex_bezier-vertex_1.png │ │ ├── shape_vertex_bezier-vertex_2.png │ │ ├── shape_vertex_quadratic-vertex_1.png │ │ ├── shape_vertex_quadratic-vertex_2.png │ │ ├── shape_2d-primitives_arc-example-1.png │ │ ├── shape_2d-primitives_arc-example-2.png │ │ ├── shape_2d-primitives_arc-example-3.png │ │ ├── shape_2d-primitives_arc-example-4.png │ │ ├── shape_2d-primitives_circle-example-1.png │ │ ├── shape_2d-primitives_line-example-1.png │ │ ├── shape_2d-primitives_line-example-2.png │ │ ├── shape_2d-primitives_point-example-1.png │ │ ├── shape_2d-primitives_quad-example-1.png │ │ ├── shape_2d-primitives_rect-example-1.png │ │ ├── shape_2d-primitives_rect-example-2.png │ │ ├── shape_2d-primitives_rect-example-3.png │ │ ├── shape_2d-primitives_square-example-1.png │ │ ├── shape_2d-primitives_ellipse-example-1.png │ │ ├── shape_2d-primitives_ellipse-example-2.png │ │ ├── shape_2d-primitives_ellipse-example-3.png │ │ ├── shape_2d-primitives_triangle-example-1.png │ │ └── shape_attributes_stroke-weight-example-1.png │ └── attributes_test.dart ├── transform │ ├── goldens │ │ ├── transform_pushMatrix_1.png │ │ ├── transform_translate-example-1.png │ │ └── transform_translate-example-2.png │ └── transform_test.dart ├── color │ └── goldens │ │ ├── color_setting_fill-example-1.png │ │ ├── color_setting_fill-example-2.png │ │ ├── color_creating-and-reading_blue.png │ │ ├── color_creating-and-reading_hue.png │ │ ├── color_creating-and-reading_red.png │ │ ├── color_setting_clear-then-draw.png │ │ ├── color_setting_nofill-example-1.png │ │ ├── color_setting_stroke-example-1.png │ │ ├── color_setting_stroke-example-2.png │ │ ├── color_creating-and-reading_alpha.png │ │ ├── color_creating-and-reading_green.png │ │ ├── color_setting_background-in-setup.png │ │ ├── color_setting_nostroke-example-1.png │ │ ├── color_creating-and-reading_lerpColor.png │ │ ├── color_setting_background-example-1.png │ │ ├── color_setting_background-example-2.png │ │ ├── color_creating-and-reading_brightness.png │ │ ├── color_creating-and-reading_saturation.png │ │ ├── color_setting_background-setup-and-draw.png │ │ ├── color_setting_clear-set-background-then-clear.png │ │ └── color_setting_clear-then-background-and-draw.png ├── environment │ ├── goldens │ │ ├── environment_size-example-1.png │ │ ├── environment_width-example-1.png │ │ └── environment_height-example-1.png │ └── environment_test.dart ├── core │ ├── goldens │ │ └── core_setup-paints-default-background.png │ └── core_test.dart ├── image │ ├── goldens │ │ └── image_loading-and-display_example-1.png │ └── loading_and_displaying_test.dart ├── decode_image_test.dart ├── test_infra.dart ├── complex_shapes_test.dart ├── input │ └── keyboard_test.dart └── processing_widget_test.dart ├── CHANGELOG.md ├── .run └── example.run.xml ├── .metadata ├── .github └── workflows │ └── pr_validation.yaml ├── pubspec.yaml ├── LICENSE ├── .gitignore └── README.md /example/ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /lib/src/input/mouse_buttons.dart: -------------------------------------------------------------------------------- 1 | enum MouseButton { 2 | left, 3 | center, 4 | right, 5 | } 6 | -------------------------------------------------------------------------------- /example/assets/mask.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/assets/mask.jpg -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Flutter Processing Example 2 | 3 | Demo app and test-bed for the `flutter_processing` package. 4 | -------------------------------------------------------------------------------- /example/assets/coffee.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/assets/coffee.png -------------------------------------------------------------------------------- /test/assets/space_100x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/assets/space_100x.png -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /example/assets/gradient.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/assets/gradient.png -------------------------------------------------------------------------------- /example/assets/logo_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/assets/logo_128.png -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /example/assets/audio-mixer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/assets/audio-mixer.png -------------------------------------------------------------------------------- /example/macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/xcuserdata/ 7 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /test/assets/audio-mixer_100x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/assets/audio-mixer_100x.png -------------------------------------------------------------------------------- /test/constants/goldens/constants.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/constants/goldens/constants.png -------------------------------------------------------------------------------- /test/goldens/complex-shapes_stars.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/goldens/complex-shapes_stars.png -------------------------------------------------------------------------------- /example/ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /example/assets/coding-train/flutter-text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/assets/coding-train/flutter-text.png -------------------------------------------------------------------------------- /test/math/goldens/math_trigonometry_cos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/math/goldens/math_trigonometry_cos.png -------------------------------------------------------------------------------- /test/math/goldens/math_trigonometry_sin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/math/goldens/math_trigonometry_sin.png -------------------------------------------------------------------------------- /test/math/goldens/math_trigonometry_tan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/math/goldens/math_trigonometry_tan.png -------------------------------------------------------------------------------- /test/random/goldens/random_gaussian_example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/random/goldens/random_gaussian_example-1.png -------------------------------------------------------------------------------- /test/random/goldens/random_gaussian_example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/random/goldens/random_gaussian_example-2.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_begin-shape_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_begin-shape_1.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_begin-shape_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_begin-shape_2.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_begin-shape_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_begin-shape_3.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_begin-shape_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_begin-shape_4.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_begin-shape_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_begin-shape_5.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_begin-shape_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_begin-shape_6.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_begin-shape_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_begin-shape_7.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_begin-shape_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_begin-shape_8.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_begin-shape_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_begin-shape_9.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_end-shape_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_end-shape_1.png -------------------------------------------------------------------------------- /test/transform/goldens/transform_pushMatrix_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/transform/goldens/transform_pushMatrix_1.png -------------------------------------------------------------------------------- /test/color/goldens/color_setting_fill-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_setting_fill-example-1.png -------------------------------------------------------------------------------- /test/color/goldens/color_setting_fill-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_setting_fill-example-2.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_begin-shape_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_begin-shape_10.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_begin-shape_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_begin-shape_11.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_bezier-vertex_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_bezier-vertex_1.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_bezier-vertex_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_bezier-vertex_2.png -------------------------------------------------------------------------------- /example/assets/coding-train/031_flappy_bird/dash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/assets/coding-train/031_flappy_bird/dash.png -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "ephemeral/Flutter-Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /test/color/goldens/color_creating-and-reading_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_creating-and-reading_blue.png -------------------------------------------------------------------------------- /test/color/goldens/color_creating-and-reading_hue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_creating-and-reading_hue.png -------------------------------------------------------------------------------- /test/color/goldens/color_creating-and-reading_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_creating-and-reading_red.png -------------------------------------------------------------------------------- /test/color/goldens/color_setting_clear-then-draw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_setting_clear-then-draw.png -------------------------------------------------------------------------------- /test/color/goldens/color_setting_nofill-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_setting_nofill-example-1.png -------------------------------------------------------------------------------- /test/color/goldens/color_setting_stroke-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_setting_stroke-example-1.png -------------------------------------------------------------------------------- /test/color/goldens/color_setting_stroke-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_setting_stroke-example-2.png -------------------------------------------------------------------------------- /test/goldens/complex-shapes_triangle-strip-circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/goldens/complex-shapes_triangle-strip-circle.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_quadratic-vertex_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_quadratic-vertex_1.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_vertex_quadratic-vertex_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_vertex_quadratic-vertex_2.png -------------------------------------------------------------------------------- /example/assets/coding-train/031_flappy_bird/pipe_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/assets/coding-train/031_flappy_bird/pipe_top.png -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "ephemeral/Flutter-Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /test/color/goldens/color_creating-and-reading_alpha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_creating-and-reading_alpha.png -------------------------------------------------------------------------------- /test/color/goldens/color_creating-and-reading_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_creating-and-reading_green.png -------------------------------------------------------------------------------- /test/color/goldens/color_setting_background-in-setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_setting_background-in-setup.png -------------------------------------------------------------------------------- /test/color/goldens/color_setting_nostroke-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_setting_nostroke-example-1.png -------------------------------------------------------------------------------- /test/environment/goldens/environment_size-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/environment/goldens/environment_size-example-1.png -------------------------------------------------------------------------------- /test/environment/goldens/environment_width-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/environment/goldens/environment_width-example-1.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_arc-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_arc-example-1.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_arc-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_arc-example-2.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_arc-example-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_arc-example-3.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_arc-example-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_arc-example-4.png -------------------------------------------------------------------------------- /test/transform/goldens/transform_translate-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/transform/goldens/transform_translate-example-1.png -------------------------------------------------------------------------------- /test/transform/goldens/transform_translate-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/transform/goldens/transform_translate-example-2.png -------------------------------------------------------------------------------- /example/assets/coding-train/031_flappy_bird/pipe_bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/assets/coding-train/031_flappy_bird/pipe_bottom.png -------------------------------------------------------------------------------- /test/color/goldens/color_creating-and-reading_lerpColor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_creating-and-reading_lerpColor.png -------------------------------------------------------------------------------- /test/color/goldens/color_setting_background-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_setting_background-example-1.png -------------------------------------------------------------------------------- /test/color/goldens/color_setting_background-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_setting_background-example-2.png -------------------------------------------------------------------------------- /test/core/goldens/core_setup-paints-default-background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/core/goldens/core_setup-paints-default-background.png -------------------------------------------------------------------------------- /test/environment/goldens/environment_height-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/environment/goldens/environment_height-example-1.png -------------------------------------------------------------------------------- /test/image/goldens/image_loading-and-display_example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/image/goldens/image_loading-and-display_example-1.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_circle-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_circle-example-1.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_line-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_line-example-1.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_line-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_line-example-2.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_point-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_point-example-1.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_quad-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_quad-example-1.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_rect-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_rect-example-1.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_rect-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_rect-example-2.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_rect-example-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_rect-example-3.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_square-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_square-example-1.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /test/color/goldens/color_creating-and-reading_brightness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_creating-and-reading_brightness.png -------------------------------------------------------------------------------- /test/color/goldens/color_creating-and-reading_saturation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_creating-and-reading_saturation.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_ellipse-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_ellipse-example-1.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_ellipse-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_ellipse-example-2.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_ellipse-example-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_ellipse-example-3.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_2d-primitives_triangle-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_2d-primitives_triangle-example-1.png -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [0.1.0] - Empty project (Jan 7, 2021) 2 | 3 | ## [0.1.1] - Implemented all 2d primitive shapes (Mar 2, 2021) 4 | 5 | ## [0.2.0] - Lots of new APIs + per-pixel support (Mar 27, 2022) -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/assets/coding-train/031_flappy_bird/flappy-bird_bk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/assets/coding-train/031_flappy_bird/flappy-bird_bk.png -------------------------------------------------------------------------------- /test/color/goldens/color_setting_background-setup-and-draw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_setting_background-setup-and-draw.png -------------------------------------------------------------------------------- /test/shape/goldens/shape_attributes_stroke-weight-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/shape/goldens/shape_attributes_stroke-weight-example-1.png -------------------------------------------------------------------------------- /test/color/goldens/color_setting_clear-set-background-then-clear.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_setting_clear-set-background-then-clear.png -------------------------------------------------------------------------------- /test/color/goldens/color_setting_clear-then-background-and-draw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/test/color/goldens/color_setting_clear-then-background-and-draw.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /example/android/app/src/main/kotlin/com/example/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.example 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthew-carroll/flutter_processing/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /lib/src/rendering/_rendering.dart: -------------------------------------------------------------------------------- 1 | part of '../_core.dart'; 2 | 3 | mixin SketchRendering on BaseSketch { 4 | set blendMode(BlendMode blendMode) { 5 | _paintingContext.fillPaint.blendMode = blendMode; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:flutter_lints/flutter.yaml 2 | 3 | # Additional information about this file can be found at 4 | # https://dart.dev/guides/language/analysis-options 5 | 6 | linter: 7 | rules: 8 | library_private_types_in_public_api: false -------------------------------------------------------------------------------- /example/macos/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | @NSApplicationMain 5 | class AppDelegate: FlutterAppDelegate { 6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 7 | return true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 23 08:50:38 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip 7 | -------------------------------------------------------------------------------- /example/macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.run/example.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /lib/flutter_processing.dart: -------------------------------------------------------------------------------- 1 | library flutter_processing; 2 | 3 | export 'src/_core.dart'; 4 | export 'src/color/_color.dart'; 5 | export 'src/image/_pimage.dart'; 6 | export 'src/input/mouse_buttons.dart'; 7 | export 'src/math/_pvector.dart'; 8 | export 'src/output/image_file_formats.dart'; 9 | export 'src/shape/shapes.dart'; 10 | -------------------------------------------------------------------------------- /lib/src/constants/_constants.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | // ignore_for_file: non_constant_identifier_names 4 | mixin SketchConstants { 5 | final TWO_PI = pi * 2; 6 | final PI = pi; 7 | final HALF_PI = pi / 2; 8 | final QUARTER_PI = pi / 4; 9 | final TAU = pi * 2; // see https://tauday.com/tau-manifesto 10 | } 11 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /lib/src/shape/_attributes.dart: -------------------------------------------------------------------------------- 1 | part of '../_core.dart'; 2 | 3 | mixin SketchShapeAttributes on BaseSketch { 4 | void strokeWeight(double newWeight) { 5 | if (newWeight < 0) { 6 | throw Exception('Stroke weight must be >= 0'); 7 | } 8 | 9 | _paintingContext.strokePaint.strokeWidth = newWeight.toDouble(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: a12e2a473a3214b4556ca589d2d9bd311ac7c6f1 8 | channel: dev 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 63062a64432cce03315d6b5196fda7912866eb37 8 | channel: dev 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /example/android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | 9 | # Remember to never publicly share your keystore. 10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app 11 | key.properties 12 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /example/macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | import file_selector_macos 9 | 10 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 11 | FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) 12 | } 13 | -------------------------------------------------------------------------------- /lib/src/input/_keyboard.dart: -------------------------------------------------------------------------------- 1 | part of '../_core.dart'; 2 | 3 | mixin SketchInputKeyboard { 4 | Set _pressedKeys = {}; 5 | 6 | bool get isKeyPressed => _pressedKeys.isNotEmpty; 7 | 8 | LogicalKeyboardKey? _key; 9 | LogicalKeyboardKey? get key => _key; 10 | 11 | void keyPressed() {} 12 | 13 | void keyTyped() {} 14 | 15 | void keyReleased() {} 16 | } 17 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md: -------------------------------------------------------------------------------- 1 | # Launch Screen Assets 2 | 3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory. 4 | 5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. -------------------------------------------------------------------------------- /lib/src/structure/_structure.dart: -------------------------------------------------------------------------------- 1 | part of '../_core.dart'; 2 | 3 | mixin SketchStructure { 4 | bool _isLooping = true; 5 | bool get isLooping => _isLooping; 6 | 7 | VoidCallback? _loop; 8 | VoidCallback? _noLoop; 9 | 10 | void loop() { 11 | _isLooping = true; 12 | _loop?.call(); 13 | } 14 | 15 | void noLoop() { 16 | _isLooping = false; 17 | _noLoop?.call(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /example/ios/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Flutter 3 | 4 | @UIApplicationMain 5 | @objc class AppDelegate: FlutterAppDelegate { 6 | override func application( 7 | _ application: UIApplication, 8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 9 | ) -> Bool { 10 | GeneratedPluginRegistrant.register(with: self) 11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.github/workflows/pr_validation.yaml: -------------------------------------------------------------------------------- 1 | name: Test project in a PR 2 | on: [pull_request] 3 | jobs: 4 | test_mac: 5 | runs-on: macos-latest 6 | steps: 7 | # Checkout the PR branch 8 | - uses: actions/checkout@v2 9 | # Setup Flutter environment 10 | - uses: subosito/flutter-action@v2 11 | with: 12 | channel: stable 13 | # Download all the packages that the app uses 14 | - run: flutter pub get 15 | # Run all tests 16 | - run: flutter test 17 | -------------------------------------------------------------------------------- /lib/src/input/_time_and_date.dart: -------------------------------------------------------------------------------- 1 | mixin SketchInputTimeAndDate { 2 | final _appStartTime = DateTime.now(); 3 | 4 | int millis() => DateTime.now().millisecondsSinceEpoch - _appStartTime.millisecondsSinceEpoch; 5 | 6 | int second() => DateTime.now().second; 7 | 8 | int minute() => DateTime.now().minute; 9 | 10 | int hour() => DateTime.now().hour; 11 | 12 | int day() => DateTime.now().day; 13 | 14 | int month() => DateTime.now().month; 15 | 16 | int year() => DateTime.now().year; 17 | } 18 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties") 4 | def properties = new Properties() 5 | 6 | assert localPropertiesFile.exists() 7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } 8 | 9 | def flutterSdkPath = properties.getProperty("flutter.sdk") 10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" 12 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_processing 2 | description: A Flutter version of Processing. 3 | version: 0.2.0 4 | homepage: https://github.com/matthew-carroll/flutter_processing 5 | 6 | environment: 7 | sdk: ">=2.12.0 <3.0.0" 8 | flutter: ">=1.17.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | 14 | fast_noise: ^2.0.0 15 | image: ^4.1.7 16 | path: ^1.8.0 17 | 18 | dev_dependencies: 19 | flutter_test: 20 | sdk: flutter 21 | flutter_lints: ^2.0.0 22 | 23 | golden_toolkit: ^0.15.0 24 | 25 | flutter: 26 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchImage@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "LaunchImage@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/macos/Runner/DebugProfile.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | com.apple.security.network.server 10 | 11 | com.apple.security.assets.pictures.read-write 12 | 13 | com.apple.security.files.user-selected.read-write 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /example/ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - Flutter (1.0.0) 3 | - integration_test (0.0.1): 4 | - Flutter 5 | 6 | DEPENDENCIES: 7 | - Flutter (from `Flutter`) 8 | - integration_test (from `.symlinks/plugins/integration_test/ios`) 9 | 10 | EXTERNAL SOURCES: 11 | Flutter: 12 | :path: Flutter 13 | integration_test: 14 | :path: ".symlinks/plugins/integration_test/ios" 15 | 16 | SPEC CHECKSUMS: 17 | Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a 18 | integration_test: a1e7d09bd98eca2fc37aefd79d4f41ad37bdbbe5 19 | 20 | PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c 21 | 22 | COCOAPODS: 1.11.2 23 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Warnings.xcconfig: -------------------------------------------------------------------------------- 1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings 2 | GCC_WARN_UNDECLARED_SELECTOR = YES 3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES 4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE 5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 6 | CLANG_WARN_PRAGMA_PACK = YES 7 | CLANG_WARN_STRICT_PROTOTYPES = YES 8 | CLANG_WARN_COMMA = YES 9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES 10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES 11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES 12 | GCC_WARN_SHADOW = YES 13 | CLANG_WARN_UNREACHABLE_CODE = YES 14 | -------------------------------------------------------------------------------- /test/core/core_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_processing/flutter_processing.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:golden_toolkit/golden_toolkit.dart'; 4 | 5 | import '../test_infra.dart'; 6 | 7 | void main() { 8 | group('core', () { 9 | processingLegacySpecTest('setup() paints light grey background by default', (tester) async { 10 | await tester.pumpWidget( 11 | Processing( 12 | sketch: Sketch.simple(setup: (s) { 13 | s.noLoop(); 14 | }), 15 | ), 16 | ); 17 | 18 | await screenMatchesGolden(tester, 'core_setup-paints-default-background'); 19 | }); 20 | }); 21 | } 22 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/AppInfo.xcconfig: -------------------------------------------------------------------------------- 1 | // Application-level settings for the Runner target. 2 | // 3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the 4 | // future. If not, the values below would default to using the project name when this becomes a 5 | // 'flutter create' template. 6 | 7 | // The application's name. By default this is also the title of the Flutter window. 8 | PRODUCT_NAME = example 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2021 com.example. All rights reserved. 15 | -------------------------------------------------------------------------------- /example/macos/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - file_selector_macos (0.0.1): 3 | - FlutterMacOS 4 | - FlutterMacOS (1.0.0) 5 | 6 | DEPENDENCIES: 7 | - file_selector_macos (from `Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos`) 8 | - FlutterMacOS (from `Flutter/ephemeral`) 9 | 10 | EXTERNAL SOURCES: 11 | file_selector_macos: 12 | :path: Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos 13 | FlutterMacOS: 14 | :path: Flutter/ephemeral 15 | 16 | SPEC CHECKSUMS: 17 | file_selector_macos: ff6dc948d4ddd34e8602a1f60b7d0b4cc6051a47 18 | FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424 19 | 20 | PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c 21 | 22 | COCOAPODS: 1.10.1 23 | -------------------------------------------------------------------------------- /example/ios/.gitignore: -------------------------------------------------------------------------------- 1 | **/dgph 2 | *.mode1v3 3 | *.mode2v3 4 | *.moved-aside 5 | *.pbxuser 6 | *.perspectivev3 7 | **/*sync/ 8 | .sconsign.dblite 9 | .tags* 10 | **/.vagrant/ 11 | **/DerivedData/ 12 | Icon? 13 | **/Pods/ 14 | **/.symlinks/ 15 | profile 16 | xcuserdata 17 | **/.generated/ 18 | Flutter/App.framework 19 | Flutter/Flutter.framework 20 | Flutter/Flutter.podspec 21 | Flutter/Generated.xcconfig 22 | Flutter/ephemeral/ 23 | Flutter/app.flx 24 | Flutter/app.zip 25 | Flutter/flutter_assets/ 26 | Flutter/flutter_export_environment.sh 27 | ServiceDefinitions.json 28 | Runner/GeneratedPluginRegistrant.* 29 | 30 | # Exceptions to above rules. 31 | !default.mode1v3 32 | !default.mode2v3 33 | !default.pbxuser 34 | !default.perspectivev3 35 | -------------------------------------------------------------------------------- /example/lib/io/_files.dart: -------------------------------------------------------------------------------- 1 | class FileName { 2 | factory FileName.fromFilePath(String path) { 3 | final fileName = path.split('/').last; 4 | return FileName( 5 | name: fileName.split('.').first, 6 | extension: fileName.split('.').last, 7 | ); 8 | } 9 | 10 | const FileName({ 11 | required this.name, 12 | required this.extension, 13 | }); 14 | 15 | final String name; 16 | final String extension; 17 | 18 | @override 19 | bool operator ==(Object other) => 20 | identical(this, other) || 21 | other is FileName && runtimeType == other.runtimeType && name == other.name && extension == other.extension; 22 | 23 | @override 24 | int get hashCode => name.hashCode ^ extension.hashCode; 25 | } 26 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.3.50' 3 | repositories { 4 | google() 5 | mavenCentral() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:4.1.0' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | mavenCentral() 18 | } 19 | } 20 | 21 | rootProject.buildDir = '../build' 22 | subprojects { 23 | project.buildDir = "${rootProject.buildDir}/${project.name}" 24 | } 25 | subprojects { 26 | project.evaluationDependsOn(':app') 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /lib/src/transform/_transform.dart: -------------------------------------------------------------------------------- 1 | part of '../_core.dart'; 2 | 3 | mixin SketchTransform on BaseSketch { 4 | void pushMatrix() { 5 | _paintingContext.canvas.save(); 6 | } 7 | 8 | void popMatrix() { 9 | _paintingContext.canvas.restore(); 10 | } 11 | 12 | void translate({ 13 | num? x, 14 | num? y, 15 | num? z, 16 | }) { 17 | if (z != null) { 18 | throw UnimplementedError('3D translations are not yet supported.'); 19 | } 20 | 21 | _paintingContext.canvas.translate(x?.toDouble() ?? 0, y?.toDouble() ?? 0); 22 | 23 | _paintingContext.markHasUnappliedCanvasCommands(); 24 | } 25 | 26 | void rotate(double angleInRadians) { 27 | _paintingContext.canvas.rotate(angleInRadians); 28 | _paintingContext.markHasUnappliedCanvasCommands(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /example/macos/Runner/MainFlutterWindow.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | class MainFlutterWindow: NSWindow { 5 | override func awakeFromNib() { 6 | let flutterViewController = FlutterViewController.init() 7 | let windowFrame = self.frame 8 | self.contentViewController = flutterViewController 9 | self.setFrame(windowFrame, display: true) 10 | 11 | RegisterGeneratedPlugins(registry: flutterViewController) 12 | 13 | super.awakeFromNib() 14 | 15 | // Remove the title bar and expand content to fill the entire window. 16 | self.setContentSize(NSSize(width: 1000, height: 650)) 17 | self.styleMask.update(with: StyleMask.fullSizeContentView) 18 | self.titleVisibility = TitleVisibility.hidden 19 | self.titlebarAppearsTransparent = true 20 | self.backgroundColor = NSColor.white 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/src/output/image_file_formats.dart: -------------------------------------------------------------------------------- 1 | enum ImageFileFormat { 2 | png, 3 | jpeg, 4 | tiff, 5 | targa, 6 | } 7 | 8 | extension ImageMetaData on ImageFileFormat { 9 | String get extension { 10 | switch (this) { 11 | case ImageFileFormat.png: 12 | return 'png'; 13 | case ImageFileFormat.jpeg: 14 | return 'jpg'; 15 | case ImageFileFormat.tiff: 16 | return 'tif'; 17 | case ImageFileFormat.targa: 18 | return 'tga'; 19 | } 20 | } 21 | 22 | String get mimeType { 23 | switch (this) { 24 | case ImageFileFormat.png: 25 | return 'image/png'; 26 | case ImageFileFormat.jpeg: 27 | return 'image/jepg'; 28 | case ImageFileFormat.tiff: 29 | return 'image/tiff'; 30 | case ImageFileFormat.targa: 31 | return 'image/targa'; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/src/math/_trigonometry.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math' as math; 2 | 3 | mixin SketchMathTrigonometry { 4 | double degrees(num angleInRadians) { 5 | return (angleInRadians / math.pi) * 180; 6 | } 7 | 8 | double radians(num degrees) { 9 | return (degrees / 180) * math.pi; 10 | } 11 | 12 | double sin(num angleInRadians) { 13 | return math.sin(angleInRadians); 14 | } 15 | 16 | double cos(num angleInRadians) { 17 | return math.cos(angleInRadians); 18 | } 19 | 20 | double tan(num angleInRadians) { 21 | return math.tan(angleInRadians); 22 | } 23 | 24 | double asin(num value) { 25 | return math.asin(value); 26 | } 27 | 28 | double acos(num value) { 29 | return math.acos(value); 30 | } 31 | 32 | double atan(num value) { 33 | return math.atan(value); 34 | } 35 | 36 | double atan2(num y, num x) { 37 | return math.atan2(y, x); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 9.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_processing_example 2 | description: Example project for flutter_processing. 3 | 4 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev 5 | 6 | version: 1.0.0+1 7 | 8 | environment: 9 | sdk: ">=2.12.0 <3.0.0" 10 | 11 | dependencies: 12 | flutter: 13 | sdk: flutter 14 | 15 | flutter_processing: 16 | path: ../ 17 | 18 | file_selector: ^1.0.3 19 | file_selector_macos: ^0.9.3+3 20 | image: ^4.1.7 21 | path: ^1.8.0 22 | patterns_canvas: ^0.3.5 23 | popover: ^0.2.6+2 24 | 25 | dev_dependencies: 26 | flutter_test: 27 | sdk: flutter 28 | integration_test: 29 | sdk: flutter 30 | flutter_lints: ^2.0.0 31 | 32 | flutter: 33 | uses-material-design: true 34 | 35 | # To add assets to your application, add an assets section, like this: 36 | assets: 37 | - assets/ 38 | - assets/coding-train/ 39 | - assets/coding-train/031_flappy_bird/ 40 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | **/ios/Flutter/.last_build_id 26 | .dart_tool/ 27 | .flutter-plugins 28 | .flutter-plugins-dependencies 29 | .packages 30 | .pub-cache/ 31 | .pub/ 32 | /build/ 33 | 34 | # Web related 35 | lib/generated_plugin_registrant.dart 36 | 37 | # Symbolication related 38 | app.*.symbols 39 | 40 | # Obfuscation related 41 | app.*.map.json 42 | 43 | # Android Studio will place build artifacts here 44 | /android/app/debug 45 | /android/app/profile 46 | /android/app/release 47 | -------------------------------------------------------------------------------- /lib/src/input/_mouse.dart: -------------------------------------------------------------------------------- 1 | part of '../_core.dart'; 2 | 3 | mixin SketchInputMouse { 4 | int _mouseX = 0; 5 | int get mouseX => _mouseX; 6 | 7 | int _mouseY = 0; 8 | int get mouseY => _mouseY; 9 | 10 | int _pmouseX = 0; 11 | int get pmouseX => _pmouseX; 12 | 13 | int _pmouseY = 0; 14 | int get pmouseY => _pmouseY; 15 | 16 | void _updateMousePosition(Offset newPosition) { 17 | _pmouseX = _mouseX; 18 | _pmouseY = _mouseY; 19 | 20 | _mouseX = newPosition.dx.round(); 21 | _mouseY = newPosition.dy.round(); 22 | } 23 | 24 | Set _pressedMouseButtons = {}; 25 | 26 | bool get isMousePressed => _pressedMouseButtons.isNotEmpty; 27 | 28 | MouseButton? _mouseButton; 29 | MouseButton? get mouseButton => _mouseButton; 30 | 31 | void mousePressed() {} 32 | 33 | void mouseDragged() {} 34 | 35 | void mouseReleased() {} 36 | 37 | void mouseClicked() {} 38 | 39 | void mouseMoved() {} 40 | 41 | void mouseWheel(double count) {} 42 | } 43 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/lib/the_coding_train/coding_challenges/030_phyllotaxis.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_processing/flutter_processing.dart'; 5 | 6 | class PhyllotaxisSketch extends Sketch { 7 | final _dotRadius = 3; 8 | final _dotDistanceMultiplier = 6; 9 | int _n = 0; 10 | 11 | @override 12 | void setup() { 13 | size(width: 400, height: 400); 14 | } 15 | 16 | @override 17 | void draw() { 18 | background(color: Colors.black); 19 | 20 | translate(x: width / 2, y: height / 2); 21 | 22 | final baseAngle = _n * 0.3; 23 | for (int i = 0; i < _n; i += 1) { 24 | final angle = i * (137.5 / 360) * (2 * pi) + baseAngle; 25 | final radius = _dotDistanceMultiplier * sqrt(i); 26 | final x = radius * cos(angle); 27 | final y = radius * sin(angle); 28 | final hue = (i / 3) % 360; 29 | 30 | fill(color: HSVColor.fromAHSV(1.0, hue, 1.0, 1.0).toColor()); 31 | noStroke(); 32 | circle(center: Offset(x, y), diameter: _dotRadius * 2); 33 | } 34 | 35 | _n += 5; 36 | _n.clamp(0, 2000); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /example/lib/demos/_empty_sketch.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | import 'package:flutter_processing_example/_processing_demo_sketch_display.dart'; 4 | 5 | /// An empty sketch demo where developers can experiment with Flutter Processing. 6 | class EmptySketchDemo extends StatefulWidget { 7 | const EmptySketchDemo({ 8 | Key? key, 9 | required this.sketchDemoController, 10 | }) : super(key: key); 11 | 12 | final SketchDemoController sketchDemoController; 13 | 14 | @override 15 | _EmptySketchDemoState createState() => _EmptySketchDemoState(); 16 | } 17 | 18 | class _EmptySketchDemoState extends State { 19 | @override 20 | Widget build(BuildContext context) { 21 | return ProcessingDemo( 22 | createSketch: createSketch, 23 | sketchDemoController: widget.sketchDemoController, 24 | ); 25 | } 26 | 27 | Sketch createSketch() { 28 | return Sketch.simple( 29 | setup: (s) { 30 | s.size(width: 500, height: 500); 31 | s.background(color: Colors.white); 32 | }, 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Matthew Carroll 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /test/decode_image_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:ui'; 2 | 3 | import 'package:flutter_test/flutter_test.dart'; 4 | 5 | import 'test_infra.dart'; 6 | 7 | void main() async { 8 | test('Decode image (dart test)', () async { 9 | await TestAssetBundle().load('space_100x.png'); 10 | 11 | final imageData = await TestAssetBundle().load('space_100x.png'); 12 | 13 | final codec = await (await ImageDescriptor.encoded( 14 | await ImmutableBuffer.fromUint8List(imageData.buffer.asUint8List()), 15 | )) 16 | .instantiateCodec(); 17 | 18 | final frame = await codec.getNextFrame(); 19 | }); 20 | 21 | testWidgets('Decode image (widget test)', (tester) async { 22 | tester.binding; 23 | tester.runAsync(() async { 24 | await TestAssetBundle().load('space_100x.png'); 25 | 26 | final imageData = await TestAssetBundle().load('space_100x.png'); 27 | 28 | final codec = await (await ImageDescriptor.encoded( 29 | await ImmutableBuffer.fromUint8List(imageData.buffer.asUint8List()), 30 | )) 31 | .instantiateCodec(); 32 | 33 | final frame = await codec.getNextFrame(); 34 | }); 35 | }); 36 | } 37 | -------------------------------------------------------------------------------- /example/lib/verify_behaviors/_mouse_and_touch.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_processing/flutter_processing.dart'; 2 | 3 | class MouseAndTouchSketch extends Sketch { 4 | MouseAndTouchSketch({ 5 | required this.width, 6 | required this.height, 7 | }); 8 | 9 | @override 10 | final int width; 11 | @override 12 | final int height; 13 | 14 | @override 15 | void setup() { 16 | size(width: width, height: height); 17 | } 18 | 19 | @override 20 | void draw() { 21 | // 22 | } 23 | 24 | @override 25 | void mousePressed() { 26 | print("Mouse pressed: ($mouseX, $mouseY)"); 27 | } 28 | 29 | @override 30 | void mouseDragged() { 31 | print("Mouse dragged: ($mouseX, $mouseY)"); 32 | } 33 | 34 | @override 35 | void mouseReleased() { 36 | print("Mouse released: ($mouseX, $mouseY)"); 37 | } 38 | 39 | @override 40 | void mouseClicked() { 41 | print("Mouse clicked: ($mouseX, $mouseY)"); 42 | } 43 | 44 | @override 45 | void mouseMoved() { 46 | print("Mouse moved: ($mouseX, $mouseY)"); 47 | } 48 | 49 | @override 50 | void mouseWheel(double count) { 51 | print("Mouse wheel: $count"); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /lib/src/color/_setting.dart: -------------------------------------------------------------------------------- 1 | part of '../_core.dart'; 2 | 3 | mixin SketchColorSetting on BaseSketch { 4 | Color _backgroundColor = const Color(0xFFC5C5C5); 5 | 6 | void background({ 7 | required Color color, 8 | }) { 9 | _backgroundColor = color; 10 | 11 | final paint = Paint()..color = color; 12 | _paintingContext.canvas.drawRect(Offset.zero & _paintingContext.size, paint); 13 | 14 | _paintingContext.markHasUnappliedCanvasCommands(); 15 | } 16 | 17 | void fill({ 18 | required Color color, 19 | }) { 20 | _paintingContext.fillPaint.color = color; 21 | } 22 | 23 | void noFill() { 24 | _paintingContext.fillPaint.color = const Color(0x00000000); 25 | } 26 | 27 | void stroke({ 28 | required Color color, 29 | }) { 30 | _paintingContext.strokePaint.color = color; 31 | } 32 | 33 | void noStroke() { 34 | _paintingContext.strokePaint.color = const Color(0x00000000); 35 | } 36 | 37 | void clear() { 38 | _backgroundColor = const Color(0x00000000); 39 | 40 | _paintingContext.canvas.drawColor(const Color(0x00000000), BlendMode.clear); 41 | 42 | _paintingContext.markHasUnappliedCanvasCommands(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /lib/src/environment/_environment.dart: -------------------------------------------------------------------------------- 1 | part of '../_core.dart'; 2 | 3 | mixin SketchEnvironment on BaseSketch, SketchColorSetting { 4 | Duration _elapsedTime = Duration.zero; 5 | void _updateElapsedTime(Duration newElapsedTime) => _elapsedTime = newElapsedTime; 6 | 7 | Duration? _lastDrawTime; 8 | 9 | int _frameCount = 0; 10 | int get frameCount => _frameCount; 11 | 12 | int _actualFrameRate = 10; 13 | int get frameRate => _actualFrameRate; 14 | 15 | Duration _desiredFrameTime = Duration(milliseconds: (1000.0 / 60).floor()); 16 | set frameRate(int frameRate) { 17 | _desiredFrameTime = Duration(milliseconds: (1000.0 / frameRate).floor()); 18 | } 19 | 20 | int _desiredWidth = 100; 21 | int _desiredHeight = 100; 22 | VoidCallback? _onSizeChanged; 23 | 24 | int get width => _desiredWidth; 25 | 26 | int get height => _desiredHeight; 27 | 28 | void size({ 29 | required int width, 30 | required int height, 31 | }) { 32 | _desiredWidth = width; 33 | _desiredHeight = height; 34 | _paintingContext.size = Size(width.toDouble(), height.toDouble()); 35 | _onSizeChanged?.call(); 36 | 37 | background(color: _backgroundColor); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /example/macos/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | $(PRODUCT_COPYRIGHT) 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /test/shape/attributes_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_processing/flutter_processing.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:golden_toolkit/golden_toolkit.dart'; 4 | 5 | import '../test_infra.dart'; 6 | 7 | void main() { 8 | group('Shape', () { 9 | group('Attributes', () { 10 | processingLegacySpecTest('strokeWeight(): example 1', (tester) async { 11 | await tester.pumpWidget( 12 | Processing( 13 | sketch: Sketch.simple( 14 | draw: (s) { 15 | s 16 | ..noLoop() 17 | ..strokeWeight(1) 18 | ..line(Offset(20, 20), Offset(80, 20)) 19 | ..strokeWeight(4) 20 | ..line(Offset(20, 40), Offset(80, 40)) 21 | ..strokeWeight(10) 22 | ..line(Offset(20, 70), Offset(80, 70)); 23 | }, 24 | ), 25 | ), 26 | ); 27 | 28 | await screenMatchesGolden(tester, 'shape_attributes_stroke-weight-example-1'); 29 | }); 30 | 31 | testWidgets('strokeWeight() invalid value', (tester) async { 32 | expect( 33 | () => Sketch.simple()..strokeWeight(-1), 34 | throwsException, 35 | ); 36 | }); 37 | }); 38 | }); 39 | } 40 | -------------------------------------------------------------------------------- /lib/src/image/_loading_and_displaying.dart: -------------------------------------------------------------------------------- 1 | part of '../_core.dart'; 2 | 3 | mixin SketchImageLoadingAndDisplaying on BaseSketch { 4 | Future loadImage(String filepath) async { 5 | final imageData = await _assetBundle!.load(filepath); 6 | final codec = await (await ImageDescriptor.encoded( 7 | await ImmutableBuffer.fromUint8List(imageData.buffer.asUint8List()), 8 | )) 9 | .instantiateCodec(); 10 | 11 | final frame = await codec.getNextFrame(); 12 | return PImage.fromPixels( 13 | frame.image.width, 14 | frame.image.height, 15 | (await frame.image.toByteData())!, 16 | // TODO: choose image type by extension 17 | ImageFileFormat.png, 18 | ); 19 | } 20 | 21 | Future image({ 22 | required PImage image, 23 | Offset origin = Offset.zero, 24 | double? width, 25 | double? height, 26 | }) async { 27 | final horizontalScale = width != null ? width / image.width : 1.0; 28 | final verticalScale = height != null ? height / image.height : 1.0; 29 | 30 | final flutterImage = await image.toFlutterImage(); 31 | 32 | _paintingContext.canvas 33 | ..save() 34 | ..translate(origin.dx, origin.dy) 35 | ..scale(horizontalScale, verticalScale) 36 | ..drawImage(flutterImage, Offset.zero, Paint()) 37 | ..restore(); 38 | 39 | _paintingContext.markHasUnappliedCanvasCommands(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /example/lib/the_coding_train/coding_challenges/103_fire_effect.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_processing/flutter_processing.dart'; 5 | import 'package:flutter_processing_example/_processing_demo_sketch_display.dart'; 6 | 7 | class CodingTrainFireEffectScreen extends StatefulWidget { 8 | const CodingTrainFireEffectScreen({ 9 | Key? key, 10 | required this.sketchDemoController, 11 | }) : super(key: key); 12 | 13 | final SketchDemoController sketchDemoController; 14 | 15 | @override 16 | _CodingTrainFireEffectScreenState createState() => _CodingTrainFireEffectScreenState(); 17 | } 18 | 19 | class _CodingTrainFireEffectScreenState extends State { 20 | @override 21 | Widget build(BuildContext context) { 22 | return ProcessingDemo( 23 | sketchDemoController: widget.sketchDemoController, 24 | createSketch: () { 25 | return _FireEffectSketch(); 26 | }, 27 | ); 28 | } 29 | } 30 | 31 | class _FireEffectSketch extends Sketch { 32 | ByteData? _flame; 33 | ByteData? _coolingMap; 34 | 35 | @override 36 | void setup() { 37 | size(width: 500, height: 500); 38 | } 39 | 40 | @override 41 | void draw() { 42 | _addTinder(); 43 | _burn(); 44 | _cool(); 45 | } 46 | 47 | void _addTinder() { 48 | // TODO: 49 | } 50 | 51 | void _burn() { 52 | // TODO: 53 | } 54 | 55 | void _cool() { 56 | // TODO: 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /example/macos/Podfile: -------------------------------------------------------------------------------- 1 | platform :osx, '10.11' 2 | 3 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 4 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 5 | 6 | project 'Runner', { 7 | 'Debug' => :debug, 8 | 'Profile' => :release, 9 | 'Release' => :release, 10 | } 11 | 12 | def flutter_root 13 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__) 14 | unless File.exist?(generated_xcode_build_settings_path) 15 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first" 16 | end 17 | 18 | File.foreach(generated_xcode_build_settings_path) do |line| 19 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 20 | return matches[1].strip if matches 21 | end 22 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\"" 23 | end 24 | 25 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 26 | 27 | flutter_macos_podfile_setup 28 | 29 | target 'Runner' do 30 | use_frameworks! 31 | use_modular_headers! 32 | 33 | flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) 34 | end 35 | 36 | post_install do |installer| 37 | installer.pods_project.targets.each do |target| 38 | flutter_additional_macos_build_settings(target) 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/src/color/_color.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/painting.dart'; 2 | 3 | mixin SketchColor { 4 | ColorMode _colorMode = ColorMode.rgb; 5 | void colorMode(ColorMode newMode) { 6 | _colorMode = newMode; 7 | } 8 | 9 | Color color({ 10 | int? grey, 11 | int alpha = 255, 12 | int? comp1, 13 | int? comp2, 14 | int? comp3, 15 | }) { 16 | assert(grey != null || (comp1 != null && comp2 != null && comp3 != null)); 17 | 18 | if (grey != null) { 19 | return Color.fromARGB(alpha, grey, grey, grey); 20 | } else { 21 | switch (_colorMode) { 22 | case ColorMode.rgb: 23 | return Color.fromARGB(alpha, comp1!, comp2!, comp3!); 24 | case ColorMode.hsb: 25 | final hsvColor = HSVColor.fromAHSV(alpha / 255, comp1! / 255, comp2! / 255, comp3! / 255); 26 | return hsvColor.toColor(); 27 | } 28 | } 29 | } 30 | 31 | Color lerpColor(Color color1, Color color2, double percent) => Color.lerp(color1, color2, percent)!; 32 | 33 | int red(Color color) => color.red; 34 | int green(Color color) => color.green; 35 | int blue(Color color) => color.blue; 36 | int alpha(Color color) => color.alpha; 37 | 38 | int hue(Color color) => (HSVColor.fromColor(color).hue * 255).round(); 39 | int saturation(Color color) => (HSVColor.fromColor(color).saturation * 255).round(); 40 | int brightness(Color color) => (HSVColor.fromColor(color).value * 255).round(); 41 | } 42 | 43 | enum ColorMode { 44 | rgb, 45 | hsb, 46 | } 47 | -------------------------------------------------------------------------------- /example/lib/demos/perlin_noise_demo.dart: -------------------------------------------------------------------------------- 1 | import 'dart:ui'; 2 | 3 | import 'package:flutter/material.dart' hide Image; 4 | import 'package:flutter_processing/flutter_processing.dart'; 5 | 6 | class PerlinNoiseDemoSketch extends Sketch { 7 | PerlinNoiseDemoSketch({ 8 | required this.width, 9 | required this.height, 10 | this.animateZIndex = false, 11 | }); 12 | 13 | @override 14 | final int width; 15 | @override 16 | final int height; 17 | final bool animateZIndex; 18 | 19 | double z = 0; 20 | 21 | @override 22 | void setup() { 23 | size(width: width, height: height); 24 | } 25 | 26 | @override 27 | Future draw() async { 28 | await loadPixels(); 29 | 30 | noiseDetail(octaves: 8); 31 | 32 | const increment = 1.5; 33 | double x = 0; 34 | double y = 0; 35 | for (int col = 0; col < width; col += 1) { 36 | for (int row = 0; row < height; row += 1) { 37 | // final grayAmount = s.random(0, 256).floor(); 38 | 39 | final perlinNoiseValue = noise(x: x, y: y, z: z); 40 | final grayAmount = (((perlinNoiseValue + 1.0) / 2.0) * 255).round(); 41 | 42 | final color = Color.fromARGB(255, grayAmount, grayAmount, grayAmount); 43 | 44 | set(x: col, y: row, color: color); 45 | 46 | y += increment; 47 | } 48 | x += increment; 49 | y = 0; 50 | } 51 | 52 | await updatePixels(); 53 | 54 | z += 5; 55 | 56 | if (!animateZIndex) { 57 | noLoop(); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | # platform :ios, '9.0' 3 | 4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 6 | 7 | project 'Runner', { 8 | 'Debug' => :debug, 9 | 'Profile' => :release, 10 | 'Release' => :release, 11 | } 12 | 13 | def flutter_root 14 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) 15 | unless File.exist?(generated_xcode_build_settings_path) 16 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" 17 | end 18 | 19 | File.foreach(generated_xcode_build_settings_path) do |line| 20 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 21 | return matches[1].strip if matches 22 | end 23 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" 24 | end 25 | 26 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 27 | 28 | flutter_ios_podfile_setup 29 | 30 | target 'Runner' do 31 | use_frameworks! 32 | use_modular_headers! 33 | 34 | flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) 35 | end 36 | 37 | post_install do |installer| 38 | installer.pods_project.targets.each do |target| 39 | flutter_additional_ios_build_settings(target) 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /example/lib/generative_art/liquid_gels.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | 4 | /// Adapted from: https://openprocessing.org/sketch/816453 5 | class LiquidGelsSketch extends Sketch { 6 | @override 7 | void setup() { 8 | size(width: 800, height: 800); 9 | } 10 | 11 | @override 12 | void draw() { 13 | blendMode = BlendMode.src; 14 | background(color: const Color.fromARGB(255, 245, 245, 245)); 15 | blendMode = BlendMode.multiply; 16 | noStroke(); 17 | translate(x: width / 2, y: height / 2); 18 | 19 | fill(color: const Color.fromARGB(255, 0, 150, 240)); 20 | drawGel(18, 50, 20, 100); 21 | 22 | fill(color: const Color.fromARGB(255, 240, 240, 0)); 23 | drawGel(15, 60, 25, 120); 24 | 25 | fill(color: const Color.fromARGB(255, 240, 0, 240)); 26 | drawGel(12, 45, 15, 150); 27 | } 28 | 29 | void drawGel(int vNnum, int nm, int sm, int fcm) { 30 | pushMatrix(); 31 | rotate(frameCount / fcm); 32 | final dr = TWO_PI / vNnum; 33 | beginShape(); 34 | for (int i = 0; i < vNnum + 3; i++) { 35 | final ind = i % vNnum; 36 | final rad = dr * ind; 37 | final r = 38 | height * 0.3 + noise(x: frameCount / nm + ind) * height * 0.1 + sin(frameCount / sm + ind) * height * 0.05; 39 | // TODO: implement curve vertex 40 | curveVertex(cos(rad) * r, sin(rad) * r); 41 | // vertex(cos(rad) * r, sin(rad) * r); 42 | } 43 | endShape(); 44 | popMatrix(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /example/lib/api_demos/_image_mask_sketch.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart' hide Image; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | import 'package:flutter_processing_example/_processing_demo_sketch_display.dart'; 4 | 5 | class ImageMaskSketchDemo extends StatefulWidget { 6 | const ImageMaskSketchDemo({ 7 | Key? key, 8 | required this.sketchDemoController, 9 | }) : super(key: key); 10 | 11 | final SketchDemoController sketchDemoController; 12 | 13 | @override 14 | _ImageMaskSketchDemoState createState() => _ImageMaskSketchDemoState(); 15 | } 16 | 17 | class _ImageMaskSketchDemoState extends State { 18 | late PImage _image1; 19 | late PImage _image2; 20 | 21 | @override 22 | Widget build(BuildContext context) { 23 | return ProcessingDemo( 24 | createSketch: createSketch, 25 | sketchDemoController: widget.sketchDemoController, 26 | ); 27 | } 28 | 29 | Sketch createSketch() { 30 | return Sketch.simple( 31 | setup: (s) async { 32 | s.size(width: 500, height: 500); 33 | s.background(color: const Color(0xFFFFFFFF)); 34 | 35 | _image1 = await s.loadImage("assets/coffee.png"); 36 | _image1.resize(width: 500, height: 500); 37 | 38 | _image2 = await s.loadImage("assets/mask.jpg"); 39 | _image2.resize(width: _image1.width, height: _image1.height); 40 | 41 | _image1.mask(maskImage: _image2); 42 | }, 43 | draw: (s) async { 44 | await s.image(image: _image1); 45 | }, 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lib/src/_core.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:io'; 3 | import 'dart:typed_data'; 4 | import 'dart:ui'; 5 | 6 | import 'package:flutter/gestures.dart'; 7 | import 'package:flutter/scheduler.dart'; 8 | import 'package:flutter/services.dart'; 9 | import 'package:flutter/widgets.dart' hide Image, TextStyle, TextAlignVertical; 10 | import 'package:flutter_processing/flutter_processing.dart'; 11 | import 'package:flutter_processing/src/constants/_constants.dart'; 12 | import 'package:flutter_processing/src/math/_random.dart'; 13 | import 'package:flutter_processing/src/math/_trigonometry.dart'; 14 | import 'package:image/image.dart' as imageFormats; 15 | import 'package:path/path.dart' as path; 16 | 17 | import '_painting_context.dart'; 18 | import 'data/conversion.dart'; 19 | import 'input/_time_and_date.dart'; 20 | import 'math/_calculations.dart'; 21 | 22 | part '_processing_widget.dart'; 23 | part '_sketch.dart'; 24 | part 'color/_setting.dart'; 25 | part 'environment/_environment.dart'; 26 | part 'input/_keyboard.dart'; 27 | part 'input/_mouse.dart'; 28 | part 'image/_loading_and_displaying.dart'; 29 | part 'image/_pixels.dart'; 30 | part 'output/_image.dart'; 31 | part 'rendering/_rendering.dart'; 32 | part 'shape/_attributes.dart'; 33 | part 'shape/_two_d_primitives.dart'; 34 | part 'shape/_vertex.dart'; 35 | part 'structure/_structure.dart'; 36 | part 'transform/_transform.dart'; 37 | part 'typography/_typography.dart'; 38 | 39 | abstract class BaseSketch { 40 | SketchPaintingContext _paintingContext = SketchPaintingContext(); 41 | 42 | AssetBundle? _assetBundle; 43 | } 44 | -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "app_icon_16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "app_icon_32.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "app_icon_32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "app_icon_64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "app_icon_128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "app_icon_256.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "app_icon_256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "app_icon_512.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "app_icon_512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "app_icon_1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /test/constants/constants_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_processing/flutter_processing.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:golden_toolkit/golden_toolkit.dart'; 4 | 5 | import '../test_infra.dart'; 6 | 7 | void main() { 8 | group('Constants', () { 9 | processingLegacySpecTest('constants', (tester) async { 10 | await tester.pumpWidget( 11 | Processing( 12 | sketch: Sketch.simple( 13 | draw: (s) { 14 | s.noLoop(); 15 | 16 | final x = s.width / 2; 17 | final y = s.height / 2; 18 | final d = s.width * 0.8; 19 | s.arc( 20 | ellipse: Ellipse.fromCenter(center: Offset(x, y), width: d, height: d), 21 | startAngle: 0, 22 | endAngle: s.QUARTER_PI, 23 | ); 24 | s.arc( 25 | ellipse: Ellipse.fromCenter(center: Offset(x, y), width: d - 20, height: d - 20), 26 | startAngle: 0, 27 | endAngle: s.HALF_PI, 28 | ); 29 | s.arc( 30 | ellipse: Ellipse.fromCenter(center: Offset(x, y), width: d - 40, height: d - 40), 31 | startAngle: 0, 32 | endAngle: s.PI, 33 | ); 34 | s.arc( 35 | ellipse: Ellipse.fromCenter(center: Offset(x, y), width: d - 60, height: d - 60), 36 | startAngle: 0, 37 | endAngle: s.TAU, 38 | ); 39 | }, 40 | ), 41 | ), 42 | ); 43 | 44 | await screenMatchesGolden( 45 | tester, 46 | 'constants', 47 | ); 48 | }); 49 | }); 50 | } 51 | -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | Example 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | example 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(FLUTTER_BUILD_NUMBER) 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | UIViewControllerBasedStatusBarAppearance 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /lib/src/shape/shapes.dart: -------------------------------------------------------------------------------- 1 | import 'dart:ui'; 2 | 3 | class Square { 4 | Square.fromLTE(Offset topLeft, double extent) 5 | : _rect = Rect.fromLTWH( 6 | topLeft.dx, 7 | topLeft.dy, 8 | extent, 9 | extent, 10 | ); 11 | 12 | Square.fromCenter(Offset center, double extent) 13 | : _rect = Rect.fromCenter( 14 | center: center, 15 | width: extent, 16 | height: extent, 17 | ); 18 | 19 | final Rect _rect; 20 | Rect get rect => _rect; 21 | } 22 | 23 | class Ellipse { 24 | Ellipse.fromLTWH({ 25 | required Offset topLeft, 26 | required double width, 27 | required double height, 28 | }) : _rect = Rect.fromLTWH( 29 | topLeft.dx, 30 | topLeft.dy, 31 | width, 32 | height, 33 | ); 34 | 35 | Ellipse.fromLTRB({ 36 | required Offset topLeft, 37 | required Offset bottomRight, 38 | }) : _rect = Rect.fromLTRB( 39 | topLeft.dx, 40 | topLeft.dy, 41 | bottomRight.dx, 42 | bottomRight.dy, 43 | ); 44 | 45 | Ellipse.fromCenter({ 46 | required Offset center, 47 | required double width, 48 | required double height, 49 | }) : _rect = Rect.fromCenter( 50 | center: center, 51 | width: width, 52 | height: height, 53 | ); 54 | 55 | Ellipse.fromCenterWithRadius({ 56 | required Offset center, 57 | required double radius1, 58 | required double radius2, 59 | }) : _rect = Rect.fromCenter( 60 | center: center, 61 | width: radius1 * 2, 62 | height: radius2 * 2, 63 | ); 64 | 65 | final Rect _rect; 66 | Rect get rect => _rect; 67 | } 68 | 69 | enum ArcMode { 70 | openStrokePieFill, 71 | open, 72 | chord, 73 | pie, 74 | } 75 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 15 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Golden failures 2 | failures/ 3 | 4 | # Miscellaneous 5 | *.class 6 | *.log 7 | *.pyc 8 | *.swp 9 | .DS_Store 10 | .atom/ 11 | .buildlog/ 12 | .history 13 | .svn/ 14 | 15 | # IntelliJ related 16 | *.iml 17 | *.ipr 18 | *.iws 19 | .idea/ 20 | 21 | # The .vscode folder contains launch configuration and tasks you configure in 22 | # VS Code which you may wish to be included in version control, so this line 23 | # is commented out by default. 24 | #.vscode/ 25 | 26 | # Flutter/Dart/Pub related 27 | **/doc/api/ 28 | .dart_tool/ 29 | .flutter-plugins 30 | .flutter-plugins-dependencies 31 | .packages 32 | .pub-cache/ 33 | .pub/ 34 | build/ 35 | 36 | # Android related 37 | **/android/**/gradle-wrapper.jar 38 | **/android/.gradle 39 | **/android/captures/ 40 | **/android/gradlew 41 | **/android/gradlew.bat 42 | **/android/local.properties 43 | **/android/**/GeneratedPluginRegistrant.java 44 | 45 | # iOS/XCode related 46 | **/ios/**/*.mode1v3 47 | **/ios/**/*.mode2v3 48 | **/ios/**/*.moved-aside 49 | **/ios/**/*.pbxuser 50 | **/ios/**/*.perspectivev3 51 | **/ios/**/*sync/ 52 | **/ios/**/.sconsign.dblite 53 | **/ios/**/.tags* 54 | **/ios/**/.vagrant/ 55 | **/ios/**/DerivedData/ 56 | **/ios/**/Icon? 57 | **/ios/**/Pods/ 58 | **/ios/**/.symlinks/ 59 | **/ios/**/profile 60 | **/ios/**/xcuserdata 61 | **/ios/.generated/ 62 | **/ios/Flutter/App.framework 63 | **/ios/Flutter/Flutter.framework 64 | **/ios/Flutter/Flutter.podspec 65 | **/ios/Flutter/Generated.xcconfig 66 | **/ios/Flutter/app.flx 67 | **/ios/Flutter/app.zip 68 | **/ios/Flutter/flutter_assets/ 69 | **/ios/Flutter/flutter_export_environment.sh 70 | **/ios/ServiceDefinitions.json 71 | **/ios/Runner/GeneratedPluginRegistrant.* 72 | 73 | # Exceptions to above rules. 74 | !**/ios/**/default.mode1v3 75 | !**/ios/**/default.mode2v3 76 | !**/ios/**/default.pbxuser 77 | !**/ios/**/default.perspectivev3 78 | -------------------------------------------------------------------------------- /example/lib/api_demos/_image_resize_sketch.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart' hide Image; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | import 'package:flutter_processing_example/_processing_demo_sketch_display.dart'; 4 | 5 | class ImageResizeSketchDemo extends StatefulWidget { 6 | const ImageResizeSketchDemo({ 7 | Key? key, 8 | required this.sketchDemoController, 9 | }) : super(key: key); 10 | 11 | final SketchDemoController sketchDemoController; 12 | 13 | @override 14 | _ImageResizeSketchDemoState createState() => _ImageResizeSketchDemoState(); 15 | } 16 | 17 | class _ImageResizeSketchDemoState extends State { 18 | late PImage _image1; 19 | late PImage _image2; 20 | late PImage _image3; 21 | 22 | @override 23 | Widget build(BuildContext context) { 24 | return ProcessingDemo( 25 | createSketch: createSketch, 26 | sketchDemoController: widget.sketchDemoController, 27 | ); 28 | } 29 | 30 | Sketch createSketch() { 31 | return Sketch.simple( 32 | setup: (s) async { 33 | s.size(width: 500, height: 500); 34 | s.background(color: const Color(0xFFFFFFFF)); 35 | 36 | _image1 = await s.loadImage("assets/coffee.png"); 37 | 38 | _image2 = await s.loadImage("assets/coffee.png"); 39 | _image2.resize(width: 200); 40 | 41 | _image3 = await s.loadImage("assets/coffee.png"); 42 | _image3.resize(width: 300, height: 150); 43 | }, 44 | draw: (s) async { 45 | await s.image(image: _image1); 46 | await s.image(image: _image2, origin: Offset((s.width - _image2.width).toDouble(), 0)); 47 | await s.image( 48 | image: _image3, 49 | origin: Offset((s.width - _image3.width).toDouble(), (s.height - _image3.height).toDouble())); 50 | }, 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example/lib/the_coding_train/coding_challenges/052_random_walker.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_processing/flutter_processing.dart'; 5 | import 'package:flutter_processing_example/_processing_demo_sketch_display.dart'; 6 | 7 | class CodingTrainRandomWalkerScreen extends StatefulWidget { 8 | const CodingTrainRandomWalkerScreen({ 9 | Key? key, 10 | required this.sketchDemoController, 11 | }) : super(key: key); 12 | 13 | final SketchDemoController sketchDemoController; 14 | 15 | @override 16 | _CodingTrainRandomWalkerScreenState createState() => _CodingTrainRandomWalkerScreenState(); 17 | } 18 | 19 | class _CodingTrainRandomWalkerScreenState extends State { 20 | late int x; 21 | late int y; 22 | 23 | Sketch createSketch() { 24 | return Sketch.simple( 25 | setup: (s) { 26 | s 27 | ..size(width: 400, height: 400) 28 | ..background(color: const Color(0xFF444444)); 29 | 30 | x = (s.width / 2).round(); 31 | y = (s.height / 2).round(); 32 | }, 33 | draw: (s) { 34 | s 35 | ..noStroke() 36 | ..fill(color: Colors.white) 37 | ..circle(center: Offset(x.toDouble(), y.toDouble()), diameter: 4); 38 | 39 | final randomDirection = Random().nextInt(4); 40 | switch (randomDirection) { 41 | case 0: 42 | x += 1; 43 | break; 44 | case 1: 45 | x -= 1; 46 | break; 47 | case 2: 48 | y += 1; 49 | break; 50 | case 3: 51 | y -= 1; 52 | break; 53 | } 54 | }, 55 | ); 56 | } 57 | 58 | @override 59 | Widget build(BuildContext context) { 60 | return ProcessingDemo( 61 | createSketch: createSketch, 62 | sketchDemoController: widget.sketchDemoController, 63 | ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /example/lib/demos/_hacking.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart' hide Image; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | import 'package:flutter_processing_example/_processing_demo_sketch_display.dart'; 4 | 5 | class HackingDemo extends StatefulWidget { 6 | const HackingDemo({ 7 | Key? key, 8 | required this.sketchDemoController, 9 | }) : super(key: key); 10 | 11 | final SketchDemoController sketchDemoController; 12 | 13 | @override 14 | _HackingDemoState createState() => _HackingDemoState(); 15 | } 16 | 17 | class _HackingDemoState extends State { 18 | late PImage _loadedImage; 19 | 20 | Sketch createSketch() { 21 | return Sketch.simple( 22 | setup: (s) async { 23 | s.size(width: 500, height: 500); 24 | 25 | _loadedImage = await s.loadImage('assets/audio-mixer.png'); 26 | }, 27 | draw: (s) async { 28 | s.image( 29 | image: _loadedImage, 30 | ); 31 | 32 | final subImage = await s.getRegion( 33 | x: 0, 34 | y: 0, 35 | width: (s.width / 2).round(), 36 | height: (s.height / 2).round(), 37 | ); 38 | // s.image(image: subImage, origin: Offset(s.width / 2, s.height / 2)); 39 | 40 | await s.loadPixels(); 41 | 42 | for (int col = 0; col < 400; ++col) { 43 | for (int row = 0; row < 400; ++row) { 44 | s.set(x: col, y: row, color: const Color(0xFF00FF00)); 45 | } 46 | } 47 | await s.setRegion(image: subImage); 48 | 49 | await s.updatePixels(); 50 | 51 | final pixelColor = await s.get(s.mouseX, s.mouseY); 52 | s 53 | // ..noStroke() 54 | ..fill(color: pixelColor) 55 | ..circle( 56 | center: Offset(s.mouseX + 50, s.mouseY + 50), 57 | diameter: 100, 58 | ); 59 | 60 | await s.loadPixels(); 61 | }, 62 | ); 63 | } 64 | 65 | @override 66 | Widget build(BuildContext context) { 67 | return ProcessingDemo( 68 | createSketch: createSketch, 69 | sketchDemoController: widget.sketchDemoController, 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /lib/src/math/_calculations.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math' as math; 2 | import 'dart:ui'; 3 | 4 | mixin SketchMathCalculations { 5 | num abs(num value) { 6 | return value.abs(); 7 | } 8 | 9 | int ceil(num value) { 10 | return value.ceil(); 11 | } 12 | 13 | num constrain(num value, num min, num max) { 14 | return value.clamp(min, max); 15 | } 16 | 17 | num dist(Offset p1, Offset p2) { 18 | return (p2 - p1).distance; 19 | } 20 | 21 | num exp(num value) { 22 | return math.exp(value); 23 | } 24 | 25 | int floor(num value) { 26 | return value.floor(); 27 | } 28 | 29 | double lerp(num start, num end, double percent) { 30 | return lerpDouble(start, end, percent)!; 31 | } 32 | 33 | num log(num value) { 34 | return math.log(value); 35 | } 36 | 37 | num mag(int x, int y, [int z = 0]) { 38 | return math.sqrt(math.pow(x, 2) + math.pow(y, 2) + math.pow(z, 2)); 39 | } 40 | 41 | num map(num value, num domainMin, num domainMax, num rangeMin, num rangeMax) { 42 | return (value - domainMin) * (rangeMax - rangeMin) / (domainMax - domainMin) + rangeMin; 43 | } 44 | 45 | num max(num a, num b, [num? c]) { 46 | final max = math.max(a, b); 47 | return c != null ? math.max(max, c) : max; 48 | } 49 | 50 | num maxInList(List list) { 51 | assert(list.isNotEmpty); 52 | return list.fold(list.first, (previousMax, newValue) => math.max(previousMax, newValue)); 53 | } 54 | 55 | num min(num a, num b, [num? c]) { 56 | final min = math.min(a, b); 57 | return c != null ? math.min(min, c) : min; 58 | } 59 | 60 | num minInList(List list) { 61 | assert(list.isNotEmpty); 62 | return list.fold(list.first, (previousMin, newValue) => math.min(previousMin, newValue)); 63 | } 64 | 65 | num norm(num value, num start, num stop) { 66 | return map(value, start, stop, 0, 1); 67 | } 68 | 69 | num pow(num base, num exponent) { 70 | return math.pow(base, exponent); 71 | } 72 | 73 | int round(num value) { 74 | return value.round(); 75 | } 76 | 77 | num sq(num value) { 78 | return value * value; 79 | } 80 | 81 | num sqrt(num value) { 82 | return math.sqrt(value); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /example/lib/generative_art/colored_circles.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart' hide Image; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | 4 | class ColoredCirclesSketch extends Sketch { 5 | ColoredCirclesSketch({ 6 | required this.width, 7 | required this.height, 8 | this.maxCircleRadius = 30.0, 9 | this.circleMargin = 5.0, 10 | this.innerCircleProbability = 0.50, 11 | }); 12 | 13 | @override 14 | final int width; 15 | @override 16 | final int height; 17 | final double maxCircleRadius; 18 | final double circleMargin; 19 | final double innerCircleProbability; 20 | 21 | @override 22 | void setup() { 23 | size(width: width, height: height); 24 | } 25 | 26 | @override 27 | Future draw() async { 28 | background(color: const Color(0xFF111111)); 29 | 30 | noStroke(); 31 | 32 | final circleDiameter = maxCircleRadius * 2; 33 | final spaceBetweenCircles = circleDiameter + (2 * circleMargin); 34 | final circlesPerRow = (width / spaceBetweenCircles).ceil() + 1; // +1 for partial circle at end of row 35 | final circlesPerColumn = (height / spaceBetweenCircles).ceil() + 1; // +1 for partial circle at end of col 36 | for (int colIndex = 0; colIndex < circlesPerRow; colIndex += 1) { 37 | for (int rowIndex = 0; rowIndex < circlesPerColumn; rowIndex += 1) { 38 | fill( 39 | color: HSVColor.fromAHSV(1.0, random(360), 0.7, 0.8).toColor(), 40 | ); 41 | 42 | final outerCircleDiameter = random(10, circleDiameter); 43 | circle( 44 | center: Offset(colIndex * spaceBetweenCircles, rowIndex * spaceBetweenCircles), 45 | diameter: outerCircleDiameter, 46 | ); 47 | 48 | if (random(1.0) < innerCircleProbability) { 49 | fill( 50 | color: HSVColor.fromAHSV(1.0, random(360), 0.7, 0.8).toColor(), 51 | ); 52 | 53 | final innerCircleDiameter = random(10, outerCircleDiameter); 54 | circle( 55 | center: Offset(colIndex * spaceBetweenCircles, rowIndex * spaceBetweenCircles), 56 | diameter: innerCircleDiameter, 57 | ); 58 | } 59 | } 60 | } 61 | 62 | noLoop(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /lib/src/data/conversion.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/painting.dart'; 2 | 3 | mixin SketchDataConversion { 4 | bool boolean(Object value) { 5 | if (value is int) { 6 | return value != 0; 7 | } else if (value is String) { 8 | return value == 'true'; 9 | } else { 10 | throw FormatException("Can't convert a value of type ${value.runtimeType} to a boolean"); 11 | } 12 | } 13 | 14 | int byte(Object value) { 15 | throw UnimplementedError(); 16 | } 17 | 18 | String char(int charCode) { 19 | return String.fromCharCode(charCode); 20 | } 21 | 22 | double float(Object value) { 23 | if (value is int) { 24 | return value.toDouble(); 25 | } else if (value is String) { 26 | return double.parse(value); 27 | } else { 28 | throw FormatException("Can't convert a value of type ${value.runtimeType} to a floating point number"); 29 | } 30 | } 31 | 32 | int toInt(Object value) { 33 | if (value is int) { 34 | return value; 35 | } else if (value is double) { 36 | return value.floor(); 37 | } else if (value is bool) { 38 | return value ? 1 : 0; 39 | } else if (value is String) { 40 | return int.parse(value); 41 | } else { 42 | throw FormatException("Can't convert a value of type ${value.runtimeType} to an integer"); 43 | } 44 | } 45 | 46 | String str(Object value) { 47 | return value.toString(); 48 | } 49 | 50 | String binary(Object value) { 51 | if (value is int) { 52 | return value.toRadixString(2); 53 | } else if (value is Color) { 54 | return value.value.toRadixString(2); 55 | } else { 56 | throw FormatException("Can't convert a value of type ${value.runtimeType} to a binary string"); 57 | } 58 | } 59 | 60 | int unbinary(String binary) => int.parse(binary, radix: 2); 61 | 62 | String hex(Object value) { 63 | if (value is int) { 64 | return value.toRadixString(16); 65 | } else if (value is Color) { 66 | return value.value.toRadixString(16); 67 | } else { 68 | throw FormatException("Can't convert a value of type ${value.runtimeType} to a hex string"); 69 | } 70 | } 71 | 72 | int unhex(String hex) => int.parse(hex, radix: 16); 73 | } 74 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply plugin: 'kotlin-android' 26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 27 | 28 | android { 29 | compileSdkVersion flutter.compileSdkVersion 30 | 31 | compileOptions { 32 | sourceCompatibility JavaVersion.VERSION_1_8 33 | targetCompatibility JavaVersion.VERSION_1_8 34 | } 35 | 36 | kotlinOptions { 37 | jvmTarget = '1.8' 38 | } 39 | 40 | sourceSets { 41 | main.java.srcDirs += 'src/main/kotlin' 42 | } 43 | 44 | defaultConfig { 45 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 46 | applicationId "com.example.example" 47 | minSdkVersion flutter.minSdkVersion 48 | targetSdkVersion flutter.targetSdkVersion 49 | versionCode flutterVersionCode.toInteger() 50 | versionName flutterVersionName 51 | } 52 | 53 | buildTypes { 54 | release { 55 | // TODO: Add your own signing config for the release build. 56 | // Signing with the debug keys for now, so `flutter run --release` works. 57 | signingConfig signingConfigs.debug 58 | } 59 | } 60 | } 61 | 62 | flutter { 63 | source '../..' 64 | } 65 | 66 | dependencies { 67 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 68 | } 69 | -------------------------------------------------------------------------------- /example/lib/generative_art/dot_field.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart' hide Image; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | 4 | class DotFieldSketch extends Sketch { 5 | DotFieldSketch({ 6 | required this.width, 7 | required this.height, 8 | this.gridSize = 30, 9 | this.dotDiameter = 3, 10 | }); 11 | 12 | @override 13 | final int width; 14 | @override 15 | final int height; 16 | final int gridSize; 17 | final double dotDiameter; 18 | 19 | @override 20 | void setup() { 21 | size(width: width, height: height); 22 | } 23 | 24 | @override 25 | Future draw() async { 26 | background(color: const Color(0xFF111111)); 27 | 28 | noStroke(); 29 | 30 | double x = gridSize.toDouble(); 31 | double y = gridSize.toDouble(); 32 | 33 | while (x < width) { 34 | while (y < height) { 35 | final dotNoise = noise( 36 | x: map(x, 0, width, 0, 1000).toDouble(), 37 | y: map(y, 0, height, 0, 1000 * (height / width)).toDouble(), 38 | z: frameCount.toDouble() / 2, 39 | ); 40 | 41 | const threshold = 0.0; 42 | const dotMaxAlpha = 0.5; 43 | if (dotNoise > threshold) { 44 | const thresholdMidpoint = (1.0 + threshold) / 2; 45 | final verticalOffset = (dotNoise - thresholdMidpoint) * 30; 46 | 47 | // Adjust the alpha so that dots that are near the boundary, 48 | // appear translucent, so that movement through the z-coord 49 | // looks continuous. 50 | final alpha = ((dotNoise - threshold) * 5).clamp(0.0, dotMaxAlpha); 51 | fill( 52 | color: HSVColor.fromAHSV(alpha, map(x, 0, width, 360, 0).toDouble(), 1.0, 1.0).toColor(), 53 | ); 54 | 55 | // // Adjust the alpha so that dots that are near the boundary, 56 | // // appear translucent, so that movement through the z-coord 57 | // // looks continuous. 58 | // final alpha = (dotNoise * 5).clamp(0.0, 0.2); 59 | // fill(color: Colors.white.withOpacity(alpha)); 60 | 61 | circle(center: Offset(x, y + verticalOffset), diameter: dotDiameter); 62 | } 63 | 64 | y += gridSize; 65 | } 66 | 67 | x += gridSize; 68 | y = gridSize.toDouble(); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /test/environment/environment_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:golden_toolkit/golden_toolkit.dart'; 5 | 6 | import '../test_infra.dart'; 7 | 8 | void main() { 9 | group('Environment', () { 10 | processingLegacySpecTest('width', (tester) async { 11 | await tester.pumpWidget( 12 | Processing( 13 | sketch: Sketch.simple( 14 | draw: (s) { 15 | s 16 | ..noLoop() 17 | ..noStroke() 18 | ..background(color: Colors.black) 19 | ..rect(rect: Rect.fromLTWH(0, 40, s.width.toDouble(), 20)) 20 | ..rect(rect: Rect.fromLTWH(0, 60, s.width / 2, 20)); 21 | }, 22 | ), 23 | ), 24 | ); 25 | 26 | await screenMatchesGolden(tester, 'environment_width-example-1'); 27 | }); 28 | 29 | processingLegacySpecTest('height', (tester) async { 30 | await tester.pumpWidget( 31 | Processing( 32 | sketch: Sketch.simple( 33 | draw: (s) { 34 | s 35 | ..noLoop() 36 | ..noStroke() 37 | ..background(color: Colors.black) 38 | ..rect(rect: Rect.fromLTWH(40, 0, 20, s.height.toDouble())) 39 | ..rect(rect: Rect.fromLTWH(60, 0, 20, s.height / 2)); 40 | }, 41 | ), 42 | ), 43 | ); 44 | 45 | await screenMatchesGolden(tester, 'environment_height-example-1'); 46 | }); 47 | 48 | processingLegacySpecTest('size()', (tester) async { 49 | // Expand the canvas to leave enough space for 50 | // a larger Processing sketch. 51 | tester.view.physicalSize = Size(250, 250); 52 | 53 | await tester.pumpWidget( 54 | Processing( 55 | sketch: Sketch.simple( 56 | setup: (s) { 57 | s 58 | ..noLoop() 59 | ..size(width: 200, height: 200); 60 | }, 61 | draw: (s) { 62 | s.circle(center: Offset(100, 100), diameter: 50); 63 | }, 64 | ), 65 | ), 66 | ); 67 | 68 | await screenMatchesGolden(tester, 'environment_size-example-1'); 69 | }); 70 | }); 71 | } 72 | -------------------------------------------------------------------------------- /example/lib/generative_art/wobbly_swarm.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | 4 | /// Adapted from: https://openprocessing.org/sketch/492096 5 | class WobblySwarmSketch extends Sketch { 6 | final mass = []; 7 | final positionX = []; 8 | final positionY = []; 9 | final velocityX = []; 10 | final velocityY = []; 11 | 12 | @override 13 | void setup() { 14 | size(width: 800, height: 800); 15 | } 16 | 17 | @override 18 | void draw() { 19 | background(color: const Color.fromARGB(255, 32, 32, 32)); 20 | 21 | noStroke(); 22 | fill(color: const Color.fromARGB(192, 255, 255, 64)); 23 | 24 | for (var particleA = 0; particleA < mass.length; particleA++) { 25 | double accelerationX = 0; 26 | double accelerationY = 0; 27 | 28 | for (var particleB = 0; particleB < mass.length; particleB++) { 29 | if (particleA != particleB) { 30 | var distanceX = positionX[particleB] - positionX[particleA]; 31 | var distanceY = positionY[particleB] - positionY[particleA]; 32 | 33 | var distance = sqrt(distanceX * distanceX + distanceY * distanceY); 34 | if (distance < 1) distance = 1; 35 | 36 | var force = (distance - 320) * mass[particleB] / distance; 37 | accelerationX += force * distanceX; 38 | accelerationY += force * distanceY; 39 | } 40 | } 41 | 42 | velocityX[particleA] = velocityX[particleA] * 0.99 + accelerationX * mass[particleA]; 43 | velocityY[particleA] = velocityY[particleA] * 0.99 + accelerationY * mass[particleA]; 44 | } 45 | 46 | for (var particle = 0; particle < mass.length; particle++) { 47 | positionX[particle] += velocityX[particle]; 48 | positionY[particle] += velocityY[particle]; 49 | 50 | circle(center: Offset(positionX[particle], positionY[particle]), diameter: 2.0 * mass[particle] * 1000); 51 | } 52 | } 53 | 54 | @override 55 | void mouseClicked() { 56 | addNewParticle(); 57 | } 58 | 59 | @override 60 | void mouseDragged() { 61 | addNewParticle(); 62 | } 63 | 64 | void addNewParticle() { 65 | mass.add(random(0.003, 0.03)); 66 | positionX.add(mouseX.toDouble()); 67 | positionY.add(mouseY.toDouble()); 68 | velocityX.add(0); 69 | velocityY.add(0); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /example/lib/the_coding_train/coding_challenges/004_purple-rain.dart: -------------------------------------------------------------------------------- 1 | import 'dart:ui'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_processing/flutter_processing.dart'; 5 | import 'package:flutter_processing_example/_processing_demo_sketch_display.dart'; 6 | 7 | class CodingTrainPurpleRainScreen extends StatefulWidget { 8 | const CodingTrainPurpleRainScreen({ 9 | Key? key, 10 | required this.sketchDemoController, 11 | }) : super(key: key); 12 | 13 | final SketchDemoController sketchDemoController; 14 | 15 | @override 16 | _CodingTrainPurpleRainScreenState createState() => _CodingTrainPurpleRainScreenState(); 17 | } 18 | 19 | class _CodingTrainPurpleRainScreenState extends State { 20 | final _droplets = []; 21 | 22 | Sketch createSketch() { 23 | return Sketch.simple( 24 | setup: (s) { 25 | s 26 | ..size(width: 256, height: 256) 27 | ..background(color: const Color.fromARGB(255, 200, 175, 220)); 28 | 29 | for (int i = 0; i < 100; ++i) { 30 | _droplets.add( 31 | Droplet( 32 | x: s.random(s.width), 33 | y: s.random(-s.height, 0), 34 | z: s.random(1), 35 | length: 20, 36 | ), 37 | ); 38 | } 39 | }, 40 | draw: (s) { 41 | s.background(color: const Color.fromARGB(255, 200, 175, 220)); 42 | 43 | for (final droplet in _droplets) { 44 | droplet 45 | ..fall(s) 46 | ..show(s); 47 | } 48 | }, 49 | ); 50 | } 51 | 52 | @override 53 | Widget build(BuildContext context) { 54 | return ProcessingDemo( 55 | createSketch: createSketch, 56 | sketchDemoController: widget.sketchDemoController, 57 | ); 58 | } 59 | } 60 | 61 | class Droplet { 62 | Droplet({ 63 | required this.x, 64 | required this.y, 65 | required this.z, 66 | required this.length, 67 | }); 68 | 69 | double x; 70 | double y; 71 | double z; 72 | double length; 73 | 74 | void fall(Sketch s) { 75 | y += lerpDouble(8, 20, z)!; 76 | 77 | if (y > s.height) { 78 | y = 0; 79 | z = s.random(1); 80 | } 81 | } 82 | 83 | void show(Sketch s) { 84 | final perspectiveLength = lerpDouble(0.2 * length, length, z)!; 85 | 86 | s 87 | ..stroke(color: const Color.fromARGB(255, 128, 43, 226)) 88 | ..line(Offset(x, y), Offset(x, y + perspectiveLength)); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /test/transform/transform_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:golden_toolkit/golden_toolkit.dart'; 5 | 6 | import '../test_infra.dart'; 7 | 8 | void main() { 9 | group('Transform', () { 10 | processingSpecTest('pushMatrix(): example 1', (tester) async { 11 | await tester.pumpWidget( 12 | Processing( 13 | sketch: Sketch.simple( 14 | draw: (s) { 15 | s 16 | ..size(width: 400, height: 400) 17 | ..noLoop() 18 | ..fill(color: Colors.white) 19 | ..rect(rect: Rect.fromLTWH(0, 0, 200, 200)) 20 | ..pushMatrix() 21 | ..translate(x: 120, y: 80) 22 | ..fill(color: Colors.black) 23 | ..rect(rect: Rect.fromLTWH(0, 0, 200, 200)) 24 | ..popMatrix() 25 | ..fill(color: Color.fromARGB(255, 100, 100, 100)) 26 | ..rect(rect: Rect.fromLTWH(60, 40, 200, 200)); 27 | }, 28 | ), 29 | ), 30 | ); 31 | 32 | await screenMatchesGolden( 33 | tester, 34 | 'transform_pushMatrix_1', 35 | ); 36 | }); 37 | 38 | processingLegacySpecTest('translate(): example 1', (tester) async { 39 | await tester.pumpWidget( 40 | Processing( 41 | sketch: Sketch.simple( 42 | draw: (s) { 43 | s 44 | ..noLoop() 45 | ..translate(x: 30, y: 20) 46 | ..rect(rect: Rect.fromLTWH(0, 0, 55, 55)); 47 | }, 48 | ), 49 | ), 50 | ); 51 | 52 | await screenMatchesGolden( 53 | tester, 54 | 'transform_translate-example-1', 55 | ); 56 | }); 57 | 58 | processingLegacySpecTest('translate(): example 2', (tester) async { 59 | await tester.pumpWidget( 60 | Processing( 61 | sketch: Sketch.simple( 62 | draw: (s) { 63 | s 64 | ..noLoop() 65 | ..rect(rect: Rect.fromLTWH(0, 0, 55, 55)) 66 | ..translate(x: 30, y: 20) 67 | ..rect(rect: Rect.fromLTWH(0, 0, 55, 55)) 68 | ..translate(x: 14, y: 14) 69 | ..rect(rect: Rect.fromLTWH(0, 0, 55, 55)); 70 | }, 71 | ), 72 | ), 73 | ); 74 | 75 | await screenMatchesGolden( 76 | tester, 77 | 'transform_translate-example-2', 78 | ); 79 | }); 80 | }); 81 | } 82 | -------------------------------------------------------------------------------- /test/image/loading_and_displaying_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_test/flutter_test.dart'; 2 | 3 | // TODO: figure out how to get this test to run without doing special 4 | // work before the test. 5 | // - The image data is loaded and cached at the beginning of the test 6 | // - The implementation of s.loadImage() is replicated at the beginning of the test, too 7 | void main() async { 8 | group('Image', () { 9 | group('Loading and Displaying', () { 10 | // TODO: uncomment this test when we figure out how to run an async 11 | // operation in a test 12 | // processingLegacySpecTest('loads and displays image asset', 13 | // (tester) async { 14 | // late FrameInfo frame; 15 | // late ByteData pixels; 16 | // 17 | // await tester.runAsync(() async { 18 | // // The following lines are the same as implementation of 19 | // // s.loadImage(). It's done here because it has to be run 20 | // // within runAsync() to avoid hanging forever. 21 | // final imageData = await TestAssetBundle().load('space_100x.png'); 22 | // 23 | // final codec = await (await ImageDescriptor.encoded( 24 | // await ImmutableBuffer.fromUint8List(imageData.buffer.asUint8List()), 25 | // )) 26 | // .instantiateCodec(); 27 | // 28 | // frame = await codec.getNextFrame(); 29 | // pixels = (await frame.image.toByteData())!; 30 | // }); 31 | // //----- end image prep ------ 32 | // 33 | // PImage loadedImage = PImage.fromPixels( 34 | // frame.image.width, frame.image.height, pixels, ImageFileFormat.png); 35 | // 36 | // await tester.pumpWidget( 37 | // DefaultAssetBundle( 38 | // bundle: TestAssetBundle(), 39 | // child: Processing( 40 | // sketch: Sketch.simple( 41 | // setup: (s) { 42 | // s.noLoop(); 43 | // 44 | // // TODO: load the image here when we figure out how 45 | // // loadedImage = await s.loadImage('space_100x.png'); 46 | // }, 47 | // draw: (s) async { 48 | // await s.image( 49 | // image: loadedImage, 50 | // ); 51 | // }, 52 | // ), 53 | // ), 54 | // ), 55 | // ); 56 | // 57 | // await screenMatchesGolden( 58 | // tester, 'image_loading-and-display_example-1'); 59 | // }); 60 | }); 61 | }); 62 | } 63 | -------------------------------------------------------------------------------- /example/lib/generative_art/solar_storm.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | 4 | /// Adapted from: https://openprocessing.org/sketch/394718 5 | class SolarStormSketch extends Sketch { 6 | static const _particleCount = 1000; 7 | 8 | final _magnetism = 10.0; 9 | final _radius = 1; 10 | final _friction = 0.05; 11 | 12 | final _particles = <_Particle>[]; 13 | 14 | @override 15 | void setup() { 16 | size(width: 800, height: 800); 17 | 18 | background(color: Colors.black); 19 | 20 | for (var i = 0; i < _particleCount; i++) { 21 | _particles.add( 22 | _Particle(position: PVector(random(width), random(height))), 23 | ); 24 | } 25 | } 26 | 27 | @override 28 | Future draw() async { 29 | noStroke(); 30 | blendMode = BlendMode.plus; 31 | 32 | for (var i = 0; i < _particles.length; i++) { 33 | final particle = _particles[i]; 34 | 35 | final distanceToMouse = dist( 36 | Offset(mouseX.toDouble(), mouseY.toDouble()), 37 | particle.position.toOffset(), 38 | ); 39 | 40 | if (distanceToMouse > 3) { 41 | particle.acceleration = PVector( 42 | _magnetism * (mouseX - particle.position.x) / (distanceToMouse * distanceToMouse), 43 | _magnetism * (mouseY - particle.position.y) / (distanceToMouse * distanceToMouse), 44 | ); 45 | } 46 | 47 | particle 48 | ..applyAcceleration() 49 | ..applyFrictionPercent(_friction) 50 | ..move(); 51 | 52 | var speed = particle.velocity.mag; 53 | var r = map(speed, 0, 5, 0, 255).toInt(); 54 | var g = map(speed, 0, 5, 64, 255).toInt(); 55 | var b = map(speed, 0, 5, 128, 255).toInt(); 56 | fill(color: Color.fromARGB(32, r, g, b)); 57 | 58 | if (particle.isInWindow(width, height)) { 59 | circle(center: particle.position.toOffset(), diameter: 2.0 * _radius); 60 | } 61 | } 62 | } 63 | } 64 | 65 | class _Particle { 66 | _Particle({ 67 | required this.position, 68 | }) : velocity = PVector(0, 0), 69 | acceleration = PVector(0, 0); 70 | 71 | PVector position; 72 | PVector velocity; 73 | PVector acceleration; 74 | 75 | void move() { 76 | position = position + velocity; 77 | } 78 | 79 | void applyAcceleration() { 80 | velocity = velocity + acceleration; 81 | } 82 | 83 | void applyFrictionPercent(double percent) { 84 | velocity = velocity * (1.0 - percent); 85 | } 86 | 87 | bool isInWindow(num width, num height) { 88 | return position.x >= 0 && position.x < width && position.y >= 0 && position.y < height; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /test/math/trigonometry_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter_processing/flutter_processing.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | import 'package:golden_toolkit/golden_toolkit.dart'; 6 | 7 | import '../test_infra.dart'; 8 | 9 | void main() { 10 | group('Math', () { 11 | group('trigonometry', () { 12 | processingLegacySpecTest('sin()', (tester) async { 13 | await tester.pumpWidget( 14 | Processing( 15 | sketch: Sketch.simple( 16 | draw: (s) { 17 | s.noLoop(); 18 | 19 | double angleInRadians = 0.0; 20 | double increment = s.TWO_PI / 25.0; 21 | 22 | for (double i = 0; i < 100; i = i + 4) { 23 | s.line(Offset(i, 50), Offset(i, 50 + sin(angleInRadians) * 40.0)); 24 | angleInRadians = angleInRadians + increment; 25 | } 26 | }, 27 | ), 28 | ), 29 | ); 30 | 31 | await screenMatchesGolden( 32 | tester, 33 | 'math_trigonometry_sin', 34 | ); 35 | }); 36 | 37 | processingLegacySpecTest('cos()', (tester) async { 38 | await tester.pumpWidget( 39 | Processing( 40 | sketch: Sketch.simple( 41 | draw: (s) { 42 | s.noLoop(); 43 | 44 | double angle = 0.0; 45 | double increment = s.TWO_PI / 25.0; 46 | 47 | for (double i = 0; i < 25; i++) { 48 | s.line(Offset(i * 4, 50), Offset(i * 4, 50 + cos(angle) * 40.0)); 49 | angle = angle + increment; 50 | } 51 | }, 52 | ), 53 | ), 54 | ); 55 | 56 | await screenMatchesGolden( 57 | tester, 58 | 'math_trigonometry_cos', 59 | ); 60 | }); 61 | 62 | processingLegacySpecTest('tan()', (tester) async { 63 | await tester.pumpWidget( 64 | Processing( 65 | sketch: Sketch.simple( 66 | draw: (s) { 67 | s.noLoop(); 68 | 69 | double angleInRadians = 0.0; 70 | double increment = s.TWO_PI / 50.0; 71 | 72 | for (double i = 0; i < 100; i = i + 2) { 73 | s.line(Offset(i, 50), Offset(i, 50 + tan(angleInRadians) * 2.0)); 74 | angleInRadians = angleInRadians + increment; 75 | } 76 | }, 77 | ), 78 | ), 79 | ); 80 | 81 | await screenMatchesGolden( 82 | tester, 83 | 'math_trigonometry_tan', 84 | ); 85 | }); 86 | }); 87 | }); 88 | } 89 | -------------------------------------------------------------------------------- /example/lib/the_coding_train/coding_challenges/036_blobby.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | import 'package:flutter_processing_example/_processing_demo_sketch_display.dart'; 4 | 5 | class CodingTrainBlobbyScreen extends StatefulWidget { 6 | const CodingTrainBlobbyScreen({ 7 | Key? key, 8 | required this.sketchDemoController, 9 | }) : super(key: key); 10 | 11 | final SketchDemoController sketchDemoController; 12 | 13 | @override 14 | _CodingTrainBlobbyScreenState createState() => _CodingTrainBlobbyScreenState(); 15 | } 16 | 17 | class _CodingTrainBlobbyScreenState extends State { 18 | @override 19 | Widget build(BuildContext context) { 20 | return ProcessingDemo( 21 | sketchDemoController: widget.sketchDemoController, 22 | createSketch: () { 23 | return _BlobbySketch(); 24 | }, 25 | ); 26 | } 27 | } 28 | 29 | class _BlobbySketch extends Sketch { 30 | @override 31 | void setup() { 32 | size(width: 500, height: 500); 33 | } 34 | 35 | @override 36 | void draw() { 37 | background(color: Colors.white); 38 | fill(color: Colors.black); 39 | 40 | const angularSteps = 64; 41 | final stepAngle = TWO_PI / angularSteps; 42 | const radius = 100; 43 | 44 | translate(x: width / 2, y: height / 2); 45 | beginShape(); 46 | for (int i = 0; i < angularSteps; i += 1) { 47 | final angle = i * stepAngle; 48 | final vertexPosition = PVector( 49 | radius * cos(angle), 50 | radius * sin(angle), 51 | ); 52 | 53 | final vertexOffset = _chooseVertexOffset(index: i, stepCount: angularSteps, angle: angle); 54 | vertexPosition.mag = vertexPosition.mag + vertexOffset; 55 | 56 | vertex(vertexPosition.x, vertexPosition.y); 57 | } 58 | endShape(close: true); 59 | } 60 | 61 | num _chooseVertexOffset({ 62 | required int index, 63 | required int stepCount, 64 | required num angle, 65 | }) { 66 | // return _randomOffset(); 67 | 68 | // return _waveOffset( 69 | // percent: index / stepCount, 70 | // cycles: 5, 71 | // ); 72 | 73 | return _perlineNoise(percent: index / stepCount, offset: frameCount / 1); 74 | } 75 | 76 | num _randomOffset() => random(10); 77 | 78 | num _waveOffset({required num percent, required int cycles}) { 79 | return 30 * sin(percent * TWO_PI * cycles); 80 | } 81 | 82 | num _perlineNoise({required num percent, required num offset}) { 83 | final noiseValue = noise( 84 | x: 1000 * cos(TWO_PI * percent), 85 | y: 1000 * sin(TWO_PI * percent), 86 | z: offset.toDouble(), 87 | ); 88 | 89 | return noiseValue * 30 - 15; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /test/random/random_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_processing/flutter_processing.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | import 'package:golden_toolkit/golden_toolkit.dart'; 7 | 8 | import '../test_infra.dart'; 9 | 10 | void main() { 11 | group('Random', () { 12 | testWidgets('random()', (tester) async { 13 | await tester.pumpWidget( 14 | Processing( 15 | sketch: Sketch.simple( 16 | draw: (s) { 17 | s 18 | ..noLoop() 19 | ..randomSeed(0); 20 | 21 | // with upper bound 22 | double randomValue = s.random(50); 23 | expect(randomValue, 41.27570359435851); 24 | 25 | // with lower and upper bound 26 | randomValue = s.random(-50, 50); 27 | expect(randomValue, 38.63148172405516); 28 | 29 | // with a lower bound that is larger than upper bound 30 | expect(() => s.random(10, 5), throwsException); 31 | }, 32 | ), 33 | ), 34 | ); 35 | }); 36 | 37 | processingLegacySpecTest('randomGaussian() - vertical distribution', (tester) async { 38 | await tester.pumpWidget( 39 | Processing( 40 | sketch: Sketch.simple( 41 | draw: (s) { 42 | s 43 | ..noLoop() 44 | ..randomSeed(0); 45 | 46 | for (int y = 0; y < 100; y++) { 47 | final x = s.randomGaussian() * 15; 48 | s.line(Offset(50, y.toDouble()), Offset(50.0 + x, y.toDouble())); 49 | } 50 | }, 51 | ), 52 | ), 53 | ); 54 | 55 | await screenMatchesGolden(tester, 'random_gaussian_example-1'); 56 | }); 57 | 58 | processingLegacySpecTest('randomGaussian() - radial distribution', (tester) async { 59 | await tester.pumpWidget( 60 | Processing( 61 | sketch: Sketch.simple( 62 | draw: (s) { 63 | s 64 | ..noLoop() 65 | ..randomSeed(0) 66 | ..translate(x: s.width / 2, y: s.height / 2) 67 | ..stroke(color: Colors.black); 68 | 69 | final distribution = List.generate(360, (index) { 70 | return s.randomGaussian() * 15; 71 | }); 72 | 73 | for (int i = 0; i < distribution.length; i++) { 74 | s.rotate(2 * pi / distribution.length); 75 | final dist = distribution[i].abs(); 76 | s.line(Offset(0, 0), Offset(dist, 0)); 77 | } 78 | }, 79 | ), 80 | ), 81 | ); 82 | 83 | await screenMatchesGolden(tester, 'random_gaussian_example-2'); 84 | }); 85 | }); 86 | } 87 | -------------------------------------------------------------------------------- /example/lib/the_coding_train/coding_challenges/028_metaballs.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_processing/flutter_processing.dart'; 5 | 6 | class MetaBallsSketch extends Sketch { 7 | final _blobCount = 6; 8 | final _blobRadius = 30.0; 9 | final _blobSpeed = 5.0; 10 | 11 | final _blobs = []; 12 | 13 | @override 14 | void setup() { 15 | size(width: 400, height: 400); 16 | 17 | for (int i = 0; i < _blobCount; i += 1) { 18 | _blobs.add( 19 | Blob( 20 | offset: Offset(random(width), random(height)), 21 | velocity: Offset.fromDirection(random(2 * pi), _blobSpeed), 22 | radius: _blobRadius, 23 | ), 24 | ); 25 | } 26 | } 27 | 28 | @override 29 | Future draw() async { 30 | background(color: Colors.black); 31 | 32 | await loadPixels(); 33 | 34 | for (int col = 0; col < width; col += 1) { 35 | for (int row = 0; row < height; row += 1) { 36 | double sum = 0; 37 | for (final blob in _blobs) { 38 | final distance = (Offset(col.toDouble(), row.toDouble()) - blob.offset).distance; 39 | 40 | // Add to brightness 41 | sum += 0.75 * blob._radius / distance; 42 | 43 | // Colors 44 | // sum += 50 * blob.radius / distance; 45 | } 46 | 47 | // Brightness 48 | set(x: col, y: row, color: HSVColor.fromAHSV(1.0, 0.0, 0.0, sum.clamp(0.0, 1.0)).toColor()); 49 | 50 | // Colors 51 | // set(x: col, y: row, color: HSVColor.fromAHSV(1.0, sum % 360, 1.0, 1.0).toColor()); 52 | } 53 | } 54 | 55 | await updatePixels(); 56 | 57 | final screenSize = Size(width.toDouble(), height.toDouble()); 58 | for (final blob in _blobs) { 59 | blob.move(screenSize); 60 | // blob.paint(this); 61 | } 62 | } 63 | } 64 | 65 | class Blob { 66 | Blob({ 67 | required Offset offset, 68 | required Offset velocity, 69 | required double radius, 70 | }) : _offset = offset, 71 | _velocity = velocity, 72 | _radius = radius; 73 | 74 | Offset _offset; 75 | Offset get offset => _offset; 76 | 77 | Offset _velocity; 78 | 79 | final double _radius; 80 | double get radius => _radius; 81 | 82 | void move(Size screenSize) { 83 | if (_offset.dx <= 0 || _offset.dx >= screenSize.width) { 84 | _velocity = Offset(-_velocity.dx, _velocity.dy); 85 | } 86 | if (_offset.dy <= 0 || _offset.dy >= screenSize.height) { 87 | _velocity = Offset(_velocity.dx, -_velocity.dy); 88 | } 89 | 90 | _offset += _velocity; 91 | } 92 | 93 | void paint(Sketch s) { 94 | s 95 | ..strokeWeight(2) 96 | ..stroke(color: Colors.white) 97 | ..noFill() 98 | ..circle(center: _offset, diameter: _radius * 2); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /example/lib/generative_art/network.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | 4 | class NetworkSketch extends Sketch { 5 | static const _nodeCount = 75; 6 | static const _maxSpeed = 0.75; 7 | static const _minDiameter = 10; 8 | static const _maxDiameter = 50; 9 | static const _maxEdgeLength = 200; 10 | static const _maxEdgeWidth = 5; 11 | static const _nodeColor = Colors.purpleAccent; 12 | static final _edgeColor = Colors.deepPurple.withOpacity(0.2); 13 | 14 | final _nodes = <_Node>[]; 15 | 16 | @override 17 | void setup() { 18 | size(width: 1000, height: 800); 19 | 20 | for (int i = 0; i < _nodeCount; i += 1) { 21 | _nodes.add(_Node( 22 | position: PVector( 23 | random(0, width), 24 | random(0, height), 25 | ), 26 | velocity: PVector.random2D() * _maxSpeed, 27 | diameter: random(_minDiameter, _maxDiameter), 28 | )); 29 | } 30 | } 31 | 32 | @override 33 | void draw() { 34 | background(color: const Color(0xFF333333)); 35 | 36 | stroke(color: _edgeColor); 37 | for (final node1 in _nodes) { 38 | for (final node2 in _nodes) { 39 | final distance = node1.position.dist(node2.position); 40 | if (distance < _maxEdgeLength) { 41 | final edgeThickness = map(distance, 0, _maxEdgeLength, _maxEdgeWidth, 0).toDouble(); 42 | strokeWeight(edgeThickness); 43 | line(node1.position.toOffset(), node2.position.toOffset()); 44 | } 45 | } 46 | } 47 | 48 | noStroke(); 49 | for (final node in _nodes) { 50 | fill( 51 | color: HSVColor.fromColor(_nodeColor) 52 | .withValue( 53 | map(node.diameter, _minDiameter, _maxDiameter, 0.9, 0.5).toDouble(), 54 | ) 55 | .toColor()); 56 | circle(center: node.position.toOffset(), diameter: node.diameter); 57 | 58 | node.move(); 59 | if (node.left > width) { 60 | node.position = PVector(-node.diameter / 2, node.position.y); 61 | } 62 | if (node.right < 0) { 63 | node.position = PVector(width + (node.diameter / 2), node.position.y); 64 | } 65 | if (node.top > height) { 66 | node.position = PVector(node.position.x, -node.diameter / 2); 67 | } 68 | if (node.bottom < 0) { 69 | node.position = PVector(node.position.x, height + (node.diameter / 2)); 70 | } 71 | } 72 | } 73 | } 74 | 75 | class _Node { 76 | _Node({ 77 | required this.position, 78 | required PVector velocity, 79 | required this.diameter, 80 | }) : _velocity = velocity; 81 | 82 | PVector position; 83 | 84 | double get left => position.x - (diameter / 2); 85 | double get right => position.x + (diameter / 2); 86 | double get top => position.y - (diameter / 2); 87 | double get bottom => position.y + (diameter / 2); 88 | 89 | final PVector _velocity; 90 | 91 | final double diameter; 92 | 93 | void move() { 94 | position += _velocity; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /test/test_infra.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:io'; 3 | 4 | import 'package:flutter/rendering.dart'; 5 | import 'package:flutter/services.dart'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | import 'package:golden_toolkit/golden_toolkit.dart'; 8 | 9 | /// Golden test that paints to a 400x400 px canvas, just like 10 | /// images in the official Processing reference from after 11 | /// Aug, 2021. 12 | /// 13 | /// See [processingLegacySpecTest] for testing reference images 14 | /// from before Aug, 2021. 15 | void processingSpecTest(String description, Future Function(WidgetTester) test) { 16 | testGoldens(description, (tester) async { 17 | tester.view 18 | ..physicalSize = Size(400, 400) 19 | ..devicePixelRatio = 1.0; 20 | 21 | await test(tester); 22 | 23 | tester.platformDispatcher.clearAllTestValues(); 24 | }); 25 | } 26 | 27 | /// Golden test that paints to a 100x100 px canvas, just like 28 | /// images in the official Processing reference from before 29 | /// Aug, 2021. 30 | /// 31 | /// See [processingSpecTest] for testing reference images from 32 | /// after Aug, 2021. 33 | void processingLegacySpecTest(String description, Future Function(WidgetTester) test) { 34 | testGoldens(description, (tester) async { 35 | // All the legacy Processing reference examples (before Aug 2021) 36 | // were 100x100 px. 37 | tester.view 38 | ..physicalSize = const Size(100, 100) 39 | ..devicePixelRatio = 1.0; 40 | 41 | await test(tester); 42 | 43 | tester.platformDispatcher.clearAllTestValues(); 44 | }); 45 | } 46 | 47 | class TestAssetBundle implements AssetBundle { 48 | static Map _cache = {}; 49 | 50 | /// [filepath] is relative to the "/test/assets/" directory. 51 | @override 52 | Future load(String filename) async { 53 | if (_cache.containsKey(filename)) { 54 | return _cache[filename]!; 55 | } 56 | 57 | final file = File('test/assets/$filename'); 58 | final fileData = await file.readAsBytes(); 59 | _cache[filename] = ByteData.view(fileData.buffer); 60 | 61 | return _cache[filename]!; 62 | } 63 | 64 | @override 65 | Future loadString(String key, {bool cache = true}) { 66 | // TODO: implement loadString 67 | throw UnimplementedError(); 68 | } 69 | 70 | @override 71 | Future loadStructuredData(String key, Future Function(String value) parser) { 72 | // TODO: implement loadStructuredData 73 | throw UnimplementedError(); 74 | } 75 | 76 | @override 77 | void evict(String key) { 78 | _cache.remove(key); 79 | } 80 | 81 | @override 82 | void clear() { 83 | _cache.clear(); 84 | } 85 | 86 | @override 87 | Future loadBuffer(String key) { 88 | // TODO: implement loadBuffer 89 | throw UnimplementedError(); 90 | } 91 | 92 | @override 93 | Future loadStructuredBinaryData(String key, FutureOr Function(ByteData data) parser) { 94 | // TODO: implement loadStructuredBinaryData 95 | throw UnimplementedError(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flutter Processing 2 | 3 | A Flutter port of [Processing](https://processing.org/reference/). 4 | 5 | This project is not affiliated with the Processing project, or related organizations. 6 | 7 | The goal of `flutter_processing` is to provide the same easy learning environment as **Processing**, but with the additional utility of a production-ready UI toolkit, called **Flutter**. With traditional Processing, there is minimal professional value in the underlying language. With `flutter_processing`, the underlying tool, Flutter, is sufficient for employment as an app UI developer. `flutter_processing` offers an educational tool and an employment opportunity all in one. 8 | 9 | Want to see how this project was implemented? Nearly every change was recorded and published to the [SuperDeclarative!](https://youtube.com/c/SuperDeclarative) channel on YouTube. 10 | 11 | To see which Processing APIs have been ported to Flutter, see the [API Checklist](README_API_CHECKLIST.md). 12 | 13 | --- 14 | 15 | Do you get value from this package? Please consider supporting SuperDeclarative! 16 | 17 | 18 | 19 | --- 20 | 21 | # Getting Started 22 | To play with some demos, clone this repository and run the example app! 23 | 24 | 25 | 26 | To paint a canvas with a sketch in Flutter, the way you would in Processing, display a `Processing` widget and implement a `Sketch`. 27 | 28 | ```dart 29 | void main() { 30 | runApp( 31 | MaterialApp( 32 | home: Processing( 33 | sketch: Sketch.simple( 34 | setup: (sketch) async { 35 | // TODO: do your typical Sketch setup 36 | // stuff here. Call methods on 37 | // the provided sketch object. 38 | }, 39 | draw: (sketch) async { 40 | // TODO: do your typical Sketch drawing 41 | // stuff here. Call methods on 42 | // the provided sketch object. 43 | }, 44 | ), 45 | ), 46 | ), 47 | ); 48 | } 49 | ``` 50 | 51 | To retain and access variables in your `Sketch`, or to implement a `Sketch` in a more traditional way, subclass `Sketch`: 52 | ```dart 53 | void main() { 54 | runApp( 55 | MaterialApp( 56 | home: Processing( 57 | sketch: MySketch(), 58 | ), 59 | ), 60 | ); 61 | } 62 | 63 | class MySketch extends Sketch { 64 | @override 65 | Future setup() async { 66 | // TODO: do setup stuff here 67 | } 68 | 69 | @override 70 | Future draw() async { 71 | // TODO: do drawing stuff here 72 | } 73 | } 74 | ``` 75 | 76 | # Get Involved 77 | If you create anything cool, be sure to post it to Twitter and tag [@SuprDeclarative](https://twitter.com/SuprDeclarative) and [@FlutterDev](https://twitter.com/FlutterDev)! 78 | 79 | If you need something implemented, or you find a bug, please checkout the [Contributing Guide](CONTRIBUTING.md) and then file an issue in the GitHub project. 80 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /example/lib/api_demos/_image_blending_sketch.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart' hide Image; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | import 'package:flutter_processing_example/_processing_demo_sketch_display.dart'; 4 | 5 | class ImageBlendSketchDemo extends StatefulWidget { 6 | const ImageBlendSketchDemo({ 7 | Key? key, 8 | required this.sketchDemoController, 9 | }) : super(key: key); 10 | 11 | final SketchDemoController sketchDemoController; 12 | 13 | @override 14 | _ImageBlendSketchDemoState createState() => _ImageBlendSketchDemoState(); 15 | } 16 | 17 | class _ImageBlendSketchDemoState extends State { 18 | late PImage _image1; 19 | late PImage _image2; 20 | late PImage _image3; 21 | 22 | @override 23 | Widget build(BuildContext context) { 24 | return ProcessingDemo( 25 | createSketch: createSketch, 26 | sketchDemoController: widget.sketchDemoController, 27 | ); 28 | } 29 | 30 | Sketch createSketch() { 31 | return Sketch.simple( 32 | setup: (s) async { 33 | s.size(width: 500, height: 500); 34 | s.background(color: const Color(0xFFFFFFFF)); 35 | 36 | _image1 = await s.loadImage("assets/coffee.png"); 37 | _image2 = await s.loadImage("assets/audio-mixer.png"); 38 | _image3 = _image1.copy(); 39 | 40 | _image1.blend( 41 | _image1, 42 | sourceRect: 43 | Rect.fromLTRB(_image1.width.toDouble() / 2, 0, _image1.width.toDouble(), _image1.height.toDouble() / 2), 44 | destRect: 45 | Rect.fromLTRB(_image1.width.toDouble() / 2, 0, _image1.width.toDouble(), _image1.height.toDouble() / 2), 46 | mode: SketchBlendMode.add, 47 | ); 48 | _image1.blend( 49 | _image2, 50 | sourceRect: Rect.fromLTRB( 51 | _image1.width.toDouble() / 2, 52 | _image1.height.toDouble() / 2, 53 | _image1.width.toDouble(), 54 | _image1.height.toDouble(), 55 | ), 56 | destRect: Rect.fromLTRB( 57 | _image1.width.toDouble() / 2, 58 | _image1.height.toDouble() / 2, 59 | _image1.width.toDouble(), 60 | _image1.height.toDouble(), 61 | ), 62 | mode: SketchBlendMode.screen, 63 | ); 64 | _image1.blend( 65 | _image2, 66 | sourceRect: Rect.fromLTRB( 67 | 0, 68 | _image1.height.toDouble() / 2, 69 | _image1.width.toDouble() / 2, 70 | _image1.height.toDouble(), 71 | ), 72 | destRect: Rect.fromLTRB( 73 | 0, 74 | 0, 75 | _image1.width.toDouble() / 2, 76 | _image1.height.toDouble() / 2, 77 | ), 78 | mode: SketchBlendMode.screen, 79 | ); 80 | 81 | // _image3.filter(ImageFilter.threshold, 0.5); 82 | // _image3.filter(ImageFilter.gray); 83 | // _image3.filter(ImageFilter.invert); 84 | // _image3.filter(ImageFilter.posterize, 4); 85 | _image3.filter(ImageFilter.erode); 86 | // _image3.filter(ImageFilter.dilate); 87 | }, 88 | draw: (s) async { 89 | await s.image(image: _image1); 90 | await s.image(image: _image3, origin: Offset(_image3.width + 10, 0)); 91 | // await s.pImage(image: _image2, origin: Offset(200, 200)); 92 | }, 93 | ); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /example/lib/the_coding_train/coding_challenges/006_mitosis_simulation.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_processing/flutter_processing.dart'; 5 | import 'package:flutter_processing_example/_processing_demo_sketch_display.dart'; 6 | 7 | class CodingTrainMitosisScreen extends StatefulWidget { 8 | const CodingTrainMitosisScreen({ 9 | Key? key, 10 | required this.sketchDemoController, 11 | }) : super(key: key); 12 | 13 | final SketchDemoController sketchDemoController; 14 | 15 | @override 16 | _CodingTrainMitosisScreenState createState() => _CodingTrainMitosisScreenState(); 17 | } 18 | 19 | class _CodingTrainMitosisScreenState extends State { 20 | final _cells = []; 21 | 22 | Sketch createSketch() { 23 | return Sketch.simple( 24 | setup: (s) { 25 | s.size(width: 512, height: 512); 26 | 27 | for (int i = 0; i < 10; ++i) { 28 | _cells.add(Cell.randomLocationAndColor(s.width, s.height)); 29 | } 30 | }, 31 | draw: (s) { 32 | s.background(color: const Color.fromARGB(255, 200, 200, 200)); 33 | 34 | for (final cell in _cells) { 35 | cell.move(); 36 | cell.show(s); 37 | } 38 | }, 39 | mouseClicked: (s) { 40 | final newCells = []; 41 | final oldCells = []; 42 | 43 | for (final cell in _cells) { 44 | if (cell.containsPoint(s.mouseX.toDouble(), s.mouseY.toDouble())) { 45 | cell.containsPoint(s.mouseX.toDouble(), s.mouseY.toDouble()); 46 | newCells.add(cell.mitosis()); 47 | newCells.add(cell.mitosis()); 48 | 49 | oldCells.add(cell); 50 | } 51 | } 52 | 53 | // Remove "dead" cells 54 | _cells.removeWhere((element) => oldCells.contains(element)); 55 | 56 | // Add new cells 57 | _cells.addAll(newCells); 58 | }, 59 | ); 60 | } 61 | 62 | @override 63 | Widget build(BuildContext context) { 64 | return ProcessingDemo( 65 | createSketch: createSketch, 66 | sketchDemoController: widget.sketchDemoController, 67 | ); 68 | } 69 | } 70 | 71 | class Cell { 72 | factory Cell.randomLocationAndColor(int width, int height) { 73 | final random = Random(); 74 | return Cell( 75 | position: Offset(random.nextDouble() * width, random.nextDouble() * height), 76 | radius: 60, 77 | color: Color.fromARGB(100, random.nextInt(155) + 100, 0, random.nextInt(155) + 100), 78 | ); 79 | } 80 | 81 | Cell({ 82 | required this.position, 83 | required this.radius, 84 | required this.color, 85 | }); 86 | 87 | Offset position; 88 | final double radius; 89 | final Color color; 90 | 91 | bool containsPoint(double x, double y) { 92 | final distance = (position - Offset(x, y)).distance; 93 | return distance <= radius; 94 | } 95 | 96 | void move() { 97 | final randomAngle = Random().nextDouble() * 2 * pi; 98 | position += Offset.fromDirection(randomAngle, 3); 99 | } 100 | 101 | void show(Sketch s) { 102 | s 103 | ..noStroke() 104 | ..fill(color: color) 105 | ..circle(center: position, diameter: radius * 2); 106 | } 107 | 108 | Cell mitosis() { 109 | return Cell( 110 | position: position, 111 | radius: radius * 0.8, 112 | color: color, 113 | ); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /test/complex_shapes_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:ui'; 2 | 3 | import 'package:flutter_processing/flutter_processing.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | import 'package:golden_toolkit/golden_toolkit.dart'; 6 | 7 | void main() { 8 | group('Complex shapes', () { 9 | testGoldens('stars', (tester) async { 10 | tester.view 11 | ..physicalSize = Size(640, 360) 12 | ..devicePixelRatio = 1.0; 13 | 14 | await tester.pumpWidget( 15 | Processing( 16 | sketch: StarsSketch(), 17 | ), 18 | ); 19 | 20 | await screenMatchesGolden(tester, 'complex-shapes_stars'); 21 | 22 | tester.platformDispatcher.clearAllTestValues(); 23 | }); 24 | 25 | testGoldens('triangle strip circle', (tester) async { 26 | tester.view 27 | ..physicalSize = Size(640, 360) 28 | ..devicePixelRatio = 1.0; 29 | 30 | await tester.pumpWidget( 31 | Processing( 32 | sketch: TriangleStripCircleSketch(), 33 | ), 34 | ); 35 | 36 | await screenMatchesGolden(tester, 'complex-shapes_triangle-strip-circle'); 37 | 38 | tester.platformDispatcher.clearAllTestValues(); 39 | }); 40 | }); 41 | } 42 | 43 | /// Adapted from: https://processing.org/examples/star.html 44 | class StarsSketch extends Sketch { 45 | @override 46 | void setup() { 47 | size(width: 640, height: 360); 48 | } 49 | 50 | @override 51 | void draw() { 52 | noLoop(); 53 | 54 | pushMatrix(); 55 | translate(x: width * 0.2, y: height * 0.5); 56 | star(0, 0, 5, 70, 3); 57 | popMatrix(); 58 | 59 | pushMatrix(); 60 | translate(x: width * 0.5, y: height * 0.5); 61 | star(0, 0, 80, 100, 40); 62 | popMatrix(); 63 | 64 | pushMatrix(); 65 | translate(x: width * 0.8, y: height * 0.5); 66 | star(0, 0, 30, 70, 5); 67 | popMatrix(); 68 | } 69 | 70 | void star(double x, double y, double radius1, double radius2, int npoints) { 71 | final angle = TWO_PI / npoints; 72 | final halfAngle = angle / 2.0; 73 | beginShape(); 74 | for (double a = 0; a < TWO_PI; a += angle) { 75 | double sx = x + cos(a) * radius2; 76 | double sy = y + sin(a) * radius2; 77 | vertex(sx, sy); 78 | 79 | sx = x + cos(a + halfAngle) * radius1; 80 | sy = y + sin(a + halfAngle) * radius1; 81 | vertex(sx, sy); 82 | } 83 | endShape(close: true); 84 | } 85 | } 86 | 87 | /// Adapted from: https://processing.org/examples/trianglestrip.html 88 | class TriangleStripCircleSketch extends Sketch { 89 | @override 90 | void setup() { 91 | size(width: 640, height: 360); 92 | } 93 | 94 | @override 95 | void draw() { 96 | noLoop(); 97 | 98 | final x = width / 2; 99 | final y = height / 2; 100 | final outsideRadius = 150; 101 | final insideRadius = 100; 102 | 103 | int numPoints = 30; 104 | double angle = 0; 105 | final angleStep = 180.0 / numPoints; 106 | 107 | beginShape(ShapeMode.triangleStrip); 108 | for (int i = 0; i <= numPoints; i++) { 109 | double px = x + cos(radians(angle)) * outsideRadius; 110 | double py = y + sin(radians(angle)) * outsideRadius; 111 | angle += angleStep; 112 | vertex(px, py); 113 | px = x + cos(radians(angle)) * insideRadius; 114 | py = y + sin(radians(angle)) * insideRadius; 115 | vertex(px, py); 116 | angle += angleStep; 117 | } 118 | endShape(); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /test/input/keyboard_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/services.dart'; 2 | import 'package:flutter/widgets.dart'; 3 | import 'package:flutter_processing/flutter_processing.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | 6 | void main() { 7 | group('Input', () { 8 | group('Keyboard', () { 9 | testWidgets('keypress lifecycle', (tester) async { 10 | LogicalKeyboardKey? key; 11 | bool isKeyPressed = false; 12 | int keyPressedCallCount = 0; 13 | int keyReleasedCallCount = 0; 14 | 15 | final focusNode = FocusNode(); 16 | focusNode.requestFocus(); 17 | 18 | await tester.pumpWidget( 19 | Processing( 20 | focusNode: focusNode, 21 | sketch: Sketch.simple( 22 | draw: (s) { 23 | s.noLoop(); 24 | }, 25 | keyPressed: (s) { 26 | keyPressedCallCount += 1; 27 | isKeyPressed = s.isKeyPressed; 28 | key = s.key; 29 | }, 30 | keyReleased: (s) { 31 | keyReleasedCallCount += 1; 32 | isKeyPressed = s.isKeyPressed; 33 | key = s.key; 34 | }, 35 | ), 36 | ), 37 | ); 38 | 39 | await tester.sendKeyDownEvent(LogicalKeyboardKey.keyA); 40 | await tester.pumpAndSettle(); 41 | 42 | expect(keyPressedCallCount, 1); 43 | expect(isKeyPressed, true); 44 | expect(key, LogicalKeyboardKey.keyA); 45 | expect(keyReleasedCallCount, 0); 46 | 47 | await tester.sendKeyUpEvent(LogicalKeyboardKey.keyA); 48 | await tester.pumpAndSettle(); 49 | 50 | expect(keyPressedCallCount, 1); 51 | expect(keyReleasedCallCount, 1); 52 | expect(isKeyPressed, false); 53 | expect(key, LogicalKeyboardKey.keyA); 54 | }); 55 | 56 | testWidgets('keyTyped invoked for non-control key', (tester) async { 57 | int keyTypedCallCount = 0; 58 | 59 | final focusNode = FocusNode(); 60 | focusNode.requestFocus(); 61 | 62 | await tester.pumpWidget( 63 | Processing( 64 | focusNode: focusNode, 65 | sketch: Sketch.simple( 66 | draw: (s) { 67 | s.noLoop(); 68 | }, 69 | keyTyped: (s) { 70 | keyTypedCallCount += 1; 71 | }, 72 | ), 73 | ), 74 | ); 75 | 76 | await tester.sendKeyDownEvent(LogicalKeyboardKey.keyA); 77 | await tester.pumpAndSettle(); 78 | 79 | expect(keyTypedCallCount, 1); 80 | }); 81 | 82 | testWidgets('keyTyped NOT invoked for control key', (tester) async { 83 | int keyTypedCallCount = 0; 84 | 85 | final focusNode = FocusNode(); 86 | focusNode.requestFocus(); 87 | 88 | await tester.pumpWidget( 89 | Processing( 90 | focusNode: focusNode, 91 | sketch: Sketch.simple( 92 | draw: (s) { 93 | s.noLoop(); 94 | }, 95 | keyTyped: (s) { 96 | keyTypedCallCount += 1; 97 | }, 98 | ), 99 | ), 100 | ); 101 | 102 | await tester.sendKeyDownEvent(LogicalKeyboardKey.control); 103 | await tester.pumpAndSettle(); 104 | 105 | expect(keyTypedCallCount, 0); 106 | }); 107 | }); 108 | }); 109 | } 110 | -------------------------------------------------------------------------------- /example/lib/the_coding_train/coding_challenges/001_starfield.dart: -------------------------------------------------------------------------------- 1 | import 'dart:ui'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_processing/flutter_processing.dart'; 5 | 6 | import '../../_processing_demo_sketch_display.dart'; 7 | 8 | class CodingTrainStarfieldScreen extends StatefulWidget { 9 | const CodingTrainStarfieldScreen({ 10 | Key? key, 11 | required this.sketchDemoController, 12 | }) : super(key: key); 13 | 14 | final SketchDemoController sketchDemoController; 15 | 16 | @override 17 | _CodingTrainStarfieldScreenState createState() => _CodingTrainStarfieldScreenState(); 18 | } 19 | 20 | class _CodingTrainStarfieldScreenState extends State { 21 | final _stars = []; 22 | 23 | Sketch createSketch() { 24 | return Sketch.simple( 25 | setup: (s) { 26 | s 27 | ..size(width: 512, height: 256) 28 | ..background(color: Colors.black); 29 | 30 | for (int i = 0; i < 100; ++i) { 31 | _stars.add( 32 | Star( 33 | x: s.random(-s.width / 2, s.width / 2), 34 | y: s.random(-s.height / 2, s.height / 2), 35 | z: s.random(s.width), 36 | ), 37 | ); 38 | } 39 | }, 40 | draw: (s) { 41 | s.background(color: Colors.black); 42 | 43 | for (final star in _stars) { 44 | star.update(s); 45 | } 46 | 47 | for (final star in _stars) { 48 | star.paintStreak(s); 49 | } 50 | 51 | for (final star in _stars) { 52 | star.paintStar(s); 53 | } 54 | }, 55 | ); 56 | } 57 | 58 | @override 59 | Widget build(BuildContext context) { 60 | return ProcessingDemo( 61 | createSketch: createSketch, 62 | sketchDemoController: widget.sketchDemoController, 63 | ); 64 | } 65 | } 66 | 67 | class Star { 68 | Star({ 69 | required this.x, 70 | required this.y, 71 | required this.z, 72 | }) : originalZ = 0 { 73 | originalZ = z; 74 | } 75 | 76 | double x; 77 | double y; 78 | double z; 79 | double originalZ; 80 | 81 | void update(Sketch s) { 82 | z -= 30; 83 | originalZ -= 10; 84 | 85 | if (z <= 0) { 86 | x = s.random(-s.width / 2, s.width / 2); 87 | y = s.random(-s.height / 2, s.height / 2); 88 | z = s.random(s.width); 89 | originalZ = z; 90 | } 91 | } 92 | 93 | void paintStreak(Sketch s) { 94 | final center = Offset(s.width / 2, s.height / 2); 95 | 96 | final perspectiveOrigin = Offset( 97 | lerpDouble(0, s.width, x / originalZ)!, 98 | lerpDouble(0, s.height, y / originalZ)!, 99 | ); 100 | final perspectivePosition = Offset( 101 | lerpDouble(0, s.width, x / z)!, 102 | lerpDouble(0, s.height, y / z)!, 103 | ); 104 | 105 | s 106 | ..stroke(color: Colors.white.withOpacity(0.3)) 107 | ..line(perspectiveOrigin + center, perspectivePosition + center); 108 | } 109 | 110 | void paintStar(Sketch s) { 111 | final center = Offset(s.width / 2, s.height / 2); 112 | 113 | final perspectiveOffset = Offset( 114 | lerpDouble(0, s.width, x / z)!, 115 | lerpDouble(0, s.height, y / z)!, 116 | ); 117 | final diameter = lerpDouble(4, 0, z / s.width)!; 118 | 119 | s 120 | ..noStroke() 121 | ..fill(color: Colors.white) 122 | ..circle(center: perspectiveOffset + center, diameter: diameter); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /lib/src/math/_random.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:fast_noise/fast_noise.dart'; 4 | 5 | mixin SketchMathRandom { 6 | Random _random = Random(); 7 | 8 | /// Sets the seed value for all [random()] invocations to the given 9 | /// [seed]. 10 | /// 11 | /// To return to a natural seed value, pass [null] for [seed]. 12 | void randomSeed(int? seed) { 13 | _random = Random(seed); 14 | } 15 | 16 | double random(num bound1, [num? bound2]) { 17 | final lowerBound = bound2 != null ? bound1 : 0; 18 | final upperBound = bound2 != null ? bound2 : bound1; 19 | 20 | if (upperBound < lowerBound) { 21 | throw Exception('random() lower bound must be less than upper bound'); 22 | } 23 | 24 | return _random.nextDouble() * (upperBound - lowerBound) + lowerBound; 25 | } 26 | 27 | int _perlinNoiseSeed = 1337; 28 | int _perlinNoiseOctaves = 4; 29 | double _perlinNoiseFalloff = 0.5; 30 | PerlinFractalNoise? _perlinNoise; 31 | 32 | /// Sets the seed value for all [noise()] invocations to the given 33 | /// [seed]. 34 | /// 35 | /// To return to a natural seed value, pass `null` for [seed]. 36 | void noiseSeed(int? seed) { 37 | _perlinNoiseSeed = seed ?? 1337; 38 | _initializePerlinNoise(); 39 | } 40 | 41 | /// Sets the number of [octaves] and the [falloff] for each octave 42 | /// for values generated by [noise()]. 43 | /// 44 | /// Omitting a value for [octaves] resets the octaves value to the 45 | /// global default. 46 | /// 47 | /// Omitting a value for [falloff] resets the falloff value to the 48 | /// global default. 49 | void noiseDetail({ 50 | int? octaves, 51 | double? falloff, 52 | }) { 53 | _perlinNoiseOctaves = octaves ?? 4; 54 | _perlinNoiseFalloff = falloff ?? 0.5; 55 | 56 | _initializePerlinNoise(); 57 | } 58 | 59 | /// Generates a random value with a Perlin noise algorithm. 60 | /// 61 | /// Returns values are in [-1.0, 1.0]. 62 | double noise({ 63 | required double x, 64 | double y = 0, 65 | double z = 0, 66 | }) { 67 | if (_perlinNoise == null) { 68 | _initializePerlinNoise(); 69 | } 70 | 71 | return _perlinNoise!.getNoise3(x, y, z); 72 | } 73 | 74 | void _initializePerlinNoise() { 75 | _perlinNoise = PerlinFractalNoise( 76 | seed: _perlinNoiseSeed, 77 | octaves: _perlinNoiseOctaves, 78 | gain: _perlinNoiseFalloff, 79 | ); 80 | } 81 | 82 | double? _previousGaussian; 83 | 84 | /// Returns a `double` from a random series of numbers having the given 85 | /// [mean] and the given [standardDeviation]. 86 | /// 87 | /// By default, the [mean] is `0.0`, and the [standardDeviation] is `1`. 88 | double randomGaussian({ 89 | num mean = 0.0, 90 | num standardDeviation = 1.0, 91 | }) { 92 | // The random Gaussian is calculated using the Marsaglia polar method 93 | // which generates TWO independent standard normal random variables, 94 | // so one is stored and used the next time the function is called. 95 | double y1, x1, x2, w; 96 | if (_previousGaussian != null) { 97 | y1 = _previousGaussian!; 98 | _previousGaussian = null; 99 | } else { 100 | do { 101 | x1 = this.random(2) - 1; 102 | x2 = this.random(2) - 1; 103 | w = x1 * x1 + x2 * x2; 104 | } while (w >= 1); 105 | w = sqrt(-2 * log(w) / w); 106 | y1 = x1 * w; 107 | _previousGaussian = x2 * w; 108 | } 109 | 110 | return y1 * standardDeviation + mean; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 64 | 65 | 71 | 73 | 79 | 80 | 81 | 82 | 84 | 85 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /example/lib/the_coding_train/coding_challenges/050_circle-packing.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | 4 | class CirclePackingSketch extends Sketch { 5 | final _newCirclesPerFrame = 100; 6 | final _maxNewCircleAttempts = 100; 7 | 8 | final _circles = []; 9 | 10 | @override 11 | void setup() { 12 | size(width: 800, height: 400); 13 | 14 | _circles.add(Circle(offset: const Offset(400, 200), radius: 1)); 15 | } 16 | 17 | @override 18 | void draw() { 19 | background(color: Colors.black); 20 | 21 | final didFindRoom = _generateNewCircles(); 22 | if (!didFindRoom) { 23 | noLoop(); 24 | } 25 | 26 | final screenSize = Size(width.toDouble(), height.toDouble()); 27 | for (final circle in _circles) { 28 | if (circle.isAgainstEdges(screenSize)) { 29 | circle.stopGrowing(); 30 | } 31 | 32 | if (circle.isGrowing) { 33 | for (final otherCircle in _circles) { 34 | if (otherCircle == circle) { 35 | continue; 36 | } 37 | 38 | if (circle.overlaps(otherCircle)) { 39 | circle.stopGrowing(); 40 | } 41 | } 42 | } 43 | 44 | circle 45 | ..grow() 46 | ..paint(this); 47 | } 48 | } 49 | 50 | /// Generates a group of new circles, if there is room to do so. 51 | /// 52 | /// Returns `true` if new circles were added, or `false` if there 53 | /// wasn't enough room. 54 | bool _generateNewCircles() { 55 | for (int i = 0; i < _newCirclesPerFrame; ++i) { 56 | late Offset randomOffset; 57 | bool overlapsOtherCircle = false; 58 | int attempts = 0; 59 | do { 60 | randomOffset = Offset(random(width), random(height)); 61 | 62 | overlapsOtherCircle = false; 63 | for (final circle in _circles) { 64 | if (circle.contains(randomOffset)) { 65 | overlapsOtherCircle = true; 66 | break; 67 | } 68 | } 69 | 70 | attempts += 1; 71 | if (attempts >= _maxNewCircleAttempts) { 72 | return false; 73 | } 74 | } while (overlapsOtherCircle); 75 | 76 | _circles.add(Circle( 77 | offset: randomOffset, 78 | radius: 1, 79 | )); 80 | } 81 | return true; 82 | } 83 | } 84 | 85 | class Circle { 86 | Circle({ 87 | required Offset offset, 88 | required double radius, 89 | }) : _offset = offset, 90 | _radius = radius; 91 | 92 | final Offset _offset; 93 | double _radius; 94 | 95 | bool _isGrowing = true; 96 | bool get isGrowing => _isGrowing; 97 | 98 | final double _strokeWeight = 2; 99 | 100 | bool isAgainstEdges(Size screenSize) { 101 | final boundaryRect = Rect.fromCircle(center: _offset, radius: _radius); 102 | 103 | return boundaryRect.left <= 0 || 104 | boundaryRect.top <= 0 || 105 | boundaryRect.right >= screenSize.width || 106 | boundaryRect.bottom >= screenSize.height; 107 | } 108 | 109 | bool contains(Offset offset) { 110 | return (offset - _offset).distance <= _radius + _strokeWeight; 111 | } 112 | 113 | bool overlaps(Circle other) { 114 | return (other._offset - _offset).distance <= (other._radius + _radius); 115 | } 116 | 117 | void grow() { 118 | if (_isGrowing) { 119 | _radius += 0.5; 120 | } 121 | } 122 | 123 | void stopGrowing() { 124 | _isGrowing = false; 125 | } 126 | 127 | void paint(Sketch s) { 128 | s 129 | ..strokeWeight(_strokeWeight) 130 | ..stroke(color: Colors.white) 131 | ..fill(color: Colors.black) 132 | ..circle(center: _offset, diameter: _radius * 2); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /example/lib/demos/_filters_sketch.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart' hide Image; 2 | import 'package:flutter_processing/flutter_processing.dart'; 3 | import 'package:flutter_processing_example/_processing_demo_sketch_display.dart'; 4 | 5 | class PImageFiltersSketchDemo extends StatefulWidget { 6 | const PImageFiltersSketchDemo({ 7 | Key? key, 8 | required this.sketchDemoController, 9 | }) : super(key: key); 10 | 11 | final SketchDemoController sketchDemoController; 12 | 13 | @override 14 | _PImageFiltersSketchDemoState createState() => _PImageFiltersSketchDemoState(); 15 | } 16 | 17 | class _PImageFiltersSketchDemoState extends State { 18 | late PImage _canvasImage; 19 | 20 | late PImage _baseImage; 21 | 22 | late PImage _thresholdImage; 23 | late PImage _grayImage; 24 | late PImage _opaqueImage; 25 | late PImage _invertedImage; 26 | late PImage _posterizedImage; 27 | late PImage _blurredImage; 28 | late PImage _erodedImage; 29 | late PImage _dilatedImage; 30 | 31 | Sketch createSketch() { 32 | return Sketch.simple( 33 | setup: (s) async { 34 | s.size(width: 800, height: 400); 35 | s.background(color: const Color(0xFFFFFFFF)); 36 | 37 | _canvasImage = PImage.empty(800, 400, ImageFileFormat.png); 38 | 39 | _baseImage = await s.loadImage("assets/coffee.png"); 40 | // _baseImage.filter(ImageFilter.gray); 41 | 42 | _thresholdImage = _baseImage.copy()..filter(ImageFilter.threshold, 0.5); 43 | _canvasImage.copyFrom( 44 | source: _thresholdImage, 45 | sourceRect: const Rect.fromLTWH(0, 0, 200, 200), 46 | destRect: const Rect.fromLTWH(0, 0, 200, 200), 47 | ); 48 | 49 | _grayImage = _baseImage.copy()..filter(ImageFilter.gray); 50 | _canvasImage.copyFrom( 51 | source: _grayImage, 52 | sourceRect: const Rect.fromLTWH(0, 0, 200, 200), 53 | destRect: const Rect.fromLTWH(200, 0, 200, 200), 54 | ); 55 | 56 | _opaqueImage = _baseImage.copy()..filter(ImageFilter.opaque); 57 | _canvasImage.copyFrom( 58 | source: _opaqueImage, 59 | sourceRect: const Rect.fromLTWH(0, 0, 200, 200), 60 | destRect: const Rect.fromLTWH(400, 0, 200, 200), 61 | ); 62 | 63 | _invertedImage = _baseImage.copy()..filter(ImageFilter.invert); 64 | _canvasImage.copyFrom( 65 | source: _invertedImage, 66 | sourceRect: const Rect.fromLTWH(0, 0, 200, 200), 67 | destRect: const Rect.fromLTWH(600, 0, 200, 200), 68 | ); 69 | 70 | _posterizedImage = _baseImage.copy()..filter(ImageFilter.posterize, 4); 71 | _canvasImage.copyFrom( 72 | source: _posterizedImage, 73 | sourceRect: const Rect.fromLTWH(0, 0, 200, 200), 74 | destRect: const Rect.fromLTWH(0, 200, 200, 200), 75 | ); 76 | 77 | _erodedImage = _baseImage.copy()..filter(ImageFilter.erode); 78 | _canvasImage.copyFrom( 79 | source: _erodedImage, 80 | sourceRect: const Rect.fromLTWH(0, 0, 200, 200), 81 | destRect: const Rect.fromLTWH(400, 200, 200, 200), 82 | ); 83 | 84 | _dilatedImage = _baseImage.copy()..filter(ImageFilter.dilate); 85 | _canvasImage.copyFrom( 86 | source: _dilatedImage, 87 | sourceRect: const Rect.fromLTWH(0, 0, 200, 200), 88 | destRect: const Rect.fromLTWH(600, 200, 200, 200), 89 | ); 90 | }, 91 | draw: (s) async { 92 | await s.image(image: _canvasImage); 93 | 94 | // await s.pImage(image: _opaqueImage); 95 | }, 96 | ); 97 | } 98 | 99 | @override 100 | Widget build(BuildContext context) { 101 | return ProcessingDemo( 102 | createSketch: createSketch, 103 | sketchDemoController: widget.sketchDemoController, 104 | ); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /lib/src/math/_pvector.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'dart:ui'; 4 | 5 | class PVector { 6 | static PVector lerp(PVector start, PVector end, num percent) { 7 | return PVector( 8 | lerpDouble(start.x, end.x, percent.toDouble())!, 9 | lerpDouble(start.y, end.y, percent.toDouble())!, 10 | ); 11 | } 12 | 13 | static num angleBetween(PVector v1, PVector v2) { 14 | return v2.heading - v1.heading; 15 | } 16 | 17 | factory PVector.random2D({int? seed}) { 18 | return PVector.fromAngle(Random(seed).nextDouble() * 2 * pi); 19 | } 20 | 21 | factory PVector.fromAngle(double radians) { 22 | return PVector( 23 | cos(radians), 24 | sin(radians), 25 | ); 26 | } 27 | 28 | factory PVector.deg0() => PVector(1, 0); 29 | factory PVector.deg45() => PVector(sqrt(2) / 2, sqrt(2) / 2); 30 | factory PVector.deg90() => PVector(0, 1); 31 | factory PVector.deg135() => PVector(-sqrt(2) / 2, sqrt(2) / 2); 32 | factory PVector.deg180() => PVector(-1, 0); 33 | factory PVector.deg225() => PVector(-sqrt(2) / 2, -sqrt(2) / 2); 34 | factory PVector.deg270() => PVector(0, -1); 35 | factory PVector.deg315() => PVector(sqrt(2) / 2, -sqrt(2) / 2); 36 | 37 | PVector(this.x, this.y); 38 | 39 | num x; 40 | 41 | num y; 42 | 43 | void set(num x, num y) { 44 | this.x = x; 45 | this.y = y; 46 | } 47 | 48 | PVector operator +(PVector other) { 49 | return PVector(x + other.x, y + other.y); 50 | } 51 | 52 | void add(PVector other) { 53 | x += other.x; 54 | y += other.y; 55 | } 56 | 57 | PVector operator -(PVector other) { 58 | return PVector(x - other.x, y - other.y); 59 | } 60 | 61 | void sub(PVector other) { 62 | x -= other.x; 63 | y -= other.y; 64 | } 65 | 66 | PVector operator *(num scalar) { 67 | return PVector(x * scalar, y * scalar); 68 | } 69 | 70 | void mult(num scalar) { 71 | x *= scalar; 72 | y *= scalar; 73 | } 74 | 75 | PVector operator /(num scalar) { 76 | return PVector(x / scalar, y / scalar); 77 | } 78 | 79 | void div(num scalar) { 80 | x /= scalar; 81 | y /= scalar; 82 | } 83 | 84 | num get heading { 85 | return atan2(y, x); 86 | } 87 | 88 | void rotate(num radians) { 89 | final newHeading = heading + radians; 90 | final magnitude = mag; 91 | 92 | x = magnitude * cos(newHeading); 93 | y = magnitude * sin(newHeading); 94 | } 95 | 96 | num get mag { 97 | return sqrt(pow(x, 2) + pow(y, 2)); 98 | } 99 | 100 | set mag(num magnitude) { 101 | if (magnitude < 0) { 102 | throw Exception("Magnitude must be >= 0"); 103 | } 104 | 105 | final currentHeading = heading; 106 | x = magnitude * cos(currentHeading); 107 | y = magnitude * sin(currentHeading); 108 | } 109 | 110 | num get magSq { 111 | return pow(x, 2) + pow(y, 2); 112 | } 113 | 114 | void normalize() { 115 | mag = 1.0; 116 | } 117 | 118 | void limit(num magnitude) { 119 | if (mag > magnitude) { 120 | mag = magnitude; 121 | } 122 | } 123 | 124 | num dist(PVector other) { 125 | return PVector(other.x - x, other.y - y).mag; 126 | } 127 | 128 | num dot(PVector other) { 129 | return mag * other.mag * cos(angleBetween(this, other)); 130 | } 131 | 132 | PVector cross(PVector other) { 133 | throw UnimplementedError( 134 | "Flutter Processing doesn't support this yet. We need 3D vectors to make this meaningful."); 135 | } 136 | 137 | List get array { 138 | return [x, y]; 139 | } 140 | 141 | PVector copy() { 142 | return PVector(x, y); 143 | } 144 | 145 | Offset toOffset() => Offset(x.toDouble(), y.toDouble()); 146 | 147 | @override 148 | bool operator ==(Object other) => 149 | identical(this, other) || other is PVector && runtimeType == other.runtimeType && x == other.x && y == other.y; 150 | 151 | @override 152 | int get hashCode => x.hashCode ^ y.hashCode; 153 | 154 | @override 155 | String toString() => "($x, $y)"; 156 | } 157 | -------------------------------------------------------------------------------- /example/lib/the_coding_train/coding_challenges/085_game_of_life.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_processing/flutter_processing.dart'; 5 | import 'package:flutter_processing_example/_processing_demo_sketch_display.dart'; 6 | 7 | class CodingTrainGameOfLifeScreen extends StatefulWidget { 8 | const CodingTrainGameOfLifeScreen({ 9 | Key? key, 10 | required this.sketchDemoController, 11 | }) : super(key: key); 12 | 13 | final SketchDemoController sketchDemoController; 14 | 15 | @override 16 | _CodingTrainGameOfLifeScreenState createState() => _CodingTrainGameOfLifeScreenState(); 17 | } 18 | 19 | class _CodingTrainGameOfLifeScreenState extends State { 20 | @override 21 | Widget build(BuildContext context) { 22 | return ProcessingDemo( 23 | sketchDemoController: widget.sketchDemoController, 24 | createSketch: () { 25 | return _GameOfLifeSketch(); 26 | }, 27 | ); 28 | } 29 | } 30 | 31 | class _GameOfLifeSketch extends Sketch { 32 | final _pixelsPerCell = 25.0; 33 | late int colCount; 34 | late int rowCount; 35 | late List> _grid; 36 | 37 | @override 38 | void setup() { 39 | size(width: 500, height: 500); 40 | 41 | colCount = (width / _pixelsPerCell).floor(); 42 | rowCount = (height / _pixelsPerCell).floor(); 43 | 44 | _grid = List.generate( 45 | colCount, 46 | (index) => List.generate( 47 | rowCount, 48 | (index) => Random().nextBool(), 49 | ), 50 | ); 51 | 52 | frameRate = 3; 53 | } 54 | 55 | @override 56 | void draw() { 57 | background(color: Colors.black); 58 | 59 | fill(color: Colors.white); 60 | for (int col = 0; col < colCount; col += 1) { 61 | for (int row = 0; row < rowCount; row += 1) { 62 | if (_grid[col][row]) { 63 | final topLeft = Offset(col * _pixelsPerCell, row * _pixelsPerCell); 64 | rect(rect: Rect.fromLTWH(topLeft.dx, topLeft.dy, _pixelsPerCell, _pixelsPerCell)); 65 | } 66 | } 67 | } 68 | 69 | _createNextGeneration(); 70 | } 71 | 72 | void _createNextGeneration() { 73 | final newGrid = List.generate( 74 | colCount, 75 | (index) => List.generate( 76 | rowCount, 77 | (index) => false, 78 | ), 79 | ); 80 | 81 | for (int col = 0; col < colCount; col += 1) { 82 | for (int row = 0; row < rowCount; row += 1) { 83 | newGrid[col][row] = _calculateNextCellValue(col: col, row: row); 84 | } 85 | } 86 | 87 | _grid = newGrid; 88 | } 89 | 90 | bool _calculateNextCellValue({ 91 | required int col, 92 | required int row, 93 | }) { 94 | int liveNeighborsCount = 0; 95 | 96 | // Top left 97 | liveNeighborsCount += col > 0 && row > 0 && _grid[col - 1][row - 1] ? 1 : 0; 98 | 99 | // Top 100 | liveNeighborsCount += row > 0 && _grid[col][row - 1] ? 1 : 0; 101 | 102 | // Top right 103 | liveNeighborsCount += col < colCount - 1 && row > 0 && _grid[col + 1][row - 1] ? 1 : 0; 104 | 105 | // Right 106 | liveNeighborsCount += col < colCount - 1 && _grid[col + 1][row] ? 1 : 0; 107 | 108 | // Bottom Right 109 | liveNeighborsCount += col < colCount - 1 && row < rowCount - 1 && _grid[col + 1][row + 1] ? 1 : 0; 110 | 111 | // Bottom 112 | liveNeighborsCount += row < rowCount - 1 && _grid[col][row + 1] ? 1 : 0; 113 | 114 | // Bottom Left 115 | liveNeighborsCount += col > 0 && row < rowCount - 1 && _grid[col - 1][row + 1] ? 1 : 0; 116 | 117 | // Left 118 | liveNeighborsCount += col > 0 && _grid[col - 1][row] ? 1 : 0; 119 | 120 | if (_grid[col][row] && liveNeighborsCount >= 2 && liveNeighborsCount <= 3) { 121 | // The living cell survives. 122 | return true; 123 | } else if (!_grid[col][row] && liveNeighborsCount == 3) { 124 | // A dead cell is born. 125 | return true; 126 | } else { 127 | // The cell dies, or remains dead. 128 | return false; 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /example/lib/demos/_hacking_demo.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:file_selector/file_selector.dart'; 4 | import 'package:flutter/material.dart' hide Image; 5 | import 'package:flutter_processing/flutter_processing.dart'; 6 | 7 | class HackingDemo extends StatefulWidget { 8 | const HackingDemo({Key? key}) : super(key: key); 9 | 10 | @override 11 | _HackingDemoState createState() => _HackingDemoState(); 12 | } 13 | 14 | class _HackingDemoState extends State { 15 | late PImage _loadedImage; 16 | 17 | File? _fileToSaveImage; 18 | 19 | Directory? _dirToSaveFrames; 20 | int _remainingFrames = 0; 21 | 22 | Future _saveImage() async { 23 | const imageFormat = ImageFileFormat.targa; 24 | late String extension; 25 | late String mimeType; 26 | switch (imageFormat) { 27 | case ImageFileFormat.png: 28 | extension = 'png'; 29 | mimeType = 'image/png'; 30 | break; 31 | case ImageFileFormat.jpeg: 32 | extension = 'jpg'; 33 | mimeType = 'image/jpeg'; 34 | break; 35 | case ImageFileFormat.tiff: 36 | extension = 'tif'; 37 | mimeType = 'image/tiff'; 38 | break; 39 | case ImageFileFormat.targa: 40 | extension = 'tga'; 41 | mimeType = 'image/targa'; 42 | break; 43 | } 44 | 45 | final fileLocation = await getSaveLocation( 46 | acceptedTypeGroups: [ 47 | XTypeGroup( 48 | extensions: [extension], 49 | mimeTypes: [mimeType], 50 | ), 51 | ], 52 | ); 53 | if (fileLocation == null) { 54 | print('User cancelled the file selection'); 55 | return; 56 | } 57 | 58 | _fileToSaveImage = File(fileLocation.path); 59 | } 60 | 61 | Future _saveImageFrame() async { 62 | final fileLocation = await getSaveLocation(); 63 | if (fileLocation == null) { 64 | print('User cancelled the file selection'); 65 | return; 66 | } 67 | 68 | _dirToSaveFrames = File(fileLocation.path).parent; 69 | _remainingFrames = 10; 70 | } 71 | 72 | @override 73 | Widget build(BuildContext context) { 74 | return Center( 75 | child: Processing( 76 | sketch: Sketch.simple( 77 | setup: (s) async { 78 | s.size(width: 500, height: 500); 79 | 80 | _loadedImage = await s.loadImage('assets/audio-mixer.png'); 81 | }, 82 | draw: (s) async { 83 | s.image( 84 | image: _loadedImage, 85 | ); 86 | 87 | final subImage = await s.getRegion( 88 | x: 0, 89 | y: 0, 90 | width: (s.width / 2).round(), 91 | height: (s.height / 2).round(), 92 | ); 93 | // s.image(image: subImage, origin: Offset(s.width / 2, s.height / 2)); 94 | 95 | await s.loadPixels(); 96 | 97 | for (int col = 0; col < 400; ++col) { 98 | for (int row = 0; row < 400; ++row) { 99 | s.set(x: col, y: row, color: const Color(0xFF00FF00)); 100 | } 101 | } 102 | await s.setRegion(image: subImage); 103 | 104 | await s.updatePixels(); 105 | 106 | final pixelColor = await s.get(s.mouseX, s.mouseY); 107 | s 108 | // ..noStroke() 109 | ..fill(color: pixelColor) 110 | ..circle( 111 | center: Offset(s.mouseX + 50, s.mouseY + 50), 112 | diameter: 100, 113 | ); 114 | 115 | await s.loadPixels(); 116 | 117 | if (_fileToSaveImage != null) { 118 | s.save(file: _fileToSaveImage!); 119 | 120 | _fileToSaveImage = null; 121 | } else if (_dirToSaveFrames != null && _remainingFrames > 0) { 122 | s.saveFrame( 123 | directory: _dirToSaveFrames!, 124 | namingPattern: 'testname_##.jpg', 125 | ); 126 | 127 | _remainingFrames -= 1; 128 | if (_remainingFrames == 0) { 129 | _dirToSaveFrames = null; 130 | } 131 | } 132 | }, 133 | ), 134 | ), 135 | ); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /test/processing_widget_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter/services.dart'; 3 | import 'package:flutter_processing/flutter_processing.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | 6 | void main() { 7 | group('Processing widget', () { 8 | testWidgets('automatically receives focus', (tester) async { 9 | int keyTypeCount = 0; 10 | 11 | await tester.pumpWidget( 12 | _buildApp( 13 | child: Processing( 14 | sketch: Sketch.simple( 15 | keyTyped: (s) { 16 | keyTypeCount += 1; 17 | }, 18 | ), 19 | ), 20 | ), 21 | ); 22 | 23 | // The Processing widget should automatically take focus. 24 | await tester.sendKeyEvent(LogicalKeyboardKey.space); 25 | 26 | expect(keyTypeCount, 1); 27 | }); 28 | 29 | testWidgets('blocks upstream key events when it has focus', (tester) async { 30 | int upstreamKeyEvent = 0; 31 | 32 | await tester.pumpWidget( 33 | _buildApp( 34 | child: Focus( 35 | focusNode: FocusNode(), 36 | onKey: (node, rawKeyEvent) { 37 | upstreamKeyEvent += 1; 38 | return KeyEventResult.ignored; 39 | }, 40 | child: Processing( 41 | sketch: Sketch.simple(), 42 | ), 43 | ), 44 | ), 45 | ); 46 | 47 | // The Processing widget should automatically take focus. 48 | await tester.sendKeyEvent(LogicalKeyboardKey.space); 49 | 50 | expect(upstreamKeyEvent, 0); 51 | }); 52 | 53 | testWidgets("passes upstream key events when it doesn't have focus", (tester) async { 54 | final outerFocusNode = FocusNode(); 55 | int upstreamKeyEvent = 0; 56 | 57 | await tester.pumpWidget( 58 | _buildApp( 59 | child: Focus( 60 | focusNode: outerFocusNode, 61 | onKey: (node, rawKeyEvent) { 62 | upstreamKeyEvent += 1; 63 | return KeyEventResult.ignored; 64 | }, 65 | child: Processing( 66 | sketch: Sketch.simple(), 67 | ), 68 | ), 69 | ), 70 | ); 71 | 72 | outerFocusNode.requestFocus(); 73 | await tester.pump(); 74 | 75 | // The Processing widget should automatically take focus. 76 | await tester.sendKeyDownEvent(LogicalKeyboardKey.space); 77 | 78 | expect(upstreamKeyEvent, 1); 79 | }); 80 | 81 | testWidgets('receives key events', (tester) async { 82 | final keysPressed = []; 83 | final keysReleased = []; 84 | final keysTyped = []; 85 | 86 | await tester.pumpWidget( 87 | _buildApp( 88 | child: Processing( 89 | sketch: Sketch.simple( 90 | keyPressed: (s) { 91 | if (s.key == null) { 92 | return; 93 | } 94 | 95 | keysPressed.add(s.key!); 96 | }, 97 | keyReleased: (s) { 98 | if (s.key == null) { 99 | return; 100 | } 101 | 102 | keysReleased.add(s.key!); 103 | }, 104 | keyTyped: (s) { 105 | if (s.key == null) { 106 | return; 107 | } 108 | 109 | keysTyped.add(s.key!); 110 | }, 111 | ), 112 | ), 113 | ), 114 | ); 115 | 116 | // The Processing widget should automatically take focus. 117 | await tester.sendKeyEvent(LogicalKeyboardKey.space); 118 | 119 | expect(keysPressed.length, 1); 120 | expect(keysPressed.first, LogicalKeyboardKey.space); 121 | 122 | expect(keysReleased.length, 1); 123 | expect(keysReleased.first, LogicalKeyboardKey.space); 124 | 125 | expect(keysTyped.length, 1); 126 | expect(keysTyped.first, LogicalKeyboardKey.space); 127 | }); 128 | }); 129 | } 130 | 131 | Widget _buildApp({ 132 | required Widget child, 133 | }) { 134 | return MaterialApp( 135 | home: child, 136 | debugShowCheckedModeBanner: false, 137 | ); 138 | } 139 | --------------------------------------------------------------------------------