kommt_noch
Grünschnabel
so ... einige tage vergangen und meinen bildschirmschoner etwas aufgebessert...
nachdem es ...auch mit dem alpha wert ging war mir der kasten zu langweilig ...
und noch n paar spielerein eingebaut ...
nu ist er fertig![Smile :) :)](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f642.png)
danke nochmal für die hilfe
<kommt_noch>
nachdem es ...auch mit dem alpha wert ging war mir der kasten zu langweilig ...
und noch n paar spielerein eingebaut ...
nu ist er fertig
![Smile :) :)](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f642.png)
danke nochmal für die hilfe
<kommt_noch>
Code:
//
// mein kleiner Bildschirmschoner version 3.2 beta
//
//
#include <iostream>
#include <stdlib.h>
#include <math.h>
//Benoetigt fuer OpenGL
#include <GL/glut.h> // OpenGL
#include <GL/glf.h> // GLF
using namespace std;
//Varable für den Transparenzwert
GLfloat t = 0.0;
//Variablen für das zufällige Erscheinen
GLfloat a = 0.0;
GLfloat b = 0.0;
// Variablen für die Spiralbewegung
GLfloat positionX = 0.0;
GLfloat positionY = 0.0;
GLfloat winkel = 0.01;
GLfloat radius = 0.01;
// Funktion die zufällige Werte für a und b generiert
void position(void)
{
GLfloat vz;
vz = rand()%2;
if (vz ==1)
a = -(rand()%34);
else
a = (rand()%34);
vz = rand()%2;
if (vz ==1)
b = -(rand()%18);
else
b = (rand()%18);
}
// Funktion durch die Veränderungen erzeugt werden
void aktion (int i)
{
if(t<1){ // objekt wird sichtbar gemacht
t += 0.01;
glutPostRedisplay();
glutTimerFunc(30 ,aktion,1);
}
else{
if(radius >= 40) {
winkel = 0.0;
t=0.0;
position();
}
winkel += 0.15/(1+ radius); // erzeugt die Bewegung
positionX = 1.5 * winkel*cos(winkel);
positionY = 1.5 * winkel*sin(winkel);
radius = sqrt(positionX*positionX + positionY*positionY);
glutPostRedisplay();
glutTimerFunc(25 ,aktion,1);
}
}
// Funktion zum erstellen des Kreuzes
// mit den Variablen c1,c2,c3,c4
// für die Farbunterschiede
void objekt(GLfloat c1, GLfloat c2, GLfloat c3, GLfloat c4){
//Beginn c2-Fläche
glColor4f(0.0,0.0,c2,t);
glBegin (GL_POLYGON);
glVertex2f (-3.0, -3.0);
glVertex2f (-3.0, -1.0);
glVertex2f (-1.0, -1.0);
glVertex2f (-1.0, -3.0);
glEnd();
glBegin (GL_POLYGON);
glVertex2f (-3.0, 1.0);
glVertex2f (-3.0, 2.0);
glVertex2f (-1.0, 2.0);
glVertex2f (-1.0, 1.0);
glEnd();
glBegin (GL_POLYGON);
glVertex2f (-2.0, 2.0);
glVertex2f (-2.0, 3.0);
glVertex2f (-1.0, 3.0);
glVertex2f (-1.0, 2.0);
glEnd();
//Beginn c3-Fläche
glColor4f(0.0,0.0,c3,t);
glBegin (GL_POLYGON);
glVertex2f (-2.0, 0.0);
glVertex2f (-3.0, 1.0);
glVertex2f (-1.0, 1.0);
glVertex2f ( 0.0, 0.0);
glEnd();
glBegin (GL_POLYGON);
glVertex2f ( 1.0, -3.0);
glVertex2f ( 0.0, -2.0);
glVertex2f ( 1.0, -1.0);
glVertex2f ( 3.0, -3.0);
glEnd();
//Beginn c4-Fläche
glColor4f(0.0,0.0,c4,t);
glBegin (GL_POLYGON);
glVertex2f (-3.0, -1.0);
glVertex2f (-2.0, 0.0);
glVertex2f ( 0.0, 0.0);
glVertex2f (-1.0, -1.0);
glEnd();
glBegin (GL_POLYGON);
glVertex2f ( 0.0, 2.0);
glVertex2f ( 1.0, 3.0);
glVertex2f ( 3.0, 3.0);
glVertex2f ( 1.0, 1.0);
glEnd();
//beginn c1-Fläche
glColor4f(0.0,0.0,c1,t);
glBegin (GL_POLYGON);
glVertex2f (-1.0, -3.0);
glVertex2f (-1.0, -1.0);
glVertex2f ( 3.0, 3.0);
glVertex2f ( 3.0, 1.0);
glEnd();
glBegin (GL_POLYGON);
glVertex2f ( 1.5, 0.5);
glVertex2f ( 3.0, -1.0);
glVertex2f ( 3.0, -3.0);
glVertex2f ( 0.5, -0.5);
glEnd();
glBegin (GL_POLYGON);
glVertex2f ( 0.5, -0.5);
glVertex2f (-1.0, 1.0);
glVertex2f (-1.0, 3.0);
glVertex2f ( 1.5, 0.5);
glEnd();
glLineWidth(3.);
// für Umrandung derFlächen
glColor4f(0.0,0.0,0.0,t);
glBegin (GL_LINE_LOOP);
glVertex2f (-3.0, 1.0);
glVertex2f (-3.0, 2.0);
glVertex2f (-2.0, 2.0);
glVertex2f (-2.0, 3.0);
glVertex2f (-1.0, 3.0);
glVertex2f (-1.0, 1.0);
glEnd();
glBegin (GL_LINE_LOOP);
glVertex2f (-3.0, -3.0);
glVertex2f (-3.0, -1.0);
glVertex2f (-1.0, -1.0);
glVertex2f (-1.0, -3.0);
glEnd();
glBegin (GL_LINE_LOOP);
glVertex2f (-3.0, -1.0);
glVertex2f (-2.0, 0.0);
glVertex2f ( 0.0, 0.0);
glVertex2f (-1.0, -1.0);
glEnd();
glBegin (GL_LINE_LOOP);
glVertex2f ( 0.0, 2.0);
glVertex2f ( 1.0, 3.0);
glVertex2f ( 3.0, 3.0);
glVertex2f ( 1.0, 1.0);
glEnd();
glBegin (GL_LINE_LOOP);
glVertex2f (-2.0, 0.0);
glVertex2f (-3.0, 1.0);
glVertex2f (-1.0, 1.0);
glVertex2f ( 0.0, 0.0);
glEnd();
glBegin (GL_LINE_LOOP);
glVertex2f ( 1.0, -3.0);
glVertex2f ( 0.0, -2.0);
glVertex2f ( 1.0, -1.0);
glVertex2f ( 3.0, -3.0);
glEnd();
glBegin (GL_LINE_LOOP);
glVertex2f ( 0.0, 0.0);
glVertex2f (-1.0, 1.0);
glVertex2f (-1.0, 3.0);
glVertex2f ( 1.0, 1.0);
glVertex2f ( 3.0, 3.0);
glVertex2f ( 3.0, 1.0);
glVertex2f ( 2.0, 0.0);
glVertex2f ( 3.0, -1.0);
glVertex2f ( 3.0, -3.0);
glVertex2f ( 1.0, -1.0);
glVertex2f (-1.0, -3.0);
glVertex2f (-1.0, -1.0);
glEnd();
glLineWidth(1.);
}
// Graphik wird erstellt
void display(void)
{
GLfloat posX = 0.0;
GLfloat posY = -5.0;
GLfloat tmp = 0.0;
//Variablen für Farbwerte
GLfloat c1 = 0.6 ;
GLfloat c2 = 0.5 ;
GLfloat c3 = 0.4 ;
GLfloat c4 = 0.3 ;
GLfloat tmpc = 0.0 ;
glClearColor(0.50 , 0.50 , 0.50 , 0.0); // macht hintergrund farbig
glClear (GL_COLOR_BUFFER_BIT);
glPolygonMode(GL_FRONT, GL_LINE);
// Schleife zum erzeugen der 4 kreuze
for(int i=0; i<4;i++){
glPushMatrix();
glScalef( 0.3 , 0.3 , 1 );
glTranslatef(positionX+posX+a, positionY+posY+b , 1.0);
glRotatef( i*90 ,0,0,1); //dreht die kreuze in die richtige position
//erstellen des Kreuzes
objekt(c1,c2,c3,c4);
//Wechsel der Farben ab zweitem Durchlauf
tmpc =c1;
c1=c4;
c4=c2;
c2=c3;
c3=tmpc;
// ändern der koordinaten des Mittelpunktes
tmp = posX ;
posX = -posY ;
posY = tmp ;
glPopMatrix();
}
glutSwapBuffers(); // Bildspeicher wird gewechselt
}
// Aenderungen des Fensters
void reshape (int w, int h)
{
float faktor1 = (float) h / (float) w;
float faktor2 = (float) w / (float) h;
glViewport (0, 0, w, h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
// Weltkoordinaten
if (w <= h)
gluOrtho2D (-8.0, 8.0, -8.0 * faktor1, 8.0 * faktor1);
else
gluOrtho2D (-8.0 * faktor2, 8.0 * faktor2, -8.0, 8.0);
glMatrixMode(GL_MODELVIEW);
}
// Tastaturabfragen
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
//glutmainloop() beenden
case 27: // Escape-Taste
exit(0);
break;
}
}
int main(int argc, char** argv)
{
// Initialisierungen (GLUT)
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA );
glutInitWindowSize (1000, 1000);
glutInitWindowPosition (200, 200);
glutCreateWindow (argv[0]);
glutFullScreen(); // FULLSCREEN
// Initialisierungen (GLF)
glfInit();
glfLoadFont("/opt/glf/fonts/arial1.glf");
// Callback Funktionen
// für transparenz erforderlich
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
srand(NULL);
position();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc (keyboard);
glutTimerFunc(2000,aktion,1); //
//Nun beginnt es;
glutMainLoop();
return 0;
}
//ende
//////////////////////////////////////////////////////////////////////////////