패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.1.0

p5

이것은 Flutter 애플리케이션에서 상호작용형 그래픽을 프로그래밍하는 데 사용할 수 있는 Processing API의 Dart 구현입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
23
좋아요
31
Pub 점수
130

패키지 설치

flutter pub add p5

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

p5 패키지는 Flutter 애플리케이션 내에서 상호작용 가능한 그래픽과 시각화를 만들 수 있도록 해주는 Processing API의 Dart 구현을 제공합니다. 인기 있는 Processing 언어에 영감을 받아 도형 그리기, 애니메이션 처리, 사용자 입력 반응 등 간단하고 직관적인 문법을 제공합니다. 이는 창의적 코딩, 데이터 시각화 및 교육 프로젝트에 이상적입니다. 이 패키지는 Android, iOS, Web, macOS, Windows, Linux 등 여러 플랫폼을 지원하여 광범위한 호환성을 보장합니다. Flutter 위젯 시스템과 원활하게 통합되어 앱에서 풍부하고 동적인 시각 효과를 구현할 수 있습니다.

사용 사례

  • 인터랙티브 예술 설치물
  • 데이터 시각화 대시보드
  • 교육용 코딩 도구
  • 창의적인 프로토타이핑
  • 애니메이션 UI 요소

주요 기능

  • 프로세싱과 유사한 구문
  • 실시간 애니메이션 지원
  • 크로스 플랫폼 렌더링
  • 마우스 및 터치 이벤트 처리
  • 내장된 모양 및 색상 함수

적합한 대상

  • 크리에이티브 코더
  • 프로그래밍을 가르치는 교육자
  • 코드를 사용하는 시각 예술가
  • 그래픽을 탐구하는 플러터 개발자
  • 초보자가 인터랙티브 디자인을 배우는 중

고려 사항

  • 저사양 기기에서 성능이 다를 수 있습니다
  • 원본 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.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.