S
hum, bin mir sehr sicher nennt sich eben so in borland ^^
hier mal mein sourcecode
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Para.h"
#include <sstream>
#include <windows.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int XCorrection = 0;
int YCorrection = 0;
float ax = 0.115;
float bx = 5;
float c = 0;
const int maxX = 100, maxY = 100;
const int minX = -100, minY = -100;
const int Feinheit = 1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::btn_EndeClick(TObject *Sender)
{
Application->Terminate();
}
//---------------------------------------------------------------------------
//--------------------Der besagte On Paint event. --------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::pb_MalenPaint(TObject *Sender)
{
// Zeichenfarben Setzen
pb_Malen->Canvas->Pen->Color=cb_Farbe->Selected;
pb_Malen->Canvas->Brush->Color=cb_HintergrundFarbe->Selected;
// Untergrund Malen
pb_Malen->Canvas->FillRect(Rect(0,0,pb_Malen->Width,pb_Malen->Height));
// Vertikale ( x , y ) X Endlos, Y = Hälfte vom Fenster
pb_Malen->Canvas->MoveTo( 0, pb_Malen->Height / 2 + YCorrection);
// Linie zur anderen Bildschirmseite
pb_Malen->Canvas->LineTo( pb_Malen->Width, pb_Malen->Height / 2 + YCorrection);
// Horizontale ( x , y ) Y Endlos, X = Hälfte vom Fenster
pb_Malen->Canvas->MoveTo( pb_Malen->Width / 2 + XCorrection, 0);
// Linie von oben nach Unten
pb_Malen->Canvas->LineTo( pb_Malen->Width / 2 + XCorrection, pb_Malen->Height);
// Skalierung
// ==========Striche
int Count = 0;// Strichabstand
while ( Count < pb_Malen->Width / 2 ){
// ------------X Achse-Striche Links----------------- X Achse ----------- Y Achse ---------
pb_Malen->Canvas->MoveTo((pb_Malen->Width/2)-Count,(pb_Malen->Height/2)-10 + YCorrection);
pb_Malen->Canvas->LineTo((pb_Malen->Width/2)-Count,(pb_Malen->Height/2)+10 + YCorrection);
// ------------X Achse-Striche Rechts---------------- X Achse ----------- Y Achse ---------
pb_Malen->Canvas->MoveTo((pb_Malen->Width/2)+Count,(pb_Malen->Height/2)-10 + YCorrection);
pb_Malen->Canvas->LineTo((pb_Malen->Width/2)+Count,(pb_Malen->Height/2)+10 + YCorrection);
// ________________________________________________________________________________________
Count += 100;// Strichabstand
}
Count = 0;
while ( Count < pb_Malen->Height / 2){
// ------------Y Achse-Striche Oben----------------- X Achse ----------- Y Achse ---------
pb_Malen->Canvas->MoveTo((pb_Malen->Width/2)-10 + XCorrection,(pb_Malen->Height/2)-Count);
pb_Malen->Canvas->LineTo((pb_Malen->Width/2)+10 + XCorrection,(pb_Malen->Height/2)-Count);
// ------------Y Achse-Striche Unten---------------- X Achse ----------- Y Achse ---------
pb_Malen->Canvas->MoveTo((pb_Malen->Width/2)-10 + XCorrection,(pb_Malen->Height/2)+Count);
pb_Malen->Canvas->LineTo((pb_Malen->Width/2)+10 + XCorrection,(pb_Malen->Height/2)+Count);
// ________________________________________________________________________________________
Count += 100;// Strichabstand
// === Note
// === Hätte man glaub ich auch einfach von links nach rechts machen koennen statt von der Mitte aus :|
// === Ausrede = Wie ein schüler ^^
// === Note End
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::cb_FarbeChange(TObject *Sender)
{
pb_Malen->Refresh();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::cb_HintergrundFarbeChange(TObject *Sender)
{
pb_Malen->Refresh();
}
//---------------------------------------------------------------------------
// ========== Bei den folgenden Buttons sollte der btn_Zeichen OnClick event aufgerufen werden
//---------------------------------------------------------------------------
void __fastcall TForm1::btn_HochClick(TObject *Sender)
{
YCorrection+=100;
pb_Malen->Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btn_RunterClick(TObject *Sender)
{
YCorrection-=100;
pb_Malen->Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btn_LinksClick(TObject *Sender)
{
XCorrection+=100;
pb_Malen->Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btn_RechtsClick(TObject *Sender)
{
XCorrection-=100;
pb_Malen->Repaint();
}
//---------------------------------------------------------------------------
//===========================================================================
//---------------------------------------------------------------------------
void __fastcall TForm1::btn_ZeichnenClick(TObject *Sender)
{
// S = Scheitelpunkt
float xS = -1 * bx / 2*ax;
float yS = -1 * bx * bx / 4*ax + c;
// P = Zu Zeichnender Punkt.
float xP = 0;
float yP = 0;
int Durchlauf = 1;
// While schleife noch fehlerbehaftet!
//while (( xP < maxX+XCorrection && xP > minX+XCorrection ) && ( yP < maxY+YCorrection && yP > minY+YCorrection))
while (( xP < maxX && xP > minX ) || ( yP < maxY && yP > minY))
{
float temporaryX, temporaryY;
if ( Durchlauf == 1 )
{
temporaryX = xS;
temporaryY = yS;
}else
{
temporaryX = xP;
temporaryY = yP;
}
xP = Feinheit * Durchlauf;
yP =( xP * xP ) * ax;
pb_Malen->Canvas->MoveTo((pb_Malen->Width/2)+temporaryX+XCorrection,(pb_Malen->Height/2)-temporaryY+YCorrection);
pb_Malen->Canvas->LineTo((pb_Malen->Width/2)+xP+XCorrection,(pb_Malen->Height/2)-yP+YCorrection);
pb_Malen->Canvas->MoveTo((pb_Malen->Width/2)-temporaryX+XCorrection,(pb_Malen->Height/2)-temporaryY+YCorrection);
pb_Malen->Canvas->LineTo((pb_Malen->Width/2)-xP+XCorrection,(pb_Malen->Height/2)-yP+YCorrection);
Durchlauf += 1;
}
// Note == Zu erweitern, erst achsenkreuz fertigstellen!
}
//---------------------------------------------------------------------------
EDIT: Uppppsss... okay vieleicht gehört das hier doch eher in Vcl ( C++ Builder )