Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
void __fastcall TFEnvelope::OnPaintGraph(TObject *Sender) { // Rahmen (5 Pixel Abstand von jeder Seite) zeichnen und PaintBox grau färben PBGraph->Canvas->Brush->Color = clSilver; PBGraph->Canvas->Rectangle(0, 0, PBGraph->Width, PBGraph->Height); PBGraph->Canvas->Pen->Color = clBlack; PBGraph->Canvas->PenPos = TPoint(4, 5); PBGraph->Canvas->LineTo(PBGraph->Width - 5, 5); PBGraph->Canvas->PenPos = TPoint(4, 5); PBGraph->Canvas->LineTo(4, PBGraph->Height - 5); PBGraph->Canvas->Pen->Color = clWhite; PBGraph->Canvas->PenPos = TPoint(PBGraph->Width - 5, PBGraph->Height - 5); PBGraph->Canvas->LineTo(PBGraph->Width - 5, 5); PBGraph->Canvas->PenPos = TPoint(PBGraph->Width - 5, PBGraph->Height - 5); PBGraph->Canvas->LineTo(4, PBGraph->Height - 5); PBGraph->Canvas->Brush->Color = clBlack; PBGraph->Canvas->Pen->Color = clNavy; int iPosition = 0; // Nummer des aktuellen Elements in der Liste int iLastI = 0; // Position des letzten Listeneintrags (Liste hat 101 Elemente , wobei das nullte Element den Wert nach 0% der Zeit und das hundertste Element den Wert nach 100% der Zeit darstellt) float fB; // Variable b der Gleichung float fValue = 0.0f, fLastValue; / /normalisierter Wert (so angepasster Wert, dass er von 0 nach x geht und nicht im negativen Bereich ist) des des aktuellen und des vorherigen behandelten Elements der Liste. for(int i = 0; i < 101; i++) // alle Elemente durchgehen { if((m_EnvelopeProfile.afPoints[i] == -999999.999f) && (i != 0) && (i != 100)) // -999999.999f bedeutet Wert nicht gesetzt (also hier interpolieren) bei der letzten und der 1. Position in der Liste wird in diesem Fall der Standard-Wert m_fDefault verwendet continue; if(m_EnvelopeProfile.afPoints[i] == -999999.999f) m_EnvelopeProfile.afPoints[i] = m_fDefault; fLastValue = fValue; fValue = -m_EnvelopeProfile.afPoints[i] + m_fMax; // aktuellen Wert normalisieren if(m_EnvelopeProfile.bIsLinear) { // [...] lineare Segmente zeichnen, wenn linear interpoliert werden soll } else { if(i == 0) PBGraph->Canvas->PenPos = TPoint(5, (int)(((float)(PBGraph->Height - 11)) / (m_fMax - m_fMin) * fValue + 5.0f)); Stift auf Anfangswert setzen (diese Zeile muss man nicht verstehen) else { fB = pow(fValue / fLastValue, 1.0f / (i - iLastI)); // b ausrechnen for(int j = PBGraph->Canvas->PenPos.x - 5; j <= (int)(((float)(PBGraph->Width - 5)) / 100.0f * (float)(i)); j++) // für die Anzahl an Pixel zwischen den beiden Elementen ausführen (5 Pixel Rahmen berücksichtigen!), PenPos.x steht an der aktuellen Position { if(fB < 1.0f) // wenn b < 1, dann exponentielle Abnahme, indem der Kehrwert von b verwendet wird und das Ergebnis der Potenzierung in den negativen Bereich gesetzt wird PBGraph->Canvas->Pixels[j][(int)(-pow(1.0f / fB, j - PBGraph->Canvas->PenPos.x + 6)) + PBGraph->Canvas->PenPos.y] = clNavy; // Pixel an Position j (aktuelle Position in Pixel) | b^Anzahl der bearbeiteten Pixel + "Startwert" (PenPos.y, Höhe des letzten Elements der Liste) setzen else PBGraph->Canvas->Pixels[j][(int)(pow(fB, j - PBGraph->Canvas->PenPos.x + 6)) + PBGraph->Canvas->PenPos.y] = clNavy; if(j == (int)(((float)(PBGraph->Width - 5)) / 100.0f * (float)(i))) // wenn das letzet Pixel des aktuellen Segments gesetzt wurde, dann Position des Stiftes anpassen if(fB < 1.0f) PBGraph->Canvas->PenPos = TPoint((int)((float)(PBGraph->Width - 5) / 100.0f * (float)(i)), (int)(-pow(1.0f / fB, j - PBGraph->Canvas->PenPos.x + 6)) + PBGraph->Canvas->PenPos.y); else PBGraph->Canvas->PenPos = TPoint((int)((float)(PBGraph->Width - 5) / 100.0f * (float)(i)), (int)(pow(fB, j - PBGraph->Canvas->PenPos.x + 6)) + PBGraph->Canvas->PenPos.y); } } } // [...] an Punkten kleine Quadrate zeichnen iPosition++; iLastI = i; } // [...] Achsen beschriften } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »the[V]oid« (05.07.2010, 23:43)
Mastermind
unregistriert
Zitat
aber die Formel, von mir sollte eigentlich stimmen
C-/C++-Quelltext |
|
1 2 3 4 5 6 |
for(int j = PBGraph->Canvas->PenPos.x - 5; j <= (int)(((float)(PBGraph->Width - 5)) / 100.0f * (float)(i)); j++) { PBGraph->Canvas->Pixels[j][(int)((PBGraph->Height - 11) / (m_fMax - m_fMin) * (fLastValue * pow((fValue + 1.0f) / (fLastValue + 1.0f), (float)(j - PBGraph->Canvas->PenPos.x - 5) / (((float)(PBGraph->Width - 5)) / 100.0f * (float)(i)))) + 5.0f)] = clNavy; if(j == (int)(((float)(PBGraph->Width - 5)) / 100.0f * (float)(i))) PBGraph->Canvas->PenPos = TPoint(j, (int)((PBGraph->Height - 11) / (m_fMax - m_fMin) * (fLastValue * pow((fValue + 1.0f) / (fLastValue + 1.0f), (float)(j - PBGraph->Canvas->PenPos.x - 5) / (((float)(PBGraph->Width - 5)) / 100.0f * (float)(i)))) + 5.0f)); } |
Mastermind
unregistriert
Quellcode |
|
1 2 3 4 5 6 7 8 |
for (j = startpixel j<=endpixel; j++) { float x = float(j-startpixel)/float(endpixel-startpixel); //für j = startpixel ist das 0 und für j = endpixel 1, so solle es ja auch sein. float y = y(x); //wie in deiner formel zeichne pixel an der stelle j, floor(y) } |
Werbeanzeige