| SexScripts : SOLVED: Use of java to write a string - https://ss.deviatenow.com:443/viewtopic.php?f=4&t=552 | Page 1 of 1 |
SOLVED: Use of java to write a string |
cd228 [ Thu Oct 22, 2015 6:35 pm ] |
|---|---|
Hello Doti. I saw your very nice code for using java to draw the images of cards dynamically in the script 'spankblackjack'. This is a bit outside my current programming-knowledge, so I hope you can answer my question. How should the code look like if I were to draw a string instead of an image? I was thinking of using this to display a countdown timer/clock, at a place a bit more appropriate than with the rest of the text. Hope you can help:) - cd228 Can be done by the following code Code: def image = new java.awt.image.BufferedImage(width, height, java.awt.image.BufferedImage.TYPE_4BYTE_ABGR)
def graphics = image.getGraphics() graphics.setFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 20)); graphics.setPaint(java.awt.Color.BLACK); graphics.drawString("Hello", 20, 50); |
|
Re: Use of java to write a string |
doti [ Thu Oct 22, 2015 7:11 pm ] |
|---|---|
Here is an excerpt of the white queen, with some text added at the end : Code: def showCards= { cards -> def width = 540 def height = 500 def image = new java.awt.image.BufferedImage(width, height, java.awt.image.BufferedImage.TYPE_4BYTE_ABGR) def graphics = image.getGraphics() def sampleImage = java.awt.Toolkit.getDefaultToolkit().getImage( "images/whitequeen/0.png") def oneWidth = sampleImage.getWidth() def oneHeight = sampleImage.getHeight() for(def i = 0;i<cards.size;i++) for(def j = 0;j<cards[i].size;j++) { def x = j * (width - oneWidth) / (Math.max(2,cards[i].size-1)) def delta = (i*j + i * 5 + j * 7) % 4 def y = i * (height - oneHeight - 3) / (Math.max(1,cards.size-1)) + delta def thisImage = javax.imageio.ImageIO.read(new File("images/whitequeen/"+cards[i][j]+".png")) if(i==0) { graphics.rotate(Math.PI, width/2, (oneHeight + 3)/2) } graphics.drawImage(thisImage, (int)x, (int)y, null) if(i==0) { graphics.rotate(-Math.PI, width/2, (oneHeight + 3)/2) } } //add text graphics.setFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 16 )); graphics.drawString("Cute !", 20, 100); setImage(image, false) } This is Swing/Java, like in this documentation : http://docs.oracle.com/javase/7/docs/ap ... ics2D.html . This wont works with Android. |
|
Re: Use of java to write a string |
cd228 [ Thu Oct 22, 2015 7:30 pm ] |
|---|---|
This is awesome!, thank you. If I were to change the font color, how would I do that? I tried with: Code: graphics.setFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 20 )); graphics.setColor(new java.awt.Color("BLACK")); graphics.drawString("Cute !", 20, 100); but it doesn't seem to work. |
|
Re: Use of java to write a string |
doti [ Thu Oct 22, 2015 7:41 pm ] |
|---|---|
I think it is the paint Code: graphics.setPaint(new java.awt.Color("BLACK"))
|
|
Re: Use of java to write a string |
cd228 [ Thu Oct 22, 2015 7:48 pm ] |
|---|---|
doti wrote: I think it is the paint Code: graphics.setPaint(new java.awt.Color("BLACK")) Then I get the following error: Error in simulation (maybe not a real error) groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.awt.Color(java.lang.String)(@ line 405) |
|
Re: Use of java to write a string |
doti [ Thu Oct 22, 2015 8:09 pm ] |
|---|---|
Code: graphics.setPaint(java.awt.Color.BLACK)
|
|
Re: Use of java to write a string |
cd228 [ Thu Oct 22, 2015 8:19 pm ] |
|---|---|
Hmm.. still doesn't work. graphics.setPaint(java.awt.Color.BLACK); produces Error in simulation (maybe not a real error) groovy.lang.MissingPropertyException: No such property: java for class: ss.FullScript_Banjo_spankblackjack(@ line 404) graphics.setPaint(new java.awt.Color.BLACK); produces Error in simulation (maybe not a real error) org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: script14455378938321490595609.groovy: 405: unexpected token: ) @ line 405, column 44. Paint(new java.awt.Color.BLACK); ^ 1 error |
|
Re: Use of java to write a string |
cd228 [ Thu Oct 22, 2015 8:27 pm ] |
|---|---|
Oops. My fault. It does work:) Thanks a lot. |
|
| Page 1 of 1 | All times are UTC + 1 hour [ DST ] |