The Dark Side of Hardware Upgrade Forum

...bringing out the worst in you since 2003...
Oggi è mar ott 06, 2026 8:28 am

Tutti gli orari sono UTC +1 ora


-->
-->

Regole del forum


-NON si parla neanche alla lontana di istruzioni per materiali esplosivi, armi da guerra, aggressivi chimici o sostanze batteriologiche nocive o pericolose o altri congegni micidiali (cit.)
-Le robe complottistiche (=cagate) mettetele in altre sezioni



Apri un nuovo argomento Rispondi all’argomento  [ 21 messaggi ] 
Autore Messaggio
 Oggetto del messaggio: Automi cellulari
MessaggioInviato: lun lug 04, 2011 8:21 am 
Schiavo
Avatar utente
Iscritto il: gio lug 15, 2010 7:35 pm
Messaggi: 5339
Località: Tua madre succhia i cazzi all'inferno, idiota
Mi sono imbattuto l'altro ieri sull'argomento. Ho cercato un libro e dopo tanta ricerca su google ho trovato link, e che dire, offre, almeno a me, una nuova prospettiva. Dalla definizione sul libro:
Cita:
Cellular automata (CA) are a class of spatially and temporally discrete, deterministic mathematical systems characterized by local interaction and an inherently parallel form of evolution.
Da wiki:
Cita:
A cellular automaton (pl. cellular automata, abbrev. CA) is a discrete model studied in computability theory, mathematics, physics, complexity science, theoretical biology and microstructure modeling. It consists of a regular grid of cells, each in one of a finite number of states, such as "On" and "Off" (in contrast to a coupled map lattice).
In altri termini è il grafico di evoluzione spaziotemporale di una funzione ricorsiva. Manca la continuità, nel senso che il grafico non sarà continuo ma a quadretti. Graficamente, considero una linea quadrettata di un quaderno corrispondente diciamo ad un vettore numerico posto orizzontalmente. Ad ogni numero o quadretto è associato un colore. Dato che il tempo è discreto, ovvero assume valori interi, al tempo t=1 il vettore sarà mutato in un secondo vettore numerico seguendo una certa funzione, o legge. Poniamo questo secondo vettore sotto al primo. Iterando il procedimento ottengo una tabella colorata di puntini. La regola è della forma:

Immagine

Dove c(t) è il valore di un quadretto o equivalentemente di una cellula o equivalentemente di una componente del vettore al tempo t. Il suo valore dipende dal valore che essa ed alcune cellule circostanti assumono nell'istante di tempo precedente. La formula tiene conto di un raggio r, ovvero dice che devo tenere conto del valore assunto da r cellule a destra, ed r a sinistra. Vi sarà chiaro nell'esempio successivo. Quando sono noti i valori che la legge assume per ogni combinazione di valori iniziale dentro al raggio, essa è completamente determinata. Consideriamo la seguente linea iniziale:

0001000

Definisco la seguente regola, se incontro queste coppie, in quella posizione nella riga sotto scriverò quel numero.
Codice:
00
0

01
1

10
0

11
1
0 quando manca la seconda cifra della coppia, ovvero quando ho 12345 inizio confrontando 12 poi 23, ecc, ma quando arrivo a 5 questo resta :alone: Quindi la precedente diventa:

Codice:
00010110
00101100
01011000
10110000

Con questa regola a caso mi sono accorto di avere ottenuto una traslazione. Vediamo il primo esempio che offre il libro. Svilupperemo la legge 30 rule 30, così si chiama, partendo da una retta con un solo punto nero al centro. Ricordiamo che ad ogni numero è associato un colore. Nel nostro caso 1=nero e 0=bianco. La forma grafica della legge ed il risultato sono i seguenti:

Immagine

Significa che quando incontro una terna quello è il colore che prende il punto subito sotto. Ho scritto un programma in C++ dove potete modificare le regole ed il vettore iniziale come pare a voi e vedere cosa ne viene fuori. Volevo ottenerne una rappresentazione grafica con le Opengl ma non riesco a capire come usarle sotto linux, puttana maiala. Ecco:

Codice:
#include<iostream>
using namespace std;

int main(){
int n=100;
int value[n][n];

for(int i=0; i<n; i++){
for(int j=0; j<n; j++)
value[i][j]=0;}
    value[0][(n)/2]=1;

for(int i=0; i<(n-1); i++){
for(int j=0; j<(n-2); j++){
if(value[i][j]==1 && value[i][j+1]==1 && value[i][j+2]==1)value[i+1][j+1]=0; else
if(value[i][j]==1 && value[i][j+1]==1 && value[i][j+2]==0)value[i+1][j+1]=0; else
if(value[i][j]==1 && value[i][j+1]==0 && value[i][j+2]==1)value[i+1][j+1]=0; else
if(value[i][j]==1 && value[i][j+1]==0 && value[i][j+2]==0)value[i+1][j+1]=1; else
if(value[i][j]==0 && value[i][j+1]==1 && value[i][j+2]==1)value[i+1][j+1]=1; else
if(value[i][j]==0 && value[i][j+1]==1 && value[i][j+2]==0)value[i+1][j+1]=1; else
if(value[i][j]==0 && value[i][j+1]==0 && value[i][j+2]==1)value[i+1][j+1]=1; else
if(value[i][j]==0 && value[i][j+1]==0 && value[i][j+2]==0)value[i+1][j+1]=0;}
}

for(int i=0; i<n; i++){
for(int j=0; j<n; j++)
if(value[i][j]==0)cout<<" "; else
if(value[i][j]==1)cout<<"*";
cout<<endl;
}

Image

La rule 30 assomiglia alla seguente foto, anche se si capisce che le legge a cui risponde la conchiglia e differente:

Image

Se è scritto male potete postare una forma migliore, se sapete usare delle librerie grafiche siete liberi di postare i risultati! Volevo infatti scrivere anche del secondo esempio, Conway's Life Game.

Vediamo alcuni passaggi del libro:
Cita:
[...]In the strongest possible
terms, the long time behavior of computationally universal dynamical systems can
be obtained only by direct simulation. No general predictive procedure is possible,
even in principle. This implies, for example, that for systems such as von Neumann’s
self-reproducing automaton, there can neither be an analytical expression that ex-
actly describes its asymptotic behavior nor an equation that defines the long-term
behavior that itself can be soIved in a time Iess than it would take the system to
evolve (modulo a polynomial function of the number of iteration steps necessary for
it to reach its final state). All such computationally irreducible systems share the
property that their own evolution effectively defines the most efficient simulation of
their behavior.
Significa sostanzialmente che in genere non ci sono equazioni esplicite per predire la forma di un automa cellulare nel lungo periodo, nemmeno teoricamente. Che cosa mi viene in mente? Se fosse possibile esprimere le leggi del mondo microscopico interamente in forma di automi cellulari, potrebbe da queste non essere possibile ricavare equazioni esplicite del mondo macroscopico. Ovvero? Ora forse capisco in parte la difficoltà della formazione di una teoria unificata. Per capire come come l'automa funziona bisogna farlo girare.
Cita:
CA as 0rigin.al Models of Fundamental Physics
CA allow studies of radically new discrete dynamical approaches to microscopic
physics, exploring the possibility that Iiature locally and digitally processes its own
future states. The entire last chapter of this book is devoted to a prolonged dis-
cussion of such potentially ground breaking niotiels of physics. Using the fact that
computationally universal systems are capable of arbitrarily complicated behavior
(in the sense that they can mimic any computation performed by a conventional
computer), the idea is to construct fundamcntally discrete field theories to compete
with existing continuous models. T h e emphasis in this class of models is ernphati-
cally not to construct a lattice-gauge-like theory; rather, in the same way as lattice-
gas CA successfully reproduce continuous fluid flow despite never having heard of
the Navier-Stokes equations, so the hope is to abstract a set of microphysical laws
that reproduce known behavior on the macro scale. A number of interesting ideas
have recently been explored. Fredkin [freclkin93]has arguably gone to the furthest
extreme by asserting that the universe is, a.t its core, a CA! We will offer a few of
our own speculations on this subject in the last chapter.
Ma ovviamente non ho ancora letto la parte finale del libro.
Cita:
What is remarkable about this very simple appearing n h e is that one can show
that it is capable of universal computation. This means that with a proper selection
of initial conditions (i.e. the initial distribution of “live” and “dead” cells), Life can
be turned into a general piirposr: computer. This fact fundamentally limits the
overall predictability of Life’s behavior.
The well known Halting Theorem, for example, asserts that there cannot exist
a general algorithm for predicting when a computer will lialt its execution of a
given program [garey79]. Given that Life is a universal computer ~- so that the
Halting Theorem applies - this means that one cannot, in general, predict whether
a particular starting configuration of live and dead cells will eventually die out.
No shortcut, is possible, even in principle. The best one can do is to sit back and
patiently await Life’s own final outcome.
Put another way, this means that if you want to predict Life’s long-term be-
havior with another “model” or by using, say, a partial differential equation, you
are doomed to fail from the outset because its long-term behavior is effectively un-
predictable
. Life - like all computationally universal systems - defines the most
efficient simulation of its own behavior.
Non ho ricontrollato bene il post quindi spero sia leggibile, vado a letto, quando mi risveglio controllo :okay:
_________________
Long Live Iran
Immagine
Top
 Profilo E-mail Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 04, 2011 8:35 am 
Schiavo
Avatar utente
Iscritto il: sab ott 09, 2010 6:48 pm
Messaggi: 1680
Località: Bernareggio
Aldin ? ha scritto:
spero sia leggibile


Vai tranquillo.
_________________
Immagine
Top
 Profilo Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 04, 2011 9:36 am 
:cereal: wall of text
Top
  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 04, 2011 9:37 am 
Schiavo
Avatar utente
Iscritto il: gio lug 22, 2010 3:58 pm
Messaggi: 8404
la parte più leggibile è il codice C (ed è identato da culo)
_________________
Working Vibes - L'Informazione | Controllo delle masse | Citizen Berlusconi | Storia del periodo berlusconiano | La mafia in politica | L'Ombra Oscura Della P2 | Promemoria | Borsellino: Lezione sulla mafia | Videocracy | Draquila
Top
 Profilo Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 04, 2011 12:02 pm 
Schiavo
Avatar utente
Iscritto il: gio lug 15, 2010 7:35 pm
Messaggi: 5339
Località: Tua madre succhia i cazzi all'inferno, idiota
toyo ? ha scritto:
la parte più leggibile è il codice C (ed è identato da culo)
Prego?
_________________
Long Live Iran
Immagine
Top
 Profilo E-mail Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 04, 2011 12:07 pm 
Schiavo
Avatar utente
Iscritto il: gio lug 22, 2010 3:58 pm
Messaggi: 8404
Aldin ? ha scritto:
toyo ? ha scritto:
la parte più leggibile è il codice C (ed è identato da culo)
Prego?


indentato*

Sempre odiato la prima n
Top
 Profilo Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 04, 2011 12:13 pm 
Schiavo
Avatar utente
Iscritto il: gio lug 15, 2010 7:35 pm
Messaggi: 5339
Località: Tua madre succhia i cazzi all'inferno, idiota
Ah, comunque ci ho messo due ore per scriverlo. Non riuscivo a correggere gli errori quando mi sono accorto di avere dimenticato di inserire la funzione main :trollface:
_________________
Long Live Iran
Immagine
Top
 Profilo E-mail Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 04, 2011 1:42 pm 
Schiavo
Avatar utente
Iscritto il: mer lug 14, 2010 5:07 pm
Messaggi: 7989
Aldin ? ha scritto:
Ah, comunque ci ho messo due ore per scriverlo. Non riuscivo a correggere gli errori quando mi sono accorto di avere dimenticato di inserire la funzione main :trollface:


Metterci uno switch - case faceva schifo? :asd:
_________________
ImmagineImmagine
Msimamizi ni super hydrauliska dickhead. LilithSChild Ni sociopath huzuni. Kuua mambo.
Top
 Profilo E-mail Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 04, 2011 1:43 pm 
Schiavo
Avatar utente
Iscritto il: mar lug 20, 2010 12:42 am
Messaggi: 7120
effeccì
_________________
Immagine
Top
 Profilo Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 04, 2011 1:45 pm 
Schiavo
Avatar utente
Iscritto il: gio lug 22, 2010 3:58 pm
Messaggi: 8404
Jarni ? ha scritto:
Aldin ? ha scritto:
Ah, comunque ci ho messo due ore per scriverlo. Non riuscivo a correggere gli errori quando mi sono accorto di avere dimenticato di inserire la funzione main :trollface:


Metterci uno switch - case faceva schifo? :asd:

Dal punto di vista dell'efficenza è esattamente =
Top
 Profilo Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 04, 2011 2:53 pm 
Schiavo
Avatar utente
Iscritto il: ven giu 17, 2011 7:09 pm
Messaggi: 1262
Aldin, a volte vorrei avere il tuo tempo libero.
_________________
eroggeno best quote 01/12/11 [eroggeno vs. disprezzo] :asd:

eroggeno ha scritto:
esattamente per questo non ti sei riprodotto

hai strarotto i coglioni con le tue sentenze da tuttologo

un coglione rsta un coglione anche a 60 anni ricordatelo


Ultima modifica di Wolfhwk, lun lug 04, 2011 4:23 pm, modificato 1 volta.
Top
 Profilo Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 04, 2011 4:01 pm 
Schiavo
Avatar utente
Iscritto il: mer lug 14, 2010 5:07 pm
Messaggi: 7989
toyo ? ha scritto:
Jarni ? ha scritto:


Metterci uno switch - case faceva schifo? :asd:

Dal punto di vista dell'efficenza è esattamente =

Ci sono letture su vettori che si possono evitare. :O
_________________
ImmagineImmagine
Msimamizi ni super hydrauliska dickhead. LilithSChild Ni sociopath huzuni. Kuua mambo.
Top
 Profilo E-mail Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 04, 2011 11:40 pm 
Schiavo
Avatar utente
Iscritto il: gio lug 15, 2010 7:35 pm
Messaggi: 5339
Località: Tua madre succhia i cazzi all'inferno, idiota
Per chi a Wolfram Mathematica: link
Per chi ha internet: http://www.wolframalpha.com/input/?i=CellularAutomaton[30%2C+{0%2C+1%2C+0%2C+1%2C+0%2C+0%2C+0}%2C+200]
La sintassi è del tipo:
Codice:
CellularAutomaton[30, {0, 1, 0, 1, 0, 0, 0}, 200]
Quindi CellularAutomaton[rule, seed, steps]
CellularAutomaton[18, RandomInteger[1, 250], 100] :woo:
Wolfhwk ? ha scritto:
Aldin, a volte vorrei avere il tuo tempo libero.
Guarda che io studio fisica eh :fagiano: ed il prissimo anno ci sono i sistemi complessi, in più voglio portare l'argomento in un esame.

Argomenti successivi del libro:

Cita:
1.3 Outline of Book
The remainder of the book is divided into eleven largely self-contained chapters.
Chapter 2 introduces some basic mathematical formalism that will be used through-
out the book, including set theory, information theory, graph theory, groups, rings
and field theory, and abstract automata. It concludes with a preliminary mathe-
matical discussion of one and two dimensional CA.
Chapter 3 provides a phenomenological introduction to generic CA. The narra-
tive includes both a mathematical description of one, two and three dimensional CA
along with guided-tour through a graphics-gallery of typical space-time patterns.
Simple ways of parameterizing the space of CA rules are described, and a sketch
of the proof of the computational universality of Conway's famous two-dimensional
Life-rule is also provided.
Chapter 4 covers much of the same ground as chapter 3 but from a more formal
dynamical systems theory approach. The discrete CA world is examined in the
context of what is known about the behavior of continuous dynamical systems, and
a number of important methodological tools developed by dynamical systems theory
(i.e. Lyapunov exponents, invariant measures, and various measures of entropy and Outline of Book 19
dimension) are used to characterize the behavior of simple CA systems.
Chapter 5 provides some examples of purely analytical tools useful for describing
CA. It discusses methods of inferring cycle-state structure from global eigenvalue
spectra, the enumeration of limit cycles, the use of shift transformations, local
structure theory, and Lyapunov functions. Some preliminary research on linking
CA behavior with the topological characteristics of the underlying lattice is also
described.
Chapter 6 is a short primer on CA and language theory, and provides a ba-
sic discussion of formal language theory, the relationship between CA and formal
language theory, power spectra of regular languages and reversible computation.
Chapter 7 discusses a variety of topics all of which are related to the class of
probabilistic CA (PCA); i.e. CA that involve some elements of probability in their
state and/or time-evolution. The chapter begins with a physicist’s overview of crit-
ical phenomena. Later sections include discussions of the equivalence between PCA
and spin models, the critical behavior of PCA, mean-field theory, CA siniulation of
conventional spin models and a stochastic version of Conway’s Life rule.
Chapter 8 describes a number of generalized CA models, including reversible
CA, coupled-map latt,ices, quantum CA, reaction-diffiision models, inimunologically
motivated CA models, random Boolean networks, smdpile models (in the context of
self-organized criticality), structurally dynamic CA (in which the tcmporal evolution
of the value of individual sites of a lattice are tlynaxnically linked to an evolving
lattice structure), and simple CA models of cornbat.
Chapter 9 provides an introductory discussion of & research area that is rapidly
growing in importance: lattice gases. Lattice gases, which are discretized models
of continuous fluids, represent an early success of CA rnodeling techniques. The
chapter begins with a short primer on continuum fluid dynamics and proceeds with
a discussion of CA lattice gas models. One of the most important results is the
observation that, under certain constraints, the macroscopic behavior of CA models
exactly reproduces that predicted by the Navier-Stokes equations.
Chapter 10 covers another important field with a great overlap with CA: neural
networks
. Beginning with a short historical survey of what is really an independent
field, chapter 10 discusses the Hopfield model, stochastic nets, Boltzman machines,
arid multi-layered perceptrons.
Chapter 11 contains a very brief introduction to what is rapidly becoming one
of the central research areas in complex systems theory; namely, artifical-life
(AL).
Owing its origins to von NeumaIin’s early explorations in self-reproducing automata,
AL has blossomed in the last decade from consisting of a few toy worlds hardly more
sophisticated than Conway’s Life-rule universe to intricately rendered 3D artificial
universes populated with interacting creatures undergoing an open-ended evolution.
Topics include a brief survey of von Neumann’s original work, Lindenmeyer systems,
Langton’s vants model, a short primer on genetic algorithms. The chapter concludes
with a discussion of an artificial-life-like mobile CA model of land warfare.
The last chapter is a broad survey of a speculative proposition that CA just
might one day prove to be even more profound in what they say about how our
universe is organized than has heretofore been appreciated. The essence of the proposition, borrowed from rniisirigs b,y Feynnian [fcyii82], Fredkin [fredkingo], Min-
sky [minsky82], Wheeler [wheel901 and others, is that the universe is fundamentally
discrete and obeys, at its core, a simple CA-like dyrianiics. Tlius begin some final
musings and R perhaps a glimpsc of a new cosinogmy!
Appendix A providcs a brief description of several existiiig hardware arid soft-
ware tools designed for CA research. Appendix B contains a useful list of CA arid
inore general coniplcxity-relatctl inforniation soiirces availablo on thc World Wide
Web (WWW), subject-sorted into a total of 91 WWW Universal Resource Loca-
tor (URL) links in 16 categories. The book is iiitlexed and iridudcs an extensive
bibliography.
_________________
Long Live Iran
Immagine
Top
 Profilo E-mail Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 11, 2011 7:53 pm 
Utente bannato
Utente bannato
Avatar utente
Iscritto il: mer lug 21, 2010 10:56 am
Messaggi: 1239
Località: solon
che cazzo è sta roba, postate della figa cristo
Top
 Profilo E-mail Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: mar lug 12, 2011 2:27 pm 
Schiavo
Avatar utente
Iscritto il: mer lug 14, 2010 5:07 pm
Messaggi: 7989
UUU ? ha scritto:
che cazzo è sta roba, postate della figa cristo

In scienza e tecnica? Che siamo, ginecologi?
_________________
ImmagineImmagine
Msimamizi ni super hydrauliska dickhead. LilithSChild Ni sociopath huzuni. Kuua mambo.
Top
 Profilo E-mail Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 18, 2011 2:55 pm 
Schiavo
Avatar utente
Iscritto il: mar set 19, 2006 11:20 pm
Messaggi: 13143
Località: Berghem Haven
Scoperti ora? :wat:
_________________
Here we are, born to be mods. We're the princes of the board, here we belong, banning to survive in a forum with the darkest users. And here we are, we're the princes of the board, here we belong, banning for survival. We've come to be the rulers of you all! :awesome:
And maybe I can't resist the winter, and maybe the silence caress me. I am everyone I am no one, living in the center of my fears
>>>> Modder Cove
>>>> Tweaker Cove
Top
 Profilo Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 18, 2011 2:59 pm 
Schiavo
Avatar utente
Iscritto il: ven gen 28, 2011 7:49 pm
Messaggi: 14331
UUU ? ha scritto:
che cazzo è sta roba, postate della figa cristo

oh hai!
_________________
Sgobbone
Immagine
Top
 Profilo Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 18, 2011 3:16 pm 
mathematician
Iscritto il: mar dic 22, 2009 12:06 am
Messaggi: 1795
lowenz ? ha scritto:
Scoperti ora? :wat:

va beh non tutti hanno 40 anni come te qui
Top
 Profilo E-mail Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: lun lug 18, 2011 4:15 pm 
Schiavo
Avatar utente
Iscritto il: mar set 19, 2006 11:20 pm
Messaggi: 13143
Località: Berghem Haven
faco ? ha scritto:
lowenz ? ha scritto:
Scoperti ora? :wat:

va beh non tutti hanno 40 anni come te qui

:yeah:
_________________
Here we are, born to be mods. We're the princes of the board, here we belong, banning to survive in a forum with the darkest users. And here we are, we're the princes of the board, here we belong, banning for survival. We've come to be the rulers of you all! :awesome:
And maybe I can't resist the winter, and maybe the silence caress me. I am everyone I am no one, living in the center of my fears
>>>> Modder Cove
>>>> Tweaker Cove
Top
 Profilo Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: mer ago 31, 2011 2:36 am 
Schiavo
Avatar utente
Iscritto il: gio lug 15, 2010 7:35 pm
Messaggi: 5339
Località: Tua madre succhia i cazzi all'inferno, idiota
Ho scritto Conway ed il programma per le varie rules in OpenGL. Il secondo è inevitabilmente inquinato dagli effetti di bordo, nel senso il seme non è solamente constituito dalla prima riga, ma anche dalla prima e dall'ultima colonna che hanno sempre valore zero. Per capirlo meglio comunque dovreste leggere il programma ed fc, il programma funziona, solo la configurazione iniziale come scritto prima risulta un poco personalizzata. Il procedimento è stato questo: ho installato le librerie, ho copiato un esempio di programma (semplicissimo) dal primo capitolo dell'OpenGL redbook nel quale ho inserito una particolare formula per scrivere quadretti con i cicli for. Ecco il programma:

Spoiler: show
Codice:
#include <GL/gl.h>
#include <GL/glut.h>
//#include <cstdlib>
#define BIANCO 1.0, 1.0, 1.0
#define NERO 0.0, 0.0, 0.0
using namespace std;

void display(void){
    glClear (GL_COLOR_BUFFER_BIT);
    glColor3f (BIANCO);
    glBegin(GL_QUADS);
    .
    .
    istruzioni per le coordinate
    .
    .
    glEnd();
    glFlush();
}

void init (void){
glClearColor (NERO, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize (500, 500);
    glutInitWindowPosition (100, 100);
    glutCreateWindow ("NOME DEL PROGRAMMA");
    init ();
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}
Ecco la modifica per le rules:
Spoiler: show
Codice:
#include <GL/gl.h>
#include <GL/glut.h>
//#include <cstdlib>
#define BIANCO 1.0, 1.0, 1.0
#define NERO 0.0, 0.0, 0.0
using namespace std;

void display(void){
    float n=450;
    int m=n;
    glClear (GL_COLOR_BUFFER_BIT);
    glColor3f (BIANCO);
//    glBegin(GL_LINES);
// for(int i=1; i<n; i++){
// glVertex2f(0.0, float(i/n));
// glVertex2f(1.0, float(i/n));
// glVertex2f(float(i/n), 0.0);
// glVertex2f(float(i/n), 1.0);}
//    glEnd();

     int value[m][m];
for(int i=0; i<m; i++){
for(int j=0; j<m; j++)
value[i][j]=0;}
value[0][(m)/2]=1;

//int c=33; srand(c);
//for(int j=0; j<m; j++)
//value[0][j]=rand()%2;

  for(int i=0; i<(m-1); i++){
for(int j=0; j<(m-2); j++){
if(value[i][j]==1 && value[i][j+1]==1 && value[i][j+2]==1)value[i+1][j+1]=0; else
if(value[i][j]==1 && value[i][j+1]==1 && value[i][j+2]==0)value[i+1][j+1]=0; else
if(value[i][j]==1 && value[i][j+1]==0 && value[i][j+2]==1)value[i+1][j+1]=0; else
if(value[i][j]==1 && value[i][j+1]==0 && value[i][j+2]==0)value[i+1][j+1]=1; else
if(value[i][j]==0 && value[i][j+1]==1 && value[i][j+2]==1)value[i+1][j+1]=1; else
if(value[i][j]==0 && value[i][j+1]==1 && value[i][j+2]==0)value[i+1][j+1]=0; else
if(value[i][j]==0 && value[i][j+1]==0 && value[i][j+2]==1)value[i+1][j+1]=1; else
if(value[i][j]==0 && value[i][j+1]==0 && value[i][j+2]==0)value[i+1][j+1]=0;}
}//rule 30: 0 0 0 1 1 1 1 0 another rule 0 0 0 1 1 0 1 0
int t[m][m];
for(int i=0; i<m; i++){
for(int j=0; j<m; j++){
t[j][i]=value[i][j];}}

for(int i=0; i<m; i++){
for(int j=0; j<m; j++){
if(t[i][j]==1)//&& t[1][j]==0
glBegin(GL_QUADS);
glVertex2f(float(i/n), 1.0-float(j/n)); glVertex2f(float(i/n)+float(1.0/n), 1.0-float(j/n));
glVertex2f(float(i/n)+float(1.0/n), 1.0-float(j/n)-float(1.0/n)); glVertex2f(float(i/n), 1.0-float(j/n)-float(1.0/n));
  glEnd();}}
  glFlush();
}

void init (void){
glClearColor (NERO, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize (500, 500);
    glutInitWindowPosition (100, 100);
    glutCreateWindow ("Regola a caso");
    init ();
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}
La regola in questo programma dovrebbe essere il frattale noto come Triangolo di Sierpinski. Modificando n si modifica la dimensione della matrice, un n troppo alto non fa andare il programma. Levando la dobbia barra nella zona glBegin(GL_LINES); si disegna anche la griglia. Per cambiare la configurazione della riga iniziale basta leggere il commento rule 30: 0 0 0 1 1 1 1 0 another rule 0 0 0 1 1 0 1 0 e modificare i numeri prima di tutti gli else. Per cambiare colore basta scambiare BIANCO e NERO in #define. Ogni colore è dato da (float, float, float)=(R,G,B) con 0<=float<=1 credo. Ho avuto la necessità di trasporre la matrice dato che la formula sui cicli for mi è venuta subito e non avevo voglia di modificarla (il diesegno veniva "trasposto" ed ho dovuto trasporre la matrice). Il programma di Conway è:
Spoiler: show
Codice:
#include <GL/gl.h>
#include <GL/glut.h>
#define NERO 0.0, 0.0, 0.0
#define VERDE 0.0, 1.0, 0.0
#define ROSSO 0.2, 0.7, 0.2
#include <windows.h>
#include <iostream>

using namespace std;

void display(int t){
    float n=9;
    int m=n;
    glClear (GL_COLOR_BUFFER_BIT);
    glColor3f(VERDE);
int a=6;
int b=n, c=n;

int v[a][b][c];
int s[a][b][c];

//inizializzo i vettori..............OK
for(int t=0; t<a; t++){
for(int i=0; i<b; i++){
for(int j=0; j<c; j++){
v[t][i][j]=s[t][i][j]=0;}}}

v[0][2][1]=1;
v[0][3][2]=1;
v[0][3][3]=1;
v[0][2][3]=1;
v[0][1][3]=1;

//eseguo la sommatoria del vicinato..OK
for(int t=0; t<a; t++){
for(int i=0; i<(b-2); i++){
for(int j=0; j<(c-2); j++){

for(int k=0; k<3; k++){
for(int l=0; l<3; l++){
s[t][i+1][j+1]+=v[t][i+k][j+l];}}
s[t][i+1][j+1]-=v[t][i+1][j+1];

//applico la regola
if(s[t][i][j]==2)v[t+1][i][j]=v[t][i][j]; else
if(s[t][i][j]==3)v[t+1][i][j]=1; else
v[t+1][i][j]=0;
}}}

//int tr[a][b][c];
//for(int t=0; t<m; t++){
//for(int i=0; i<m; i++){
//for(int j=0; j<m; j++){
//tr[t][j][i]=v[t][i][j];}}}

for(int i=0; i<m; i++){
for(int j=0; j<m; j++){
if(v[t][i][j]==1)
glBegin(GL_QUADS);
glVertex2f(float(i/n), 1.0-float(j/n)); glVertex2f(float(i/n)+float(1.0/n), 1.0-float(j/n));
glVertex2f(float(i/n)+float(1.0/n), 1.0-float(j/n)-float(1.0/n)); glVertex2f(float(i/n), 1.0-float(j/n)-float(1.0/n));
  glEnd();}}

    glColor3f (ROSSO);
    glBegin(GL_LINES);
for(int i=1; i<n; i++){
glVertex2f(0.0, float(i/n));
glVertex2f(1.0, float(i/n));
glVertex2f(float(i/n), 0.0);
glVertex2f(float(i/n), 1.0);}
    glEnd();
    glFlush();

  //stampo a schermo...................OK
for(int i=0; i<b; i++){
for(int j=0; j<c; j++){
if(v[t][i][j]==1)
cout<<"*"; else
cout<<"0";}
cout<<"\n";}
cout<<"\n\n";
  //rendo il tutto ciclic..............OK
    t++;
    if(t<=a){
        Sleep(500);
        display(t);}
//      else display(0);
}

void init (void){
glClearColor (NERO, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

void vai(){
init();
display(0);
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize (250, 250);
    glutInitWindowPosition (500, 200);
    glutCreateWindow (".::Conway's Game of Life::. The Glider");
    glutDisplayFunc(vai);
    glutMainLoop();
    return 0;
}
Ho reso la funsione display() ricorsiva ed utilizzato la funzione Sleep(milisecondi) di windows.h per mostrare così la variazione dell'immagine nel tempo. La matrice è inizializzata a zero e verso la riga 20 si scegono i valori della matrice al tempo t=0. C'è però un grosso difetto. Una matrice v[][n][n] con n>11 non fa andare il programma, non posso così creare scenari complessi. Il nucleo di Conway è questo:
Spoiler: show
Codice:
#include<iostream>
using namespace std;

int main(){
int a=5;
int b=10;
int c=10;

int v[a][b][c];
int s[a][b][c];

//inizializzo i vettori..............OK
for(int t=0; t<a; t++){
for(int i=0; i<b; i++){
for(int j=0; j<c; j++){
v[t][i][j]=s[t][i][j]=0;}}}

//v[0][1][1]=1;
//v[0][1][2]=1;
//v[0][2][2]=1;
//v[0][2][3]=1;
//v[0][3][2]=1;

v[0][2][1]=1;
v[0][3][2]=1;
v[0][3][3]=1;
v[0][2][3]=1;
v[0][1][3]=1;

//eseguo la sommatoria del vicinato..OK
for(int t=0; t<a; t++){
for(int i=0; i<(b-2); i++){
for(int j=0; j<(c-2); j++){

for(int k=0; k<3; k++){
for(int l=0; l<3; l++){
s[t][i+1][j+1]+=v[t][i+k][j+l];}}
s[t][i+1][j+1]-=v[t][i+1][j+1];

//applico la regola
if(s[t][i][j]==2)v[t+1][i][j]=v[t][i][j]; else
if(s[t][i][j]==3)v[t+1][i][j]=1; else
v[t+1][i][j]=0;

}}}

//verifico ad occhio la sommatoria...OK
for(int i=1; i<5; i++){
for(int j=1; j<5; j++){
cout<<s[1][i][j]<<"\n";}}

//stampo a schermo...................OK
for(int t=0; t<a; t++){
for(int i=0; i<b; i++){
for(int j=0; j<c; j++){
if(v[t][i][j]==1)
cout<<"*"; else
cout<<"0";}
cout<<"\n";}
cout<<"\n\n";}

return 0;
}
Qualche programmatore sa perché? Edit: risolto nel programma successivo.
_________________
Long Live Iran
Immagine


Ultima modifica di Aldin, dom set 18, 2011 7:19 am, modificato 1 volta.
Top
 Profilo E-mail Non connesso  
 
 Oggetto del messaggio: Re: Automi cellulari
MessaggioInviato: dom set 18, 2011 7:14 am 
Schiavo
Avatar utente
Iscritto il: gio lug 15, 2010 7:35 pm
Messaggi: 5339
Località: Tua madre succhia i cazzi all'inferno, idiota
Riscritto Conway su linux senza opengl. Fatelo partire dalla vostra distro con il comando ./a.out x y z k h dove le variabili sono rispettivamente:

x=passi temporali+3
y=numero di righe
z=numero di colonne
k=seme della matrice pseudocasuale di uni e zeri
h=tempo di aggiornamento in secondi

Se avete un monitor con 16xx pixel di larghezza mettete il terminale a tutto schermo e date ./a.out 100 50 100 2 1 per esempio. Ovviamente prima va compilato con g++ nomeprogramma.C. Le matrici degli automi cono in realtà due affiancate, v[t][0][f][i][j] e v[t][1][f][i][j] dove t ed f sono parametri. Ne ho usate due per potere in seguito parallelizzare il programma su due core. Sono inoltre collegate sul bordo, ed a sua volta la matrice destra ricongiunge il suo bordo destro al bordo sinistro della matrice sinistra. Ancora, ogni matrice ha la sua parte superiore collegata alla sua parte inferiore, realizzando nel complesso la figura di un sostegno toroidale. Questo è uno screen con i parametri dati precedentemente. Mettendo a tutto schermo il terminale, la figura si aggiorna ogni secondo sovrapponendosi e da così l'impressione di movimento.

Immagine

La didascalia NASCE/STAZIONA in realtà è faziosa e sta a significare che la sommatoria sul vicinato di Moore da rispettivamente 3 e 2.
Spoiler: show
Codice:
#include<iostream>
#include<unistd.h>
#include<cstdlib>
using namespace std;

int main(int argc, char **argv){
int a=(int)strtol(argv[1], (char**)NULL, 10);
int b=(int)strtol(argv[2], (char**)NULL, 10);
int c=(int)strtol(argv[3], (char**)NULL, 10);
int p=2,f=2;
int v[a][p][f][b][c];
srand((int)strtol(argv[4], (char**)NULL, 10));
//inizializzo i vettori..............OK
for(int t=0; t<a; t++){
for(int u=0; u<p; u++){
for(int h=0; u<p; u++){
for(int i=0; i<b; i++){
for(int j=0; j<c; j++){
v[t][u][h][i][j]=rand()%2;}}}}}

/*
v[0][0][0][4][3]=1;
v[0][0][0][5][4]=1;
v[0][0][0][5][5]=1;
v[0][0][0][4][5]=1;
v[0][0][0][3][5]=1;
*/
/* spaceship
v[0][0][0][1][2]=1;
v[0][0][0][1][5]=1;
v[0][0][0][2][6]=1;
v[0][0][0][3][2]=1;
v[0][0][0][3][6]=1;
v[0][0][0][4][3]=1;
v[0][0][0][4][4]=1;
v[0][0][0][4][5]=1;
v[0][0][0][4][6]=1;
*/

for(int i=0; i<b; i++){
v[0][1][0][i][0]=v[0][0][0][i][c-2];
v[0][1][0][i][1]=v[0][0][0][i][c-1];}

//eseguo la sommatoria del vicinato..OK
for(int t=0; t<(a-2); t++){
for(int u=0; u<p; u++){
for(int i=1; i<(b-1); i++){
for(int j=1; j<(c-1); j++){

for(int k=-1; k<2; k++){
for(int l=-1; l<2; l++){
v[t][u][1][i][j]+=v[t][u][0][i+k][j+l];}}
v[t][u][1][i][j]-=v[t][u][0][i][j];

//applico la regola
if(v[t][u][1][i][j]==2)v[t+1][u][0][i][j]=v[t][u][0][i][j]; else
if(v[t][u][1][i][j]==3)v[t+1][u][0][i][j]=1; else
v[t+1][u][0][i][j]=0;
}}}
for(int i=0; i<b; i++){
v[t+1][0][0][i][c-1]=v[t+1][1][0][i][1];
v[t+1][1][0][i][0]=v[t+1][0][0][i][c-2];
v[t+1][1][0][i][c-1]=v[t+1][0][0][i][1];
v[t+1][0][0][i][0]=v[t+1][1][0][i][c-2];}

for(int j=0; j<c; j++){
v[t+1][0][0][0][j]=v[t+1][0][0][b-2][j];
v[t+1][0][0][b-1][j]=v[t+1][0][0][1][j];
v[t+1][1][0][0][j]=v[t+1][1][0][b-2][j];
v[t+1][1][0][b-1][j]=v[t+1][1][0][1][j];}
}

//stampo a schermo...................OK
for(int t=0; t<(a-2); t++){
for(int i=0; i<(b-2); i++){
for(int j=0; j<c; j++){
if((v[t][0][0][i][j]==1)&&(v[t][0][1][i][j]==2)) cout<<"\033[1;34m0\033[0m"; else
if((v[t][0][0][i][j]==1)&&(v[t][0][1][i][j]==3)) cout<<"\033[1;32m0\033[0m"; else cout<<" ";}
for(int j=2; j<(c-2); j++){
if((v[t][1][0][i][j]==1)&&(v[t][1][1][i][j]==2)) cout<<"\033[1;34m0\033[0m"; else
if((v[t][1][0][i][j]==1)&&(v[t][1][1][i][j]==3)) cout<<"\033[1;32m0\033[0m"; else cout<<" ";}
cout<<"\n";}
cout<<"                    \033[1;20mtempo\033[0m: "<<t<<"          \033[1;32mNASCE\033[0m     "<<"\033[1;34mSTAZIONA\033[0m";
cout<<"\n\n";
sleep((int)strtol(argv[5], (char**)NULL, 10));}

return 0;
}
_________________
Long Live Iran
Immagine
Top
 Profilo E-mail Non connesso  
 
Visualizza ultimi messaggi:  Ordina per  
Apri un nuovo argomento Rispondi all’argomento  [ 21 messaggi ] 
-->

Tutti gli orari sono UTC +1 ora


Chi c’è in linea

Visitano il forum: Nessuno e 0 ospiti


Non puoi aprire nuovi argomenti
Non puoi rispondere negli argomenti
Non puoi modificare i tuoi messaggi
Non puoi cancellare i tuoi messaggi
Non puoi inviare allegati

Vai a:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Traduzione Italiana phpBB.it