Ich bin total aufgeregt. Was wollte ich eigentlich posten?
Ah, jetzt ja. Ich saß gestern Abend vor meinem Rechner und habe den heise-Ticker gelesen. Dabei bin ich auf folgendes gestoßen: Digitale Bilderrahmen zweckentfremdet | heise Foto. Was mich vor allem begeisterte war die Verwendung des DPF also Clocktwo: QLOCKTWO BY BIEGERT & FUNK der Link ist hin und wieder down, dann klonblog.com/2009/05/28/clocktwo-die-uhr-ohne-zeiger/.
Was mich nicht begeisterte, war der Vorschlag das ganze mit einem Grafikprogramm zu erstellen. Was, wenn die Buchstaben zu hell, zu dunkel, zu groß, zu klein, ... wären? Also musste ein Programm her. Da es die Arbeit von ca. drei Stunden ist, darf nicht zu viel erwartet werden. Aber es tut ...
Der Code ist nicht allzu lange,darum werde ich ihn direkt posten.
Als erstes die Klasse "Zeitgeber.cs"
Quellcode
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ClockTwo
- {
- class Zeitgeber
- {
- Dictionary<int, Stunde> dictStunde = new Dictionary<int, Stunde> ();
- Dictionary<int, Minute> dictMinute = new Dictionary<int, Minute>();
- Dictionary<int, string> dictPostMin = new Dictionary<int, string>();
- Dictionary<int,int[]> dictMS = new Dictionary<int,int[]> ();
- GrWr grwr = new GrWr(0, 0);
- public Zeitgeber()
- {
- // Nachfilgender Teil steuert die Hell/Dunkel Sequenzen in "dictMinute"
- // Index 1 => 5 Min; Index 2 => 10 Min; usw.
- // Da wo eine 1 steht ist es hell, da wo eine 2 steht ist es dunkel
- // spart jede Menge Tiparbeit
- dictMS.Add (1, new int[] { 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 });
- dictMS.Add (2, new int[] { 1, 2, 1, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2, 2 });
- dictMS.Add (3, new int[] { 1, 2, 1, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2 });
- dictMS.Add (4, new int[] { 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 1 });
- dictMS.Add (5, new int[] { 1, 2, 1, 2, 2, 1, 2, 1, 2, 2, 2, 1, 2, 2 });
- dictMS.Add (6, new int[] { 1, 2, 1, 2, 1, 2, 2, 1, 2, 2, 2, 1, 2, 2 });
- dictMS.Add (7, new int[] { 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2 });
- dictMS.Add (8, new int[] { 1, 2, 1, 2, 1, 2, 2, 2, 2, 1, 2, 1, 2, 2 });
- dictMS.Add (9, new int[] { 1, 2, 1, 2, 2, 1, 2, 2, 2, 1, 2, 1, 2, 2 });
- dictMS.Add (10, new int[] { 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2 });
- dictMS.Add (11, new int[] { 1, 2, 1, 2, 2, 1, 2, 1, 2, 2, 2, 2, 2, 2 });
- dictMS.Add (12, new int[] { 1, 2, 1, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2 });
- // Befüllt die Klasse "Stunde" und packt sie in ein Dictionary
- // Der erste Teil ist die Stunde, der zweite Teil sind Füllzeichen.
- // Füllzeichen sind nie hell. Das Boolean sorgt bei "true" für einen Umbruch.
- dictStunde.Add (1, new Stunde("E I N S", " P T W ", false));
- dictStunde.Add (2, new Stunde("Z W E I", "", true));
- dictStunde.Add (3, new Stunde("D R E I", " S V B ", false));
- dictStunde.Add (4, new Stunde("V I E R", "", true));
- dictStunde.Add (5, new Stunde("F Ü N F", " R S ", false));
- dictStunde.Add (6, new Stunde("S E C H S", "", true));
- dictStunde.Add (7, new Stunde("S I E B E N", " T ", false));
- dictStunde.Add (8, new Stunde("A C H T", " ", true));
- dictStunde.Add (9, new Stunde("N E U N", " ", false));
- dictStunde.Add(10, new Stunde("Z E H N", " ", false));
- dictStunde.Add(11, new Stunde("E L F", "", true));
- dictStunde.Add(12, new Stunde("Z W Ö L F", " S D W K L S", false));
- // hier stecken die Minuten. Gesteuert von oben
- dictMinute.Add (1, new Minute ("E S", false));
- dictMinute.Add (2, new Minute (" A", false));
- dictMinute.Add (3, new Minute (" I S T", false));
- dictMinute.Add (4, new Minute (" A", false));
- dictMinute.Add (5, new Minute (" F Ü N F", true));
- dictMinute.Add (6, new Minute ("Z E H N", false));
- dictMinute.Add (7, new Minute (" U A D", false));
- dictMinute.Add (8, new Minute (" V O R", false));
- dictMinute.Add (9, new Minute (" G", true));
- dictMinute.Add (10, new Minute ("N A C H", false));
- dictMinute.Add (11, new Minute (" V I E R T E L", true));
- dictMinute.Add (12, new Minute ("H A L B", false));
- dictMinute.Add (13, new Minute (" V O R", false));
- dictMinute.Add (14, new Minute (" N A C H", true));
- // Ist ein Versuch und muss nicht beachtet werden.
- dictPostMin.Add(1, "A A A A A A A A A A A");
- }
- public void generiere()
- {
- DateTime dt = new DateTime();
- dt = DateTime.Parse("00:20");
- for (int i = 1; i <= 720; i++)
- {
- grwr = new GrWr(0, 0);
- grwr.setStartPunkt(58, 0);
- grwr.ladeBitmap("6x8.jpg");
- int std = dt.Hour;
- int min = dt.Minute;
- if (min >= 20) std++;
- int fmin = min / 5;
- minute(dictMS[fmin+1]);
- stunde(std);
- postMin(min % 5);
- string fname = (dt.Hour.ToString()).PadLeft(2, '0') + (dt.Minute.ToString()).PadLeft(2, '0');
- grwr.speichereDatei("clock\\"+fname+".jpg");
- dt = dt + TimeSpan.FromMinutes(1);
- }
- }
- private void minute(int[] minute)
- {
- grwr.nl();
- for (int i = 1; i <= 14; i++)
- {
- grwr.schreibeText(dictMinute[i].minute, minute[i-1]);
- if (dictMinute[i].umbruch == true)
- {
- grwr.nl();
- }
- }
- }
- private void stunde (int std)
- {
- for (int i=1; i<=12; i++)
- {
- if (i == std) grwr.schreibeText(dictStunde[i].std, 1); else grwr.schreibeText(dictStunde[i].std, 2);
- grwr.schreibeText(dictStunde[i].filler , 2);
- if (dictStunde[i].umbruch == true)
- {
- grwr.nl();
- }
- }
- }
- private void postMin (int pm)
- {
- grwr.nl();
- if (pm == 0)
- {
- grwr.schreibeText("A ", 2);
- grwr.schreibeText("0 ", 1);
- grwr.schreibeText("F 1 W 2 U 3 R 4 N", 2);
- }
- if (pm == 1)
- {
- grwr.schreibeText("A 0 F ", 2);
- grwr.schreibeText("1 ", 1);
- grwr.schreibeText("W 2 U 3 R 4 N", 2);
- }
- if (pm == 2)
- {
- grwr.schreibeText("A 0 F 1 W ", 2);
- grwr.schreibeText("2 ", 1);
- grwr.schreibeText("U 3 R 4 N", 2);
- }
- if (pm == 3)
- {
- grwr.schreibeText("A 0 F 1 W 2 U ", 2);
- grwr.schreibeText("3 ", 1);
- grwr.schreibeText("R 4 N", 2);
- }
- if (pm == 4)
- {
- grwr.schreibeText("A 0 F 1 W 2 U 3 R ", 2);
- grwr.schreibeText("4 ", 1);
- grwr.schreibeText("N", 2);
- }
- }
- }
- }
Die Klasse "Stunde.cs"
Quellcode
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ClockTwo
- {
- class Stunde
- {
- public string std { get; set; }
- public string filler { get; set; }
- public bool umbruch { get; set; }
- public Stunde(string std, string filler, bool umbruch)
- {
- this.std = std;
- this.filler = filler;
- this.umbruch = umbruch;
- }
- }
- }
Die Klasse "Minute.cs"
Quellcode
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ClockTwo
- {
- class Minute
- {
- public string minute { get; set; }
- public string filler { get; set; }
- public bool umbruch { get; set; }
- public Minute(string minute, bool umbruch)
- {
- this.minute = minute;
- this.umbruch = umbruch;
- }
- }
- }
Bleibt noch die Klasse "GrWr.cs"
Quellcode
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Drawing.Drawing2D;
- using System.Drawing.Text;
- namespace ClockTwo
- {
- // hier ist wichtig zu wissen, dass man mit Teilstrings arbeiten kann.
- // Die Klasse merkt sich alles was in einer Zeile steht und packt vor
- // einen neuen Text Leerzeichen (funktioniert nur bei Monospace!!!)
- // Ist einfach, aber tut soweit und spart gefrickel mit Pixeln
- // Wird ein Newline "nl" an der Klasse aufgerufen, löscht sich der Speicher
- // und es gibt durch die Addition eines Offsets eine neue Zeile.
- class GrWr
- {
- String aktTxt = "";
- Graphics graphicImage;
- Bitmap bitMapImage;
- int x, y;
- int step = 62;
- public GrWr (int x, int y)
- {
- this.x = x;
- this.y = y;
- }
- public void setStartPunkt(int x, int y)
- {
- this.x = x;
- this.y = y;
- aktTxt = "";
- }
- public void nl()
- {
- this.y = this.y + step;
- aktTxt = "";
- }
- public void ladeBitmap (String grafik)
- {
- bitMapImage = new Bitmap (grafik);
- graphicImage = Graphics.FromImage (bitMapImage);
- graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
- }
- public void schreibeText(string text, int farbe)
- {
- string vorspann = "";
- int anz = aktTxt.Length;
- vorspann = vorspann.PadLeft(anz, ' ');
- SolidBrush db = null;
- if (farbe == 1) {db = new SolidBrush(Color.White);}
- if (farbe == 2)
- {
- Color customColor = Color.FromArgb(80, Color.DarkGray);
- db = new SolidBrush(customColor);
- }
- Font df = new Font("Consolas", 30, FontStyle.Bold);
- Point dp = new Point( x, y );
- graphicImage.DrawString ( vorspann + text, df, db, dp);
- aktTxt = aktTxt + text;
- }
- public void speichereDatei(String datei)
- {
- bitMapImage.Save (datei,ImageFormat.Jpeg);
- //bitMapImage.Save
- //(Response.OutputStream, ImageFormat.Jpeg);
- }
- }
- }
Eine Form anlegen, ein Button drauf und da folgenden Code rein:
Jetzt füttert man eine JPG Datei im Format von 600x800, die den Hintergrund bildet.
Der Name ist "6x8.jpg". Bei mir war die z.B. schwarz.
Mein Code ist wie immer in perfekter Weise selbstkommentierend.
Sollten Fragen auftreten, einfach die Frage stellen.
Hab fertig.
Es ist besser zu schweigen und für einen Narren gehalten zu werden, als zu reden und damit alle Zweifel zu beseitigen ...
Dieser Beitrag wurde bereits 8 mal editiert, zuletzt von wasawasa ()