Accueil > > > FRACTALE NEWTON-RAPHSON VERSION GLUT
FRACTALE NEWTON-RAPHSON VERSION GLUT
Information sur la source
Description
Programme permettant de générer la fractale de Newton-Raphson. f(z) = z^3-1=0 où z = x+iy. La méthode de Newton-Raphson: xn = xn-1 - f(xn-1)/f'(xn-1) f'(z)=3z² z = z -f(z)/f'(z) = (2/3)*z + 1/3z² or z = x+iy => z = (2/3)*(x+yi) + 1/3*(x+yi)2 donc : z = (2/3)*(x+yi) + ((x2 - y2) - 2*x*yi)/3*((x2 - y2)2 + 4*x2*y2) posons: d = 3*((x2 - y2)2 + 4*x2*y2) finalement: z = [(2/3)*x + (x2 - y2)/d] + [(2/3)*y - 2*x*y/d]i **** Mon programme met assez de temps pour générer la fractale. Si quelqu'un sait comme améliorer ça, poster moi un message. Autre chose: Avec un click droit on zoom et click gauche on dézoom.
Source
- //Programme qui génére la Fractale de Newton-Raphson
- //Programmé par Jarod1980 - 02/08/2005
- // f(z) = z^3-1=0
- // où z = x+iy. La méthode de Newton-Raphson: xn = xn-1 - f(xn-1)/f'(xn-1)
- // f'(z)=3z²
- //z = z -f(z)/f'(z) = (2/3)*z + 1/3z² or z = x+iy => z = (2/3)*(x+yi) + 1/3*(x+yi)2
- // donc : z = (2/3)*(x+yi) + ((x2 - y2) - 2*x*yi)/3*((x2 - y2)2 + 4*x2*y2)
- // posons:
- // d = 3*((x2 - y2)2 + 4*x2*y2)
- //finalement: z = [(2/3)*x + (x2 - y2)/d] + [(2/3)*y - 2*x*y/d]i
-
- #include <GL/glut.h>
- #include <stdio.h>
- #include <math.h>
-
-
- typedef unsigned char uchar;
-
- void disp(void);
- void reshape(int x,int y);
- void mouse(int button,int state, int x, int y);
- void keyb(uchar key,int x,int y);
- void CrearPaleta(void);
-
- static int winx;
- static int winy;
- static double xbegin = -2.0;
- static double xend=2.0;
- static double ybegin = -2.0;
- static double yend=2.0;
-
- int R,G,B;
- int ColorRGB[256][3];
- int color;
-
-
- int main(int argc, char **argv){
-
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
- glutCreateWindow("Fractale Newton-Raphson");
- glutInitWindowSize(600,600);
-
- CreerPalette();
- glClearColor(1.0,1.0,1.0,0.0);
- glutDisplayFunc(disp);
- glutReshapeFunc(reshape);
- glutMouseFunc(mouse);
- glutKeyboardFunc(keyb);
- glutMainLoop();
- }
-
-
- void disp(void){
- float i,j;
- double deltax, deltay;
- double x, y, tmp, xx, yy, d;
- int color, row, col, count;
- int maxiter = 2048; //nombre d'itérations
-
- deltax = (xend - xbegin)/winx;
- deltay = (yend - ybegin)/winy;
-
- glClear(GL_COLOR_BUFFER_BIT);
-
- // debut définition
- glBegin(GL_POINTS);
-
- // pour chaque pixel à l'écran
- for(i=0;i<winx;i++){
-
- for( j=0;j<winy;j++){
- x = xbegin + i * deltax;
- y = ybegin + j * deltay;
- count=0;
- while (count<maxiter)
- {
- xx = x*x;
- yy = y*y;
- d = 3.0*((xx - yy)*(xx - yy) + 4.0*xx*yy);
- if (d == 0.0)
- d = 0.000001;
- tmp=x;
- x = (2.0/3.0)*x + (xx - yy)/d;
- y = (2.0/3.0)*y - 2.0*tmp*y/d;
- count+=1;
- }
- if (x>0.0)
- color = count%64;
- else
- {
- if ((x<-0.3) && (y>0.0))
- color = (count%64) + 64;
- else
- color = (count%64) + 128;
- }
- R=ColorRGB[color][0];
- G=ColorRGB[color][1];
- B=ColorRGB[color][2];
-
- glColor3f (R,G,B);
- glVertex2f(i,j); //on trace
- }
- }
- glEnd();
-
- glutSwapBuffers();
- }
-
- void keyb(uchar key, int x, int y){
- if(key=='Q'||key=='q'){
- exit(0);
- }else if(key=='r'){
- xbegin = -1.8;
- xend=1.1;
- ybegin = -1.2;
- yend=1.2;
- reshape(winx,winy);
- }
-
- }
- //fonction permettant de zoomer avec la souris
- //click droit pour zoom ( + ), gauche pour zoom( - )
- void mouse(int button,int state,int x,int y){
-
- if(state == GLUT_DOWN){
-
- y = winy - y;
- double dx = (xend-xbegin);
- double dy = (yend-ybegin);
- if(dx != 0 && dy != 0){
- if(button == GLUT_LEFT){
- xend = x * dx/winx +xbegin + dx/10;
- xbegin = x * dx/winx +xbegin - dx/10;
-
- yend = y * dy/winy +ybegin + dy/10;
- ybegin = y * dy/winy +ybegin - dy/10;
- }else{
- xend = x * dx/winx +xbegin + 5*dx;
- xbegin = x * dx/winx +xbegin - 5*dx;
-
- yend = y * dy/winy +ybegin + 5*dy;
- ybegin = y * dy/winy +ybegin - 5*dy;
-
- }
- glutPostRedisplay();
- }else{
-
- printf("appuyer sur 'r' pour reset");
- }
- }
- }
-
- void reshape(int x,int y){
- winx =x;
- winy =y;
- glViewport(0,0,x,y);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D(0,x,0,y);
- glMatrixMode(GL_MODELVIEW);
- glutPostRedisplay();
- }
- void CreerPalette(void)
- {
- int i;
-
- for (i=0; i<256; i++)
- {
- if (i<64)
- {
- ColorRGB[i][0] = 192 + i;
- ColorRGB[i][1] = 0;
- ColorRGB[i][2] = 0;
- }
- else if ((i>63) && (i<128))
- {
- ColorRGB[i][0] = 0;
- ColorRGB[i][1] = (192 + i)-64;
- ColorRGB[i][2] = 0;
- }
- else if ((i>127)&&(i<192))
- {
- ColorRGB[i][0] = 0;
- ColorRGB[i][1] = 0;
- ColorRGB[i][2] = (192 + i)-128;
- }
- }
- }
//Programme qui génére la Fractale de Newton-Raphson
//Programmé par Jarod1980 - 02/08/2005
// f(z) = z^3-1=0
// où z = x+iy. La méthode de Newton-Raphson: xn = xn-1 - f(xn-1)/f'(xn-1)
// f'(z)=3z²
//z = z -f(z)/f'(z) = (2/3)*z + 1/3z² or z = x+iy => z = (2/3)*(x+yi) + 1/3*(x+yi)2
// donc : z = (2/3)*(x+yi) + ((x2 - y2) - 2*x*yi)/3*((x2 - y2)2 + 4*x2*y2)
// posons:
// d = 3*((x2 - y2)2 + 4*x2*y2)
//finalement: z = [(2/3)*x + (x2 - y2)/d] + [(2/3)*y - 2*x*y/d]i
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
typedef unsigned char uchar;
void disp(void);
void reshape(int x,int y);
void mouse(int button,int state, int x, int y);
void keyb(uchar key,int x,int y);
void CrearPaleta(void);
static int winx;
static int winy;
static double xbegin = -2.0;
static double xend=2.0;
static double ybegin = -2.0;
static double yend=2.0;
int R,G,B;
int ColorRGB[256][3];
int color;
int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("Fractale Newton-Raphson");
glutInitWindowSize(600,600);
CreerPalette();
glClearColor(1.0,1.0,1.0,0.0);
glutDisplayFunc(disp);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutKeyboardFunc(keyb);
glutMainLoop();
}
void disp(void){
float i,j;
double deltax, deltay;
double x, y, tmp, xx, yy, d;
int color, row, col, count;
int maxiter = 2048; //nombre d'itérations
deltax = (xend - xbegin)/winx;
deltay = (yend - ybegin)/winy;
glClear(GL_COLOR_BUFFER_BIT);
// debut définition
glBegin(GL_POINTS);
// pour chaque pixel à l'écran
for(i=0;i<winx;i++){
for( j=0;j<winy;j++){
x = xbegin + i * deltax;
y = ybegin + j * deltay;
count=0;
while (count<maxiter)
{
xx = x*x;
yy = y*y;
d = 3.0*((xx - yy)*(xx - yy) + 4.0*xx*yy);
if (d == 0.0)
d = 0.000001;
tmp=x;
x = (2.0/3.0)*x + (xx - yy)/d;
y = (2.0/3.0)*y - 2.0*tmp*y/d;
count+=1;
}
if (x>0.0)
color = count%64;
else
{
if ((x<-0.3) && (y>0.0))
color = (count%64) + 64;
else
color = (count%64) + 128;
}
R=ColorRGB[color][0];
G=ColorRGB[color][1];
B=ColorRGB[color][2];
glColor3f (R,G,B);
glVertex2f(i,j); //on trace
}
}
glEnd();
glutSwapBuffers();
}
void keyb(uchar key, int x, int y){
if(key=='Q'||key=='q'){
exit(0);
}else if(key=='r'){
xbegin = -1.8;
xend=1.1;
ybegin = -1.2;
yend=1.2;
reshape(winx,winy);
}
}
//fonction permettant de zoomer avec la souris
//click droit pour zoom ( + ), gauche pour zoom( - )
void mouse(int button,int state,int x,int y){
if(state == GLUT_DOWN){
y = winy - y;
double dx = (xend-xbegin);
double dy = (yend-ybegin);
if(dx != 0 && dy != 0){
if(button == GLUT_LEFT){
xend = x * dx/winx +xbegin + dx/10;
xbegin = x * dx/winx +xbegin - dx/10;
yend = y * dy/winy +ybegin + dy/10;
ybegin = y * dy/winy +ybegin - dy/10;
}else{
xend = x * dx/winx +xbegin + 5*dx;
xbegin = x * dx/winx +xbegin - 5*dx;
yend = y * dy/winy +ybegin + 5*dy;
ybegin = y * dy/winy +ybegin - 5*dy;
}
glutPostRedisplay();
}else{
printf("appuyer sur 'r' pour reset");
}
}
}
void reshape(int x,int y){
winx =x;
winy =y;
glViewport(0,0,x,y);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,x,0,y);
glMatrixMode(GL_MODELVIEW);
glutPostRedisplay();
}
void CreerPalette(void)
{
int i;
for (i=0; i<256; i++)
{
if (i<64)
{
ColorRGB[i][0] = 192 + i;
ColorRGB[i][1] = 0;
ColorRGB[i][2] = 0;
}
else if ((i>63) && (i<128))
{
ColorRGB[i][0] = 0;
ColorRGB[i][1] = (192 + i)-64;
ColorRGB[i][2] = 0;
}
else if ((i>127)&&(i<192))
{
ColorRGB[i][0] = 0;
ColorRGB[i][1] = 0;
ColorRGB[i][2] = (192 + i)-128;
}
}
}
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
la methode de newton raphson [ par crippella ]
Bonjour, svp est ce que vous pouvez m'indiquer comment faire un programme sur MATLAB ce programme doit demander à l'utilisateur d'entrer une fonction
Device context et StretchBlt ? [ par tavernier ]
Bonjour, je suis en train de faire un générateur de fractale et j'ai besoin de mettre la fractale de coté pour ne pas avoir à tout recalculer pour la
Sauver les pixels!! :s [ par Gendal67 ]
Bonjour à tous!Je suis en cous de création d'une application qui doit "dessiner" toute seule dans une fenêtre (tracer des fracales pour
Methode de Newton - Minimisation [ par r_farez ]
Salut, je cherche le code source de la methode de Newton pour rechercher le minimum d'une fonction. (en C)Si quelqu'un peut m'aider ce serait cool!Mer
fractale tpe [ par zolies fleurs ]
je dois réaliser un tpe sur les fractales et la nature. je voudrais télécharger un logiciel simple pour pouvoir réaliser quelque f
fractale tpe [ par zolies fleurs ]
g encore un petit probleme de logiciel, g du mal a utiliser chaospro pour réaliser des fractales . je ne vois pas très bien le rapport
recherche du zero methode de newton [ par fadelon111 ]
bjr,je cherche le code de la recherche du zero par la methode de newton.merci.
Méthode de Newton [ par cocotte03 ]
bonjour,je souhaite résoudre F(x)=0 en codant la méthode de Newton en C++. Mais mon problème principal est que je ne sais pas comment le faire car la
Loi de newton. [ par ralekely ]
Bonjour à tous!Je souhaite resoudre un problème, qui je dois avouer, est plus un problème physique qu'un problème de code.Voilà: Je souhaite modeliser
fractale faits a bases de triangles equilaterales en langages C [ par mbaye01 ]
je voudrai faire des fractales a base de triangles equilaterales on doit donner les coordonnees de 2 points et le niveau de recursivité et on obtient
|
Derniers Blogs
SHAREPOINT 2010 : COMPARAISON ENTRE LA VERSION 2007 ET LA VERSION 2010SHAREPOINT 2010 : COMPARAISON ENTRE LA VERSION 2007 ET LA VERSION 2010 par phil
Avant de passer en mode "rentrée" pour la reprise en main de ce blog après une longue période de vacances, j'en profite pour poster quelsues liens qui m'ont été bien utiles pour expliquer, depuis quelques mois déjà, quelles différences il existe en te...
Cliquez pour lire la suite de l'article par phil QUELQUES TRUCS INTéRESSANTS (05/09/2010)QUELQUES TRUCS INTéRESSANTS (05/09/2010) par coq
Cette fois-ci : .NET Debug / Performance Sécurité SQL Server .NET Determining if a type is defined in the .NET Framework (blog de Scott Dorman) Ha tiens, je n'avais jamais vraiment pensé à utiliser le jeton de clé publique...
Cliquez pour lire la suite de l'article par coq ENUMERABLECOLLECTIONENUMERABLECOLLECTION par Matthieu MEZIL
Prenons le scénario suivant. On utilise MVVM. On a les deux classes suivantes dans le model : public class Child { } public class Parent { private ObservableCollection < Child > _children; public ObservableCollection < Child > Children { get {...
Cliquez pour lire la suite de l'article par Matthieu MEZIL [HS] CHROME 6 + MOI = COUP DE GUEULE ![HS] CHROME 6 + MOI = COUP DE GUEULE ! par JeremyJeanson
Attention, le poste qui suit n'est pas la complainte d'une personne : Qui n'aime pas Chrome. D'un anti Google. D'un développeur qui a un poil énorme dans la main. Ceux qui me fréquentent savent que je change de navigateur favori tous les 2 ou 3 mois afin ...
Cliquez pour lire la suite de l'article par JeremyJeanson
Forum
LISTE ET TABLEAULISTE ET TABLEAU par dida87
Cliquez pour lire la suite par dida87
Logiciels
WebLogAndPass (1.0.0)WEBLOGANDPASS (1.0.0)WebLogAndPass est un logiciel permettant de mémoriser vos sites préférés et pour chacun d'entre-e... Cliquez pour télécharger WebLogAndPass uTorrent (2.0.4)UTORRENT (2.0.4)C'est un client BitTorrent très puissant et très performant. Comme son nom l'indique, uTorrent (m... Cliquez pour télécharger uTorrent Bureau de Gestion - ERP Devis Facturation (2.02)BUREAU DE GESTION - ERP DEVIS FACTURATION (2.02)- Version gratuite du 10/06/2010
Le Bureau de Gestion est un logiciel dédié à la gestion de l'en... Cliquez pour télécharger Bureau de Gestion - ERP Devis Facturation 4Videosoft Transfert iPod Mac (3.2.08)4VIDEOSOFT TRANSFERT IPOD MAC (3.2.08)4Videosoft Transfert iPod-Mac caractérise principalement à transférer les fichiers iPod vers Mac.... Cliquez pour télécharger 4Videosoft Transfert iPod Mac 4Videosoft HD Convertisseur (3.3.08)4VIDEOSOFT HD CONVERTISSEUR (3.3.08)Etant le meilleur HD Vidéo Convertisseur, 4Videosoft HD Convertisseur, vous pouvez regarder la vi... Cliquez pour télécharger 4Videosoft HD Convertisseur
|