0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Processingで丸いウィンドウを表示する

Last updated at Posted at 2025-01-21

はじめに

「おめシス」がデスクトップマスコットアプリを作ったので、Processingで矩形ではないwindow表示について調べた結果です。非矩形はできましたが、まだ、画像入力でshapeの自動生成まで出来ていません。

昔は、色々出ましたね。
ペプシマンのが、印象に残ってる。

環境

MacOS 13
Processing 4.2

使用画像

AIに星を書いてもらったら、精緻なものが登場。
Designer2s.png

Designer2.png

プログラム

かなりAIに書いてもらいました。javaのawtライブラリを使います。

import java.awt.Frame;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.Color;
import processing.awt.PSurfaceAWT;
//import java.awt.geom.Path2D;

PImage img;
PShape svg;
Frame frame;

void setup() {
  size(512, 512);
  img = loadImage("Designer2.png");
  surface.setVisible(false); // Processingのウィンドウを非表示にする
  
  // 新しいフレームを作成
  frame = new Frame();
  frame.setUndecorated(true); // ウィンドウの装飾を削除
  frame.setBackground(new Color(0, 0, 0, 0)); // ウィンドウを透明にする

  // 楕円形のウィンドウを作成
  Shape shape = new Ellipse2D.Float(0, 0, 512, 512);
  frame.setShape(shape);

  // フレームを表示
  frame.setSize(512, 512);
  frame.setLocation(100, 100);
  frame.setVisible(true);

  // Processingの描画をフレームに追加
  PSurfaceAWT.SmoothCanvas canvas = (PSurfaceAWT.SmoothCanvas) surface.getNative();
  frame.add(canvas);
}

void draw() {
  background(0, 0, 0); // 背景を黒に設定
  image(img, 0, 0, 512, 512);
  frame.setLocation((100+frameCount*3)%(width*3), 100);
}

ウィンドウを透明にできるのですが、background命令で透明は扱えないので、黒で塗っています。
shapeを画像から生成できたらと思ったのですが、難航して、時間がかかりそうなので、別の機会に。

任意形状のwindowが開ければ、なんとかなるかと。

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?