commit 3ecabe62facb0afc22b72faeffaf15d890ecbfde Author: Mysaa Date: Wed May 19 00:04:11 2021 +0200 Premier commit - Introdution au système git. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f939098 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +# Extensions de compilation LaTeX +*.aux +*.toc +*.synctex.gz +*.out +*.log +*.snm +*.nav +svg-inkscape/ + +__pycache__ +*compresse.pdf +.metadata diff --git a/3dmaker.py b/3dmaker.py new file mode 100644 index 0000000..64e5e61 --- /dev/null +++ b/3dmaker.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed May 15 18:43:29 2019 + +@author: mysaa +""" + +""" + Les hhmaps seront des np array bidimentionnels de listes a nombre impair d'éléments +""" + + diff --git a/Diapo/Diapo.pdf b/Diapo/Diapo.pdf new file mode 100644 index 0000000..4cd23ee Binary files /dev/null and b/Diapo/Diapo.pdf differ diff --git a/Diapo/Diapo.tex b/Diapo/Diapo.tex new file mode 100644 index 0000000..2aec890 --- /dev/null +++ b/Diapo/Diapo.tex @@ -0,0 +1,275 @@ +\documentclass[11pt]{beamer} + +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage[french]{babel} +\usepackage{amsmath} +\usepackage{amsfonts} +\usepackage{amssymb} +\usepackage{graphicx} +\usepackage{multicol} +\usepackage{courier} +\usepackage{appendix} +\usepackage{appendixnumberbeamer} +\usepackage{minted} + +\usetheme{Madrid} +%\usetheme{Warsaw} + +\addtobeamertemplate{frametitle}{ + \let\insertframetitle\insertsectionhead}{} +\addtobeamertemplate{frametitle}{ + \let\insertframesubtitle\insertsubsectionhead}{} + + +\makeatletter +\CheckCommand*\beamer@checkframetitle{\@ifnextchar\bgroup\beamer@inlineframetitle{}} +\renewcommand*\beamer@checkframetitle{\global\let\beamer@frametitle\relax\@ifnextchar\bgroup\beamer@inlineframetitle{}} +\makeatother + + +\hypersetup{pdfpagemode=FullScreen} +% Transition en fade-in par défaut +\addtobeamertemplate{background canvas}{\transfade[duration=0.4]}{} + + + +\usebeamercolor{orchid} + +\begin{document} + \author{Samy Avrillon - 24817} + \title{Stockage et génération de topographie artificielle de fond océanique} + \subtitle{Projet "Sonar de l'infini"} + \logo{\includegraphics[width=.5cm]{logoLafayette}} + \institute{Lycée Lafayette} + %\subject{} + %\setbeamercovered{transparent} + %\setbeamertemplate{navigation symbols}{} + \begin{frame}[plain] + \maketitle + \end{frame} + + \section*{Sommaire} + \begin{frame} + \frametitle{Sommaire} + \pause + \begin{multicols}{2} + \tableofcontents[pausesections] + \end{multicols} + \end{frame} + + \section{Introduction} + \subsection{Le but : un format inéxistant} + \begin{frame} + \pause + \begin{columns} + \column{0.5\textwidth} + \begin{itemize} + \item<2-4> Un champ des hauteurs + \item<3-4> Une discrétisation 3D + \item<4> Quelques formats privés + \end{itemize} + \column{0.5\textwidth} + \only<2>{ + \begin{figure} + \includegraphics[width=\textwidth]{heightmapExample} + \caption{Exemple de champ de hauteur} + \end{figure} + } + \only<3>{ + \begin{figure} + \includegraphics[width=\textwidth]{discretisation3d} + \caption{Exemple de discrétisation 3d de l'espace} + \end{figure} + + } + \end{columns} + + \end{frame} + \subsection{Débouchés et utilisations} + \begin{frame} + \pause + \begin{columns} + \column{0.5\textwidth} + \begin{itemize}[<+->] + \item<2-4> Jeu vidéo on monde ouvert + \item<3-4> Graphisme, cinéma + \item<4> Simulation physique ou de rover + \end{itemize} + \column{0.5\textwidth} + \only<2>{ + \begin{figure} + \includegraphics[width=\textwidth]{minecraftOcean} + \caption{Capture du jeu vidéo Minecraft} + \end{figure} + } + \only<3>{ + \begin{figure} + \includegraphics[width=0.8\textwidth]{nemoCoraux} + \includegraphics[width=0.8\textwidth]{samyTortue} + \caption{Extrait des films \fg{} Le monde de némo \og et \fg{} Le Voyage extraordinaire de Samy \og} + \end{figure} + } + \end{columns} + \end{frame} + \section{Le format TMF} + \subsection{Contraintes} + \begin{frame} + \pause + \begin{itemize}[<+->] + \item Liberté totale + \item Complexité spatiale + \item Référencabilité + \end{itemize} + \end{frame} + + \subsection{Modélisation} + \begin{frame} + \frametitle{Modélisation} + \pause + \begin{figure} + \includegraphics[height=0.6\textheight]{fond} + \caption{Représentation 2D du stockage des colonnes} + \end{figure} + \end{frame} + \subsection{Réalité du stoquage} + \begin{frame} + Ici format de fichier, + \end{frame} + \subsection{Algorithme d'abstraction: tmfeur} + + \section{Module Objection} + + \subsection{Minecraft} + \begin{frame} + \pause + \begin{figure} + \includegraphics[height=0.6\textheight]{minecraftGrottes} + \caption{Usage de Minecraft comme moteur graphique} + \end{figure} + \end{frame} + \subsection{Rectangle} + \begin{frame} + \pause + \begin{figure} + \includegraphics[height=0.6\textheight]{recImage} + \caption{Usage de rectangles} + \end{figure} + \end{frame} + \subsection{Colonnes} + \begin{frame} + \pause + \begin{figure} + \includegraphics[height=0.6\textheight]{filImage} + \caption{Usage de parallélépipèdes} + \end{figure} + \end{frame} + \subsection{Triangles} + \begin{frame} + \pause + \begin{figure} + \includegraphics[height=0.6\textheight]{triImage} + \caption{Usage de triangles} + \end{figure} + \end{frame} + \section{Génération} + + \subsection{Contraintes} + \begin{frame} + \pause + \begin{itemize}[<+->] + \item Infinité + \item Répétabilité + \item Modulabilité + \end{itemize} + \end{frame} + + \subsection{Noisette} + + \subsubsection{Méthodes et attributs} + \begin{frame} + \pause + \begin{itemize}[<+->] + \item \texttt{getChunk(self,x,y,n)} + \item \texttt{\_\_add\_\_(self,other)} + \item \texttt{\_\_rmul\_\_(self,other)} + \item \texttt{\_\_sub\_\_(self,other)} + + \end{itemize} + \end{frame} + \subsubsection{Bruits généraux} + \begin{frame} + \pause + \begin{itemize}[<+->] + \item Bruit sur le cercle trigonométrique + \item Bruit avec des interpolations linéaires + \item Bruit avec des droites + \item Bruit de Perlin (2d) + \item Bruit fractal + \end{itemize} + \end{frame} + \subsection{Cartman} + + \begin{frame} + \frametitle{Bruit de Perlin} + \pause + \begin{figure} + \includegraphics[height=0.6\textheight]{perlin} + \caption{Heightmap créée par un bruit de perlin} + \end{figure} + \end{frame} + + \begin{frame} + \frametitle{Bruit Fractal} + \begin{columns} + \pause + \begin{column}{0.5\textwidth} + \begin{figure} + \includegraphics[width=0.8\textwidth]{bfractal} + \caption{Bruit fractal avec peu de droites} + \end{figure} + \end{column} + \pause + \begin{column}{0.5\textwidth} + \begin{figure} + \includegraphics[width=0.8\textwidth]{hfractal} + \caption{Bruit fractal avec plus de droites} + \end{figure} + \end{column} + \end{columns} + \end{frame} + + \subsubsection{Quelques algorithmes} + \begin{frame} + Bruit Caverne à présenter + \end{frame} + + + \appendix + \section{Sommaire} + \begin{frame} + TODO sommaire de l'appendice + \end{frame} + + \section{Python} + \subsection{data.py} + \begin{frame}[allowframebreaks] + \inputminted[fontsize=\footnotesize,breaklines=true]{python}{data.py} + \end{frame} + \subsection{objection.py} + \begin{frame}[allowframebreaks] + \inputminted[fontsize=\footnotesize,breaklines=true]{python}{objection.py} + \end{frame} + \subsection{perlin.py} + \begin{frame}[allowframebreaks] + \inputminted[fontsize=\footnotesize,breaklines=true]{python}{perlin.py} + \end{frame} + \subsection{tmf.py} + \begin{frame}[allowframebreaks] + \inputminted[fontsize=\footnotesize,breaklines=true]{python}{tmf.py} + \end{frame} + + + +\end{document} \ No newline at end of file diff --git a/Diapo/bernardLogo.png b/Diapo/bernardLogo.png new file mode 100644 index 0000000..61fcf4e Binary files /dev/null and b/Diapo/bernardLogo.png differ diff --git a/Diapo/bfractal.png b/Diapo/bfractal.png new file mode 100644 index 0000000..00390dd Binary files /dev/null and b/Diapo/bfractal.png differ diff --git a/Diapo/compressateur b/Diapo/compressateur new file mode 100644 index 0000000..928e38e --- /dev/null +++ b/Diapo/compressateur @@ -0,0 +1,2 @@ +#!/bin/bash +gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=Diapo-compesse.pdf Diapo.pdf diff --git a/Diapo/data.py b/Diapo/data.py new file mode 100644 index 0000000..3c6df36 --- /dev/null +++ b/Diapo/data.py @@ -0,0 +1,153 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +Created on Wed Aug 28 17:39:43 2019 + +Module contanant les classes générales structurant les données, ainsi que les + +@author: mysaa +""" +import numpy as np + +def appendeur(l1,l2): + """ + Effectue l1=l1+l2 de manière opti + """ + for l in l2: + l1.append(l) + +class WorldChunk(): + + def getSize(self): + raise NotImplementedError("Vous avez fait un monde qui n'implemente pas cette méthode. Vous êtes bizzare vous savez ? Un monde sans taille !!!") + + + def getColumn(self,x,y): + raise NotImplementedError("Vous avez fait un monde qui n'implemente pas cette méthode. Vous êtes bizzare vous savez ?") + + + def asList(self): + return [ [self.getColumn(x,y) for y in range(self.size[1])] for x in range(self.size[0]) ] + + def getIndexed(self,fullCoords=False,addZero=False): + points = [] + pointIndexes = [0] + for pos in np.ndindex(self.getSize()): + col = self.getColumn(pos[0],pos[1]) + if(addZero): col = np.insert(col,0,0) + if(fullCoords): col = [(pos[0],pos[1],c) for c in col] + appendeur(points,col) + pointIndexes.append(pointIndexes[-1]+len(col)) + return points,pointIndexes + + +class CollageWorldChunk(WorldChunk): + + def __init__(self,chunk,xp,yp,xy): + + self.orgChunk,self.xp,self.yp,self.xy = chunk,xp,yp,xy + self.orgSize = chunk.getSize() + + def getSize(self) : return (self.orgChunk.size[0]+1,self.orgChunk.size[1]+1) + + def getColumn(self,x,y): + xout,yout = x>=self.orgSize[0],y>=self.orgSize[1] + if(xout and yout): + return self.xy.getColumn(x-self.orgSize[0],y-self.orgSize[1]) + if(xout): + return self.xp.getColumn(x-self.orgSize[0],y) + if(yout): + return self.yp.getColumn(x,y-self.orgSize[1]) + + return self.orgChunk.getColumn(x,y) + +class ArrayedWorldChunk(WorldChunk): + + def fromList(liste): + size = len(liste),len(liste[0]) + indexes=np.empty(size[0]*size[1]+1,dtype=np.uint32) + index = 0 + data = [] + for y in range(size[1]): + for x in range(size[0]): + indexes[x+size[0]*y]=index + data += liste[x][y] + index += len(liste[x][y]) + indexes[size[0]*size[1]] = index + data = np.array(data,dtype=np.float) + return ArrayedWorldChunk(size,indexes,data) + + def __init__(self,size,indexes,data): + self.size = size + self.indexes=indexes + self.data=data + + + def getColumn(self,x,y): + i0,i1 = self.indexes[x+self.size[0]*y],self.indexes[x+self.size[0]*y+1] + return self.data[i0:i1] + + def getSize(self) : return self.size + + + + + + + + + +class Noise: + + def getChunk(self,x,y,n): + """ + Cette fonction renvoie un array numpy de taille rx*ry correspondant au chunk x y avec le seed donné. + Cette fonction doit être déterministe (si les attributs de l'objets ne sont pas changés bien sur) + """ + raise NotImplementedError("Vous avez fait un bruit qui n'implemente pas cette méthode. Vous êtes bizzare vous savez ?") + + + + def __add__(self,other): + + def addedChunk(self,x,y,n): + return self.noise1.getChunk(x,y,n) + self.noise2.getChunk(x,y,n) + noise = Noise() + noise.noise1 = self + noise.noise2 = other + noise.getChunk = addedChunk + return noise + + def __iadd__(self,other): + + return self.__add__(other) + + def __rmul__(self,other): + + if type(other) in ['float','int']: + def mulChunk(self,x,y,n): + return self.prop*self.noise1.getChunk(x,y,n) + noise = Noise() + noise.noise1 = self + noise.prop = other + noise.getChunk = mulChunk + else: + def mulChunk(self,x,y,n): + return self.noise1.getChunk(x,y,n) * self.noise2.getChunk(x,y,n) + noise = Noise() + noise.noise1 = self + noise.noise2 = other + noise.getChunk = mulChunk + return noise + + def __sub__(self,other): + + def subChunk(self,x,y,n): + return self.noise1.getChunk(x,y,n) - self.noise2.getChunk(x,y,n) + noise = Noise() + noise.noise1 = self + noise.noise2 = other + noise.getChunk = subChunk + return noise + \ No newline at end of file diff --git a/Diapo/discretisation3d.png b/Diapo/discretisation3d.png new file mode 100644 index 0000000..840d621 Binary files /dev/null and b/Diapo/discretisation3d.png differ diff --git a/Diapo/filImage.png b/Diapo/filImage.png new file mode 100644 index 0000000..da6c447 Binary files /dev/null and b/Diapo/filImage.png differ diff --git a/Diapo/fond.svg b/Diapo/fond.svg new file mode 100644 index 0000000..1aa1252 --- /dev/null +++ b/Diapo/fond.svg @@ -0,0 +1,665 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + z=42m + z=0m + + diff --git a/Diapo/heightmapExample.png b/Diapo/heightmapExample.png new file mode 100644 index 0000000..ad406b9 Binary files /dev/null and b/Diapo/heightmapExample.png differ diff --git a/Diapo/hfractal.png b/Diapo/hfractal.png new file mode 100644 index 0000000..3017373 Binary files /dev/null and b/Diapo/hfractal.png differ diff --git a/Diapo/logoLafayette.png b/Diapo/logoLafayette.png new file mode 100644 index 0000000..6a8d4e6 Binary files /dev/null and b/Diapo/logoLafayette.png differ diff --git a/Diapo/logo_lafayette.svg b/Diapo/logo_lafayette.svg new file mode 100644 index 0000000..1b1b6ce --- /dev/null +++ b/Diapo/logo_lafayette.svg @@ -0,0 +1,98 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/Diapo/minecraftGrottes.png b/Diapo/minecraftGrottes.png new file mode 100644 index 0000000..5da8cba Binary files /dev/null and b/Diapo/minecraftGrottes.png differ diff --git a/Diapo/minecraftOcean.jpg b/Diapo/minecraftOcean.jpg new file mode 100644 index 0000000..11d3386 Binary files /dev/null and b/Diapo/minecraftOcean.jpg differ diff --git a/Diapo/nemoCoraux.png b/Diapo/nemoCoraux.png new file mode 100644 index 0000000..24762df Binary files /dev/null and b/Diapo/nemoCoraux.png differ diff --git a/Diapo/objection.py b/Diapo/objection.py new file mode 100644 index 0000000..d4c0fc6 --- /dev/null +++ b/Diapo/objection.py @@ -0,0 +1,365 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Aug 22 19:46:36 2019 + +@author: mysaa +""" +import numpy as np +from data import CollageWorldChunk +from perlin import CavernedNoise2,TestNoise + + + +def getTriangles(x0,y0,chunk,xp,yp,xy): + + + nx,ny = chunk.size + newChunk = CollageWorldChunk(chunk,xp,yp,xy) + +# pointIndexes = np.zeros((nx+1,ny+1),dtype=np.uint32) +# pointLengthes = np.zeros((nx+1,ny+1),dtype=np.uint32) +# points = [] +# +# +# pos = 0 +# for j in range(ny): +# for i in range(nx): +# carotte = [(x0+i/nx,y0+j/ny,z) for z in sorted([0.]+list(chunk.getColumn(i,j)))] +# points += carotte +# pointLengthes[i,j] = len(carotte) +# pointIndexes[i,j] = pos +# pos+=len(carotte) +# carotte = [(x0+1,y0+j/ny,z) for z in sorted([0.]+list(xp.getColumn(0,j)))] +# points += carotte +# pointLengthes[nx,j]= len(carotte) +# pointIndexes[nx,j] = pos +# pos+=len(carotte) +# for i in range(nx): +# carotte = [(x0+i/nx,y0+1,z) for z in sorted([0.]+list(yp.getColumn(i,0)))] +# points += carotte +# pointLengthes[i,ny] = len(carotte) +# pointIndexes[i,ny] = pos +# pos+=len(carotte) +# carotte = [(x0+1,y0+1,z) for z in sorted([0.]+list(xy.getColumn(0,0)))] +# points += carotte +# pointLengthes[nx,ny] = len(carotte) +# pointIndexes[nx,ny] = pos + + + + points,pointIndexes = newChunk.getIndexed(fullCoords=True,addZero=True) + + points=[(p[0]/nx+x0,p[1]/ny+y0,p[2]) for p in points] + pointLengthes = np.reshape([pointIndexes[i+1]-pointIndexes[i] for i in range(len(pointIndexes)-1)],(nx+1,ny+1)) + pointIndexes = np.reshape(pointIndexes[:-1],(nx+1,ny+1)) + print(points,pointIndexes,pointLengthes) + + + + + + + triangles = [] + + + for x in range(nx*2): + for y in range(ny): + # On récupère les coordonées entières du triangle indicé (x,y) + if(x%2==0): + col0=(x//2 ,y ) + col1=(x//2+1,y ) + col2=(x//2 ,y+1) + else: + col0=(x//2+1,y+1) + col1=(x//2+1,y ) + col2=(x//2 ,y+1) + + # On récupère la liste des points dans la colonne + colonne0 = points[pointIndexes[col0[0],col0[1]]:pointIndexes[col0[0],col0[1]]+pointLengthes[col0[0],col0[1]]] + colonne1 = points[pointIndexes[col1[0],col1[1]]:pointIndexes[col1[0],col1[1]]+pointLengthes[col1[0],col1[1]]] + colonne2 = points[pointIndexes[col2[0],col2[1]]:pointIndexes[col2[0],col2[1]]+pointLengthes[col2[0],col2[1]]] + #print("colonne:",colonne1) + # st contient des triplets (numéro de colonne,index interne dans la colonne,coordonée z) + st = [(0,i,colonne0[i][2]) for i in range(len(colonne0))] + st += [(1,i,colonne1[i][2]) for i in range(len(colonne1))] + st += [(2,i,colonne2[i][2]) for i in range(len(colonne2))] + + + # On y trie par coordonée z + st = sorted(st,key=lambda c:c[2]) + + #Liste des coordonées des colonnes, pour pouvoir sélectionner les coordonées selon l'index de la colonne + cols = [col0,col1,col2] + # Là, tout est bon à peu près + + i=0 + try: + while iF else 1 + (2*n**2+6*n+4)/(F**(2*n+4)) * ((x**2)/(2*n+4)-(F**2)/(2*n+2))*abs(x)**(2*n+2) + + + def __init__(self,F,D,epsilon,droiteMaker,n = 1): + self.F = F + self.D = D + self.epsilon = epsilon + if type(droiteMaker) == int: + droiteMaker = DroiteNoise(droiteMaker,F,D) + self.droiteMaker = droiteMaker + self.interpol = FractalNoise.interpolizer(n,F) + + def getChunk(self,x,y,n): + drts = self.droiteMaker.getChunk(x,y) + chunk = np.zeros(n) + epsilon = self.epsilon + interpol = self.interpol + + def dst(x0,x1,y0,y1): + return sqrt( (x1-x0)**2 + (y1-y0)**2 ) + + def kelkote(drt,x,y): + dx = drt[0] + dy = drt[1] + #print(x,y,dx,dy) + return 1 if (np.exp(1j*(drt[2]+pi/2)) * ((x-dx)+(dy-y)*1j)).real >= 0 else -1 + + # FractalNoise(0.7,511,0.01,42).getChunk(3,3,(16,16)) + #33.8 s ± 72.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) + for d in drts: + drteffect = lambda i,j : interpol(dst(d[0],i/n[0] + x,d[1],j/n[1] + y))*kelkote(d,i/n[0] + x,j/n[1] + y)*epsilon + chunk += np.fromfunction(np.vectorize(drteffect),n) + + # FractalNoise(0.7,511,0.01,42).getChunk(3,3,(16,16)) + #28.9 s ± 344 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) +# for i in range(n[0]): +# for j in range(n[1]): +# posx = i/n[0] + x +# posy = j/n[1] + y +# value = 0 +## print(i,j) +# for d in drts: +# value += interpol(dst(d[0],posx,d[1],posy))*kelkote(d,posx,posy)*epsilon +# chunk[i,j] = value + return chunk + + +class TestNoise(Noise): + + nn = PerlinNoise + + def getChunk(self,x,y,n): + + indexes = np.array([i for i in range(n[0]*n[1]+1)]) + data = np.ones((n[0]*n[1])) + return WorldChunk(n,indexes,data) + + + + +class CavernedNoise(Noise): + + perlinSurface = None + perlinGrotte = None + perlinFond = None + + def __init__(self): + self.perlinSurface = PerlinNoise(.5,64) + self.perlinGrotte = PerlinNoise(7 ,77) + self.perlinFond = PerlinNoise(.3 ,23) + + + def getChunk(self,x,y,n): + chk = self.perlinSurface.getChunk(x,y,n) + fond = self.perlinFond.getChunk(x,y,n) + grotte=self.perlinGrotte.getChunk(x,y,n) + + out = [] + + for i in range(n[0]): + lig = [] + for j in range(n[1]): + if(grotte[i,j]>.2): # Pas de grotte + lig.append([chk[i,j]]) + elif(grotte[i,j]>0): + lig.append([fond[i,j]]) + else: + lig.append([fond[i,j],chk[i,j]-0.1*abs(grotte[i,j]),chk[i,j]]) + out.append(lig) + + return out + + +class CavernedNoise2(Noise): + + perlinCielH = None + perlinGHaut = None + perlinGH = None + perlinGHp = None + perlinGBas = None + + #-x^(4)+4x^(3)-6x^(2)+4x + + def __init__(self,seed): + self.perlinCielH = PerlinNoise(7 ,seed) + self.perlinGHaut = PerlinNoise(5 ,seed) + self.perlinGH = PerlinNoise(25 ,seed) + self.perlinGHp = PerlinNoise(1 ,seed) + self.perlinGBas = PerlinNoise(5 ,seed) + + + def getChunk(self,x,y,n): + gtTransform = np.vectorize(lambda x : 0 if x<0 else sqrt(2*x-x**2)**1.5) + transform=lambda M,a,b : M*b+a + cielH = transform(self.perlinCielH.getChunk(x,y,n),28,28) + gHaut = transform(self.perlinGHaut.getChunk(x,y,n),60,20) + ghp = transform(self.perlinGHp.getChunk(x,y,n) ,0.005,0.005) + ghh = transform(self.perlinGHp.getChunk(x,y,n) ,0.5,0.5) + gBas = transform(self.perlinGBas.getChunk(x,y,n),10,10) + gh = gtTransform(ghp+ghh) + + toit = 128 + + out = [] + + + + for i in range(n[0]): + lig = [] + for j in range(n[1]): + ch = cielH[i,j] # la hauteur entre la surface et le ciel + ght = gHaut[i,j] # haut limite de la grotte + gbs = gBas[i,j] # bas limite de la grotte + hauteur=gh[i,j] # pourcentage de hauteur de la grotte + grh = (ght+gbs +hauteur*(ght-gbs))/2 # vrai plafond de la grotte + grb = (ght+gbs -hauteur*(ght-gbs))/2 # vrai sol de la grotte + if(ght<=40):print(ght) + if hauteur==0: + # Pas de grotte + lig.append([toit-ch]) + elif(grh+ch>=toit): + # La grotte est ouverte sur la surface + lig.append([grb]) + else: + # Grotte souterraine et surface + lig.append([grb,grh,toit-ch]) + + out.append(lig) + + return ArrayedWorldChunk.fromList(out) + + + +#for c in cmaps: +# pp.figure() +# print(c) +# pp.imshow(I, cmap=c) + + + + +#sys.exit() +####### Fenêtre graphique ####### +#from PyQt5.QtWidgets import QVBoxLayout,QHBoxLayout,QPushButton,QWidget,QApplication,QFormLayout,QLabel,QTextEdit,QDial +# +#app = QApplication([]) +# +#class ExplorerWidget(QWidget): +# +# def __init__(): +# print('wow') +# +##### Control Panel #### +#seedSelector = QTextEdit() +#ndroitesSelector = QDial() +# +#cPanel = QFormLayout() +#cPanel.addWidget(QLabel("Seed : ")) +#cPanel.addWidget(seedSelector) +#cPanel.addWidget(QLabel("Nombre de droites :")) +#cPanel.addWidget(ndroitesSelector) +# +#globalL = QHBoxLayout() +#globalL.addStretch(1) +#globalL.addLayout(cPanel) +# +#window = QWidget() +#window.setLayout(globalL) +#window.show() +# +#app.exec_() + +# +#(x0,x1,y0,y1) = (0,4,0,4) +#n = 100 +# +# +#x = np.linspace(x0,x1,n) +#y = np.linspace(y0,y1,n) +#x00 = int(x0)-1 +#y00 = int(y0)-1 +#x11 = int(x1)+1 +#y11 = int(y1)+1 +#gradient = np.exp(np.random.rand(x11-x00+1,y11-y00+1)*2*np.pi*1j) +#X,Y = np.meshgrid(x,y) +##print(gradient) +# +#def lerp(a0, a1, w): +# return a0 + (a1-a0)*(-2*w*w*w+3*w*w) +# +#def dotGridGradient(ix, iy, x, y): +# dx = x - ix +# dy = y - iy +# return (np.conj(gradient[iy-y00][ix-x00])*(dx+1j*dy)).real +# +#def bruit(x,y): +# (x0,y0) = (int(x),int(y)) +# (x1,y1) = (x0+1,y0+1) +# +# sx = x - x0; +# sy = y - y0; +# +# n0 = dotGridGradient(x0, y0, x, y); +# n1 = dotGridGradient(x1, y0, x, y); +# ix0 = lerp(n0, n1, sx); +# n0 = dotGridGradient(x0, y1, x, y); +# n1 = dotGridGradient(x1, y1, x, y); +# ix1 = lerp(n0, n1, sx); +# return lerp(ix0, ix1, sy); +# +# +# +#Z = np.zeros((n,n)) +#for i in range(n): +# for j in range(n): +# Z[i,j] = bruit(x[i],y[j]) +# +#pp.imshow(Z,cmap='autumn') +# +#fig = pp.figure() +#ax = pp.axes(projection='3d') +# +#ax.view_init(80, 42) +#ax.plot_surface(X,Y,Z, rstride=1, cstride=1, +# cmap='autumn', edgecolor='none') + + + + + diff --git a/Diapo/pythonhighlight.sty b/Diapo/pythonhighlight.sty new file mode 100644 index 0000000..47b4521 --- /dev/null +++ b/Diapo/pythonhighlight.sty @@ -0,0 +1,137 @@ +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{pythonhighlight}[2011/09/19 python code highlighting; provided by Olivier Verdier ] + + +\RequirePackage{listings} +\RequirePackage{xcolor} + +\renewcommand*{\lstlistlistingname}{Code Listings} +\renewcommand*{\lstlistingname}{Code Listing} +\definecolor{gray}{gray}{0.5} +\colorlet{commentcolour}{green!50!black} + +\colorlet{stringcolour}{red!60!black} +\colorlet{keywordcolour}{magenta!90!black} +\colorlet{exceptioncolour}{yellow!50!red} +\colorlet{commandcolour}{blue!60!black} +\colorlet{numpycolour}{blue!60!green} +\colorlet{literatecolour}{magenta!90!black} +\colorlet{promptcolour}{green!50!black} +\colorlet{specmethodcolour}{violet} + +\newcommand*{\framemargin}{3ex} + +\newcommand*{\literatecolour}{\textcolor{literatecolour}} + +\newcommand*{\pythonprompt}{\textcolor{promptcolour}{{>}{>}{>}}} + +\lstdefinestyle{mypython}{ +%\lstset{ +%keepspaces=true, +language=python, +showtabs=true, +tab=, +tabsize=2, +basicstyle=\ttfamily\footnotesize,%\setstretch{.5}, +stringstyle=\color{stringcolour}, +showstringspaces=false, +alsoletter={1234567890}, +otherkeywords={\%, \}, \{, \&, \|}, +keywordstyle=\color{keywordcolour}\bfseries, +emph={and,break,class,continue,def,yield,del,elif ,else,% +except,exec,finally,for,from,global,if,import,in,% +lambda,not,or,pass,print,raise,return,try,while,assert,with}, +emphstyle=\color{blue}\bfseries, +emph={[2]True, False, None}, +emphstyle=[2]\color{keywordcolour}, +emph={[3]object,type,isinstance,copy,deepcopy,zip,enumerate,reversed,list,set,len,dict,tuple,xrange,append,execfile,real,imag,reduce,str,repr}, +emphstyle=[3]\color{commandcolour}, +emph={Exception,NameError,IndexError,SyntaxError,TypeError,ValueError,OverflowError,ZeroDivisionError}, +emphstyle=\color{exceptioncolour}\bfseries, +%upquote=true, +morecomment=[s]{"""}{"""}, +commentstyle=\color{commentcolour}\slshape, +%emph={[4]1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, +emph={[4]ode, fsolve, sqrt, exp, sin, cos,arctan, arctan2, arccos, pi, array, norm, solve, dot, arange, isscalar, max, sum, flatten, shape, reshape, find, any, all, abs, plot, linspace, legend, quad, polyval,polyfit, hstack, concatenate,vstack,column_stack,empty,zeros,ones,rand,vander,grid,pcolor,eig,eigs,eigvals,svd,qr,tan,det,logspace,roll,min,mean,cumsum,cumprod,diff,vectorize,lstsq,cla,eye,xlabel,ylabel,squeeze}, +emphstyle=[4]\color{numpycolour}, +emph={[5]__init__,__add__,__mul__,__div__,__sub__,__call__,__getitem__,__setitem__,__eq__,__ne__,__nonzero__,__rmul__,__radd__,__repr__,__str__,__get__,__truediv__,__pow__,__name__,__future__,__all__}, +emphstyle=[5]\color{specmethodcolour}, +emph={[6]assert,yield}, +emphstyle=[6]\color{keywordcolour}\bfseries, +emph={[7]range}, +emphstyle={[7]\color{keywordcolour}\bfseries}, +% emph={[7]self}, +% emphstyle=[7]\bfseries, +literate=*% +{:}{{\literatecolour:}}{1}% +{=}{{\literatecolour=}}{1}% +{-}{{\literatecolour-}}{1}% +{+}{{\literatecolour+}}{1}% +{*}{{\literatecolour*}}{1}% +{**}{{\literatecolour{**}}}2% +{/}{{\literatecolour/}}{1}% +{//}{{\literatecolour{//}}}2% +{!}{{\literatecolour!}}{1}% +%{(}{{\literatecolour(}}{1}% +%{)}{{\literatecolour)}}{1}% +{[}{{\literatecolour[}}{1}% +{]}{{\literatecolour]}}{1}% +{<}{{\literatecolour<}}{1}% +{>}{{\literatecolour>}}{1}% +{>>>}{\pythonprompt}{3}% +,% +%aboveskip=.5ex, +frame=trbl, +%frameround=tttt, +%framesep=.3ex, +rulecolor=\color{black!40}, +%framexleftmargin=\framemargin, +%framextopmargin=.1ex, +%framexbottommargin=.1ex, +%framexrightmargin=\framemargin, +%framexleftmargin=1mm, framextopmargin=1mm, frame=shadowbox, rulesepcolor=\color{blue},#1 +%frame=tb, +backgroundcolor=\color{white}, +breakindent=.5\textwidth,frame=single,breaklines=true% +%} +} + +\newcommand*{\inputpython}[3]{\lstinputlisting[firstline=#2,lastline=#3,firstnumber=#2,frame=single,breakindent=.5\textwidth,frame=single,breaklines=true,style=mypython]{#1}} + +\lstnewenvironment{python}[1][]{\lstset{style=mypython}}{} + +\lstdefinestyle{mypythoninline}{ +style=mypython,% +basicstyle=\ttfamily,% +keywordstyle=\color{keywordcolour},% +emphstyle={[7]\color{keywordcolour}},% +emphstyle=\color{exceptioncolour},% +literate=*% +{:}{{\literatecolour:}}{2}% +{=}{{\literatecolour=}}{2}% +{-}{{\literatecolour-}}{2}% +{+}{{\literatecolour+}}{2}% +{*}{{\literatecolour*}}2% +{**}{{\literatecolour{**}}}3% +{/}{{\literatecolour/}}{2}% +{//}{{\literatecolour{//}}}{2}% +{!}{{\literatecolour!}}{2}% +%{(}{{\literatecolour(}}{2}% +%{)}{{\literatecolour)}}{2}% +{[}{{\literatecolour[}}{2}% +{]}{{\literatecolour]}}{2}% +{<}{{\literatecolour<}}{2}% +{<=}{{\literatecolour{<=}}}3% +{>}{{\literatecolour>}}{2}% +{>=}{{\literatecolour{>=}}}3% +{==}{{\literatecolour{==}}}3% +{!=}{{\literatecolour{!=}}}3% +{+=}{{\literatecolour{+=}}}3% +{-=}{{\literatecolour{-=}}}3% +{*=}{{\literatecolour{*=}}}3% +{/=}{{\literatecolour{/=}}}3% +%% emphstyle=\color{blue},% +} + +\newcommand*{\pyth}{\lstinline[style=mypythoninline]} + diff --git a/Diapo/recImage.png b/Diapo/recImage.png new file mode 100644 index 0000000..ae28fe0 Binary files /dev/null and b/Diapo/recImage.png differ diff --git a/Diapo/samyTortue.jpeg b/Diapo/samyTortue.jpeg new file mode 100644 index 0000000..d7b0a23 Binary files /dev/null and b/Diapo/samyTortue.jpeg differ diff --git a/Diapo/tmf.py b/Diapo/tmf.py new file mode 100644 index 0000000..b155480 --- /dev/null +++ b/Diapo/tmf.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" + Module contant les fonctions permettant de lire et écrire des fichiers dans le format TMF + + @author: mysaa +""" + + +class WorldSaver(): + + def __init__(): + regSize=0 diff --git a/Diapo/triImage.png b/Diapo/triImage.png new file mode 100644 index 0000000..3a268e5 Binary files /dev/null and b/Diapo/triImage.png differ diff --git a/MCOT/mcot.pdf b/MCOT/mcot.pdf new file mode 100644 index 0000000..3b0c864 Binary files /dev/null and b/MCOT/mcot.pdf differ diff --git a/MCOT/mcot.tex b/MCOT/mcot.tex new file mode 100644 index 0000000..8721f90 --- /dev/null +++ b/MCOT/mcot.tex @@ -0,0 +1,86 @@ +\documentclass[10pt,a4paper]{article} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage[french]{babel} +\usepackage{amsmath} +\usepackage{amsfonts} +\usepackage{amssymb} +\usepackage{graphicx} +\usepackage{hyperref} +\usepackage{tabularx} + +% les tableaux on désormais tous des lignes +%\let \clone@tabularcr \@tabularcr +%\def\@tabularcr{\clone@tabularcr\hline} + + + +\author{Samy Avrillon} +\title{Mise en Cohérence des Objectifs du TIPE (MCOT)} +\begin{document} + + \maketitle + + \tableofcontents + + \newpage + + Professeur encadrant : Mr H.\textbf{RICHARD} + + \part{Titre, motivation et ancrage} + + \begin{description} + \item[Titre] \underline{\smash{Stockage et génération de topographie artificielle de fond océanique}} + + \item[Motivation] La génération des océans de Minecraft semble magique : aléatoire et pourtant déterministe. J'ai voulu étudier ce phénomène de pseudo-aléatoire et j'en ai été conduit à créer un format de fichier pour stocker ces topographies de manière plus optimisée que les formats actuels (triangles ou discrétisation 3D) + + \item[Ancrage] Créer et stocker des fonds océaniques permet de pouvoir créer des images graphiques d'océans pour le cinéma de manière automatisée ou de créer des environnements pour des simulation ou jeu vidéo + \end{description} + + + + \part{Positionnements thématiques et mots-clés} + + \section{Positionnement thématique} + + INFORMATIQUE + INFORMATIQUE + INFORMATIQUE + + \section{Mots clés} + \begin{tabular}{|c|c|} + Français & English \\ + \hline + Format de fichier & File format \\ + Génération de carte & Map generator \\ + Pseudo-aléatoire & Pseudorandom \\ + Champ de hauteur & Heightmap \\ + Infographie & Computer graphics \\ + \end{tabular} + + \part{Bibliographie commentée} + Le bruit de Perlin a été créé par Ken Perlin pour le film Tron{[}2{]}. Ce bruit a permit à Markus Persson de créer Minecraft, une révolution dans le monde vidéoludique {[}1{]}. Dans ce jeu, le joueur est libre de progresser dans un monde qui se génère avec lui. De nombreux jeux ont ensuite repris ce concept de génération \og procédurale \fg + Dans Minecraft l'espace est discrétisé en trois dimensions, ce qui sert très bien le jeu. Mais pour générer de grandes surfaces, cette façon de stocker est très peu optimisée spatialement. Je voulais donc changer pour une version discrétisée en deux dimensions à la manière d'un champ de hauteur, mais permettant de représenter des grottes (plusieurs changements de densité sur une même colonne). Les jeux actuels manquent en effet de degrés de profondeur. Il n'y a qu'une surface. Le format permettrait de pouvoir développer des mondes plus complexes + + \part{Problématique retenue} + Comment créer et stocker de manière efficace et modulable une topographie de fond océanique + + \part{Objectifs du TIPE} + Mon objectif est de créer un format de fichier, le \textit{TMF} (topographic map format), permettant de stocker une carte potentiellement infinie représentant la topographie d'une région d'un océan aussi grand que souhaité. Ce format est accompagné de trois modules python. Le premier permet à d'autres programmes python de lire et écrire des fichiers TMF à travers une interface orientée objet. Le second génère procéduralement et pseudo-aléatoirement des topographies/cartes sous-marines réalistes (ou non). Le troisième convertit les objets topographiques en objets graphiques, à base de triangles, pouvant directement être affiché par l'ordinateur (par exemple au format OBJ). + + \part{Liste des références bibliographiques} + + \begin{tabularx}{\textwidth}{cXXX} + Index & Auteur & Titre & Référence \\\hline \\ + {[}1{]} & Markus Persson alias Notch & Terrain Generation part 1 & \url{https://notch.tumblr.com/post/3746989361/terrain-generation-part-1} \\[+20pt] + {[}2{]} & Ken Perlin & Making Noise - based on a talk at GDCHardcore & \url{https://web.archive.org/web/20160408014440/http://www.noisemachine.com/talk1/index.html} \\[+20pt] + + \hline \\ + & & & \url{http://universe.tuxfamily.org/oldblog/index.php?tag/Heightmap}\\ + + \end{tabularx} + + + + +\end{document} \ No newline at end of file diff --git a/MinecraftScreenShots/2019-08-05_20.48.22.png b/MinecraftScreenShots/2019-08-05_20.48.22.png new file mode 100644 index 0000000..c72cf52 Binary files /dev/null and b/MinecraftScreenShots/2019-08-05_20.48.22.png differ diff --git a/MinecraftScreenShots/2019-08-05_20.48.30.png b/MinecraftScreenShots/2019-08-05_20.48.30.png new file mode 100644 index 0000000..5d78920 Binary files /dev/null and b/MinecraftScreenShots/2019-08-05_20.48.30.png differ diff --git a/MinecraftScreenShots/2019-08-05_20.48.37.png b/MinecraftScreenShots/2019-08-05_20.48.37.png new file mode 100644 index 0000000..f1a5bf9 Binary files /dev/null and b/MinecraftScreenShots/2019-08-05_20.48.37.png differ diff --git a/MinecraftScreenShots/2019-08-05_20.48.55.png b/MinecraftScreenShots/2019-08-05_20.48.55.png new file mode 100644 index 0000000..ca79ea7 Binary files /dev/null and b/MinecraftScreenShots/2019-08-05_20.48.55.png differ diff --git a/MinecraftScreenShots/2019-08-05_20.49.29.png b/MinecraftScreenShots/2019-08-05_20.49.29.png new file mode 100644 index 0000000..8c918d6 Binary files /dev/null and b/MinecraftScreenShots/2019-08-05_20.49.29.png differ diff --git a/MinecraftScreenShots/2019-08-27_22.13.22.png b/MinecraftScreenShots/2019-08-27_22.13.22.png new file mode 100644 index 0000000..a612473 Binary files /dev/null and b/MinecraftScreenShots/2019-08-27_22.13.22.png differ diff --git a/MinecraftScreenShots/2019-08-27_22.13.46.png b/MinecraftScreenShots/2019-08-27_22.13.46.png new file mode 100644 index 0000000..279ce59 Binary files /dev/null and b/MinecraftScreenShots/2019-08-27_22.13.46.png differ diff --git a/MinecraftScreenShots/2019-08-27_22.13.55.png b/MinecraftScreenShots/2019-08-27_22.13.55.png new file mode 100644 index 0000000..a073556 Binary files /dev/null and b/MinecraftScreenShots/2019-08-27_22.13.55.png differ diff --git a/MinecraftScreenShots/2019-08-27_22.13.57.png b/MinecraftScreenShots/2019-08-27_22.13.57.png new file mode 100644 index 0000000..9216e19 Binary files /dev/null and b/MinecraftScreenShots/2019-08-27_22.13.57.png differ diff --git a/MinecraftScreenShots/2019-08-27_22.14.06.png b/MinecraftScreenShots/2019-08-27_22.14.06.png new file mode 100644 index 0000000..5da8cba Binary files /dev/null and b/MinecraftScreenShots/2019-08-27_22.14.06.png differ diff --git a/MinecraftScreenShots/2019-08-27_22.14.22.png b/MinecraftScreenShots/2019-08-27_22.14.22.png new file mode 100644 index 0000000..d307c4c Binary files /dev/null and b/MinecraftScreenShots/2019-08-27_22.14.22.png differ diff --git a/MinecraftScreenShots/2019-08-27_22.14.47.png b/MinecraftScreenShots/2019-08-27_22.14.47.png new file mode 100644 index 0000000..860c50c Binary files /dev/null and b/MinecraftScreenShots/2019-08-27_22.14.47.png differ diff --git a/Presentation/SonarPresentation.pdf b/Presentation/SonarPresentation.pdf new file mode 100644 index 0000000..448ad2e Binary files /dev/null and b/Presentation/SonarPresentation.pdf differ diff --git a/Presentation/SonarPresentation.tex b/Presentation/SonarPresentation.tex new file mode 100644 index 0000000..c349274 --- /dev/null +++ b/Presentation/SonarPresentation.tex @@ -0,0 +1,126 @@ +\documentclass[11pt,aspectratio=169]{beamer} + +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage[french]{babel} +\usepackage[clean,pdf]{svg} +\usepackage{multimedia} +\usetheme{Madrid} + +\hypersetup{pdfpagemode=FullScreen} + +% Transition en fade-in par défaut +\addtobeamertemplate{background canvas}{\transfade[duration=0.4]}{} + +\begin{document} + \author{Samy AVRILLON - 24817} + \title{Le Sonar de l'infini} + \subtitle{Génération de fond marins informatisés aléatoires} + \logo{\includegraphics[width=.5cm]{bernardLogo}} + \institute{Lycée lafayette} + \date{Années 2018-2020} + %\subject{} + %\setbeamercovered{transparent} + %\setbeamertemplate{navigation symbols}{} + \frame[plain]{\maketitle} + + %\iffalse + \begin{frame} + \frametitle{Sommaire} + \pause + \tableofcontents[pausesections] + \end{frame} + %\fi + + \section{Présentation du projet} + \begin{frame} + \begin{figure} + \includegraphics[width=0.7\textwidth]{magicInstinctSoftware} + \caption{Capture d'écran du logiciel \textit{Magic Instinct Software}} + \end{figure} + \end{frame} + + \begin{frame} + /media/mysaa/2761-7FF91/Sonar/Presentation/fond.pdf + /media/mysaa/2761-7FF91/Sonar/Presentation/fond.svg + /media/mysaa/2761-7FF91/Sonar/Presentation/minecraftOcean.jpg + \end{frame} + + \begin{frame} + \frametitle{Différentes applications} + \pause + \begin{itemize}[<+->] + \item Jeu vidéo + \item Simulation océaniques + \item Entrainement d'IA de rover (\textit{Cf Quentin SOUVIGNET}) + \item Graphisme + \end{itemize} + \end{frame} + + \section{Cahier des charges} + \begin{frame} + \frametitle{Liste des contraintes} + \pause + \begin{itemize}[<+->] + \item Infinité + \item Répétabilité + \item Modulabilité + \end{itemize} + \end{frame} + + \section{Solutions de génération} + \begin{frame} + \frametitle{Bruit de Perlin} + \pause + \begin{figure} + \includegraphics[height=0.7\textheight]{perlin} + \caption{Heightmap créée par un bruit de perlin} + \end{figure} + \end{frame} + + \begin{frame} + \frametitle{Bruit Fractal} + \begin{columns} + \pause + \begin{column}{0.5\textwidth} + \begin{figure} + \includegraphics[width=0.8\textwidth]{bfractal} + \caption{Bruit fractal avec peu de droites} + \end{figure} + \end{column} + \pause + \begin{column}{0.5\textwidth} + \begin{figure} + \includegraphics[width=0.8\textwidth]{hfractal} + \caption{Bruit fractal avec plus de droites} + \end{figure} + \end{column} + \end{columns} + \end{frame} + + \section{Un format de fichier} + + \begin{frame} + \frametitle{Contraintes du format} + \pause + \begin{itemize}[<+->] + \item Liberté totale + \item Complexité spaciale + \item Référencabilité + \end{itemize} + \end{frame} + + \begin{frame} + \frametitle{La structure d'une carte} + \centering + \includesvg[height=0.85\textheight]{fond} + \end{frame} + + % Derniere frame de fin + \bgroup + \setbeamercolor{background canvas}{bg=black} + \begin{frame}[plain]{} + \end{frame} + \egroup + +\end{document} \ No newline at end of file diff --git a/Presentation/bernardLogo.png b/Presentation/bernardLogo.png new file mode 100644 index 0000000..61fcf4e Binary files /dev/null and b/Presentation/bernardLogo.png differ diff --git a/Presentation/bernardLogo.svg b/Presentation/bernardLogo.svg new file mode 100644 index 0000000..b193bd4 --- /dev/null +++ b/Presentation/bernardLogo.svg @@ -0,0 +1,69 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/Presentation/bfractal.png b/Presentation/bfractal.png new file mode 100644 index 0000000..00390dd Binary files /dev/null and b/Presentation/bfractal.png differ diff --git a/Presentation/fond.svg b/Presentation/fond.svg new file mode 100644 index 0000000..1aa1252 --- /dev/null +++ b/Presentation/fond.svg @@ -0,0 +1,665 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + z=42m + z=0m + + diff --git a/Presentation/hfractal.png b/Presentation/hfractal.png new file mode 100644 index 0000000..3017373 Binary files /dev/null and b/Presentation/hfractal.png differ diff --git a/Presentation/magicInstinctSoftware.png b/Presentation/magicInstinctSoftware.png new file mode 100644 index 0000000..9bf6c93 Binary files /dev/null and b/Presentation/magicInstinctSoftware.png differ diff --git a/Presentation/minecraftOcean.jpg b/Presentation/minecraftOcean.jpg new file mode 100644 index 0000000..11d3386 Binary files /dev/null and b/Presentation/minecraftOcean.jpg differ diff --git a/Presentation/perlin.png b/Presentation/perlin.png new file mode 100644 index 0000000..cabd303 Binary files /dev/null and b/Presentation/perlin.png differ diff --git a/Python/data.py b/Python/data.py new file mode 100644 index 0000000..3c6df36 --- /dev/null +++ b/Python/data.py @@ -0,0 +1,153 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +Created on Wed Aug 28 17:39:43 2019 + +Module contanant les classes générales structurant les données, ainsi que les + +@author: mysaa +""" +import numpy as np + +def appendeur(l1,l2): + """ + Effectue l1=l1+l2 de manière opti + """ + for l in l2: + l1.append(l) + +class WorldChunk(): + + def getSize(self): + raise NotImplementedError("Vous avez fait un monde qui n'implemente pas cette méthode. Vous êtes bizzare vous savez ? Un monde sans taille !!!") + + + def getColumn(self,x,y): + raise NotImplementedError("Vous avez fait un monde qui n'implemente pas cette méthode. Vous êtes bizzare vous savez ?") + + + def asList(self): + return [ [self.getColumn(x,y) for y in range(self.size[1])] for x in range(self.size[0]) ] + + def getIndexed(self,fullCoords=False,addZero=False): + points = [] + pointIndexes = [0] + for pos in np.ndindex(self.getSize()): + col = self.getColumn(pos[0],pos[1]) + if(addZero): col = np.insert(col,0,0) + if(fullCoords): col = [(pos[0],pos[1],c) for c in col] + appendeur(points,col) + pointIndexes.append(pointIndexes[-1]+len(col)) + return points,pointIndexes + + +class CollageWorldChunk(WorldChunk): + + def __init__(self,chunk,xp,yp,xy): + + self.orgChunk,self.xp,self.yp,self.xy = chunk,xp,yp,xy + self.orgSize = chunk.getSize() + + def getSize(self) : return (self.orgChunk.size[0]+1,self.orgChunk.size[1]+1) + + def getColumn(self,x,y): + xout,yout = x>=self.orgSize[0],y>=self.orgSize[1] + if(xout and yout): + return self.xy.getColumn(x-self.orgSize[0],y-self.orgSize[1]) + if(xout): + return self.xp.getColumn(x-self.orgSize[0],y) + if(yout): + return self.yp.getColumn(x,y-self.orgSize[1]) + + return self.orgChunk.getColumn(x,y) + +class ArrayedWorldChunk(WorldChunk): + + def fromList(liste): + size = len(liste),len(liste[0]) + indexes=np.empty(size[0]*size[1]+1,dtype=np.uint32) + index = 0 + data = [] + for y in range(size[1]): + for x in range(size[0]): + indexes[x+size[0]*y]=index + data += liste[x][y] + index += len(liste[x][y]) + indexes[size[0]*size[1]] = index + data = np.array(data,dtype=np.float) + return ArrayedWorldChunk(size,indexes,data) + + def __init__(self,size,indexes,data): + self.size = size + self.indexes=indexes + self.data=data + + + def getColumn(self,x,y): + i0,i1 = self.indexes[x+self.size[0]*y],self.indexes[x+self.size[0]*y+1] + return self.data[i0:i1] + + def getSize(self) : return self.size + + + + + + + + + +class Noise: + + def getChunk(self,x,y,n): + """ + Cette fonction renvoie un array numpy de taille rx*ry correspondant au chunk x y avec le seed donné. + Cette fonction doit être déterministe (si les attributs de l'objets ne sont pas changés bien sur) + """ + raise NotImplementedError("Vous avez fait un bruit qui n'implemente pas cette méthode. Vous êtes bizzare vous savez ?") + + + + def __add__(self,other): + + def addedChunk(self,x,y,n): + return self.noise1.getChunk(x,y,n) + self.noise2.getChunk(x,y,n) + noise = Noise() + noise.noise1 = self + noise.noise2 = other + noise.getChunk = addedChunk + return noise + + def __iadd__(self,other): + + return self.__add__(other) + + def __rmul__(self,other): + + if type(other) in ['float','int']: + def mulChunk(self,x,y,n): + return self.prop*self.noise1.getChunk(x,y,n) + noise = Noise() + noise.noise1 = self + noise.prop = other + noise.getChunk = mulChunk + else: + def mulChunk(self,x,y,n): + return self.noise1.getChunk(x,y,n) * self.noise2.getChunk(x,y,n) + noise = Noise() + noise.noise1 = self + noise.noise2 = other + noise.getChunk = mulChunk + return noise + + def __sub__(self,other): + + def subChunk(self,x,y,n): + return self.noise1.getChunk(x,y,n) - self.noise2.getChunk(x,y,n) + noise = Noise() + noise.noise1 = self + noise.noise2 = other + noise.getChunk = subChunk + return noise + \ No newline at end of file diff --git a/Python/filImage.png b/Python/filImage.png new file mode 100644 index 0000000..da6c447 Binary files /dev/null and b/Python/filImage.png differ diff --git a/Python/guy.py b/Python/guy.py new file mode 100644 index 0000000..92d7d58 --- /dev/null +++ b/Python/guy.py @@ -0,0 +1,264 @@ +# -*- coding: utf-8 -*- + +from PyQt5.QtWidgets import (QWidget, QSlider, QApplication, + QHBoxLayout, QVBoxLayout, QLabel, QLineEdit, QDesktopWidget, QPushButton, QComboBox) +from PyQt5.QtCore import QObject, Qt +from PyQt5.QtGui import QPainter, QFont, QColor, QPen, QImage, QPixmap + +from perlin import PerlinNoise + +import matplotlib.pyplot as pp +import numpy as np +from math import floor,ceil +import threading +import sys + +try: application +except NameError: application = QApplication([]) + +class MapNavigator(QWidget): + + carte = QLabel() + + def __init__(self): + super().__init__() + self.setWindowTitle("Navigateur") + + ### Centrer la fenetre ### + + self.resize(750,505) + + self.initFrame() + + + self.show() + self.centrer() + + def centrer(self): + qtRectangle = self.frameGeometry() + centerPoint = QDesktopWidget().availableGeometry().center() + qtRectangle.moveCenter(centerPoint) + self.move(qtRectangle.topLeft()) + + + def initFrame(self): + ##### Config ##### + + globalayout = QHBoxLayout() + + configl = QVBoxLayout() + configl.setAlignment(Qt.AlignTop) + + ## Fichier ## + fichier = QHBoxLayout() + fichierlabel = QLabel("Fichier :") + fichiertext = QLineEdit() + fichier.addWidget(fichierlabel) + fichier.addWidget(fichiertext) + + ## Refresh ## + refresh = QPushButton("Refresh") + + ## Coords ## + Xs = QHBoxLayout() + posxlabel = QLabel("x:") + posxtext = QLineEdit() + lxlabel = QLabel("lx:") + lxtext = QLineEdit() + Xs.addWidget(posxlabel) + Xs.addWidget(posxtext) + Xs.addWidget(lxlabel) + Xs.addWidget(lxtext) + + Ys = QHBoxLayout() + posylabel = QLabel("y:") + posytext = QLineEdit() + lylabel = QLabel("ly:") + lytext = QLineEdit() + Ys.addWidget(posylabel) + Ys.addWidget(posytext) + Ys.addWidget(lylabel) + Ys.addWidget(lytext) + + ## Redraw ## + redraw = QPushButton("Redraw") + + ## Colormap ## + colormap = QHBoxLayout() + colormaplabel = QLabel("Color map :") + colormapchooser = QComboBox()#["Noir","Blanc","Rouge","Vert","Bleu"]) + colormap.addWidget(colormaplabel) + colormap.addWidget(colormapchooser) + + + + configl.addLayout(fichier) + configl.addWidget(refresh) + configl.addLayout(Xs) + configl.addLayout(Ys) + configl.addWidget(redraw) + configl.addLayout(colormap) + globalayout.addLayout(configl) + globalayout.addWidget(self.carte) + + self.setLayout(globalayout) + + lastx,lasty = None,None + def mouseMoveEvent(self,e): + dx,dy = e.x() - self.lastx,e.y() - self.lasty + print(dx/self.generator.w*self.generator.rx,dy/self.generator.h*self.generator.ry) + self.lastx,self.lasty = e.x(),e.y() + self.generator.x += dx/self.generator.w*self.generator.rx + self.generator.y += dy/self.generator.h*self.generator.ry + def mousePressEvent(self,e): + self.lastx,self.lasty = e.x(),e.y() + def mouseReleaseEvent(self,e): + self.lastx,self.lasty = None,None + + def closeEvent(self,e): + self.generator.running = False + + + def getChunk(self,x,y,rx,ry): + + if (x,y) not in self.generated: + self.genqueue.append((x,y)) + return np.zeroes((rx,ry)) + return self.generated[(x,y)] + + + def updateImage(self): + x,y = self.x,self.y + rx,ry = self.rx,self.ry + w,h = self.w,self.h + lx,ly = w/rx,h/ry + + #out = np.zeros((self.WIDTH,self.HEIGTH)) + + x0 = x-lx/2 + x1 = x+lx/2 + y0 = y-ly/2 + y1 = y+ly/2 + + cx0,cy0 = int((x0-floor(x0))*rx),int((y0-floor(y0))*ry) + cx1,cy1 = int((x1-floor(x1))*rx),int((y1-floor(y1))*ry) + zx,zy = int((1+floor(x0)-x0)*rx),int((1+floor(y0)-y0)*ry) + + print(x0,x1,y0,y1,cx0,cy0,w,h,lx,ly) + for i in range(floor(x0),floor(x1)+1): + + for j in range(floor(y0),floor(y1)+1): + chk = self.getChunk(i,j,rx,ry) + + cx,dx = cx0 if i==floor(x0) else 0 , cx1 if i==floor(x1) else rx + cy,dy = cy0 if j==floor(y0) else 0 , cy1 if j==floor(y1) else ry + + ax,ay = 0 if i==floor(x0) else zx+(i-floor(x0)-1)*rx , 0 if j==floor(y0) else zy+(j-floor(y0)-1)*ry + bx,by = ax + (dx-cx) , ay + (dy-cy) + + + print(i,j,"->",ax,bx,cx,dx,ay,by,cy,dy) + out[ax:bx,ay:by] = chk[cx:dx,cy:dy] + + + + self.setImage(out) + + +class Generator(threading.Thread): + + label = None + + noise = None + + generated = {} + genqueue = [] + + running = True + + x,y = 0,0 + rx,ry = 256,256 + w,h = 512,512 + + def __init__(self,linkedLabel,noise): + super().__init__() + self.label = linkedLabel + self.noise = noise + + def getChunk(self,x,y,rx,ry): + + if (x,y) not in self.generated: + self.genqueue.append((x,y)) + chunk = self.noise.getChunk(x,y,(rx,ry)) + self.generated[(x,y)] = chunk + return self.generated[(x,y)] + + + def setImage(self,im): + im = np.uint8((im - im.min())/im.ptp()*255.0) + + qi = QImage(im.data, im.shape[1], im.shape[0], im.shape[1], QImage.Format_Indexed8) + + qp = QPixmap.fromImage(qi) + + self.label.setPixmap(qp) + + + def run(self): + out = np.zeros((self.w,self.h)) + while(self.running): + x,y = self.x,self.y + rx,ry = self.rx,self.ry + w,h = self.w,self.h + lx,ly = w/rx,h/ry + + #out = np.zeros((self.WIDTH,self.HEIGTH)) + + x0 = x-lx/2 + x1 = x+lx/2 + y0 = y-ly/2 + y1 = y+ly/2 + + cx0,cy0 = int((x0-floor(x0))*rx),int((y0-floor(y0))*ry) + cx1,cy1 = int((x1-floor(x1))*rx),int((y1-floor(y1))*ry) + zx,zy = int((1+floor(x0)-x0)*rx),int((1+floor(y0)-y0)*ry) + + print(x0,x1,y0,y1,cx0,cy0,w,h,lx,ly) + for i in range(floor(x0),floor(x1)+1): + + for j in range(floor(y0),floor(y1)+1): + self.setImage(out) + chk = self.getChunk(i,j,rx,ry) + + cx,dx = cx0 if i==floor(x0) else 0 , cx1 if i==floor(x1) else rx + cy,dy = cy0 if j==floor(y0) else 0 , cy1 if j==floor(y1) else ry + + ax,ay = 0 if i==floor(x0) else zx+(i-floor(x0)-1)*rx , 0 if j==floor(y0) else zy+(j-floor(y0)-1)*ry + bx,by = ax + (dx-cx) , ay + (dy-cy) + + + print(i,j,"->",ax,bx,cx,dx,ay,by,cy,dy) + out[ax:bx,ay:by] = chk[cx:dx,cy:dy] + + + + self.setImage(out) + print('Bybye !') + + + +nav = MapNavigator() + +seed=42 +perl1 = PerlinNoise(10 ,seed) +perl2 = PerlinNoise(5 ,seed) +perl3 = PerlinNoise(1 ,seed) + +noise = perl1+.1*perl2+.03*perl3 +generator = Generator(nav.carte,noise) +nav.generator = generator +generator.start() + +###### Content ##### + + diff --git a/Python/guy2.py b/Python/guy2.py new file mode 100644 index 0000000..cfe9e98 --- /dev/null +++ b/Python/guy2.py @@ -0,0 +1,234 @@ +# -*- coding: utf-8 -*- + +from PyQt5.QtWidgets import (QWidget, QSlider, QApplication, + QHBoxLayout, QVBoxLayout, QLabel, QLineEdit, QDesktopWidget, QPushButton, QComboBox) +from PyQt5.QtCore import QObject, Qt +from PyQt5.QtGui import QPainter, QFont, QColor, QPen, QImage, QPixmap + +from perlin import PerlinNoise,FractalNoise + +import matplotlib.pyplot as pp +import numpy as np +from math import floor,ceil +from time import sleep +import threading +import sys + +#application = QApplication([]) + +class MapNavigator(QWidget): + + carte = QLabel() + + def __init__(self): + super().__init__() + self.setWindowTitle("Navigateur") + + ### Centrer la fenetre ### + + self.resize(750,505) + + self.initFrame() + + + self.show() + self.centrer() + + + def centrer(self): + qtRectangle = self.frameGeometry() + centerPoint = QDesktopWidget().availableGeometry().center() + qtRectangle.moveCenter(centerPoint) + self.move(qtRectangle.topLeft()) + + + def initFrame(self): + ##### Config ##### + + globalayout = QHBoxLayout() + + configl = QVBoxLayout() + configl.setAlignment(Qt.AlignTop) + + ## Fichier ## + fichier = QHBoxLayout() + fichierlabel = QLabel("Fichier :") + fichiertext = QLineEdit() + fichier.addWidget(fichierlabel) + fichier.addWidget(fichiertext) + + ## Refresh ## + refresh = QPushButton("Refresh") + + ## Coords ## + Xs = QHBoxLayout() + posxlabel = QLabel("x:") + posxtext = QLineEdit() + lxlabel = QLabel("lx:") + lxtext = QLineEdit() + Xs.addWidget(posxlabel) + Xs.addWidget(posxtext) + Xs.addWidget(lxlabel) + Xs.addWidget(lxtext) + + Ys = QHBoxLayout() + posylabel = QLabel("y:") + posytext = QLineEdit() + lylabel = QLabel("ly:") + lytext = QLineEdit() + Ys.addWidget(posylabel) + Ys.addWidget(posytext) + Ys.addWidget(lylabel) + Ys.addWidget(lytext) + + ## Redraw ## + redraw = QPushButton("Redraw") + + ## Colormap ## + colormap = QHBoxLayout() + colormaplabel = QLabel("Color map :") + colormapchooser = QComboBox()#["Noir","Blanc","Rouge","Vert","Bleu"]) + colormap.addWidget(colormaplabel) + colormap.addWidget(colormapchooser) + + + + configl.addLayout(fichier) + configl.addWidget(refresh) + configl.addLayout(Xs) + configl.addLayout(Ys) + configl.addWidget(redraw) + configl.addLayout(colormap) + globalayout.addLayout(configl) + globalayout.addWidget(self.carte) + + self.setLayout(globalayout) + + lastx,lasty = None,None + def mouseMoveEvent(self,e): + dx,dy = e.x() - self.lastx,e.y() - self.lasty + print(dx/self.rx,dy/self.ry) + self.lastx,self.lasty = e.x(),e.y() + self.x += -dy/self.rx + self.y += -dx/self.ry + self.updateImage()# TODO separer le updateImage dans un autre thread pour éviter de l'appeler 1000 fois. Plutot set un tag indiquant qu'il faudrait l'appeler. + def mousePressEvent(self,e): + self.lastx,self.lasty = e.x(),e.y() + def mouseReleaseEvent(self,e): + self.lastx,self.lasty = None,None + + def closeEvent(self,e): + self.generator.running = False + + + x,y = 0,0 + rx,ry = 256,256 + w,h = 512,512 + + def getChunk(self,x,y,rx,ry): + + if (x,y) not in self.generator.generated: + self.generator.genqueue.append((x,y)) + return np.zeros((rx,ry)) + return self.generator.generated[(x,y)] + + def updateImage(self): + x,y = self.x,self.y + rx,ry = self.rx,self.ry + w,h = self.w,self.h + lx,ly = w/rx,h/ry + + out = np.zeros((self.w,self.h)) + + x0 = x-lx/2 + x1 = x+lx/2 + y0 = y-ly/2 + y1 = y+ly/2 + + cx0,cy0 = int((x0-floor(x0))*rx),int((y0-floor(y0))*ry) + cx1,cy1 = int((x1-floor(x1))*rx),int((y1-floor(y1))*ry) + zx,zy = int((1+floor(x0)-x0)*rx),int((1+floor(y0)-y0)*ry) + + print(x0,x1,y0,y1,cx0,cy0,w,h,lx,ly) + for i in range(floor(x0),floor(x1)+1): + + for j in range(floor(y0),floor(y1)+1): + chk = self.getChunk(i,j,rx,ry) + + cx,dx = cx0 if i==floor(x0) else 0 , cx1 if i==floor(x1) else rx + cy,dy = cy0 if j==floor(y0) else 0 , cy1 if j==floor(y1) else ry + + ax,ay = 0 if i==floor(x0) else zx+(i-floor(x0)-1)*rx , 0 if j==floor(y0) else zy+(j-floor(y0)-1)*ry + bx,by = ax + (dx-cx) , ay + (dy-cy) + + + print(i,j,"->",ax,bx,cx,dx,ay,by,cy,dy) + out[ax:bx,ay:by] = chk[cx:dx,cy:dy] + + + + self.setImage(out) + def setImage(self,im): + im = np.uint8((im - im.min())/im.ptp()*255.0) + + qi = QImage(im.data, im.shape[1], im.shape[0], im.shape[1], QImage.Format_Indexed8) + + qp = QPixmap.fromImage(qi) + + self.carte.setPixmap(qp) + + +class Generator(threading.Thread): + + updatefunc = None + + noise = None + res = None + + generated = {} + genqueue = [] + + running = True + + def __init__(self,updatefunc,noise,res): + super().__init__() + self.updatefunc = updatefunc + self.noise = noise + self.res = res + + + + + + def run(self): + while(self.running): + if(len(self.genqueue) > 0): + x,y = self.genqueue.pop(0) + if (x,y) in self.generated: + continue + chunk = self.noise.getChunk(x,y,self.res) + self.generated[(x,y)] = chunk + self.updatefunc() + else: + sleep(0.01) + print('Bybye !') + + + +nav = MapNavigator() + +seed=42 +perl1 = PerlinNoise(10 ,seed) +perl2 = PerlinNoise(5 ,seed) +perl3 = PerlinNoise(1 ,seed) + +noise = perl1+.1*perl2+.03*perl3 +generator = Generator(nav.updateImage,noise,(nav.rx,nav.ry)) +nav.generator = generator +generator.start() +nav.updateImage() + + +###### Content ##### + + diff --git a/Python/mcpi/.gitattributes b/Python/mcpi/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/Python/mcpi/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/Python/mcpi/.gitignore b/Python/mcpi/.gitignore new file mode 100644 index 0000000..858b795 --- /dev/null +++ b/Python/mcpi/.gitignore @@ -0,0 +1,33 @@ +*.py[cdo] +pythonhosted/ + +# Editor detritus +*.vim +*.swp +tags +.vscode + +# Packaging detritus +*.egg +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +coverage +.coverage +.tox +.cache + +# Generated documentation +docs/_build \ No newline at end of file diff --git a/Python/mcpi/CHANGELOG.md b/Python/mcpi/CHANGELOG.md new file mode 100644 index 0000000..e2dd4a6 --- /dev/null +++ b/Python/mcpi/CHANGELOG.md @@ -0,0 +1,10 @@ +# Change Log + +## 2018-05-01 v1.1.0 + ++ packaged and released onto [PyPI](https://pypi.org) ++ it seemed ridiculous calling this v1.0.0 given the maturity of this library, so it has become v1.1.0 + +## in the past v1.0.0 + ++ the library was created it was used but never packaged. \ No newline at end of file diff --git a/Python/mcpi/LICENSE b/Python/mcpi/LICENSE new file mode 100644 index 0000000..1f95d26 --- /dev/null +++ b/Python/mcpi/LICENSE @@ -0,0 +1,5 @@ +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Python/mcpi/README.md b/Python/mcpi/README.md new file mode 100644 index 0000000..de09596 --- /dev/null +++ b/Python/mcpi/README.md @@ -0,0 +1,46 @@ +# Minecraft: Pi edition API Python Library + +`mcpi` Python library for communicating with [Minecraft: Pi edition](https://minecraft.net/en-us/edition/pi/) and [RaspberryJuice](https://github.com/zhuowei/RaspberryJuice). + +## Installation + +### Windows + +``` +pip3 install mcpi +``` + +### Linux / MacOS + +```bash +sudo pip3 install mcpi +``` + +## History + +The [Minecraft: Pi edition](https://minecraft.net/en-us/edition/pi/) Python library was originally created by Mojang and released with Minecraft: Pi edition. + +Initial supported was provided for Python 2 only, but during a sprint at PyconUK 2014 it was migrated to Python 3 and [py3minepi](https://github.com/py3minepi/py3minepi) was created. + +The ability to hack Minecraft from Python was very popular and the [RaspberryJuice](https://github.com/zhuowei/RaspberryJuice) plugin was created for Minecraft Java edition. RaspberryJuice also extended the API adding additional features. + +This python library supports Python 2 & 3 and Minecraft: Pi edition and RaspberryJuice. + +Documentation for the Minecraft: Pi edition and RaspberryJuice API's can be found at [www.stuffaboutcode.com/p/minecraft-api-reference.html](http://www.stuffaboutcode.com/p/minecraft-api-reference.html). + +It was released onto [PyPI](https://pypi.org) in May 2018. + +If you want some cool additional tools for modifying Minecraft, check out [minecraft-stuff](https://minecraft-stuff.readthedocs.io/en/latest/). + +## Sources + +This library is a collection of the following sources: + ++ [Minecraft: Pi edition](https://minecraft.net/en-us/edition/pi/) ++ [Python 3 Minecraft: Pi edition library](https://github.com/py3minepi/py3minepi) + +## Licenses + ++ mcpi - [LICENSE.txt](https://github.com/martinohanlon/mcpi/blob/master/LICENSE) ++ Minecraft: Pi edition LICENSE - [minecraft-pi-edition-LICENSE.txt](https://github.com/martinohanlon/mcpi/blob/master/minecraft-pi-edition-LICENSE.txt) + diff --git a/Python/mcpi/__init__.py b/Python/mcpi/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Python/mcpi/block.py b/Python/mcpi/block.py new file mode 100644 index 0000000..52c8502 --- /dev/null +++ b/Python/mcpi/block.py @@ -0,0 +1,97 @@ +class Block: + """Minecraft PI block description. Can be sent to Minecraft.setBlock/s""" + def __init__(self, id, data=0): + self.id = id + self.data = data + + def __cmp__(self, rhs): + return hash(self) - hash(rhs) + + def __eq__(self, rhs): + return self.id == rhs.id and self.data == rhs.data + + def __hash__(self): + return (self.id << 8) + self.data + + def withData(self, data): + return Block(self.id, data) + + def __iter__(self): + """Allows a Block to be sent whenever id [and data] is needed""" + return iter((self.id, self.data)) + + def __repr__(self): + return "Block(%d, %d)"%(self.id, self.data) + +AIR = Block(0) +STONE = Block(1) +GRASS = Block(2) +DIRT = Block(3) +COBBLESTONE = Block(4) +WOOD_PLANKS = Block(5) +SAPLING = Block(6) +BEDROCK = Block(7) +WATER_FLOWING = Block(8) +WATER = WATER_FLOWING +WATER_STATIONARY = Block(9) +LAVA_FLOWING = Block(10) +LAVA = LAVA_FLOWING +LAVA_STATIONARY = Block(11) +SAND = Block(12) +GRAVEL = Block(13) +GOLD_ORE = Block(14) +IRON_ORE = Block(15) +COAL_ORE = Block(16) +WOOD = Block(17) +LEAVES = Block(18) +GLASS = Block(20) +LAPIS_LAZULI_ORE = Block(21) +LAPIS_LAZULI_BLOCK = Block(22) +SANDSTONE = Block(24) +BED = Block(26) +COBWEB = Block(30) +GRASS_TALL = Block(31) +WOOL = Block(35) +FLOWER_YELLOW = Block(37) +FLOWER_CYAN = Block(38) +MUSHROOM_BROWN = Block(39) +MUSHROOM_RED = Block(40) +GOLD_BLOCK = Block(41) +IRON_BLOCK = Block(42) +STONE_SLAB_DOUBLE = Block(43) +STONE_SLAB = Block(44) +BRICK_BLOCK = Block(45) +TNT = Block(46) +BOOKSHELF = Block(47) +MOSS_STONE = Block(48) +OBSIDIAN = Block(49) +TORCH = Block(50) +FIRE = Block(51) +STAIRS_WOOD = Block(53) +CHEST = Block(54) +DIAMOND_ORE = Block(56) +DIAMOND_BLOCK = Block(57) +CRAFTING_TABLE = Block(58) +FARMLAND = Block(60) +FURNACE_INACTIVE = Block(61) +FURNACE_ACTIVE = Block(62) +DOOR_WOOD = Block(64) +LADDER = Block(65) +STAIRS_COBBLESTONE = Block(67) +DOOR_IRON = Block(71) +REDSTONE_ORE = Block(73) +SNOW = Block(78) +ICE = Block(79) +SNOW_BLOCK = Block(80) +CACTUS = Block(81) +CLAY = Block(82) +SUGAR_CANE = Block(83) +FENCE = Block(85) +GLOWSTONE_BLOCK = Block(89) +BEDROCK_INVISIBLE = Block(95) +STONE_BRICK = Block(98) +GLASS_PANE = Block(102) +MELON = Block(103) +FENCE_GATE = Block(107) +GLOWING_OBSIDIAN = Block(246) +NETHER_REACTOR_CORE = Block(247) diff --git a/Python/mcpi/connection.py b/Python/mcpi/connection.py new file mode 100644 index 0000000..ab078e8 --- /dev/null +++ b/Python/mcpi/connection.py @@ -0,0 +1,63 @@ +import socket +import select +import sys +from .util import flatten_parameters_to_bytestring + +""" @author: Aron Nieminen, Mojang AB""" + +class RequestError(Exception): + pass + +class Connection: + """Connection to a Minecraft Pi game""" + RequestFailed = "Fail" + + def __init__(self, address, port): + self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.socket.connect((address, port)) + self.lastSent = "" + + def drain(self): + """Drains the socket of incoming data""" + while True: + readable, _, _ = select.select([self.socket], [], [], 0.0) + if not readable: + break + data = self.socket.recv(1500) + e = "Drained Data: <%s>\n"%data.strip() + e += "Last Message: <%s>\n"%self.lastSent.strip() + sys.stderr.write(e) + + def send(self, f, *data): + """ + Sends data. Note that a trailing newline '\n' is added here + + The protocol uses CP437 encoding - https://en.wikipedia.org/wiki/Code_page_437 + which is mildly distressing as it can't encode all of Unicode. + """ + + s = b"".join([f, b"(", flatten_parameters_to_bytestring(data), b")", b"\n"]) + + self._send(s) + + def _send(self, s): + """ + The actual socket interaction from self.send, extracted for easier mocking + and testing + """ + self.drain() + self.lastSent = s + + self.socket.sendall(s) + + def receive(self): + """Receives data. Note that the trailing newline '\n' is trimmed""" + s = self.socket.makefile("r").readline().rstrip("\n") + if s == Connection.RequestFailed: + raise RequestError("%s failed"%self.lastSent.strip()) + return s + + def sendReceive(self, *data): + """Sends and receive data""" + self.send(*data) + return self.receive() diff --git a/Python/mcpi/event.py b/Python/mcpi/event.py new file mode 100644 index 0000000..ccf023b --- /dev/null +++ b/Python/mcpi/event.py @@ -0,0 +1,45 @@ +from .vec3 import Vec3 + +class BlockEvent: + """An Event related to blocks (e.g. placed, removed, hit)""" + HIT = 0 + + def __init__(self, type, x, y, z, face, entityId): + self.type = type + self.pos = Vec3(x, y, z) + self.face = face + self.entityId = entityId + + def __repr__(self): + sType = { + BlockEvent.HIT: "BlockEvent.HIT" + }.get(self.type, "???") + + return "BlockEvent(%s, %d, %d, %d, %d, %d)"%( + sType,self.pos.x,self.pos.y,self.pos.z,self.face,self.entityId); + + @staticmethod + def Hit(x, y, z, face, entityId): + return BlockEvent(BlockEvent.HIT, x, y, z, face, entityId) + +class ChatEvent: + """An Event related to chat (e.g. posts)""" + POST = 0 + + def __init__(self, type, entityId, message): + self.type = type + self.entityId = entityId + self.message = message + + def __repr__(self): + sType = { + ChatEvent.POST: "ChatEvent.POST" + }.get(self.type, "???") + + return "ChatEvent(%s, %d, %s)"%( + sType,self.entityId,self.message); + + @staticmethod + def Post(entityId, message): + return ChatEvent(ChatEvent.POST, entityId, message) + diff --git a/Python/mcpi/minecraft-pi-edition-LICENSE.txt b/Python/mcpi/minecraft-pi-edition-LICENSE.txt new file mode 100644 index 0000000..80e8128 --- /dev/null +++ b/Python/mcpi/minecraft-pi-edition-LICENSE.txt @@ -0,0 +1,6 @@ +*** The real license isn't finished yet, here's what goes in plain english *** + +You may execute the minecraft-pi binary on a Raspberry Pi or an emulator +You may use any of the source code included in the distribution for any purpose (except evil) + +You may not redistribute any modified binary parts of the distribution diff --git a/Python/mcpi/minecraft.py b/Python/mcpi/minecraft.py new file mode 100644 index 0000000..ad52c59 --- /dev/null +++ b/Python/mcpi/minecraft.py @@ -0,0 +1,210 @@ +from .connection import Connection +from .vec3 import Vec3 +from .event import BlockEvent, ChatEvent +from .block import Block +import math +from .util import flatten + +""" Minecraft PI low level api v0.1_1 + + Note: many methods have the parameter *arg. This solution makes it + simple to allow different types, and variable number of arguments. + The actual magic is a mix of flatten_parameters() and __iter__. Example: + A Cube class could implement __iter__ to work in Minecraft.setBlocks(c, id). + + (Because of this, it's possible to "erase" arguments. CmdPlayer removes + entityId, by injecting [] that flattens to nothing) + + @author: Aron Nieminen, Mojang AB""" + +""" Updated to include functionality provided by RaspberryJuice: +- getBlocks() +- getDirection() +- getPitch() +- getRotation() +- getPlayerEntityId() +- pollChatPosts() """ + +def intFloor(*args): + return [int(math.floor(x)) for x in flatten(args)] + +class CmdPositioner: + """Methods for setting and getting positions""" + def __init__(self, connection, packagePrefix): + self.conn = connection + self.pkg = packagePrefix + + def getPos(self, id): + """Get entity position (entityId:int) => Vec3""" + s = self.conn.sendReceive(self.pkg + b".getPos", id) + return Vec3(*list(map(float, s.split(",")))) + + def setPos(self, id, *args): + """Set entity position (entityId:int, x,y,z)""" + self.conn.send(self.pkg + b".setPos", id, args) + + def getTilePos(self, id): + """Get entity tile position (entityId:int) => Vec3""" + s = self.conn.sendReceive(self.pkg + b".getTile", id) + return Vec3(*list(map(int, s.split(",")))) + + def setTilePos(self, id, *args): + """Set entity tile position (entityId:int) => Vec3""" + self.conn.send(self.pkg + b".setTile", id, intFloor(*args)) + + def getDirection(self, id): + """Get entity direction (entityId:int) => Vec3""" + s = self.conn.sendReceive(self.pkg + b".getDirection", id) + return Vec3(*map(float, s.split(","))) + + def getRotation(self, id): + """get entity rotation (entityId:int) => float""" + return float(self.conn.sendReceive(self.pkg + b".getRotation", id)) + + def getPitch(self, id): + """get entity pitch (entityId:int) => float""" + return float(self.conn.sendReceive(self.pkg + b".getPitch", id)) + + def setting(self, setting, status): + """Set a player setting (setting, status). keys: autojump""" + self.conn.send(self.pkg + b".setting", setting, 1 if bool(status) else 0) + + +class CmdEntity(CmdPositioner): + """Methods for entities""" + def __init__(self, connection): + CmdPositioner.__init__(self, connection, b"entity") + + +class CmdPlayer(CmdPositioner): + """Methods for the host (Raspberry Pi) player""" + def __init__(self, connection): + CmdPositioner.__init__(self, connection, b"player") + self.conn = connection + + def getPos(self): + return CmdPositioner.getPos(self, []) + def setPos(self, *args): + return CmdPositioner.setPos(self, [], args) + def getTilePos(self): + return CmdPositioner.getTilePos(self, []) + def setTilePos(self, *args): + return CmdPositioner.setTilePos(self, [], args) + def getDirection(self): + return CmdPositioner.getDirection(self, []) + def getRotation(self): + return CmdPositioner.getRotation(self, []) + def getPitch(self): + return CmdPositioner.getPitch(self, []) + +class CmdCamera: + def __init__(self, connection): + self.conn = connection + + def setNormal(self, *args): + """Set camera mode to normal Minecraft view ([entityId])""" + self.conn.send(b"camera.mode.setNormal", args) + + def setFixed(self): + """Set camera mode to fixed view""" + self.conn.send(b"camera.mode.setFixed") + + def setFollow(self, *args): + """Set camera mode to follow an entity ([entityId])""" + self.conn.send(b"camera.mode.setFollow", args) + + def setPos(self, *args): + """Set camera entity position (x,y,z)""" + self.conn.send(b"camera.setPos", args) + + +class CmdEvents: + """Events""" + def __init__(self, connection): + self.conn = connection + + def clearAll(self): + """Clear all old events""" + self.conn.send(b"events.clear") + + def pollBlockHits(self): + """Only triggered by sword => [BlockEvent]""" + s = self.conn.sendReceive(b"events.block.hits") + events = [e for e in s.split("|") if e] + return [BlockEvent.Hit(*list(map(int, e.split(",")))) for e in events] + + def pollChatPosts(self): + """Triggered by posts to chat => [ChatEvent]""" + s = self.conn.sendReceive(b"events.chat.posts") + events = [e for e in s.split("|") if e] + return [ChatEvent.Post(int(e[:e.find(",")]), e[e.find(",") + 1:]) for e in events] + +class Minecraft: + """The main class to interact with a running instance of Minecraft Pi.""" + def __init__(self, connection): + self.conn = connection + + self.camera = CmdCamera(connection) + self.entity = CmdEntity(connection) + self.player = CmdPlayer(connection) + self.events = CmdEvents(connection) + + def getBlock(self, *args): + """Get block (x,y,z) => id:int""" + return int(self.conn.sendReceive(b"world.getBlock", intFloor(args))) + + def getBlockWithData(self, *args): + """Get block with data (x,y,z) => Block""" + ans = self.conn.sendReceive(b"world.getBlockWithData", intFloor(args)) + return Block(*list(map(int, ans.split(",")))) + + def getBlocks(self, *args): + """Get a cuboid of blocks (x0,y0,z0,x1,y1,z1) => [id:int]""" + s = self.conn.sendReceive(b"world.getBlocks", intFloor(args)) + return map(int, s.split(",")) + + def setBlock(self, *args): + """Set block (x,y,z,id,[data])""" + self.conn.send(b"world.setBlock", intFloor(args)) + + def setBlocks(self, *args): + """Set a cuboid of blocks (x0,y0,z0,x1,y1,z1,id,[data])""" + self.conn.send(b"world.setBlocks", intFloor(args)) + + def getHeight(self, *args): + """Get the height of the world (x,z) => int""" + return int(self.conn.sendReceive(b"world.getHeight", intFloor(args))) + + def getPlayerEntityIds(self): + """Get the entity ids of the connected players => [id:int]""" + ids = self.conn.sendReceive(b"world.getPlayerIds") + return list(map(int, ids.split("|"))) + + def getPlayerEntityId(self, name): + """Get the entity id of the named player => [id:int]""" + return int(self.conn.sendReceive(b"world.getPlayerId", name)) + + def saveCheckpoint(self): + """Save a checkpoint that can be used for restoring the world""" + self.conn.send(b"world.checkpoint.save") + + def restoreCheckpoint(self): + """Restore the world state to the checkpoint""" + self.conn.send(b"world.checkpoint.restore") + + def postToChat(self, msg): + """Post a message to the game chat""" + self.conn.send(b"chat.post", msg) + + def setting(self, setting, status): + """Set a world setting (setting, status). keys: world_immutable, nametags_visible""" + self.conn.send(b"world.setting", setting, 1 if bool(status) else 0) + + @staticmethod + def create(address = "localhost", port = 4711): + return Minecraft(Connection(address, port)) + + +if __name__ == "__main__": + mc = Minecraft.create() + mc.postToChat("Hello, Minecraft!") diff --git a/Python/mcpi/setup.py b/Python/mcpi/setup.py new file mode 100644 index 0000000..3e078ef --- /dev/null +++ b/Python/mcpi/setup.py @@ -0,0 +1,36 @@ +from setuptools import setup + +__project__ = 'mcpi' +__desc__ = 'Python library for the Minecraft Pi edition and RaspberryJuice API' +__version__ = '1.1.0' +__author__ = "Martin O'Hanlon" +__author_email__ = 'martin@ohanlonweb.com' +__license__ = 'MIT' +__url__ = 'https://github.com/martinohanlon/mcpi' + +__classifiers__ = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Education", + "Intended Audience :: Developers", + "Topic :: Education", + "Topic :: Games/Entertainment", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", +] + +setup(name=__project__, + version = __version__, + description = __desc__, + url = __url__, + author = __author__, + author_email = __author_email__, + license = __license__, + packages = [__project__], + classifiers = __classifiers__, + zip_safe=False) \ No newline at end of file diff --git a/Python/mcpi/util.py b/Python/mcpi/util.py new file mode 100644 index 0000000..9791072 --- /dev/null +++ b/Python/mcpi/util.py @@ -0,0 +1,18 @@ +import collections + +def flatten(l): + for e in l: + if isinstance(e, collections.Iterable) and not isinstance(e, str): + for ee in flatten(e): yield ee + else: yield e + +def flatten_parameters_to_bytestring(l): + return b",".join(map(_misc_to_bytes, flatten(l))) + +def _misc_to_bytes(m): + """ + Convert an arbitrary object into a string encoded as a CP437 series of bytes. + + See `Connection.send` for more details. + """ + return str(m).encode("cp437") diff --git a/Python/mcpi/vec3.py b/Python/mcpi/vec3.py new file mode 100644 index 0000000..f0cd42a --- /dev/null +++ b/Python/mcpi/vec3.py @@ -0,0 +1,114 @@ +class Vec3: + def __init__(self, x=0, y=0, z=0): + self.x = x + self.y = y + self.z = z + + def __add__(self, rhs): + c = self.clone() + c += rhs + return c + + def __iadd__(self, rhs): + self.x += rhs.x + self.y += rhs.y + self.z += rhs.z + return self + + def length(self): + return self.lengthSqr() ** .5 + + def lengthSqr(self): + return self.x * self.x + self.y * self.y + self.z * self.z + + def __mul__(self, k): + c = self.clone() + c *= k + return c + + def __imul__(self, k): + self.x *= k + self.y *= k + self.z *= k + return self + + def clone(self): + return Vec3(self.x, self.y, self.z) + + def __neg__(self): + return Vec3(-self.x, -self.y, -self.z) + + def __sub__(self, rhs): + return self.__add__(-rhs) + + def __isub__(self, rhs): + return self.__iadd__(-rhs) + + def __repr__(self): + return "Vec3(%s,%s,%s)"%(self.x,self.y,self.z) + + def __iter__(self): + return iter((self.x, self.y, self.z)) + + def _map(self, func): + self.x = func(self.x) + self.y = func(self.y) + self.z = func(self.z) + + def __cmp__(self, rhs): + dx = self.x - rhs.x + if dx != 0: return dx + dy = self.y - rhs.y + if dy != 0: return dy + dz = self.z - rhs.z + if dz != 0: return dz + return 0 + + def __eq__(self, rhs): + if self.x == rhs.x and self.y == rhs.y and self.z == rhs.z: + return True + + return False + + def iround(self): self._map(lambda v:int(v+0.5)) + def ifloor(self): self._map(int) + + def rotateLeft(self): self.x, self.z = self.z, -self.x + def rotateRight(self): self.x, self.z = -self.z, self.x + +def testVec3(): + # Note: It's not testing everything + + # 1.1 Test initialization + it = Vec3(1, -2, 3) + assert it.x == 1 + assert it.y == -2 + assert it.z == 3 + + assert it.x != -1 + assert it.y != +2 + assert it.z != -3 + + # 2.1 Test cloning and equality + clone = it.clone() + assert it == clone + it.x += 1 + assert it != clone + + # 3.1 Arithmetic + a = Vec3(10, -3, 4) + b = Vec3(-7, 1, 2) + c = a + b + assert c - a == b + assert c - b == a + assert a + a == a * 2 + + assert a - a == Vec3(0,0,0) + assert a + (-a) == Vec3(0,0,0) + + # Test repr + e = eval(repr(it)) + assert e == it + +if __name__ == "__main__": + testVec3() diff --git a/Python/minecrafter.py b/Python/minecrafter.py new file mode 100644 index 0000000..693fe77 --- /dev/null +++ b/Python/minecrafter.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +""" +Created on Fri Jun 14 14:16:11 2019 + +@author: savrillon +""" + +from data import WorldChunk +import math +import numpy as np +import mcpi.minecraft as minecraft +import random +import mcpi.block as block +from perlin import CavernedNoise2 + + +mc = minecraft.Minecraft.create() +mc.postToChat("Hello World !") +playerPos = mc.player.getPos() +tp = True +lights = True +chunk = (math.floor(playerPos.x/16),math.floor(playerPos.z/16)) + +noise = CavernedNoise2(456) + +size = 64 +for i in range(0,size): + for j in range(0,size): + cx,cy = chunk[0]+i,chunk[1]+j + print("Géneration de "+str(i)+","+str(j)) + mc.postToChat("Géneration de "+str(i)+","+str(j)) + if tp: + mc.player.setPos(cx*16+8,playerPos.y,cy*16+8) + data = noise.getChunk(cx,cy,(16,16)) + #print(data) + #data = np.abs(data) + x0,z0 = cx*16,cy*16 + x1,z1 = x0 + 15 , z0 + 15 + y0,y1 = 4,128-1 + h = y1-y0 + + mc.setBlocks(x0,y0,z0,x1,y1,z1,block.IRON_BLOCK) + + for dx in range(0,16): + for dz in range(0,16): + x,z = x0+dx,z0+dz + boule = True + fm1 = y0 + for f in sorted(data[dx][dz]): + if f < 0 :print(f) + mc.setBlocks(x,y0+fm1,z,x,y0+f,z,block.STONE if boule else block.AIR) + #mc.setBlock(x,y0+fm1,z,x,d,z,block.STONE if boule else block.AIR) + boule = not boule + fm1 = f + mc.setBlocks(x,y0+fm1,z,x,y1,z,block.AIR) + + +if(lights): + for _ in range(256*size**2): + x=random.randint(0,size*16)+chunk[0]*16 + y=random.randint(y0,y1) + x=random.randint(0,size*16)+chunk[1]*16 + if(mc.getBlock(x,y,z)==block.STONE.id): + mc.setBlock(x,y,z,block.GLOWSTONE_BLOCK) + + + +print(chunk) + diff --git a/Python/objection.py b/Python/objection.py new file mode 100644 index 0000000..d480f1b --- /dev/null +++ b/Python/objection.py @@ -0,0 +1,374 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Aug 22 19:46:36 2019 + +@author: mysaa +""" +import numpy as np +from data import CollageWorldChunk +from perlin import CavernedNoise2,TestNoise + + + +def getTriangles(x0,y0,chunk,xp,yp,xy): + + + nx,ny = chunk.size + newChunk = CollageWorldChunk(chunk,xp,yp,xy) + +# pointIndexes = np.zeros((nx+1,ny+1),dtype=np.uint32) +# pointLengthes = np.zeros((nx+1,ny+1),dtype=np.uint32) +# points = [] +# +# +# pos = 0 +# for j in range(ny): +# for i in range(nx): +# carotte = [(x0+i/nx,y0+j/ny,z) for z in sorted([0.]+list(chunk.getColumn(i,j)))] +# points += carotte +# pointLengthes[i,j] = len(carotte) +# pointIndexes[i,j] = pos +# pos+=len(carotte) +# carotte = [(x0+1,y0+j/ny,z) for z in sorted([0.]+list(xp.getColumn(0,j)))] +# points += carotte +# pointLengthes[nx,j]= len(carotte) +# pointIndexes[nx,j] = pos +# pos+=len(carotte) +# for i in range(nx): +# carotte = [(x0+i/nx,y0+1,z) for z in sorted([0.]+list(yp.getColumn(i,0)))] +# points += carotte +# pointLengthes[i,ny] = len(carotte) +# pointIndexes[i,ny] = pos +# pos+=len(carotte) +# carotte = [(x0+1,y0+1,z) for z in sorted([0.]+list(xy.getColumn(0,0)))] +# points += carotte +# pointLengthes[nx,ny] = len(carotte) +# pointIndexes[nx,ny] = pos + + + + points,pointIndexes = newChunk.getIndexed(fullCoords=True,addZero=True) + + points=[(p[0]/nx+x0,p[1]/ny+y0,p[2]) for p in points] + pointLengthes = np.reshape([pointIndexes[i+1]-pointIndexes[i] for i in range(len(pointIndexes)-1)],(nx+1,ny+1)) + pointIndexes = np.reshape(pointIndexes[:-1],(nx+1,ny+1)) + print(points,pointIndexes,pointLengthes) + + + + + + + triangles = [] + + + for x in range(nx*2): + for y in range(ny): + # On récupère les coordonées entières du triangle indicé (x,y) + if(x%2==0): + col0=(x//2 ,y ) + col1=(x//2+1,y ) + col2=(x//2 ,y+1) + else: + col0=(x//2+1,y+1) + col1=(x//2+1,y ) + col2=(x//2 ,y+1) + + # On récupère la liste des points dans la colonne + colonne0 = points[pointIndexes[col0[0],col0[1]]:pointIndexes[col0[0],col0[1]]+pointLengthes[col0[0],col0[1]]] + colonne1 = points[pointIndexes[col1[0],col1[1]]:pointIndexes[col1[0],col1[1]]+pointLengthes[col1[0],col1[1]]] + colonne2 = points[pointIndexes[col2[0],col2[1]]:pointIndexes[col2[0],col2[1]]+pointLengthes[col2[0],col2[1]]] + #print("colonne:",colonne1) + # st contient des triplets (numéro de colonne,index interne dans la colonne,coordonée z) + st = [(0,i,colonne0[i][2]) for i in range(len(colonne0))] + st += [(1,i,colonne1[i][2]) for i in range(len(colonne1))] + st += [(2,i,colonne2[i][2]) for i in range(len(colonne2))] + + + # On y trie par coordonée z + st = sorted(st,key=lambda c:c[2]) + + #Liste des coordonées des colonnes, pour pouvoir sélectionner les coordonées selon l'index de la colonne + cols = [col0,col1,col2] + # Là, tout est bon à peu près + + i=0 + try: + while ivide + voff[v3[0]] = v3 + else: + # Changement vide->plein + von[v3[0]] = v3 + voff[v3[0]] = None + if not None in von and not None in voff: + # Les deux colonnes ont disparu + # On peut créer le rectangle entre les deux derniers à avoir disparu et leur point d'apparitions + v3,v4 = st[i],st[i-1] + v1,v2 = von[v3[0]],von[v4[0]] + triangle1 = [pointIndexes[cols[v[0]]] + v[1] for v in (v1,v2,v3)] + triangle2 = [pointIndexes[cols[v[0]]] + v[1] for v in (v1,v3,v4)] + triangles.append(triangle1) + triangles.append(triangle2) + break + + else: + # On est dans le cas ou v1,v2,v3 correspondent à trois colonnes + # différentes (le cas (1,1,1) ayant déjà été filtré par la première condition) + + # On ajoute le triangle en dessous + triangle = [pointIndexes[cols[v[0]]] + v[1] for v in (v1,v2,v3)] + triangles.append(triangle) + + # On "attends" jusqu'à ce que les trois colonnes soient à nouveau vides + vs = [None,None,None] + while None in vs: + print("Quentin",st,i,vs) + v = st[i] ; i+=1 + vs[v[0]] = v if vs[v[0]]==None else None + + # Avec cette mthode, on déssine le triangle avec les derniers points étant apparus (les plus hauts) + triangle = [pointIndexes[cols[v[0]]] + v[1] for v in vs] + triangles.append(triangle) + + continue + + + + + except ValueError: + # Une fin de liste a été atteinte, la colonne n'a pas été refermée: lance un warn + print("Attention ! Une colonne n'avait pas de toit. veuillez vérifier que vos colonnes aient un nombre impair de coordonées, merci !") + + return points,triangles + ######################################## +# while iF else 1 + (2*n**2+6*n+4)/(F**(2*n+4)) * ((x**2)/(2*n+4)-(F**2)/(2*n+2))*abs(x)**(2*n+2) + + + def __init__(self,F,D,epsilon,droiteMaker,n = 1): + self.F = F + self.D = D + self.epsilon = epsilon + if type(droiteMaker) == int: + droiteMaker = DroiteNoise(droiteMaker,F,D) + self.droiteMaker = droiteMaker + self.interpol = FractalNoise.interpolizer(n,F) + + def getChunk(self,x,y,n): + drts = self.droiteMaker.getChunk(x,y) + chunk = np.zeros(n) + epsilon = self.epsilon + interpol = self.interpol + + def dst(x0,x1,y0,y1): + return sqrt( (x1-x0)**2 + (y1-y0)**2 ) + + def kelkote(drt,x,y): + dx = drt[0] + dy = drt[1] + #print(x,y,dx,dy) + return 1 if (np.exp(1j*(drt[2]+pi/2)) * ((x-dx)+(dy-y)*1j)).real >= 0 else -1 + + # FractalNoise(0.7,511,0.01,42).getChunk(3,3,(16,16)) + #33.8 s ± 72.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) + for d in drts: + drteffect = lambda i,j : interpol(dst(d[0],i/n[0] + x,d[1],j/n[1] + y))*kelkote(d,i/n[0] + x,j/n[1] + y)*epsilon + chunk += np.fromfunction(np.vectorize(drteffect),n) + + # FractalNoise(0.7,511,0.01,42).getChunk(3,3,(16,16)) + #28.9 s ± 344 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) +# for i in range(n[0]): +# for j in range(n[1]): +# posx = i/n[0] + x +# posy = j/n[1] + y +# value = 0 +## print(i,j) +# for d in drts: +# value += interpol(dst(d[0],posx,d[1],posy))*kelkote(d,posx,posy)*epsilon +# chunk[i,j] = value + return chunk + + +class TestNoise(Noise): + + nn = PerlinNoise + + def getChunk(self,x,y,n): + + indexes = np.array([i for i in range(n[0]*n[1]+1)]) + data = np.ones((n[0]*n[1])) + return WorldChunk(n,indexes,data) + + + + +class CavernedNoise(Noise): + + perlinSurface = None + perlinGrotte = None + perlinFond = None + + def __init__(self): + self.perlinSurface = PerlinNoise(.5,64) + self.perlinGrotte = PerlinNoise(7 ,77) + self.perlinFond = PerlinNoise(.3 ,23) + + + def getChunk(self,x,y,n): + chk = self.perlinSurface.getChunk(x,y,n) + fond = self.perlinFond.getChunk(x,y,n) + grotte=self.perlinGrotte.getChunk(x,y,n) + + out = [] + + for i in range(n[0]): + lig = [] + for j in range(n[1]): + if(grotte[i,j]>.2): # Pas de grotte + lig.append([chk[i,j]]) + elif(grotte[i,j]>0): + lig.append([fond[i,j]]) + else: + lig.append([fond[i,j],chk[i,j]-0.1*abs(grotte[i,j]),chk[i,j]]) + out.append(lig) + + return out + + +class CavernedNoise2(Noise): + + perlinCielH = None + perlinGHaut = None + perlinGH = None + perlinGHp = None + perlinGBas = None + + #-x^(4)+4x^(3)-6x^(2)+4x + + def __init__(self,seed): + self.perlinCielH = PerlinNoise(7 ,seed) + self.perlinGHaut = PerlinNoise(5 ,seed) + self.perlinGH = PerlinNoise(25 ,seed) + self.perlinGHp = PerlinNoise(1 ,seed) + self.perlinGBas = PerlinNoise(5 ,seed) + + + def getChunk(self,x,y,n): + gtTransform = np.vectorize(lambda x : 0 if x<0 else sqrt(2*x-x**2)**1.5) + transform=lambda M,a,b : M*b+a + cielH = transform(self.perlinCielH.getChunk(x,y,n),28,28) + gHaut = transform(self.perlinGHaut.getChunk(x,y,n),60,20) + ghp = transform(self.perlinGHp.getChunk(x,y,n) ,0.005,0.005) + ghh = transform(self.perlinGHp.getChunk(x,y,n) ,0.5,0.5) + gBas = transform(self.perlinGBas.getChunk(x,y,n),10,10) + gh = gtTransform(ghp+ghh) + + toit = 128 + + out = [] + + + + for i in range(n[0]): + lig = [] + for j in range(n[1]): + ch = cielH[i,j] # la hauteur entre la surface et le ciel + ght = gHaut[i,j] # haut limite de la grotte + gbs = gBas[i,j] # bas limite de la grotte + hauteur=gh[i,j] # pourcentage de hauteur de la grotte + grh = (ght+gbs +hauteur*(ght-gbs))/2 # vrai plafond de la grotte + grb = (ght+gbs -hauteur*(ght-gbs))/2 # vrai sol de la grotte + if(ght<=40):print(ght) + if hauteur==0: + # Pas de grotte + lig.append([toit-ch]) + elif(grh+ch>=toit): + # La grotte est ouverte sur la surface + lig.append([grb]) + else: + # Grotte souterraine et surface + lig.append([grb,grh,toit-ch]) + + out.append(lig) + + return ArrayedWorldChunk.fromList(out) + + + +#for c in cmaps: +# pp.figure() +# print(c) +# pp.imshow(I, cmap=c) + + + + +#sys.exit() +####### Fenêtre graphique ####### +#from PyQt5.QtWidgets import QVBoxLayout,QHBoxLayout,QPushButton,QWidget,QApplication,QFormLayout,QLabel,QTextEdit,QDial +# +#app = QApplication([]) +# +#class ExplorerWidget(QWidget): +# +# def __init__(): +# print('wow') +# +##### Control Panel #### +#seedSelector = QTextEdit() +#ndroitesSelector = QDial() +# +#cPanel = QFormLayout() +#cPanel.addWidget(QLabel("Seed : ")) +#cPanel.addWidget(seedSelector) +#cPanel.addWidget(QLabel("Nombre de droites :")) +#cPanel.addWidget(ndroitesSelector) +# +#globalL = QHBoxLayout() +#globalL.addStretch(1) +#globalL.addLayout(cPanel) +# +#window = QWidget() +#window.setLayout(globalL) +#window.show() +# +#app.exec_() + +# +#(x0,x1,y0,y1) = (0,4,0,4) +#n = 100 +# +# +#x = np.linspace(x0,x1,n) +#y = np.linspace(y0,y1,n) +#x00 = int(x0)-1 +#y00 = int(y0)-1 +#x11 = int(x1)+1 +#y11 = int(y1)+1 +#gradient = np.exp(np.random.rand(x11-x00+1,y11-y00+1)*2*np.pi*1j) +#X,Y = np.meshgrid(x,y) +##print(gradient) +# +#def lerp(a0, a1, w): +# return a0 + (a1-a0)*(-2*w*w*w+3*w*w) +# +#def dotGridGradient(ix, iy, x, y): +# dx = x - ix +# dy = y - iy +# return (np.conj(gradient[iy-y00][ix-x00])*(dx+1j*dy)).real +# +#def bruit(x,y): +# (x0,y0) = (int(x),int(y)) +# (x1,y1) = (x0+1,y0+1) +# +# sx = x - x0; +# sy = y - y0; +# +# n0 = dotGridGradient(x0, y0, x, y); +# n1 = dotGridGradient(x1, y0, x, y); +# ix0 = lerp(n0, n1, sx); +# n0 = dotGridGradient(x0, y1, x, y); +# n1 = dotGridGradient(x1, y1, x, y); +# ix1 = lerp(n0, n1, sx); +# return lerp(ix0, ix1, sy); +# +# +# +#Z = np.zeros((n,n)) +#for i in range(n): +# for j in range(n): +# Z[i,j] = bruit(x[i],y[j]) +# +#pp.imshow(Z,cmap='autumn') +# +#fig = pp.figure() +#ax = pp.axes(projection='3d') +# +#ax.view_init(80, 42) +#ax.plot_surface(X,Y,Z, rstride=1, cstride=1, +# cmap='autumn', edgecolor='none') + + + + + diff --git a/Python/recImage.png b/Python/recImage.png new file mode 100644 index 0000000..ae28fe0 Binary files /dev/null and b/Python/recImage.png differ diff --git a/Python/sanstitre0.py b/Python/sanstitre0.py new file mode 100644 index 0000000..6cf6232 --- /dev/null +++ b/Python/sanstitre0.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Nov 21 11:49:30 2019 + +@author: savrillon +""" + +from perlin import PerlinNoise +import numpy as np + +graine = 42 +zoom=0.2 +pos = np.random.randint(0,0xFFFFFFF,(2,)) +taille=(100,100) +P = PerlinNoise(zoom,graine) +chunk = P.getChunk(pos[0],pos[1],taille) + +chunk -= (chunk<0)*chunk +chunk *= 1000 +chunk = chunk.astype(int) + +print(chunk) + diff --git a/Python/testPerlin.py b/Python/testPerlin.py new file mode 100644 index 0000000..c3942ec --- /dev/null +++ b/Python/testPerlin.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Aug 29 23:53:47 2019 + +@author: mysaa +""" + +import numpy as np +import matplotlib.pyplot as pp +import random as rnd +import perlin + + +N = 42 +values = [] +pp.xlabel('valeur') +pp.ylabel('compte') +pp.title('Valeur du bruit de perlin') + +#tt = np.vectorize(lambda x : x//0.01) + +noise = perlin.PerlinNoise(2.3,42)#,wrapper = lambda x : np.tanh(x*3.8622)) +while True: + #print("\r{}".format(i), end='\r') + for _ in range(N): + chunk = noise.getChunk(rnd.randint(0,167342),rnd.randint(0,941132),(16,16)) + values += np.reshape(chunk, (1,256))[0].tolist() + [n,X, V]=pp.hist(values,range=(-1,1),bins=201,log=True, color = '#2aff00',edgecolor = 'black') + pp.draw() + pp.pause(0.1) + +#pp.figure() +#X = np.linspace(-1,1,2000) +#pp.plot(X,X) \ No newline at end of file diff --git a/Python/tmf.py b/Python/tmf.py new file mode 100644 index 0000000..b155480 --- /dev/null +++ b/Python/tmf.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" + Module contant les fonctions permettant de lire et écrire des fichiers dans le format TMF + + @author: mysaa +""" + + +class WorldSaver(): + + def __init__(): + regSize=0 diff --git a/Python/triImage.png b/Python/triImage.png new file mode 100644 index 0000000..3a268e5 Binary files /dev/null and b/Python/triImage.png differ diff --git a/SonarDeLInfini.pdf b/SonarDeLInfini.pdf new file mode 100644 index 0000000..b61461f Binary files /dev/null and b/SonarDeLInfini.pdf differ diff --git a/SonarDeLInfini.tex b/SonarDeLInfini.tex new file mode 100644 index 0000000..c5b162f --- /dev/null +++ b/SonarDeLInfini.tex @@ -0,0 +1,91 @@ +\documentclass[10pt,a4paper]{article} + +\usepackage[margin=2.5cm]{geometry} +\usepackage[francais]{babel} +\usepackage{lmodern} +\usepackage[latin1]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{amsmath} +\usepackage{amsfonts} +\usepackage{amssymb} +\usepackage{graphicx} + + +\author{Mysaa (Samy AVRILLON)} +\title{Le sonar de l'infini} +\begin{document} + + \maketitle + + \tableofcontents + + \newpage + + + \part{Problèmatique} + + L'objectif de ce TIPE est de générer des fonds marins aléatoires, réalistes ou au moins 'utiles'. Les applications possibles seraient, par exemple + \begin{itemize} + \item La générations de photographies de synthèse de paysages aléatoires, dans le cinéma par exemple. Les paramètres seront ainsi déterminés de manière à créer les paysages les plus réaliste possible, ou modifiés pour servir un message artistique (par exemple, demander un sol plus imparfait). + + \item De la génération procédurale dans des jeux vidéos. L'exemple le plus pertinent est le jeu vidéo \textit{Minecraft}, où le joueur évolue dans un monde généré aléatoirement grâce à une graine (\textit{seed} en anglais) de manière déterministe (deux mondes générés avec une même graine seront rigoureusement identiques). De plus, le moteur de génération est géré de manière à ce que l'on puisse lui demander de générer une zone 'loin' sans qu'il n'ait à générer toutes les zones à partir de l'origine. Enfin, la carte générée est potentiellement infinie (limité bien sur par la taille de stockage allouée aux entiers et aux flottants). + + \item De la génération de fonds pour des tests en simulation d'IA de robot sous-marin (voir projet de Quentin SOUVIGNET) ou pour tester des simulations de tsunami. + \end{itemize} + + De ces possibles application, je tire un \og Cahier des charges \fg de mon générateur : + + \begin{itemize} + \item Laisser accès au plus de paramètres possible, pour une meilleure personnalisation. + + \item Permettre une génération procédurale, déterministe et non liée à l'origine. + + \item Limiter la complexité en temps du programme, éventuellement la complexité spatiale. + \end{itemize} + + \part{Génération} + + Je vais présenter dans cette partie les différents algorithmes implémentés, leurs applications possibles, leurs caractéristiques. + + \section{Bruit de Perlin} + + Il s'agit d'un bruit très flou (voir Figure \ref{perlinExample}). Il peut être utilisé pour la génération d'une carte grande échelle, indiquant les variations globales du terrain. + \begin{figure}[h] + \centering + \includegraphics[height = 8cm]{"perlin"} + \caption{Exemple de génération d'un bruit de Perlin sur une zone de 5x5} + \label{perlinExample} + \end{figure} + Je vais maintenant donner une description simplifiée de fonctionnement de l'algorithme : Il génère d'abord une carte de gradients 2D de norme unitaire de direction et sens aléatoires (vecteurs du cercle trigonométrique), positionnés en chaque noeud entier. Ensuite, il \og lance une nappe \fg qui va prendre une forme imposée par les gradients. L'algorithme met en jeu une fonction d'interpolation pour déterminer les valeurs hors des noeuds, ce qui peut être un paramètre sur lequel agir. + + L'avantages de cet algorithme est sa rapidité et sa faible complexité spatiale. + + \section{Bruit fractal} + + Cet algorithme génère des droites de manière aléatoires, ce qui sépare pour chaque droite le plan en deux, et surélève l'un des deux cotés. Ce bruit est beaucoup plus \og granuleux \fg que le brut de perlin, et semble par conséquent plus réaliste. Le problème est que cette méthode est incompatible avec l'infinité de la map. On ne peux en effet pas charger l'infinité des droites du plan pour générer un carré (une célèbre équation annonce que $ \forall x \in \mathbb{R} \;,\; x < +\infty$). J'ai donc modifié l'algorithme en restreignant l'action des droites progressivement (grâce à une fonction d'interpolation, paramétrable elle aussi) Voir Figure \ref{fractExample} pour deux exemples avec plus ou moins de droites par region. L'inconvenient de cette methode est qu'elle devient vite coûteuse lorsque l'on augmente le nombre de droites. + + \begin{figure}[h] + \centering + \includegraphics[height = 7cm]{"bfractal"} + \includegraphics[height = 7cm]{"hfractal"} + \caption{Bruit fractal avec peu à gauche et beaucoup à droite de droites par chunk} + \label{fractExample} + \end{figure} + + \part{Définition des paramètres et de presets} + + A faire ... + + \part{Ouverture} + + Je vais ici lister différents extensions pouvant être apportées à l'étude, si le sujet devient complètement traité. + + \begin{itemize} + \item Créer un moteur de générations d'images des fonds marins générés précédemment, notamment avec la technique du ray-tracing. + \item Textures de l'eau aléatoires, des coraux aléatoires, avec une texture ayant l'air organique ... + \item Créer un moteur physique simplifié permettant à un joueur virtuel de se déplacer dans l'océan virtuel. Déterminer le meilleur rapport coût algorithmique/réalisme + \end{itemize} + + + +\end{document} \ No newline at end of file diff --git a/bfractal.png b/bfractal.png new file mode 100644 index 0000000..00390dd Binary files /dev/null and b/bfractal.png differ diff --git a/hfractal.png b/hfractal.png new file mode 100644 index 0000000..3017373 Binary files /dev/null and b/hfractal.png differ diff --git a/perlin.png b/perlin.png new file mode 100644 index 0000000..cabd303 Binary files /dev/null and b/perlin.png differ diff --git a/tipe_tests.svg b/tipe_tests.svg new file mode 100644 index 0000000..b238b04 --- /dev/null +++ b/tipe_tests.svg @@ -0,0 +1,3173 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/tipe_tests.svg.png b/tipe_tests.svg.png new file mode 100644 index 0000000..1fb157c Binary files /dev/null and b/tipe_tests.svg.png differ