PurePunch Contest #2

Share your advanced PureBasic knowledge/code with the community.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

It's not a problem, and as they're not so much utilities, it's welcome! :)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

rrpl wrote: I'm sure it can probably be made smaller yet, but not much smaller. :)
Four lines shorter:

Code: Select all

w=600:h=150:OpenWindow(0,0,30,w,h,"Littlest Magnifier",#PB_Window_SystemMenu)
StickyWindow(0,1):M=3:ImageGadget(0,0,0,w,h,0):While WindowEvent()<>16:c.point
GetCursorPos_(c):Gosub S:n=ResizeImage(0,w,h):SetGadgetState(0,n):Delay(50)
Wend:End:S:CreateImage(0,w/M,h/M):hd=StartDrawing(ImageOutput(0)):D=GetDC_(0)
BitBlt_(hd,0,0,w/M,h/M,D,c\x,c\y,#SRCCOPY):StopDrawing():ReleaseDC_(0,D):Return
User avatar
Arctic Fox
Enthusiast
Enthusiast
Posts: 609
Joined: Sun Dec 21, 2008 5:02 pm
Location: Aarhus, Denmark

Post by Arctic Fox »

rrpl wrote:So I put this little magnifier together.
This was actually my first idea, but I couldn't make it work :lol: (what a funny incident)
Good job anyway :o
rrpl
Enthusiast
Enthusiast
Posts: 121
Joined: Fri Apr 18, 2008 7:22 am
Location: Australia

Post by rrpl »

Thanks Trond
Four lines shorter:
But you didn't get it down to one line like I thought you would!

Updated Magnifier with up/down arrow to increase/decrease magnification.

Code: Select all

;*****************************************************************************
;*
;* Name   : Littlest Magnifier - Mark 2
;* Author : rrpl (much help from Trond in shrinking the code)
;* Date   : 23 June 09
;* Notes  : Change magnification using up/down arrows
;*
;***************************************************************************** 
w=600:h=150:OpenWindow(0,0,30,w,h,"Littlest Magnifier",#PB_Window_SystemMenu)
StickyWindow(0,1):M=3:ImageGadget(0,0,0,w,h,0):AddKeyboardShortcut(0,38,1)
AddKeyboardShortcut(0,40,2):While a<>16:a=WindowEvent():c.point
GetCursorPos_(c):Gosub S:n=ResizeImage(0,w,h):SetGadgetState(0,n)
If a=#PB_Event_Menu:b=EventMenu():If b=1 And M<10:M=M+1:ElseIf b=2 And M>2
M=M-1:EndIf:EndIf:Delay(50):Wend:End:S:CreateImage(0,w/M,h/M)
hd=StartDrawing(ImageOutput(0)):D=GetDC_(0)
BitBlt_(hd,0,0,w/M,h/M,D,c\x,c\y,#SRCCOPY):StopDrawing():ReleaseDC_(0,D)
Return
Who knows with further help from Trond I might be able to add some special FX as well, and win this thing(illegally!-who cares bro).
:twisted:
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

Here is my 2nd contribution for this competition which works on windows only! Its not easy to have good timing results... so i hope the intro and its effects works ok on your system (not to slow nor to fast) and hope you enjoy this production. Applications auto exit! Best regards and good luck to all contributors...

Code: Select all

;*****************************************************************************
;*
;* Name   : DemoManiac - small multipart intro (Windows only!)
;* Author : Thorsten Will - aka 'Mr.Vain of Secretly!'
;* Date   : 23.06.2009
;* Notes  : Entry for the PurePunch Contest #2
;*          The rule is to code something in max 10 lines of 80 characters!
;*          I tried to code a small multipart intro with timing and music! ^^
;*          Win32 API has been used for timing, because smaller as pb commands.
;*
;*          This intro features:
;*              - blue background noise
;*              - colorful XOr pattern
;*              - fractal (flipping and zooming while transforming)
;*              - abstract moving lines (changing color)
;*              - background music (timing with fx isnt nice nor easy this way)
;*              - flashing text
;*              - auto exit
;*
;*          P L E A S E   D I S A B L E   T H E   D E B U G G E R  !!! 
;*
;***************************************************************************** 
s=timeGetTime_():InitMovie():LoadMovie(0,"c:\windows\media\onestop.mid"):b=255
InitSprite():OpenScreen(640,480,32,""):PlayMovie(0,0):Repeat:r=ScreenOutput()
StartDrawing(r):e=(timeGetTime_()-s)/100:t.f+0.05:For m=0 To 639:For n=0 To 479
g=64:Plot(m,n,(g+Random(g))<<16):d=826:w=Sin(t)*b:If e>=0 And e<152:h=Cos(t)*b
ElseIf e>152 And e<393:h=w:EndIf:q.f=(n-b)/h:p.f=(m-b)/w:x.f=0:y.f=t/21:z=100
For i=1 To 24:u.f=x*x-y*y+p:v.f=2*x*y+q:If u*u+v*v>4:Goto E:EndIf:x=u:y=v:Next
Plot(m,n,RGB(m!n,96,m*n/740)):E:o=$FF:Next:Next:If e>393 And e<665:For i=0 To b
x=Cos(l.f):y=Sin(l):m=z*-Sin(i+(x*z))+c:g=c*Sin(i+(x*c))+b+c:n=z*-Cos(i+(y*z))+c
h=c*Cos(i+(y*c))+b:c=150:LineXY(m,n,g,h,o*t*4):Next:l=t/b:ElseIf e>665 And e<d
DrawingMode(1):DrawText(b,b,"END",w):EndIf:StopDrawing():FlipBuffers():Until e>d  
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

:shock:

got a message about a missing dll but it ran fine anyway.

Took a while to end (had me a bit worried :) but Very Very impressive.

cheers
rrpl
Enthusiast
Enthusiast
Posts: 121
Joined: Fri Apr 18, 2008 7:22 am
Location: Australia

Post by rrpl »

va!n Wrote:
so i hope the intro and its effects works ok on your system (not to slow nor to fast) and hope you enjoy this production
works fine on my computer on WinXP -very impressive to get so much stuff happening with such little code. Timing seemed about right. 8)
User avatar
nase09
User
User
Posts: 33
Joined: Sat Jun 07, 2008 11:45 am

Post by nase09 »

nice!
va!n wrote: - background music (timing with fx isnt nice nor easy this way)
but no music if your WinDir is not named "c:\windows" :( - why don't you use GetEnvironmentVariable("windir") to get the Path ? :lol: (just kidding.. this command is sooo loooong..)
rrpl
Enthusiast
Enthusiast
Posts: 121
Joined: Fri Apr 18, 2008 7:22 am
Location: Australia

Post by rrpl »

Just for laughs really and to keep the number of utilities up - A Pure Punch 2 Validator that validates itself into the contest. It ignores comment lines, blanks lines, and lines with only spaces, removes spaces from start and end of line, only count characters on the basis of string function Len - I hope this fits with the contest guidelines!?

A special disclaimer: this is not an official Pure Punch 2 validator! :lol:
It reports the number of lines and names the lines exceeding 80 characters.

Code: Select all

;*****************************************************************************
;*
;* Name   : Pure Punch 2 Validator
;* Author : rrpl 
;* Date   : 23 June 09
;* Notes  : Paste Code into Pure Punch 2 Validator, click on Check
;*
;***************************************************************************** 
l=10:w=500:h=400:OpenWindow(0,0,30,w,h,"PP Validator",#PB_Window_SystemMenu)
c=80:EditorGadget(0,0,0,w,h-35):SetGadgetText(0,";Paste Code Here"):r.s=#CRLF$
ButtonGadget(1,25,h-30,100,25,"Check"):u.s=r+";Total Lines =":While a<>16:
a=WindowEvent():If a=#PB_Event_Gadget:If EventGadget()=1:Gosub v:EndIf:EndIf
Delay(9):Wend:End:v:For i=0 To CountGadgetItems(0)-1:s.s=GetGadgetItemText(0,i)
s=Trim(s):If s<>"":If Left(s,1)<>";":n=n+1:If Len(s)<81:Else:t.s=t+Str(n)+";"
EndIf:EndIf:EndIf:Next:If n<11 And t="":m.s=";":For j=1 To 77:m=m+"*":Next
m=m+r:o.s="Valid for Pure Punch 2":m=m+";PP2 Validator : Above code is "
AddGadgetItem(0,-1,m+o+u+Str(n)):Else:If t<>"":q.s="; Check Line/s ":EndIf
AddGadgetItem(0,-1,m+"NOT "+o+u+Str(n)+q+t):EndIf:n=0:t="":Return
;*****************************************************************************
;PP2 Validator : Above code is Valid for Pure Punch 2
;Total Lines =10
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

thx for feedback :-).

@nase09:
Mhhh... what windows version do you have, that the path isnt c:\Windows\ ? I agree, GetEnvVar would be nice or the constant something like #Windows\ or so would be nice to fix the prob! But using GetEnvVar does not fit in the size of source and i dont know if and how to write the constant in PB to get the windows folder back...

Btw, do you managed it to fix the path to enjoy the intro with full music? ^^
best regards
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

I made a program that strips unnecessary spaces and pushes lines together (as long as they don't get wider than 80 characters).
Of course, this program is small enough to fit into the contest because it was processed by itself. :wink:

Code: Select all

;***************************************************************************** 
;* 
;* Name   : PurePunchCruncher
;* Author : Trond
;* Date   : 23 June 09 
;* Notes  : Only runs in ascii mode on plain text source files
;* Notes  : Specify an existing input file before running
;* 
;*****************************************************************************

ReadFile(0,GetHomeDirectory()+"my documents\infile.pb")
CreateFile(1,"c:\out.pb"):E.s:L.c:Macro IsAlNum(L)
((UCase(Chr(L))<>LCase(Chr(L)))Or(L>='0'And L<='9')):EndMacro:While Eof(0)=0
L=ReadCharacter(0):Select L:Case#LF:Case#CR,';':If N+Len(E)+1>80
WriteString(1,#CRLF$):N=Len(E):Else:If E:N+Len(E)+1:WriteString(1,":"):EndIf
EndIf:WriteString(1,E):E="":S=0:Repeat:L=ReadCharacter(0):Until Eof(0)Or L=#LF
Case Asc("'"),'"':E+Chr(L):O=L:Repeat:L=ReadCharacter(0):E+Chr(L)
Until Eof(0)Or L=#CR Or L=O:Case' ':S=1:Default:If S=1
If IsAlNum(Asc(UCase(Right(E,1)))):If IsAlNum(L):E+" ":EndIf:EndIf:EndIf
E+Chr(L):S=0:EndSelect:Wend:RunProgram("c:\out.pb")
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

MrVain> Yeah, you did it! That's a lot better! And I love the end!!!
rrpl> nice, and easy :)
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Post by dobro »

Code: Select all

;*****************************************************************************
;*
;* Name   : Taches de Martin
;* Author : Dobro
;* Date   : 23/Juin/2009
;* Notes  : -exit white mouse right button
;*
;***************************************************************************** 
xp=2:yp=2:EX=320:Ey=200:InitSprite():InitMouse():OpenScreen(320,200,32,"")
CreateImage(1,320,200,32):StartDrawing(ImageOutput(1)):For t= 1 To 5000
Circle(Random(EX-1),Random(Ey-1),5,Random (1<<12)):Next:StopDrawing():Repeat 
 StartDrawing(ImageOutput(1)):For xp=2 To EX-1:For yp=2 To Ey-1:cs1=Point(xp-1,yp-1)
 cs2=Point(xp+1,yp+1):cs3=Point(xp,yp-1):cs4=Point(xp,yp+1):cs5=Point(xp+1,yp):
 cs6=Point(xp-1,yp):cs7=Point(xp-1,yp+1):cs8=Point(xp+1,yp-1)
 Circle(xp,yp,1,(cs1+cs2+cs3+cs4+cs5+cs6+cs7+cs8)/8):ExamineMouse():
If MouseButton(2):End:EndIf:Next:Next:StopDrawing():
StartDrawing(ScreenOutput()):DrawImage(ImageID(1),0,0):StopDrawing()
FlipBuffers():ForEver

Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

OpenScreen(320,200,32,"")
Some VGAs do not allow that resolutions. :?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
idle
Always Here
Always Here
Posts: 5839
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Post by idle »

Cam Mover or the ugly Window Test!

requires web cam!
32 bit windows only.

Code: Select all

;*****************************************************************************
;*
;* Name   :Cam Mover or the ugly Window Test:
;* Author :idle - andrew ferguson
;* Date   :24/06/2009
;* Notes  :windows 32bit only
;*        :hit esc To quit 
;*        :If the webcam isn't set at 320 x 240 remove the comment on line 9
;*        :Don't set it less than 320 x 240  
;*        ;If your system can't find avicap32.dll add this string to the openlibary command  
;*        :system drive "C:\Windows\system32\avicap32.dll"  
;*****************************************************************************
OpenLibrary(1,"avicap32.dll"):*p=GetFunction(1,"capCreateCaptureWindowW")
ExamineDesktops():Global q=DesktopWidth(0),z=DesktopHeight(0),w=320,h=240,t,n,e
Macro sm(b,c,d):SendMessage_(n,b,c,d):EndMacro:Global lx.f,ly.f,dx,dy,f=z/2-h/2
Procedure FC(j,*v.long):*r.long=*v\l+3:sx.f:sy.f:a.f:While d<230400:y=d%w:x=d/w
c=*r\l:sx+x*c:sy+y*c:a+c:d+3:*r+3:Wend:If t>20:dx=(sx/a)-lx:dy=(sy/a)-ly:Else
lx=(sx/a):ly=(sy/a):t+1:EndIf:e+dx:f+dy:If e<0:e=0:ElseIf e>q-w:e=q-w:EndIf
If f<0:f=0:ElseIf f>z-h:f=z-h:EndIf:ResizeWindow(0,e,f,w,h):EndProcedure:s.s  
u=OpenWindow(0,0,0,w,h,s,$CA0001):n=CallFunctionFast(*p,s,1<<28*5,0,0,w,h,u,0)
e=q/2-w/2:Sm(1034,0,0):sm(1076,60,0):sm(1074,1,0):sm(1029,0,@FC());sm(1065,0,0)
Repeat:Until WaitWindowEvent()=16 Or GetAsyncKeyState_(#VK_ESCAPE)&$1

Last edited by idle on Thu Jun 25, 2009 6:29 am, edited 7 times in total.
Post Reply