In fact post-processing. Image -> memBlock grab Pixels. -> array -> File.
Part of my project :
// Project: Hubibox
// Created: 2017-11-29
// By : Hubert BAYRE.
// Credit additionnel : FillFlood technique
// https://forum.thegamecreators.com/thread/213305
// Created: 2015-01-13
// By: Paul Harthen
//-------------------------------------------------------------------------------------------------------------------------
//
// JEU DESSIN
//
//-------------------------------------------------------------------------------------------------------------------------
#Constant DESSIN_LARGEUR_IMAGE 1600
#Constant DESSIN_HAUTEUR_IMAGE 900
#Constant DESSIN_DESSINER 1
#Constant DESSIN_REMPLIR 2
Global Dessin_modele_pixelStore as integer[ DESSIN_LARGEUR_IMAGE, DESSIN_HAUTEUR_IMAGE ]
Global Dessin_modele_pixelStoreStack as integer[ 20000 ]
Global Dessin_modele_memBlock as Integer
Global Dessin_ecran_image as Integer
Global Dessin_ecran_sprite as Integer
Global Dessin_num_modele as Integer
Global Dessin_num_fichier as Integer
Global Dessin_sprite_outils as Integer
Global Dessin_image_outils as Integer
Global Dessin_operation as Integer
Global Dessin_texte_num_modele as Integer
Global Dessin_texte_num_fichier as Integer
Global Dessin_texte_message as Integer
Global Dessin_message_timer as Integer
Global Dessin_taille_pinceau as Integer
Type DessinZoneType
Id as Integer
x as Integer
y as Integer
Largeur as Integer
Hauteur as Integer
EndType
Type Dessin_stylo_type
Rouge as Integer
Bleu as Integer
Vert as Integer
Taille as Integer
EndType
Global Dessin_Stylo as Dessin_stylo_type
Global Dessin_tableau_zones as DessinZoneType[]
Global Dessin_etat_jeu as Integer
Global Dessin_son_enregistrement as Integer
Global Dessin_son_outils as Integer
//-------------------------------------------------------------------------------------------------------------------------
//
// FONCTIONS
//
//-------------------------------------------------------------------------------------------------------------------------
Function Dessin_creer_message (Texte as String)
SetTextString (Dessin_texte_message, Texte)
Dessin_message_timer = GetMilliseconds()
EndFunction
Function Dessin_afficher_message ()
If GetMilliseconds() - Dessin_message_timer > 2000
SetTextString (Dessin_texte_message, "")
Endif
EndFunction
Function Dessin_ajouter_zone (Id as Integer, Texte as String, x as Integer, y as Integer, Largeur as Integer, Hauteur as Integer)
Local z as DessinZoneType
z.Id = Id
z.x = x
z.y = y
z.Largeur = Largeur
z.Hauteur = Hauteur
Dessin_tableau_zones.Insert (z)
Endfunction
Function Charger_jeu_dessin()
Aller_dossier_jeux ("jeu02/data/")
Local x as Integer
Local y as Integer
x = 1386
y = 0
Dessin_ajouter_zone (1,"Point1", x+016,y+010,82,52)
Dessin_ajouter_zone (2,"Point2", x+116,y+010,82,52)
Dessin_ajouter_zone (3,"Point3", x+016,y+070,82,52)
Dessin_ajouter_zone (4,"Point4", x+116,y+070,82,52)
Dessin_ajouter_zone (5,"Point5", x+016,y+130,82,52)
Dessin_ajouter_zone (6,"Point6", x+116,y+130,82,52)
Dessin_ajouter_zone (7, "Rouge", x+016,y+210,82,52)
Dessin_ajouter_zone (8, "Bleu", x+016,y+270,82,52)
Dessin_ajouter_zone (9, "Magenta", x+016,y+332,82,52)
Dessin_ajouter_zone (10, "Noir", x+016,y+396,82,52)
Dessin_ajouter_zone (11, "Vert", x+116,y+210,82,52)
Dessin_ajouter_zone (12, "Jaune", x+116,y+270,82,52)
Dessin_ajouter_zone (13, "Cyan", x+116,y+332,82,52)
Dessin_ajouter_zone (14, "Blanc", x+116,y+396,82,52)
Dessin_ajouter_zone (15, "Effacer", x+12,y+780,190,40)
Dessin_ajouter_zone (16, "Enregistrer", x+12,y+720,188,40)
Dessin_ajouter_zone (17, "Quitter", x+12,y+840,188,50)
Dessin_ajouter_zone (18, "Modele", x+48,y+564,116,48)
Dessin_ajouter_zone (19, "Modele flèche gauche", x+000,y+563,66,40)
Dessin_ajouter_zone (20, "Modele flèche droite", x+172,y+563,66,40)
Dessin_ajouter_zone (21, "Charger", x+48,y+644,116,48)
Dessin_ajouter_zone (22, "Charger flèche gauche", x+000,y+643,66,40)
Dessin_ajouter_zone (23, "Charger flèche droite", x+172,y+643,66,40)
Dessin_ajouter_zone (24, "Dessiner", x+16,y+460,82,46)
Dessin_ajouter_zone (25, "Remplir", x+116,y+460,82,46)
Dessin_stylo.Taille = 4
Dessin_stylo.Rouge = 0
Dessin_stylo.vert = 0
Dessin_stylo.Bleu = 0
Dessin_ecran_image = CreateRenderImage (DESSIN_LARGEUR_IMAGE,DESSIN_HAUTEUR_IMAGe,0,0)
Dessin_ecran_sprite = CreateSprite (Dessin_ecran_image)
SetSpritePosition (Dessin_ecran_sprite, 0,0)
SetSpriteDepth (Dessin_ecran_sprite, 3)
SetRenderToImage (Dessin_ecran_image,0)
SetClearColor(255,255,255)
ClearScreen()
SetRenderToScreen()
Dessin_image_outils = LoadImageRaw ("jeu_dessiner.png")
Dessin_sprite_outils = CreateSprite (Dessin_image_outils)
SetSpritePosition (Dessin_sprite_outils, x,y)
SetSpriteTransparency (Dessin_sprite_outils,0)
SetSpriteDepth (Dessin_sprite_outils,1)
Dessin_son_enregistrement = LoadSoundOggRaw ("enregistrer.ogg")
Dessin_son_outils = LoadSoundOggRaw ("choix.ogg")
Dessin_operation = DESSIN_DESSINER
Dessin_num_modele = 1
Dessin_num_fichier = 1
Dessin_texte_num_modele = CreateText (str(Dessin_num_modele))
SetTextFont (Dessin_texte_num_modele, Font2)
SetTextSize (Dessin_texte_num_modele, 32)
SetTextPosition (Dessin_texte_num_modele, x+140,y+580)
SetTextColor (Dessin_texte_num_modele, 255,255,0,255)
SetTextAlignment (Dessin_texte_num_modele,1)
SetTextDepth (Dessin_texte_num_modele,1)
Dessin_texte_num_fichier = CreateText (str(Dessin_num_fichier))
SetTextFont (Dessin_texte_num_fichier, Font2)
SetTextSize (Dessin_texte_num_fichier, 32)
SetTextPosition (Dessin_texte_num_fichier, x+148,y+662)
SetTextColor (Dessin_texte_num_fichier, 255,255,0,255)
SetTextAlignment (Dessin_texte_num_fichier,1)
SetTextDepth (Dessin_texte_num_fichier,1)
Dessin_texte_message = CreateText ("")
SetTextFont (Dessin_texte_message, Font2)
SetTextSize (Dessin_texte_message, 40)
SetTextPosition (Dessin_texte_message, DESSIN_LARGEUR_IMAGE / 2,10)
SetTextColor (Dessin_texte_message, 0,0,0,255)
SetTextAlignment (Dessin_texte_message,1)
SetTextDepth (Dessin_texte_message,0)
EndFunction
Function Dessin_tester_zone (x as Integer, y as Integer)
Local i as Integer
Local Id as Integer
Id = -1
For i=0 to Dessin_tableau_zones.Length
If x > Dessin_tableau_zones[i].x and x < Dessin_tableau_zones[i].x + Dessin_tableau_zones[i].Largeur
If y > Dessin_tableau_zones[i].y and y < Dessin_tableau_zones[i].y + Dessin_tableau_zones[i].Hauteur
Id = Dessin_tableau_zones[i].Id
PlaySound (Dessin_son_outils)
ExitFunction Id
EndIf
EndIf
Next
EndFunction Id
Function Dessin_enregistrer_fichier()
Local Fichier as String
Local Chemin as String
Chemin = "raw:" + GetDocumentsPath()
Chemin = Chemin + "/hubibox_dessins/"
If Dessin_num_modele <=9
Fichier = "dessin_0" + Str(Dessin_num_fichier) + ".png"
Else
Fichier = "dessin_" + Str(Dessin_num_fichier) + ".png"
Endif
Dessin_creer_message ("Le fichier '" + Fichier + "' a été enregistré.")
SaveImage (Dessin_ecran_image, Chemin + Fichier)
Playsound (Dessin_son_enregistrement)
EndFunction
Function Dessin_charger_fichier()
Local Fichier as String
Local Chemin as String
Chemin = "raw:" + GetDocumentsPath()
Chemin = Chemin + "/hubibox_dessins/"
If Dessin_num_modele <=9
Fichier = "dessin_0" + Str(Dessin_num_fichier) + ".png"
Else
Fichier = "dessin_" + Str(Dessin_num_fichier) + ".png"
Endif
If GetFileExists (Chemin + Fichier)
Dessin_ecran_image = LoadImage (Chemin + Fichier)
Playsound (Dessin_son_enregistrement)
SetSpriteImage ( Dessin_ecran_sprite, Dessin_ecran_image )
Dessin_creer_message ("Le fichier '" + Fichier + "' a été chargé.")
Else
Dessin_creer_message ("Le fichier '" + Fichier + "' n'a pas été trouvé.")
EndIf
EndFunction
Function Dessin_jouer()
Local x as Integer
Local y as Integer
Local Id as Integer
x = GetPointerX()
y = GetPointerY()
MessageInfo_afficher()
Dessin_afficher_message()
If x > 1400
If Pointeur_tester() = TRUE
Id = Dessin_tester_zone(x,y)
If Id <> -1
Select Id
Case 1
Dessin_stylo.Taille = 4
EndCase
Case 2
Dessin_stylo.Taille = 8
EndCase
Case 3
Dessin_stylo.Taille = 12
EndCase
Case 4
Dessin_stylo.Taille = 16
EndCase
Case 5
Dessin_stylo.Taille = 24
EndCase
Case 6
Dessin_stylo.Taille = 34
EndCase
Case 7
Dessin_stylo.Rouge = 255
Dessin_stylo.Vert = 0
Dessin_stylo.Bleu = 0
EndCase
Case 8
Dessin_stylo.Rouge = 0
Dessin_stylo.Vert = 0
Dessin_stylo.Bleu = 255
EndCase
Case 9
Dessin_stylo.Rouge = 255
Dessin_stylo.Vert = 0
Dessin_stylo.Bleu = 255
EndCase
Case 10
Dessin_stylo.Rouge = 0
Dessin_stylo.Vert = 0
Dessin_stylo.Bleu = 0
EndCase
Case 11
Dessin_stylo.Rouge = 0
Dessin_stylo.Vert = 255
Dessin_stylo.Bleu = 0
EndCase
Case 12
Dessin_stylo.Rouge = 255
Dessin_stylo.Vert = 255
Dessin_stylo.Bleu = 0
EndCase
Case 13
Dessin_stylo.Rouge = 0
Dessin_stylo.Vert = 255
Dessin_stylo.Bleu = 255
EndCase
Case 14
Dessin_stylo.Rouge = 255
Dessin_stylo.Vert = 255
Dessin_stylo.Bleu = 255
EndCase
Case 15
Dessin_effacer_ecran()
EndCase
Case 16
Dessin_enregistrer_fichier()
EndCase
Case 17
Dessin_etat_jeu = JEU_QUITTER
EndCase
Case 18
Dessin_charger_modele()
EndCase
Case 19
If Dessin_num_modele > 1
Dec Dessin_num_modele, 1
Else
Dessin_num_modele = 10
EndIf
SetTextString (Dessin_texte_num_modele, Str(Dessin_num_modele))
EndCase
Case 20
If Dessin_num_modele <= 9
Inc Dessin_num_modele, 1
Else
Dessin_num_modele = 1
EndIf
SetTextString (Dessin_texte_num_modele, Str(Dessin_num_modele))
EndCase
Case 21
Dessin_charger_fichier()
EndCase
Case 22
If Dessin_num_fichier > 1
Dec Dessin_num_fichier, 1
Else
Dessin_num_fichier = 10
EndIf
SetTextString (Dessin_texte_num_fichier, Str(Dessin_num_fichier))
EndCase
Case 23
If Dessin_num_fichier <= 9
Inc Dessin_num_fichier, 1
Else
Dessin_num_fichier = 1
EndIf
SetTextString (Dessin_texte_num_fichier, Str(Dessin_num_fichier))
EndCase
Case 24
Dessin_operation = DESSIN_DESSINER
EndCase
Case 25
Dessin_operation = DESSIN_REMPLIR
EndCase
EndSelect
EndIf
If y > 508 and y < 559
Dessin_AttrapperCouleur (x,y)
EndIf
EndIf
Else
Select Dessin_operation
Case DESSIN_REMPLIR
If Pointeur_tester() = TRUE
Local Dessin_couleur_fond as Integer
If GetMemBlockExists(Dessin_modele_memBlock) = TRUE
DeleteMemblock (Dessin_modele_memBlock)
EndIf
Dessin_modele_memBlock = CreateMemBlockFromImage (Dessin_ecran_image)
Dessin_couleur_fond = Dessin_modele_GetPixel ( Dessin_modele_memBlock, 0, 0, DESSIN_LARGEUR_IMAGE ) // Grab first pixel and set the colour as background colour, this will not be a black line on the pic
Dessin_modele_remplir(Dessin_stylo.Rouge,Dessin_stylo.Vert, Dessin_stylo.Bleu)
Dessin_ecran_image = CreateImageFromMemBlock (Dessin_modele_memBlock)
SetSpriteImage ( Dessin_ecran_sprite, Dessin_ecran_image )
EndIf
EndCase
Case DESSIN_DESSINER
If GetPointerState() = 1
SetRenderToImage(Dessin_ecran_image,0)
Local Dessin_couleur as Integer
Dessin_couleur = MakeColor (Dessin_stylo.Rouge,Dessin_stylo.Vert, Dessin_stylo.Bleu)
Dessin_ellipse (x,y,Dessin_stylo.Taille/2,Dessin_stylo.Taille/2, Dessin_couleur)
SetRenderToScreen()
EndIf
EndCase
EndSelect
EndIf
EndFunction
Function Dessin_effacer_ecran()
SetRenderToImage (Dessin_ecran_image,0)
SetClearColor(255,255,255)
ClearScreen()
SetRenderToScreen()
EndFunction
Function Dessin_liberer_jeu()
If GetMemBlockExists(Dessin_modele_memBlock) = TRUE
DeleteMemblock (Dessin_modele_memBlock)
EndIf
SetSpriteDepth(Dessin_ecran_sprite,20)
DeleteSprite (Dessin_sprite_outils)
DeleteSPrite (Dessin_ecran_sprite)
DeleteImage (Dessin_image_outils)
DeleteImage (Dessin_ecran_image)
DeleteSound (Dessin_son_enregistrement)
DeleteSound (Dessin_son_outils)
DeleteText (Dessin_texte_num_fichier)
DeleteText (Dessin_texte_num_modele)
DeleteText (Dessin_texte_message)
EndFunction
Function Dessin_ellipse(xc as Integer, yc as Integer, a as Integer, b as Integer, Color as Integer)
// http://enchantia.com/graphapp/doc/tech/ellipses.html
// McIlroy's algorithm
/* e(x,y) = b^2*x^2 + a^2*y^2 - a^2*b^2 */
Local x as Integer
Local y as Integer
Local width as Integer
Local a2 as Integer
Local b2 as Integer
Local crit1 as Integer
Local crit2 as Integer
Local crit3 as Integer
Local t as Integer
Local dxt as Integer
Local dyt as Integer
Local d2xt as Integer
Local d2yt as Integer
x = 0
y = b
width = 1
a2 = a * a
b2 = b * b
crit1 = -(a2/4 + mod(a,2) + b2)
crit2 = -(b2/4 + mod(b,2) + a2)
crit3 = -(b2/4 + mod (b,2))
t = -a2 * y /* e(x+1/2,y-1/2) - (a^2+b^2)/4 */
dxt = 2 * b2 * x
dyt = -2 * a2 * y
d2xt = 2 * b2
d2yt = 2 * a2
While y>=0 and x <= a
If t + b2 * x <= crit1 or t + a2 * y <= crit3 /* e(x+1,y-1/2) <= 0 */ /* e(x+1/2,y) <= 0 */
//Incx()
x = x + 1
dxt = dxt + d2xt
t = t + dxt
width = width + 2
ElseIf t - a2*y > crit2 /* e(x+1/2,y-1) > 0 */
DrawLine (xc-x, yc-y,xc-x + width, yc-y,Color, Color)
If (y <> 0) Then DrawLine(xc-x, yc+y, xc-x+ width, yc+y, Color, Color)
//Incy()
y = y - 1
dyt = dyt + d2yt
t = t + dyt
Else
DrawLine (xc - x, yc - y, xc - x+ width, yc - y, Color, Color)
If (y <> 0) Then DrawLine(xc - x, yc + y, xc - x + width, yc + y, Color, Color)
// IncX
x = x + 1
dxt = dxt + d2xt
t = t + dxt
//Incy()
y = y - 1
dyt = dyt + d2yt
t = t + dyt
width = width + 2
EndIf
EndWhile
If b = 0 Then DrawLine (xc - a, yc, xc - a + 2 * a + 1, yc, Color, Color)
EndFunction
Function Dessin_creer_fichier_donnees (Fichier as String)
Local f as Integer
Local Colonne as Integer
Local Rangee as Integer
Local Valeur as Integer
Aller_dossier_jeux ("jeu02/modeles/")
f = OpenToWrite (Chemin_externe + Fichier)
WriteString (f, "--- Fichier données dessin hubibox ---")
For Colonne=0 To DESSIN_LARGEUR_IMAGE
For Rangee=0 To DESSIN_HAUTEUR_IMAGE
Valeur = Dessin_modele_pixelStore[Colonne, Rangee]
WriteInteger (f, Valeur)
Next
Next
CloseFile (f)
EndFunction
Function Dessin_charger_fichier_donnees (Fichier as String)
Local f as Integer
Local Colonne as Integer
Local Rangee as Integer
Local Valeur as Integer
Aller_dossier_jeux ("jeu02/modeles/")
f = OpenToRead (Chemin_externe + Fichier)
ReadString (f) // Rien
For Colonne=0 To DESSIN_LARGEUR_IMAGE
For Rangee=0 To DESSIN_HAUTEUR_IMAGE
Valeur = ReadInteger (f)
Dessin_modele_pixelStore[Colonne, Rangee] = Valeur
Next
Next
CloseFile (f)
EndFunction
Function Dessin_charger_modele ()
Local Dessin_couleur_fond as Integer
Local Fichier_png as String
Local Fichier_dat as String
If Dessin_num_modele <=9
Fichier_png = "modele_0" + Str(Dessin_num_modele) + ".png"
Else
Fichier_png = "modele_" + Str(Dessin_num_modele) + ".png"
Endif
Fichier_dat = ReplaceString (Fichier_png, ".png", ".dat",1)
Aller_dossier_jeux ("jeu02/modeles/")
If GetFileExists (Chemin_externe + "/" + Fichier_png)
// set screen properties and images
// picture is 1600 x 900 and has 2 colours for white background and black lines
Dessin_ecran_image = LoadImageRaw ( Fichier_png )
If GetMemBlockExists (Dessin_modele_memBlock) = TRUE
DeleteMemBlock(Dessin_modele_memBlock)
EndIf
Dessin_modele_memBlock = CreateMemblockFromImage ( Dessin_ecran_image )
Dessin_couleur_fond = Dessin_modele_GetPixel ( Dessin_modele_memBlock, 0, 0, DESSIN_LARGEUR_IMAGE ) // Grab first pixel and set the colour as background colour, this will not be a black line on the pic
Dessin_couleur_fond = 765 // equivalent blanc r=255,v=255,b=255
// set display properties
If GetFileExists (Chemin_externe + "/" + Fichier_dat)
Dessin_creer_message ("Le fichier modèle '" + Fichier_png + "' est en cours de chargement...")
Sync()
Dessin_charger_fichier_donnees(Fichier_dat)
Else
Dessin_creer_message ("Veuillez patienter, le fichier modèle '" + Fichier_png + "' est en cours de post-traitement...")
Sync()
Dessin_modele_StoreFillPixels ( Dessin_modele_memBlock, DESSIN_LARGEUR_IMAGE,DESSIn_HAUTEUR_IMAGE, Dessin_couleur_fond )
Dessin_creer_fichier_donnees (Fichier_dat)
EndIf
SetSpriteImage (Dessin_ecran_sprite, Dessin_ecran_image)
Dessin_creer_message ("Le fichier modèle '" + Fichier_png + "' a été chargé")
Else
Dessin_creer_message ("Le fichier modèle '" + Fichier_png + "' n'a pas été trouvé !")
EndIf
EndFunction
Function Dessin_modele_remplir (Rouge as Integer, Vert as Integer, Bleu as Integer)
Local PixelCheck as Integer
Local Alpha as Integer
Local x as Integer
Local y as Integer
x = GetPointerX()
y = GetPointerY()
while GetPointerReleased()=0
Sync()
Endwhile
// Checks pointer is in the main screen area to fill picture
If x >= 0 and x <= DESSIN_LARGEUR_IMAGE and y >= 0 and y <= DESSIN_HAUTEUR_IMAGE
// Checks the pixel Array at the pointer location
Pixelcheck = Dessin_modele_PixelStore [ x+1, y+1 ]
// If this location contains a black line then ignore the fill as don't want to fill in the black lines
// If location is the background then colour the area with a random colour but not transparent re Alpha
If Pixelcheck <> 0
Alpha = 255
Dessin_modele_FloodFill ( Dessin_modele_memBlock, x, y, DESSIN_LARGEUR_IMAGE, DESSIN_HAUTEUR_IMAGE, Rouge, Vert, Bleu, Alpha )
Endif
Endif
EndFunction
Function Dessin_modele_StoreFillPixels ( MemBlockInput as Integer , Largeur_image as Integer , Hauteur_image as Integer , Couleur_fond as Integer)
// grab Memory Block pixels into an array from screen to store each fill area as a seperate value
// This fills the Array values to zero's
Local x as Integer
Local y as Integer
Local i as Integer
Local newFillAreaRow as Integer
Local FillAreaNum as Integer
Local newColour as Integer
local oldColour as Integer
Local RowsAgain as Integer
Local ColumnsAgain as Integer
Local Rangees as Integer
Local Colonnes as Integer
Local Couleur_test as Integer
Local Couleur_dessus as Integer
Local Couleur_gauche as Integer
For y = 0 to Hauteur_image
For x = 0 to Largeur_image
Dessin_modele_PixelStore [ Largeur_image, Hauteur_image ] = 0
Next
Next
For i = 0 To 20000
Dessin_Modele_pixelStoreStack [ i ] = 0
Next
newFillAreaRow = 0
/*
This For/Next routine checks every pixel in the memBlock and also checks the pixel
above and to the left for areas to fill with numbers.
This creates an Array with numbers similar to a Picture By Numbers card.
I use this method instead of flood fill on the fly for speed of colouring
otherwise it is too slow.
*/
For Rangees = 1 to Hauteur_image
Dessin_creer_message ("Veuillez patienter est en cours de post-traitement : " + Str ( (Colonnes-1) + (Rangees-1) * DESSIN_LARGEUR_IMAGE) + "/" + Str(DESSIN_HAUTEUR_IMAGE * DESSIN_LARGEUR_IMAGE) )
Sync()
For Colonnes = 1 to Largeur_image
// Sets Couleur_test to pixel value at co-ords in the memBlock
Couleur_test = Dessin_modele_GetPixel ( memBlockInput, Colonnes-1, Rangees-1, Largeur_image )
// If the Couleur_test is equal to the background colour Couleur_fond then find fill area (zero is a black line so will leave Array value as zero)
If Couleur_test = Couleur_fond
// Sets pixels above and left to zero incase rows and columns are at the edge of the screen
Couleur_dessus = 0
couleur_gauche = 0
// Checks for edge of screen
If Rangees > 1 Then Couleur_dessus = Dessin_modele_PixelStore [ Colonnes, Rangees - 1 ]
If Colonnes > 1 Then Couleur_gauche = Dessin_modele_PixelStore [ Colonnes - 1 , Rangees ]
If Couleur_dessus = 0 and Couleur_gauche = 0
NewFillAreaRow = NewFillAreaRow + 1
FillAreaNum = NewFillAreaRow
Dessin_modele_PixelStoreStack [ newFillAreaRow ] = Rangees
Else
If Couleur_gauche <> 0 and Couleur_dessus <> 0
If Couleur_gauche = Couleur_dessus
FillAreaNum = Couleur_gauche
Else
newColour = Couleur_dessus
oldColour = Couleur_gauche
/*
The below For/Next Stack:
Checks rows/columns for new fill area number that
has been created and if this area is not enclosed
with a black line changes these numbers to the correct
fill area number
*/
For rowsAgain = Dessin_modele_pixelStoreStack [ oldColour ] to Rangees
For columnsAgain = 1 to Largeur_image
If Dessin_modele_pixelStore [ columnsAgain, rowsAgain ] = oldColour
Dessin_modele_pixelStore [ columnsAgain, rowsAgain ] = newColour
If rowsAgain < Dessin_modele_pixelStoreStack [ newColour ] Then Dessin_modele_PixelStoreStack [ newColour ] = rowsAgain
Endif
Next
Next
FillAreaNum = newColour
Endif
Else
FillAreaNum = Couleur_gauche + Couleur_dessus
Endif
Endif
// Sets a fill area value to the pixelStore Array - This Array is the same size as the colouring screen
Dessin_modele_pixelStore [ Colonnes, Rangees ] = FillAreaNum
Endif
Next
Next
Endfunction
Function Dessin_modele_GetPixel ( MemBlockIn as Integer, x as Integer, y as Integer, Largeur as Integer )
// function to obtain colour value (RGB) and Alpha value if needed of each pixel in the memory block
/*
I add the values for RGB together and return this value as one integer as I do not
need seperate values to check my fill areas for the Array in pixelStore, I only
need to check for the values of the background and the black lines in my
image to colour
*/
Local PixelColourRGB as Integer
Local Rouge as Integer
Local Vert as Integer
Local Bleu as Integer
Local Alpha as Integer
Local OffsetPixel as Integer
OffsetPixel = 12 + (( x + ( y * Largeur )) * 4 )
Rouge = GetMemBlockByte ( MemBlockIn, OffsetPixel )
Vert = GetMemBlockByte ( MemBlockIn, OffsetPixel + 1 )
Bleu = GetMemBlockByte ( MemBlockIn, OffsetPixel + 2 )
Alpha = GetMemBlockByte ( MemBlockIn, OffsetPixel + 3 )
PixelColourRGB = Rouge + Vert + Bleu
Endfunction PixelColourRGB
Function Dessin_modele_FloodFill ( MemBlockIn as Integer, x as Integer, y as Integer, Largeur as Integer, Hauteur as Integer, Rouge as Integer, Vert as Integer, Bleu as Integer, Alpha as Integer)
// Function to fill area with colour inside the memblock
/*
This checks the area of the image at the x/y co-ords where the pointer is and
stores this value in pixelcheck.
It then checks the full Array of pixelStore for the image and stores a new
RGBA value to the memBlock at the location on the Array with the same value
as in pixelcheck, thus filling the numbered area like colour by numbers card.
*/
Local Rangee as Integer
Local Colonne as Integer
Local PixelCheck as Integer
Local OffsetPixel as Integer
PixelCheck = Dessin_modele_PixelStore [ x+1, y+1 ]
For Rangee = 1 To Hauteur
For Colonne = 1 To Largeur
If Dessin_modele_pixelStore [ Colonne, Rangee ] = Pixelcheck
OffsetPixel = 12 + (( (Colonne-1) + ( ( Rangee-1) * Largeur )) * 4 )
SetMemblockByte( MemBlockIn, OffsetPixel, Rouge )
SetMemblockByte( MemBlockIn, OffsetPixel+1, Vert )
SetMemblockByte( MemBlockIn, OffsetPixel+2, Bleu )
SetMemblockByte( MemBlockIn, OffsetPixel+3, Alpha )
Endif
Next
Next
Endfunction
Function Dessin_AttrapperCouleur(X as integer,Y as Integer)
Local Couleur as Dessin_stylo_type
Local Mem as Integer
Local Largeur as Integer
Local xx as Integer
Local OffsetPixel as Integer
Largeur = GetImageWidth (Dessin_image_outils)
Mem = createMemblockfromImage(Dessin_image_outils)
xx = x - GetSpriteX (Dessin_sprite_outils)
OffsetPixel = 12 + (( xx + ( y * Largeur )) * 4 )
Couleur.Rouge = GetMemBlockByte ( Mem, OffsetPixel )
Couleur.Vert = GetMemBlockByte ( Mem, OffsetPixel + 1 )
Couleur.Bleu = GetMemBlockByte ( Mem, OffsetPixel + 2 )
Deletememblock(Mem)
Dessin_stylo.Rouge = Couleur.Rouge
Dessin_stylo.Vert = Couleur.Vert
Dessin_stylo.Bleu = Couleur.Bleu
EndFunction
//-------------------------------------------------------------------------------------------------------------------------
//
// PROGRAMME
//
//-------------------------------------------------------------------------------------------------------------------------
Function Jouer_jeu_deux()
Charger_jeu_dessin()
Pointeur_vider()
Dessin_etat_jeu = JEU_DEBUT_NIVEAU
Repeat
Dessin_jouer()
If GetRawKeyPressed(27)
Ecrire_dans_journal ("Fin du programme, sortie par touche ECHAP.")
End
EndIf
Pointeur_afficher()
Sync()
If GetRawKeyPressed (TOUCHE_CAPTURE_ECRAN)
Capturer_image_ecran()
EndIf
Until Dessin_etat_jeu = JEU_QUITTER
Dessin_liberer_jeu()
EndFunction
//-------------------------------------------------------------------------------------------------------------------------
//
// FIN DE PROGRAMME
//
//-------------------------------------------------------------------------------------------------------------------------