0

I have to create the above imagecircle with text

The text inside is variable. What I mean is that I want to pass 2 values to it for display and these values keep changing. I am trying this:

(define (circle-text vx vy) (underlay/align "center" "center" (circle 40 "outline" "blue") (text "("vx", "vy")" 14 "blue")))

But this obviously doesnt work. Please suggest me any better syntax or anything.

Leif Andersen
  • 21,580
  • 20
  • 67
  • 100
user3868051
  • 1,147
  • 2
  • 22
  • 43
  • Yes, I see the problem. What is the error message you're getting? – John Clements Sep 29 '16 at 17:34
  • 1
    Check out `string-append` – Leif Andersen Sep 29 '16 at 18:25
  • Check out `format` or `~a` – Ben Greenman Sep 29 '16 at 19:41
  • @BenGreenman this is clearly using 2htdp/image. As such, it's likely that `format` or `~a` is not allowed in the class they are taking. – Leif Andersen Sep 29 '16 at 21:00
  • I was surprised, but [`format` is actually in the docs for BSL](http://docs.racket-lang.org/htdp-langs/beginner.html#%28def._htdp-beginner._%28%28lib._lang%2Fhtdp-beginner..rkt%29._format%29%29). It's included with the rest of the BSL string functions. Now the question is whether students should use it when they see it in the BSL docs – Alex Knauth Sep 30 '16 at 01:59

1 Answers1

2

Try this:

(text (string-append "(" vx ", " vy ")") 14 "blue")

The above works assuming that vx and vy are already strings. If not, use this:

(text (string-append "(" (number->string vx) ", " (number->string vy) ")") 14 "blue")

Given that you're using Racket, this is even simpler:

(text (format "(~a, ~a)" vx vy) 14 "blue")
Óscar López
  • 232,561
  • 37
  • 312
  • 386