搜尋套件、儲存庫與 APP 分類

套件詳情v0.1.0

p5

這是 Dart 實作的 Processing API,可用於在 Flutter 應用程式中編程互動式圖形。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
23
喜歡數
31
Pub 分數
130

安裝套件

flutter pub add p5

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

p5 套件提供 Processing API 的 Dart 實作,讓開發者能在 Flutter 應用中建立互動式圖形與視覺化。受到廣受歡迎的 Processing 語言啟發,它提供簡單直覺的語法來繪製形狀、處理動畫並回應使用者輸入。這使其非常適合創意編程、資料視覺化與教育專案。該套件支援多個平台,包括 Android、iOS、Web、macOS、Windows 與 Linux,確保廣泛的相容性。它與 Flutter 的 widget 系統無縫整合,讓應用程式能呈現豐富且動態的視覺效果。

適用情境

  • 互動藝術裝置
  • 資料視覺化儀表板
  • 教育類編碼工具
  • 創意原型設計
  • 動畫UI元素

主要特色

  • 類似處理的語法
  • 即時動畫支援
  • 跨平台渲染
  • 滑鼠和觸控事件處理
  • 內建的形狀和顏色函數

適合對象

  • 創意程式設計師
  • 教授程式設計的教育工作者
  • 使用程式碼的視覺藝術家
  • Flutter 開發者探索圖形
  • 初學者學習互動設計

使用建議

  • 效能可能在低階裝置上有所差異
  • 與原始 Processing 相比,文件較少
  • 不適用於複雜的遊戲開發
  • 需要了解基本的圖形概念
  • 由於渲染引擎,可能導致應用程式體積增加

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

p5.dart

A Dart implementation of the Processing API for Flutter. Processing is a software sketchbook and a language for learning how to code within the context of the visual arts.

Note: this is an experimental library that only implements a few functions from the Processing API. Class names and structure will likely change in the future. And feel free to fork and play around with the code :-)

Getting Started

Add the p5 package to your Flutter app. For help using packages, see Flutter's online documentation.

You need to implement the widget containing the Processing sketch, and the sketch itself.

A simple widget tree is the follwing:

import 'package:flutter/material.dart';

import "package:p5/p5.dart";
import "sketch.dart";

void main() => runApp(new MyApp());

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  @override
  _MyHomePageState createState() {
    return new _MyHomePageState();
  }
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'P5 Demo',
      theme: new ThemeData(
        // This is the theme of your application.
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'P5 Demo Home Page'),
    );
  }
}

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
  MySketch sketch;
  PAnimator animator;

  @override
  void initState() {
    super.initState();
    sketch = new MySketch();
    // Need an animator to call the draw() method in the sketch continuously,
    // otherwise it will be called only when touch events are detected.
    animator = new PAnimator(this);
    animator.addListener(() {
      setState(() {
        sketch.redraw();
      });
    });
    animator.run();
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(title: new Text("P5 Draw!")),
      backgroundColor: const Color.fromRGBO(200, 200, 200, 1.0),
      body: new Center(
        child:new PWidget(sketch),
      ),
    );
  }
}

The MySketch class has to extend the base PPainter class in the p5 package, and implement the setup() and draw() functions, just like in Processing sketch:

class MySketch extends PPainter {
  void setup() {
    size(300, 300);
  }

  void draw() {
    background(color(255, 255, 255));
  }
}

Both pieces of code can be inside single dart file, or on separate files for better clarity.

A simple drawing sketch can be implemented by handling the mouse dragging, and storing the pointer positions in a list of PVector object holding the (x, y) coordinates, which are then used to draw lines:

class MySketch extends PPainter {
  var strokes = new List<List<PVector>>();

  void setup() {
    fullScreen();
  }

  void draw() {
    background(color(255, 255, 255));

    noFill();
    strokeWeight(10);
    stroke(color(10, 40, 200, 60));
    for (var stroke in strokes) {
      beginShape();
      for (var p in stroke) {
        vertex(p.x, p.y);
      }
      endShape();
    }
  }

  void mousePressed() {
    strokes.add([new PVector(mouseX, mouseY)]);
  }

  void mouseDragged() {
    var stroke = strokes.last;
    stroke.add(new PVector(mouseX, mouseY));
  }
}

Notice that the size of the drawing area can be made to fill the entire app by using fullScreen(). The app should give similar results for both iOS and Android.

For help getting started with Flutter, view our online documentation.

For help on editing package code, view the documentation.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。