# -*- coding: utf-8 -*-
"""
Created on Wed Jul 22 14:40:00 2026

@author: anplo
"""

import matplotlib.pyplot as plt
import random as rd
    
#Q1-Q2

#les points aleatoires:
N = 100
for i in range(N):
    plt.plot(rd.random(),rd.random(),"xr")
    
#le carre :
plt.plot([0,0,1,1,0],[0,1,1,0,0], "b")
plt.axis("equal")
plt.show()

#%%

#Q3 Q4
x = 0; p = 0.05
while(x < 1):
    x += p
    #Lignes horizontales :
    plt.plot([0,1],[x,x], "b", linewidth = 0.5)
    
    #Lignes verticales :
    plt.plot([x,x],[0,1], "b", linewidth = 0.5)
    
plt.plot([0,0,1,1,0],[0,1,1,0,0], "b")
plt.axis("equal")
plt.show()

#%%
#Q5
x = 0; p = 0.05
while(x < 1):
    x += p
    plt.plot([1,x],[x,1], "b", linewidth = 0.5)
    plt.plot([0,x],[x,0], "b", linewidth = 0.5)
    
plt.plot([0,0,1,1,0],[0,1,1,0,0], "b")
plt.axis("equal")
plt.show()

#%%
import numpy as np

#Q6
X,Y = [],[]
N = 100
for i in range(0,N+1):
    theta = 2*np.pi*i/N
    x = np.cos( theta )
    y = np.sin(theta )
    
    X.append(x)
    Y.append(y)

plt.plot(X,Y)

#Q7
X,Y = [],[]
n = 409
for i in range(0,n):
    theta = 2*np.pi*i/n
    x = np.cos( theta )
    y = np.sin(theta )
    
    X.append(x)
    Y.append(y)
    #plt.plot(x,y,"or")
   
#Q8 (fixer j=2 et n =10)
#Q9 (choisir j quelconque et n quelconque)

j = 112
for i in range(n):
    m = (i*j)%n 
    plt.plot([X[i],X[m]], [Y[i],Y[m]], color = "blue", linewidth = 0.2)
        
plt.axis("equal")
plt.show()



#%%



import numpy as np
import matplotlib.pyplot as plt

#Q10 Je fais abcssices et ordonnées dans la même fonction
def coord(n):
    X = []; Y = []
    for k in range(n+1):
        a = 2*k*np.pi/n
        X.append( np.cos(a) )
        Y.append( np.sin(a) )
    return X,Y

#Q11
def polygone(n):
    X,Y = coord(n)
    plt.plot(X,Y, ".-", linewidth = 1)
    plt.axis("equal")
    plt.title(" n = "+str(n))
    
    #Pour améliorer l'affichage des titres :
    plt.xticks([])   
    plt.yticks([]) 
    
#Q12
plt.subplot(2,2,1); polygone(5)
plt.subplot(2,2,2); polygone(6)
plt.subplot(2,2,3); polygone(8)
plt.subplot(2,2,4); polygone(10)
plt.show()   
 #%%
 

def polygone_rot(n):
    X,Y = coord(n)
    Xr = []; Yr = []
    
    for i in range(n+1):
        Xr.append(-2*Y[i])
        Yr.append(2*X[i])
        
    plt.xticks([])  
    plt.yticks([]) 
    plt.plot(Xr,Yr)
    plt.axis("equal")

plt.subplot(2,2,1); polygone_rot(5)
plt.subplot(2,2,2); polygone_rot(6)
plt.subplot(2,2,3); polygone_rot(9)
plt.subplot(2,2,4); polygone_rot(20)
plt.show()           

#%%

#Q13
def coord_etoiles(n, trait_construc = False):
    X,Y = coord(n)
    Xr = []; Yr = []
    
    for i in range(n+1):
        a = np.pi/n
        Xr.append(3*(np.cos(a)*X[i]-np.sin(a)*Y[i]))
        Yr.append(3*(np.sin(a)*X[i]+np.cos(a)*Y[i]))
        
    X1 = insere(X,Xr); Y1 = insere(Y,Yr)
    
    plt.title(" n = "+str(n))
    return X1,Y1

#Q14.1
def insere(L1,L2):
    L = []; 
    for i in range(len(L1)):
        L.append(L1[i])
        L.append(L2[i])
    return L
    
#Q14.2 
def etoile(n):
    X,Y = coord_etoiles(n,True)
    
    plt.xticks([])  
    plt.yticks([]) 
    plt.plot(X,Y, "-")
    
    plt.axis("equal")
  
#Q14.3
plt.subplot(2,2,1); etoile(4)
plt.subplot(2,2,2); etoile(5)
plt.subplot(2,2,3); etoile(6)
plt.subplot(2,2,4); etoile(20)
plt.show() 

#%%
def liste_position_impaire(n):
    L = []
    for i in range((n+1)//2):
        if(i!= n//2):
            L.append(i)
        L.append(n//2+i)
    return L


def melange(L):
    n = len(L)
    L1 = liste_position_impaire(n)
    L_new = []
    
    for i in range(n):
        L_new.append(L[L1[i]])
    
    return L_new

print(melange([1,2,3,4,5,6,7,8,9]))
    

def etoile(n):
    X,Y = coord(n)
    X = melange(X)
    Y = melange(Y)
    plt.plot(X,Y, "x-")
    

    plt.title(" n = "+str(n))
    plt.axis("equal")
    

plt.subplot(2,2,1); etoile(5)
plt.subplot(2,2,2); etoile(6)
plt.subplot(2,2,3); etoile(9)
plt.subplot(2,2,4); etoile(20)
plt.show()   
#%%
    













