如何画“生化危机”带秋千

发布于 2024-08-30 13:53:54 字数 237 浏览 6 评论 0原文

我正在为即将到来的测试练习我的挥杆能力,弗里德给了我画这样的生物危害标志的想法:

alt text http://img62.imageshack.us/img62/8372/lab6b.gif

我可以用 Elipse2D 绘制圆圈,但不知何故我需要切割这 3 个三角形。我有什么想法可以做到这一点吗?

I'm practicing my swing abilities for the upcoming test, and fried gave me idea to draw biohazard sign like this :

alt text http://img62.imageshack.us/img62/8372/lab6b.gif

I could draw the circles with Elipse2D, but then I somehow need to cut those 3 triangles. Any ideas how I can do that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千年*琉璃梦 2024-09-06 13:53:54

为此,您可以使用 Java2D 和 canvas。您可能使用的东西是圆和弧。您应该有三个 30 度的圆弧。

我尝试在框架上使用简单的图形。

这是一种尝试

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JComponent;
import javax.swing.JFrame;

public class Biohazard {
    public static void main(String[] args) {
        new Biohazard();
    }

    public Biohazard() {
        JFrame frame = new JFrame("Biohazard");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MyComponent());
        frame.setSize(260, 280);
        frame.setVisible(true);
    }

    public class MyComponent extends JComponent {
        public void paint(Graphics g) {
            int height = 120;
            int width = 120;
            g.setColor(Color.yellow);
            g.fillOval(60, 60, height, width);
            g.setColor(Color.black);
            g.drawOval(60, 60, height, width);

            int swivels = 6;
            int commonx, commony, commonh, commonw;

            for(int i=0;i<swivels;i++){
                commonx = commony = 120-i*10;
                commonh = commonw = i*20;
                g.drawArc(commonx, commony, commonh, commonw, 60 , 60);
                g.drawArc(commonx, commony, commonh, commonw, 180 , 60);
                g.drawArc(commonx, commony, commonh, commonw, 300 , 60);
            }
        }
    }
}

原始的:源代码可以在 http://pastebin.com/HSNFx7Gq 找到

< a href="https://i.sstatic.net/WFySE.png" rel="nofollow noreferrer">输入图像描述这里

You can use Java2D and canvas for this. The things that you may be using are, Circle and Arc. You should have three arcs with 30 degrees.

I tried using simple graphics over the frame.

Here is an attempt

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JComponent;
import javax.swing.JFrame;

public class Biohazard {
    public static void main(String[] args) {
        new Biohazard();
    }

    public Biohazard() {
        JFrame frame = new JFrame("Biohazard");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MyComponent());
        frame.setSize(260, 280);
        frame.setVisible(true);
    }

    public class MyComponent extends JComponent {
        public void paint(Graphics g) {
            int height = 120;
            int width = 120;
            g.setColor(Color.yellow);
            g.fillOval(60, 60, height, width);
            g.setColor(Color.black);
            g.drawOval(60, 60, height, width);

            int swivels = 6;
            int commonx, commony, commonh, commonw;

            for(int i=0;i<swivels;i++){
                commonx = commony = 120-i*10;
                commonh = commonw = i*20;
                g.drawArc(commonx, commony, commonh, commonw, 60 , 60);
                g.drawArc(commonx, commony, commonh, commonw, 180 , 60);
                g.drawArc(commonx, commony, commonh, commonw, 300 , 60);
            }
        }
    }
}

The original one : source code can be found at http://pastebin.com/HSNFx7Gq

enter image description here

も让我眼熟你 2024-09-06 13:53:54

您可以使用 Arc2D类通过指定 startextent 参数(以度为单位)来绘制每条线。

You can use the Arc2D class to draw each line by specifying the start and extent parameters in degrees.

或十年 2024-09-06 13:53:54

也许这实际上很简单(我不确定 Swing API 如何处理线条)。从圆心到圆周上的点绘制线条,然后跳过这些部分进行线条绘制。

Maybe this is actually quite easy (I'm not sure how the Swing API handles lines). Draw lines coming out from the center to the points on the circumference of a circle, and just skip those portions for line drawing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文