Advertisement
Guest User

azdqs

a guest
Oct 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. def construit_carre(x,y,s, couleur):
  2. carre = '<rect '
  3. carre += 'x="'+str(x)+'" '
  4. carre += 'y="'+str(y)+'" '
  5. carre += 'width="'+str(s)+'" '
  6. carre += 'height="'+str(s)+'" '
  7. carre += 'style="stroke:#000000;stroke-width:4;fill:'+couleur_hexa_string(*couleur)+'"/>'
  8. return carre
  9.  
  10. def couleur_hexa_string(r,g,b):
  11. hexa = "#"
  12.  
  13. hexa_r = nombre_hexa_string(r)
  14. hexa += "0"*(2-len(hexa_r)) + hexa_r
  15.  
  16. hexa_g = nombre_hexa_string(g)
  17. hexa += "0"*(2-len(hexa_g)) + hexa_g
  18.  
  19. hexa_b = nombre_hexa_string(b)
  20. hexa += "0"*(2-len(hexa_b)) + hexa_b
  21. return hexa
  22.  
  23. def nombre_hexa_string(nombre):
  24. if nombre < 10:
  25. return str(nombre)
  26. if nombre < 16:
  27. return chr(65 + nombre - 10)
  28. i = 0
  29. while 16**(i+1) < nombre:
  30. i += 1
  31. quotient = nombre//16**i
  32. reste = nombre - 16**i*quotient
  33. return nombre_hexa_string(quotient)+nombre_hexa_string(reste)
  34.  
  35. print('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="600" height="600">')
  36. for x in range(5, 500, 15):
  37. cx = round(255 -(x/500)*255)
  38. for y in range(5, 500, 15):
  39. cy = round(255 -(y/500)*255)
  40. # if cx < cy:
  41. # print(construit_carre(x,y,10, (cx,cy,0)))
  42.  
  43. # if cy < cx:
  44. # print(construit_carre(x,y,10, (cx,cy,0)))
  45.  
  46. # if cy > cx - 150 and cx > cy - 150:
  47. # print(construit_carre(x,y,10, (cx,cy,0)))
  48. print('</svg>')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement