home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
aminet
/
ph_progs.lha
/
PH_PROGS.AMOS
/
Pixel_Tools.AMOS
/
Pixel_Tools.amosSourceCode
Wrap
AMOS Source Code
|
1993-06-02
|
7KB
|
239 lines
'****************************************************************************
'** PIXEL TOOLS - By Paul Hickman - 2/4/93 - E-Mail ph@doc.ic.ac.uk **
'****************************************************************************
'
'If you have any questions / find any special features(bugs) or improvments
'please E-Mail me......
'
'The Demo Code requires any IFF picture of low resolution, and <=32 colours.
'It is loaded by the line below, and is currently from the orignal AMOS data
'disk, supplied with version 1.1. If you don't have this disk, then change
'it to any 320x200 or larger IFF picture.
'
Load Iff "AMOS_DATA:IFF/amospic.iff",1
'
'
Screen Hide 1
Screen Open 0,320,256,32,Lowres
Flash Off : Curs Off : Cls 0 : Get Palette 1
A$="Press Any Key To Continue"
PIXELCOPY[1,40,0,104,119,0,20,20,16]
PIXELWRITER[A$,1,Screen Width/2-Len(A$)*4,100,9,True]
Wait Key
PIXELCLEAR[A$,1,Screen Width/2-Len(A$)*4,100]
PIXELBLANK[20,0,310,200,15,0]
End
'
'****************************************************************************
'*** END OF DEMO CODE - NOW AN EXPLANATION OF HOW TO USE THE PROCEDURES ***
'****************************************************************************
'
'Parameters: PIXELWRITER / PIXELCLEAR
'
'A$ : String to be typed
'S2 : Number for a temporary screen (Created Internally)
'X : X-position of text
'Y : Y-position of text (Top of characters, not baseline)
'FC : Text Foreground Colour
'BC : Text Background Colour (-1 = Transparent)
'
'NOTE: S2 should be the same for pixelwrite & the corresponding pixel clear,
'and pixel write creates screen s2, and pixel clear uses it to replace the
'old data under the text, the destroys it. If you use pixelwrite without pixel
'clear, the you should close screen s2 afterwards.
'
'
'Parameters: PIXELBLANK / PIXELCOPY
'
'S1 : Source Screen
'S2 : Destination Screen
'
'X1 : Source/Clear Rectangle Left Edge X Co-ordinate
'X2 : Source/Clear Rectangle Right Edge X Co-ordinate
'Y1 : Source/Clear Rectangle Top Edge Y Co-ordinate
'Y2 : Source/Clear Rectangle Bottom Edge Y Co-ordinate
'
'X3 : Destination Rectangle Left Edge X Co-ordinate
'Y3 : Destination Rectangle Top Edge Y Co-ordinate
'
'SZ : Size of Mosaic Squares in pixels
'C : Colour to fill with.
'
'NOTE: As with cls & screen copy, the area x1,y1 to x2-1,y2-1 is actually
'cleared / copied, not x1,y1 to x2,y2.
'
'
'The following restrictions apply to PIXELBLANK & PIXEL COPY :-
'
' - The Dimemsions X2-X1 & Y2-Y1 Are Greater Than Or Equal To The Pixel Size
'
' - The Larger Dimension of X2-X1 & Y2-Y1 must be at least The Pixel Size
' sqaured in length. e.g. Using pixel size 4, the rectangle must be 16
' pixels in width or height.
'
'
'Each of the four procedures will work independantly of the others, except
'PIXELCLEAR, which can only be used after a PIXELWRITE.
'
'****************************************************************************
'** HERE ARE THE PROCEDURES, USE BLOCK STORE TO COPY THEM INTO YOUR CODE **
'****************************************************************************
'
Procedure PIXELWRITER[A$,S2,X,Y,FC,BC]
'
L=Len(A$)-1
Dim O(63),C(L)
'
'Create a pixel list
'
For A=0 To 63 : O(A)=A : Next
'
'Shuffle to pixel list
'
For A=0 To 30
A1=Rnd(63) : A2=Rnd(63)
A3=O(A1) : O(A1)=O(A2) : O(A2)=A3
Next
'
'Assign a random starting position in the list to each character
'
For A=1 To L : C(A)=Rnd(64) : Next
'
'Plot string on the temporary screen with correct colours
'
S1=Screen
Screen Open S2,Len(A$)*8+8,8,Screen Colour,Lowres : Screen Hide S2
If BC>0
Ink FC,BC : Cls BC : JAM1=True
Else
Ink FC : JAM1=False : Cls 0
End If
Gr Writing 0 : Text 0,6,A$
'
'Plot the pixels
'
For C=0 To 63
For B=0 To L
'
'Calculate Position Of This Pixel
'
Add C(B),1,0 To 63
XX=B*8+Int(O(C(B))/8) : YY=Int(O(C(B))) and 7
'
'Swap pixel on actual and temporary screens if not transparent
'(But always copy actual screen pixel to temporary screen)
'
Screen S1 : C1=Point(X+XX,Y+YY)
Screen S2 : C2=Point(XX,YY)
Ink C1 : Plot XX,YY
Screen S1
If(C2>0) or JAM1
Ink C2 : Plot X+XX,Y+YY
End If
Next
Next
'
End Proc
Procedure PIXELCLEAR[A$,S2,X,Y]
'
'Generate Pixel & Character Lists as in PIXELWRITER
'
L=Len(A$)-1
Dim O(63),C(L)
For A=0 To 63 : O(A)=A : Next
For A=0 To 30 : A1=Rnd(63) : A2=Rnd(63)
A3=O(A1) : O(A1)=O(A2) : O(A2)=A3
Next
For A=1 To L : C(A)=Rnd(64) : Next
'
'Copy Temporary screen to Actual Screen
'
S1=Screen
For C=0 To 63
For B=0 To L
Add C(B),1,0 To 63
XX=B*8+Int(O(C(B))/8) : YY=Int(O(C(B))) and 7
Screen S2 : P=Point(XX,YY)
Screen S1 : Ink P : Plot X+XX,Y+YY
Next
Next
Screen Close S2
Screen S1
End Proc
Procedure PIXELBLANK[X1,Y1,X2,Y2,SZ,C]
'
'This works by considering groups of 8x8 squares as characters, and ploting
'each character from a random starting place in the pixel list.
'
'Find Width & Height Of Rectangle In Squares, and Divide By 8, Rounding Up
'
AX=Min(1,Int(7+Int((X2-X1+SZ-1)/SZ))/8) : AY=Min(1,Int(7+Int((Y2-Y1+SZ-1)/SZ))/8)
'
'Create an 8x8 pixel map, and assign random starting positions to each
'"character"
'
Dim O(63),C(AX*AY)
For A=0 To AX*AY : C(A)=A : Next
For A=0 To 63 : O(A)=A : Next
For A=0 To AX*AY
A1=Rnd(63) : A2=Rnd(63)
A3=O(A1) : O(A1)=O(A2) : O(A2)=A3
A1=Rnd(AX*AY-1) : A2=Rnd(AX*AY-1)
A3=C(A1) : C(A1)=C(A2) : C(A2)=A3
Next
'
'Plot Squares
'
For AA=0 To 63
For BB=0 To AX*AY
'
'Calculate position in rectangle or this square
'
Y=Int(C(BB)/AX) : X=(C(BB)-AX*Y)
A=O((X*Y+X+2*Y+5*X+8*Y+AA) and 63)
XX=(X*8+Int(A/8))*SZ : YY=(Y*8+(A and 7))*SZ
'
'If it is within bounds, clear the valid portion of the square
'
If(XX+X1<=X2) and(YY+Y1<=Y2)
Cls C,X1+XX,Y1+YY To Min(X1+XX+SZ,X2),Min(Y1+YY+SZ,Y2)
End If
Next : Next
End Proc
Procedure PIXELCOPY[S1,X1,Y1,X2,Y2,S2,X3,Y3,SZ]
'
'Create Pixel List & "Character" as with PIXELBLANK
'
AX=Max(1,Int(7+Int((X2-X1+SZ-1)/SZ))/8) : AY=Max(1,Int(7+Int((Y2-Y1+SZ-1)/SZ))/8)
Dim O(63),C(AX*AY)
For A=0 To AX*AY : C(A)=A : Next
For A=0 To 63 : O(A)=A : Next
For A=0 To AX*AY
A1=Rnd(63) : A2=Rnd(63)
A3=O(A1) : O(A1)=O(A2) : O(A2)=A3
A1=Rnd(AX*AY-1) : A2=Rnd(AX*AY-1)
A3=C(A1) : C(A1)=C(A2) : C(A2)=A3
Next
'
'Plot Squares
'
For AA=0 To 63
For BB=0 To AX*AY
'
'Calculate Position
'
Y=Int(C(BB)/AX) : X=(C(BB)-AX*Y)
A=O((X*Y+X+2*Y+5*X+8*Y+AA) and 63)
XX=(X*8+Int(A/8))*SZ : YY=(Y*8+(A and 7))*SZ
'
'Copy the portion of the square within the rectangle
'
' If(XX+X1<=X2) and(YY+Y1<=Y2)
Screen Copy S1,X1+XX,Y1+YY,Min(X1+XX+SZ,X2),Min(Y1+YY+SZ,Y2) To S2,X3+XX,Y3+YY
' End If
Next : Next
End Proc
'
'****************************************************************************
'* Support AMOS on the internet - upload source code or compiled programs *
'****************************************************************************