Zurück (C) Christof Ermer, Regensburg
Gästebuch 
(public. sonst besser Email)  ChristofErmer@gmail.com



24.01.2022

Linkliste:
#Grafik_In_Windows
#CODE_Sinus
#CODE_LISSAJOUSCHE_FIGUR
#CODE_Dynamische_Lissajousche_Figur
#CODE_FRAKALE

DEV-C++
Von Bloodshed wird noch immer die veraltete Version 4.9.9.2 (März 2005) als „aktuell“ bereitgestellt,
neuere Versionen erschienen sämtlich unter dem Namen Orwell Dev-C++.
https://de.wikipedia.org/wiki/Orwell_Dev-C%2B%2B

Im DEV-C++ wir als Compiler der GnuC Compiler ,genannt "MinGW" genutzt.
Download: http://orwelldevcpp.blogspot.de/
Heute 20.09.2017  DEV-CPP 5.11     TDM-GCC 4.9.2 Compiler

Es ist nicht gewährleistet, das  die MinGW Compiler-Version aktuell ist.
Deshalb ist evtl eine manuelle MinGW Update erforderlich.
Insztallationsanleitung für Orwell DEV-C++ ; http://www.physik-abc.de/programmieren/windows/dev/installiere_dev.html



Bibliotheken einbinden:
Unter Projektoptionen->Parameter->Linker wählst du aus dem lib Verzeichnis von DevCpp einfach die o.g. lib aus. //"libgdi32.a
Projekt--> Projekt Optionen -->  Parameter --> Linker   --> //C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib32\libgdi32.a
Möglichkeit 2 : #pragma comment(lib,"libgdi32.a")   // einbinden von lib
Bibliotheken einbinden:
Unter Projektoptionen->Parameter->Linker wählst du aus dem lib Verzeichnis von DevCpp einfach die o.g. lib aus. //"libgdi32.a
Projekt--> Projekt Optionen -->  Parameter --> Linker   --> //C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib32\libgdi32.a

libgdi32.a liegt Bsp: zugleich als 64 und 32 Bit version unter
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib32

Störend war eine PATH Ungebungsvariable Eintragung des WINAVR Compilers. Braucht aber WINAVR





// ******************
int Round(float fIn)
// ******************
{
return (int)floor(fIn+0.5);
}




Was man in "C"  immer braucht::
Grafikausgabe unter  Windows mit DEV_CPP.

#include "pch.h"
#include <windows.h>
#include <iostream>
#include <limits>
#include <stdexcept>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <complex> // Wichig  ohne .h
#include "main.h"

using namespace std;
//GLOBAL
HWND hWnd;
HDC hDC;
hWnd = GetConsoleWindow();
if( hWnd != NULL ){ MoveWindow(hWnd ,200,10 ,WINX_WIDTH+100, WINY_WIDTH+60 ,TRUE); }
hDC = GetDC(hWnd); 

while (getchar() != 'x');
    system("pause");  
    ReleaseDC(hWnd, hDC);
    DeleteDC(hDC);

#define COULOUR_MAX_VAL    16777216UL
    SetPixel(hDC, C_Zeta.real() * VERGROESSERUNGSGFAKT + WINX_H, C_Zeta.imag() * VERGROESSERUNGSGFAKT + WINY_H, RGB(220, 220, 220));



#define gotoxy(x,y) printf("\033[%d;%dH", (x), (y))  // Nicht sicher im Anspringen von X/Y

//besser als #define gotoxy(x,y) printf("\033[%d;%dH", (x), (y))
// *********************************
void gotoxy(int x, int y)
// *********************************
{
    char essq[100];  // String variable to hold the escape sequence
    char xstr[100];  // Strings to hold the x and y coordinates
    char ystr[100];  // Escape sequences must be built with characters/
    //  ** Convert the screen coordinates to strings
    sprintf_s(xstr, "%d", x);
    sprintf_s(ystr, "%d", y);
    //   ** Build the escape sequence (vertical move)
    essq[0] = '\0';
    strcat_s(essq, "\033[");
    strcat_s(essq, ystr);
    // ** Described in man terminfo as vpa=\E[%p1%dd  ** Vertical position absolute
    strcat_s(essq, "d");
    //  ** Horizontal move  ** Horizontal position absolute 
    strcat_s(essq, "\033[");
    strcat_s(essq, xstr);
    // Described in man terminfo as hpa=\E[%p1%dG
    strcat_s(essq, "G"); //  ** Execute the escape sequence  ** This will move the cursor to x, y
    printf("%s", essq);
}



Makefile.win
# Project: Graf
# Makefile created by Dev-C++ 5.11

CPP      = g++.exe
CC       = gcc.exe
WINDRES  = windres.exe
OBJ      = main.o
LINKOBJ  = main.o
LIBS     = -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib" -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc  "C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib/libgdi32.a"
INCS     = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include"
CXXINCS  = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++"
BIN      = Graf.exe
CXXFLAGS = $(CXXINCS)
CFLAGS   = $(INCS)
RM       = rm.exe -f

.PHONY: all all-before all-after clean clean-custom

all: all-before $(BIN) all-after

clean: clean-custom
    ${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
    $(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)

main.o: main.cpp
    $(CPP) -c main.cpp -o main.o $(CXXFLAGS)


Beispiel. fertiges Projekt: Lissajusche Figur : Graf_Iissaj.zip

Speicherorte: Quicklinks:
D:\Dev_Cpp
D:\Program Files (x86)\Dev-Cpp\devcpp.exe

MinGW = Der GNU Compiler  -DOS version.
MinGW64 ist total veraltet --> macht compilerfehler---> austauschen
http://www.mingw.org/
https://sourceforge.net/projects/mingw-w64/
https://sourceforge.net/projects/orwelldevcpp/files/Compilers/MinGW/

Bibliotheken einbinden:
Unter Projektoptionen->Parameter->Linker wählst du aus dem lib Verzeichnis von DevCpp einfach die o.g. lib aus. //"libgdi32.a
Projekt--> Projekt Optionen -->  Parameter --> Linker   --> //C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib32\libgdi32.a



BEISPIELE:
/*
Verstärkung Vu --> Instrumenten DIFF-OP
run this program using the console pauser or add your own getch, system("pause") or input loop */
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
// using std::cout;
// using std::cin;
using namespace std;

int main(int argc, char *argv[])
{
float fR1;float fR2;float fU1;float fU2;float fUA;
/*cout >> "fU1 eingeben:";
fU1 = cin;
cout >> "fU2 eingeben:";
fU2 = cin;
*/

// 0.1 V DIFF
fU1=1.1;
fU2=1.0;
fR1=100000;
fR2=10000;
cout << "fU1=" << fU1 << "fU2=" << fU2 << endl;

/*
cout << "fR1 eingeben:";
cin >> fR1;
cout << endl;
cout << "fR2 eingeben:";
cin >> fR2;
*/

cout << endl;
cout << "fR1=" << fR1 << "   fR2=" << fR2 << endl;

fUA = (fU1 - fU2) * ( 1 + (2*fR1/fR2));
cout << "UA " <<  fUA << endl;

//Vu=
fUA = 1+ (2*fR1/fR2);
cout << "Verstärkung= " <<  fUA << endl;

system("PAUSE");   
return 0;



SINUS

/*
 https://www.tutorials.de/threads/grafiken-zeichnen-in-der-konsole.194602/
MinGW erneuern
https://sourceforge.net/projects/orwelldevcpp/files/Compilers/MinGW/

libgdi32.a mit dazulinken:
Programmier-Knowhow_DEV_C++
Unter Projektoptionen->Parameter->Linker wählst du aus dem lib Verzeichnis von DevCpp einfach die o.g. lib aus.
*/
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

//#pragma comment(lib,"libgdi32.a")   // einbinden von lib
//using namespace std;
//C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib32\libgdi32.a
int main(void)
{
 unsigned int uiXX;
 unsigned int uiYY;
 
    SetConsoleTitle("Zeichnen in Dos");
    //HWND hWnd = FindWindow(NULL, "Zeichnen in Dos");
    //alternative zu FindWindow
    HWND hWnd = GetConsoleWindow();
    HDC hDC = GetDC(hWnd);
    {
        //Pixel setzen               
        for (uiXX=0; uiXX < 640; uiXX++)
            {
                uiYY= round(240 + 240*sin(2*3.1415926 * (uiXX / 640.0)));
                 SetPixel(hDC, uiXX, uiYY, RGB(255,255,255));
            }
    }
    ReleaseDC(hWnd, hDC);
    DeleteDC(hDC);
   
    //std::cin.get();
    system("pause");  
    return 0;       
};/* run this program


LISSAJUSCHE FIGUR

include <windows.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

/
void delay(int delay)
{
 int now=time(NULL);
 int later=now+delay;
 while(now<=later)now=time(NULL);
}

int main(void)
{
 unsigned int uiXX;
 unsigned int uiYY;
 unsigned long ulNN;
 
    #define Y_WIDTH 480
    #define Y_SPAN  Y_WIDTH/2.0

    SetConsoleTitle("Grafik in Dos");
    //HWND hWnd = FindWindow(NULL, "Grafik in Dos");
    //alternative zu FindWindow
    HWND hWnd = GetConsoleWindow();
    HDC hDC = GetDC(hWnd);   

    //Pixel setzen               
    for ( ulNN=0;  ulNN < 1000000UL;  ulNN++)
        {
            uiYY= round(Y_SPAN + Y_SPAN * sin(100.0 * ulNN) );
            uiXX= round(Y_SPAN + Y_SPAN * cos(150.0 * ulNN) );            
            //delay( 1);
            Sleep(1);           
            SetPixel(hDC, uiXX, uiYY, RGB(255,255,255));
        }

    ReleaseDC(hWnd, hDC);
    DeleteDC(hDC);
   
    //std::cin.get();
    system("pause");  
    return 0;       
};


Dynamische Lissajusche Figur:
/*
STANDARD 480 * 800?
Speicherort
D:\Dev_Cpp

https://www.tutorials.de/threads/grafiken-zeichnen-in-der-konsole.194602/
MinGW erneuern
https://sourceforge.net/projects/orwelldevcpp/files/Compilers/MinGW/

libgdi32.a mit dazulinken:
Programmier-Knowhow_DEV_C++
Unter Projektoptionen->Parameter->Linker wählst du aus dem lib Verzeichnis von DevCpp einfach die o.g. lib aus.
D:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib32\libgdi32.a
*/

#pragma comment(lib,"libgdi32.a")   // einbinden von lib

#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

using namespace std;

void delay(int delay)
{
 int now=time(NULL);
 int later=now+delay;
 while(now<=later)now=time(NULL);
}

int main(void)
{
 unsigned int uiCC;
 unsigned int uiXX;
 unsigned int uiYY;
 unsigned long ulNN;
 
    #define Y_WIDTH 480
    #define Y_SPAN  Y_WIDTH/2.0

    SetConsoleTitle("Grafik in Dos");
    //HWND hWnd = FindWindow(NULL, "Grafik in Dos");
    //alternative zu FindWindow
  
  
while(1)
{
 HWND hWnd = GetConsoleWindow();
        HDC hDC = GetDC(hWnd);   
   for( uiCC=50; uiCC < 200;  uiCC+=10)
           {
            //Pixel setzen               
        for ( ulNN=0;  ulNN < 100000UL;  ulNN++)
            {
                uiYY= round(Y_SPAN + Y_SPAN * sin(100.0 * ulNN) );
                uiXX= round(Y_SPAN + Y_SPAN * cos( (float)uiCC * ulNN) );            
                //delay( 1);
                //Sleep(1);           
                SetPixel(hDC, uiXX, uiYY, RGB(255,255,255));
            };
        Sleep(200);           
        system("cls");
        };

    ReleaseDC(hWnd, hDC);
    DeleteDC(hDC);
};
    //std::cin.get();
    system("pause");  
    return 0;       
};/* run this program using the console pauser or add your own getch, system("pause") or input loop */




FRAKTALE:
/*
D:\Dev_Cpp
D:\Dev_Cpp\Graf_Fraktal2

STANDARD 480 * 800?
Speicherort
D:\Dev_Cpp
MinGW erneuern

https://www.tutorials.de/threads/grafiken-zeichnen-in-der-konsole.194602/
https://sourceforge.net/projects/orwelldevcpp/files/Compilers/MinGW/

libgdi32.a mit dazulinken:
Unter Projektoptionen->Parameter->Linker wählst du aus dem lib Verzeichnis von DevCpp einfach die o.g. lib aus.

libgdi32.a liegt Bsp: zugleich als 64 und 32 Bit version unter
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib32

*/

#pragma comment(lib,"libgdi32.a")   // einbinden von lib

#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "main.h"
//#include <time.h>

using namespace std;

#define XX_WIDTH 800
#define XX_SPAN  XX_WIDTH
#define YYY_WIDTH 480
#define YY_SPAN  YY_WIDTH


#define MATRIX_ZEILEN     480.0
#define MATRIX_SPALTEN    480.0
#define COULOUR_MAX_VAL    16777216UL

#define ITERATION_MAX    25000UL
#define X_MIN             -1.6
#define X_WIDTH            2.8

#define Y_MIN             -1.5
#define Y_WIDTH            3.0
typedef signed char     int8_t;
typedef unsigned char     uint8_t;
typedef signed int     int16_t;
typedef unsigned int     uint16_t;
typedef signed long int     int32_t;
typedef unsigned long int     uint32_t;
typedef signed long long int     int64_t;
typedef unsigned long long int     uint64_t;

//GLOBAL
HWND hWnd;
HDC hDC;
unsigned long IterationMax  = ITERATION_MAX;
unsigned char u8Rot, u8Gruen, u8Blau;

//Fraktalberechnung
// ****************************************************************
void Fraktal( double fX_Min, double fX_Width,double fY_Min, double fY_Width )
// ****************************************************************
{
    //ANFANG
//http://warp.povusers.org/Mandelbrot/

uint8_t u8Event = 0;

uint16_t u16XX;
uint16_t u16YY;
uint16_t u16IterNN;
uint16_t u16IterMax = ITERATION_MAX;
float fIterCoulourquotient;
uint32_t u32Coulour;

double fRN;
double fIN;
double fReal;
double fImag;
double fBetrag;
double fINC_X; //OFFSET
double fINC_Y; //OFFSET
double fXC;
double fYC;
//float  _Complex a = 1;

system("cls");

fINC_X = fX_Width / MATRIX_ZEILEN;     //OFFSET
fINC_Y = fY_Width / MATRIX_SPALTEN ; //OFFSET

fXC = fX_Min;
fYC = fY_Min;
// Zn+^= Z^2 + C
for( u16YY = 0 ; u16YY < MATRIX_SPALTEN ; u16YY++)   
    {
    for( u16XX = 0 ; u16XX < MATRIX_ZEILEN ; u16XX++)
        {
        fRN     = 0;
        fIN     = 0;       
        //u8Event &= ~ITERATION_ENDE;   
       
        for( u16IterNN=0; u16IterNN < u16IterMax; u16IterNN++)
            {
            fReal    = fRN * fRN;
            fImag    = fIN * fIN;
            fBetrag    = (fReal* fReal) + (fImag * fImag);
            if( fBetrag >= 4.0 )
                {
                u32Coulour = round( ( (float)u16IterNN / (float)u16IterMax  ) * (float)COULOUR_MAX_VAL);
               
               
                u8Rot =  (unsigned char)(u32Coulour  );
                u8Gruen =  (unsigned char)(u32Coulour >> 8),
                u8Blau  =   (unsigned char)(u32Coulour >> 16);
                SetPixel(hDC, u16XX, u16YY, RGB(u8Rot, u8Gruen, u8Blau));           
                break;
                };          
            fIN    = (fIN * fRN * 2 ) + fYC;
            fRN = fReal - fImag + fXC;   
            };       
        fXC += fINC_X;
        };      
    fXC = fX_Min;  //Weider auf Anfang stellen
    fYC += fINC_Y;
    };
};
// ----------------------------------------------------------------------------
int main(void)
{
double dX_Min = X_MIN;
double dX_Width = X_WIDTH;
double dY_Min = Y_MIN;
double dY_Width = Y_WIDTH;

SetConsoleTitle("Fraktal in Command Grafik");
    //HWND hWnd = FindWindow(NULL, "Grafik in Dos");
    //alternative zu FindWindow
hWnd = GetConsoleWindow();
hDC = GetDC(hWnd);      

         dX_Min = -1.8;
        dX_Width = 2.3;
        dY_Min = -1.3;
        dY_Width = 2.6;       
        Fraktal( dX_Min, dX_Width, dY_Min, dY_Width );
       
    ReleaseDC(hWnd, hDC);
    DeleteDC(hDC);
    //std::cin.get();
    system("pause");  
    return 0;       
};/* run this program using the console pauser or add your own getch, system("pause") or input loop */