drawline with image
BlitzMax Forums/BlitzMax Beginners Area/drawline with image
| ||
Hello I am writing here in the BlitzMax, but my problem relates to almost all basic. Well, I can not cope in a standard way using in-built commands draw the line (solid). As far as using the command: DrawLine x, y, x 1, y1 I don't have any problems this if you want to use an image for example. about the size of 1 x 1 pixel and have the same effect as using the above commands can not cope. Do I have to use a separate function on their own, or just the command ready for example. in BlitzMax? And below this effect using-BUT! DrawLine x, y, x 1, y1: Graphics 800, 600 While Not A KeyDown (Key_Escape) MX = MouseX () We = MouseY () If the MouseDown (1) DrawLine, x,y, mx, my Endif x = mx y = my Flip Wend Very please help Blicek |
| ||
Hi, not sure what you are trying to accomplish, but when I run this: SuperStrict Graphics 800, 600 Local mx:Int, my:Int, x:Int, y:Int While Not KeyDown (Key_Escape) mx = MouseX() my = MouseY() If MouseDown(1) Then DrawLine (x, y, mx, my) EndIf x = mx y = my Flip Wend ...it draws white solid line when I press left mousebutton. -Henri |
| ||
I mean to draw the image on the screen rather than using the drawline. |
| ||
DrawImage() |
| ||
After all, I wrote that I want to get the effect of the line, but using an image rather than using the DrawLine! For example, whereas the image as a 1 x 1 pixel and i want this pixel to draw a continuous line. And here is my problem !. I'm waiting for help Blicek |
| ||
Theoretically you can draw a line made from an image... but if you draw a line, which is made from a 1x1pix image it will be the same as drawing a regular line, because a 1x1pix image will only have one point of one single color. Not really an image! Draw a line made of an image: Function DrawImageLine(X#,Y#,X1#,Y1#,Img:Image) Local delta#=(Y1-Y)/(X1-X) For local i%=0 to (X1-X) DrawImage Img, X+i, Y+delta*i Next End Function But if you are sure, that the image is always only 1x1pix, you could pick the color of this pixel and use is for the regualr DrawLine() command. I'm not 100% sure, but this can be a way to find out a pixel color in an image: Global R%,G%,B% Function GetImageColor(X#,Y#,Img:Image) Local Pic:TPixMap=LockImage(Img) local Color%=ReadColor(Pic,X,Y) R=(Color Shr 0) & 255 G=(Color Shr 8) & 255 B=(Color Shr 16) & 255 UnlockImage Img End Function |
| ||
Ok Here's what I meant! Thanks a lot-BUT I had to fix myself a mouse to draw anything on the screen here is the code: Graphics 800, 600 IMG = LoadImage ("g:/bm/work/point .png") While Not A KeyDown (Key_Escape) x 1 # = MouseX () Y1 = MouseY () DrawImageLine (X, # Y, # X 1, Y1, # #, Img) x = x 1 # y # = n # Flip Wend Function DrawImageLine (X, # Y, # X 1, Y1, # #, Img) Local delta # = (Y1 # s #)/(x 1-X # #) For Local and% = 0 (x 1 #-X #) If the MouseDown (1) DrawImage Img, X, # + and Y # + delta # and Endif Next End Function and here is the drawing but only in the right side and the left side does not work? Why? Please reply Blicek |
| ||
I found a better algo which uses the principe of pythagoras:SuperStrict Graphics 800, 600 Global X%, Y%, X1%, Y1% Global Img:TImage = LoadImage ("Pixel.png") DrawImage Img,0,0 X = MouseX () Y = MouseY () While Not KeyDown (Key_Escape) If MouseDown(1) X1 = MouseX () Y1 = MouseY () If (X1<>X) Or (Y1<>Y) DrawImageLine (X, Y, X1, Y1, Img) X = X1 Y = Y1 EndIf EndIf Flip Wend Function DrawImageLine (X#, Y#, X1#, Y1#,Img:TImage) Local length# = Sqr((X1-X)^2+(Y1-Y)^2) Local deltaX# = (X1-X)/length Local deltaY# = (Y1-Y)/length For Local i%=0 To length X=X+deltaX Y=Y+deltaY DrawImage Img,X,Y Next End Function there are a lot of bug in your code... 1. What are you doing with all these '#'? In my codes they are used to define FLOAT-variables. 2. Do not use a variable named 'AND', because it is a reserved word in BlitzMax 3. In "While Not A KeyDown" the "A" is wrong! The same with "the" in "If the MouseDown (1)" |
| ||
Graphics 800,600 SetBlend Alphablend Local img:TImage = CreateImage(1,3) Local pxm:TPixmap = LockImage(img) pxm.WritePixel(0,0,$10FFFFFF) pxm.WritePixel(0,1,$FFFFFFFF) pxm.WritePixel(0,2,$10FFFFFF) DrawImage img,-1,0 ' preload image to graphics buffer SetImageHandle(img,0,1) Function Line(x1:Float,y1:Float,x2:Float,y2:Float,img:TImage) Local ox:Float,oy:Float GetScale(ox,oy) Local oa:Float = GetRotation() Local vx:Float = x2-x1 Local vy:Float = y2-y1 Local ang:Float = ATan2(vy,vx) length:Float = Sqr(vx*vx+vy*vy) SetScale(length,1) SetRotation(ang) DrawImage(img,x1,y1) SetScale(ox,oy) SetRotation(oa) End Function SetColor(0,255,0) Local ms:Int= MilliSecs() Line(100,100,500,150,img) Line(500,150,400,300,img) Line(400,300,100,300,img) Line(100,300,100,100,img) ms = MilliSecs()-ms DrawText ms + " Millisecs to draw",10,10 DrawText "Press a key to exit ",100,500 Flip WaitKey() this might be better as this produce AA lines. |
| ||
[code] . |
| ||
OK OK Very thanks for all Blicek |