Paint sample

Post

Posted
Rating:
#1 (In Topic #847)
Avatar
Regular
tincho is in the usergroup ‘Regular’
Hello friends.
Could someone please tell me how to stop paint from drawing a line when it is positioned on another point.
The problem appears between point 4 and 5 which should not be drawn.
In the example I try to draw the capital letter "A" but you see the result.
<IMG src="https://i.imgur.com/g0CQKjB.png"> </IMG>

Code (gambas)

  1. Private afPoints As New Float[][]
  2.  
  3. Public Sub ToolButton1_Click()
  4.  
  5.   afPoints.Add([10, 100])
  6.   afPoints.Add([60, 10])
  7.  
  8.   afPoints.Add([60, 10])
  9.   afPoints.Add([110, 100])
  10.  
  11.   afPoints.Add([30, 50])
  12.   afPoints.Add([80, 50])
  13.  
  14.   DrawingArea1.Refresh
  15.  
  16.  
  17. Public Sub DrawingArea1_Draw()
  18.  
  19.  
  20.   If afPoints.Count > 0 Then
  21.     Paint.Brush = Paint.Color(Color.Red)
  22.     Paint.LineWidth = 3
  23.  
  24.     For z = 0 To afPoints.Max - 1
  25.       Paint.MoveTo(afPoints[0], afPoints[1])
  26.       Paint.LineTo(afPoints[z + 1][0], afPoints[z + 1][1])
  27.       Paint.Stroke
  28.     Next
  29.  
  30.  
Regrds
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
This code should help (I had to change your line 27 as it caused a crash): -

Code (gambas)

  1. Private afPoints As New Float[][]
  2.  
  3. Public Sub ToolButton1_Click()
  4.  
  5.   afPoints.Add([10, 100])
  6.   afPoints.Add([60, 10])
  7.  
  8.   afPoints.Add([60, 10])
  9.   afPoints.Add([110, 100])
  10.  
  11.   afPoints.Add([30, 50])
  12.   afPoints.Add([80, 50])
  13.  
  14.   DrawingArea1.Refresh
  15.  
  16.  
  17. Public Sub DrawingArea1_Draw()
  18.  
  19.  
  20.   If afPoints.Count > 0 Then
  21.     Paint.Brush = Paint.Color(Color.Red)
  22.     Paint.LineWidth = 3
  23.  
  24.     For z = 0 To afPoints.Max - 1
  25.       If z = afPoints.Max - 2 Then
  26.         Paint.NewPath()
  27.       Else
  28.         Paint.MoveTo(afPoints[z][0], afPoints[z][1])
  29.         Paint.LineTo(afPoints[z + 1][0], afPoints[z + 1][1])
  30.       Endif
  31.       Paint.Stroke
  32.     Next
  33.  

<IMG src="https://www.cogier.com/gambas/LetterA.png"> </IMG>
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Regular
tincho is in the usergroup ‘Regular’

cogier said

This code should help (I had to change your line 27 as it caused a crash): -
ok, it works, but now I add the "E" and…

Code (gambas)

  1. ' Gambas class file
  2.  
  3. Private afPoints As New Float[][]
  4.  
  5. Public Sub Lettering_Click()
  6.  
  7.   afPoints.Clear
  8.   Select Last.Tag
  9.     Case "a"
  10.       afPoints.Add([10, 100])
  11.       afPoints.Add([60, 10])
  12.  
  13.       afPoints.Add([60, 10])
  14.       afPoints.Add([110, 100])
  15.  
  16.       afPoints.Add([30, 50])
  17.       afPoints.Add([80, 50])
  18.       DrawingArea1.Refresh
  19.  
  20.     Case "e"
  21.       afPoints.Add([10, 100])
  22.       afPoints.Add([10, 10])
  23.  
  24.       afPoints.Add([10, 10])
  25.       afPoints.Add([110, 10])
  26.  
  27.       afPoints.Add([10, 50])
  28.       afPoints.Add([80, 50])
  29.  
  30.       afPoints.Add([10, 100])
  31.       afPoints.Add([110, 100])
  32.  
  33.  
  34.   DrawingArea1.Refresh
  35.  
  36.  
  37. Public Sub DrawingArea1_Draw()
  38.  
  39.  
  40.   If afPoints.Count > 0 Then
  41.     Paint.Brush = Paint.Color(Color.Red)
  42.     Paint.LineWidth = 3
  43.  
  44.     For z = 0 To afPoints.Max - 1
  45.       If z = afPoints.Max - 2 Then
  46.         Paint.NewPath()
  47.       Else
  48.         Paint.MoveTo(afPoints[z][0], afPoints[z][1])
  49.         Paint.LineTo(afPoints[z + 1][0], afPoints[z + 1][1])
  50.       Endif
  51.       Paint.Stroke
  52.     Next
  53.   Else
  54.     DrawingArea1.Children.Clear
  55.  
  56.  
  57.  
I looking for the general method.
However, with your example, I am closer to achieving it. Thanks  :D
Regards
Online now: No Back to the top
1 guest and 0 members have just viewed this.