racket / htdp

Other
93 stars 70 forks source link

Support for flipping text? for emojis #161

Open jestarray opened 3 years ago

jestarray commented 3 years ago
(require 2htdp/image)

(flip-horizontal (text "🦈" 100 "red"))

; ERROR: flip: cannot flip shapes that contain text

is it possible to make flip-horizontal and flip-vertical work with text images in 2htdp/image ? Arguably the color parameter is not needed for emojis. I can think of a few emoji centric games that could be fun to students. 🚣‍♂️ A fun game I can think of is rowing a boat left and right to avoid a shark from underneath or something, and getting flip-horizontal to change the boat facing direction. Thanks

samth commented 3 years ago

Note that rotate works on text, so it should be relatively easy to do some things here.

jestarray commented 3 years ago

I think all we need to do is to delete this check? : https://github.com/racket/htdp/blob/6d8926510bd48aaeec3f6dba9364f3d08e8e1601/htdp-lib/2htdp/private/image-more.rkt#L1002

    [(text? atomic-shape)
     (error 'flip "cannot flip shapes that contain text")]

but I don't know how to have racket require my local modified version of htdp. Can someone test this? Thanks.

By removing said check above I get:

../../usr/share/racket/pkgs/htdp-lib/2htdp/private/image-more.rkt:964:21: flip-atomic: broke its own contract
  promised: np-atomic-shape?
  produced: #<void>
  in: the range of
      (-> np-atomic-shape? np-atomic-shape?)
  contract from: (function flip-atomic)
  blaming: (function flip-atomic)
   (assuming the contract is correct)
  at: <pkgs>/htdp-lib/2htdp/private/image-more.rkt:966:18

So it's not just removing 1 line.. Edit: so it seems cairo can do these text flipping transformations since im testing it atm in C.

rfindler commented 3 years ago

There are a number of methods for flipped text that need to be implemented, notably image equality. I believe the internal data structure has to change to accommodate flipped text. (It isn't just about drawing things.)