AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Grafik Programmierung

Ein Thema von Contace · begonnen am 23. Okt 2018 · letzter Beitrag vom 1. Nov 2018
 
Contace

Registriert seit: 22. Okt 2018
44 Beiträge
 
#27

AW: Grafik Programmierung

  Alt 29. Okt 2018, 21:49
Harry Stahl,

ja das seh ich genauso, nur ohne referenz werd ich nicht viel lernen können.

Ich bin mittlerweile auf visual umgestiegen zur graphikprogrammierung gibt es da genug bücher.

Allerdings hab ich ein problem, ich weiß nicht warum der Kreis nicht ganz rum geht.


Grüße

Code:
protected override void OnPaint(PaintEventArgs e)
    {
        Graphics g = e.Graphics;
        SetScale(g);
        DrawFace(g);
        base.OnPaint(e);
    }
    private void InitializeComponent()
    {
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
        this.ClientSize = new System.Drawing.Size(800, 600);

    }

    [STAThread]
    static void Main()
    {
        Application.Run(new DrawStringAlignACircle());
    }

    private void SetScale(Graphics g)
    {
        g.TranslateTransform(Width / 2, Height / 2);

        float inches = Math.Min(Width / g.DpiX, Height / g.DpiX);

        g.ScaleTransform(inches * g.DpiX / 2000, inches * g.DpiY / 2000);
    }

    private void DrawFace(Graphics g)
    {
        Brush brush = new SolidBrush(ForeColor);
        Font font = new Font("Arial", 15);

        float x, y;

        const int numHours = 100;
        const int deg = 360 / numHours;
        const int FaceRadius = 700;

        for (int i = 1; i <= numHours; i++)
        {
            x = GetCos(i * deg + 90) * FaceRadius;
            y = GetSin(i * deg - 90) * FaceRadius;

            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;

            g.DrawString(i.ToString(), font, brush, -x, -y, format);

        }
        brush.Dispose();
        font.Dispose();
    }

    private static float GetSin(float degAngle)
    {
        return (float)Math.Sin(Math.PI * degAngle / 180f);
    }

    private static float GetCos(float degAngle)
    {
        return (float)Math.Cos(Math.PI * degAngle / 180f);
    }

}
Angehängte Grafiken
Dateityp: jpg circle.JPG (41,1 KB, 21x aufgerufen)

Geändert von Contace (29. Okt 2018 um 22:40 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:45 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz