little squared and the line
Posted: Fri Aug 16, 2024 8:25 am
I share you a nice effect of line when you click (left and hold on) and then move you will see it
Here the code :

Here the code :
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Coded with Purebasic v.6.11 by threedslider 15/08/2024
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Structure _rgb
r.i
g.i
b.i
EndStructure
Structure squared
x.f
y.f
EndStructure
color._rgb
color\r = 255
color\g = 0
color\b = 0
Procedure.f interpolate(a.f, b.f, t.f)
If t > 1.0
t = 1.0
EndIf
If t < 0.0
t = 0.0
EndIf
ProcedureReturn a + t*(b-a)
EndProcedure
Procedure draw_squared(_x.f, _y.f, *mycolor._rgb )
For y=0 To 3
For x=0 To 3
Line(x+_x, y+_y, 1, 3, RGB(*mycolor\r, *mycolor\g, *mycolor\b))
Next
Next
EndProcedure
Procedure.i draw_line(_x, _y, *mycolor._rgb, xm, ym)
mybool = #False
If MouseButton(#PB_MouseButton_Left)
mouse_x = xm
mouse_y = ym
mybool = #True
EndIf
For m = 1 To 1000
ms.f = m/1000.0
If mybool
draw_squared(interpolate(_x, mouse_x, ms*0.5), interpolate(_y, mouse_y, ms*0.5), *mycolor)
Else
draw_squared(_x, _y, *mycolor)
EndIf
Next
EndProcedure
InitSprite()
InitKeyboard()
InitMouse()
OpenWindow(1, 0,0,800 / DesktopResolutionX(),600 / DesktopResolutionY(),"Spiral in moving", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(1),0,0,800,600,0,0,0)
Repeat
ExamineKeyboard()
Repeat
event = WindowEvent()
Until event = 0
ClearScreen(RGB(0,0,0))
ExamineKeyboard()
ExamineMouse()
xm = MouseX()
ym = MouseY()
StartDrawing(ScreenOutput())
For y = 0 To 4
For x = 0 To 4
;move.f + 100/10000.0
If xm < 3
xm = 3
Else
If xm >790
xm = 790
EndIf
EndIf
If ym < 3
ym = 3
Else
If ym > 590
ym = 590
EndIf
EndIf
draw_line(50+x*100, 50+y*100, color, xm, ym)
Next
Next
draw_squared(xm, ym , color)
StopDrawing()
If KeyboardPushed(#PB_Key_Escape)
End
EndIf
FlipBuffers()
ForEver
End