4 question so far (next letters, color picker/change color, scale/zoom on key, reverse key)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
love2duser
Prole
Posts: 7
Joined: Fri Jan 27, 2017 6:58 am

4 question so far (next letters, color picker/change color, scale/zoom on key, reverse key)

Post by love2duser »

1. I trying to draw letters vertically in alphabet order:
Thats what I have now and it draws only next letter ('B') in my example

Code: Select all

letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "V", "X", "Y", "Z"}
function love.draw()
for x = 2, drawWidth do
    for z = 1, 10 do
      love.graphics.setColor(0, 0, 0, 255)
      love.graphics.print(string.char(string.byte(letters[1]) + z), (x - 1) * defaulPixelSize, 0)
    end
  end
UPD: Solved, answer here: viewtopic.php?f=4&t=83429&p=208727#p208727
2. Where I can find example of code to color specific draw (rectangle in my case), when I click on it? Ideally I want something like color picker, with most used colors and picker itself to appear, when I click on rectangle.
So something like: click on rectangle -> select color -> color it
Currently I draw a lot of rectangles (with love.graphics.rectangle) in for...do just the same way I used for first question, so I trying to fill specific rectangle I clicked on, but not all rectangles from for...do
So far I found Dither on github, maybe will be able to use some logic for picker, from it.
UPD: I was able to solve first part of question checking this tutorial: https://simplegametutorials.github.io/life/
I also found nice picker (not exactly as i want, but something) here: viewtopic.php?f=5&t=80492#p208493
But I have no idea how to display some area with picker only when I click rectangle, and use picked color for coloring.

Code: Select all

-- I only color in specified color now
  elseif grid[y][x] then
        --Should be somewhere here in my current code
        love.graphics.setColor(0, 0, 255)
        love.graphics.rectangle("fill", (x - 1) * defaulPixelSize, (y - 1) * defaulPixelSize, defaulPixelSize, defaulPixelSize)
3. I want to zoom and unzoom 2x when I click "+" "-" keys.
Tried something like it:

Code: Select all

function love.load ()
function love.keypressed(key)
  if key == "+" then
    love.graphics.scale(2,2)
  end
  function love.keypressed(key)
  if key == "-" then
    love.graphics.scale(0.5,0.5)
  end
 
4. How I can reverse action on the same key?

Code: Select all

if love.keyboard.isDown('f') then
    love.window.setFullscreen(true, "desktop")
  end
UPD: Solved, answer here: viewtopic.php?f=4&t=83429#p208721
Want to exit fullscreen when I press "f" second time, then fullscreen again, when I press "f" again etc...
Last edited by love2duser on Fri Jan 27, 2017 6:55 pm, edited 2 times in total.
love2duser
Prole
Posts: 7
Joined: Fri Jan 27, 2017 6:58 am

Re: 4 question so far (next letters, color picker/change color, scale/zoom on key, reverse key)

Post by love2duser »

Was able to partly solve question two, without any picker yet. But at least now I know how to select and color specified rectangle.
This tutorial helped me with it: https://simplegametutorials.github.io/life/
So yes, basically now I need to figure out some function to draw picker with common colors and color selection instead straight painting with test color.
love2duser
Prole
Posts: 7
Joined: Fri Jan 27, 2017 6:58 am

Re: 4 question so far (next letters, color picker/change color, scale/zoom on key, reverse key)

Post by love2duser »

Found nice colorpiker here: viewtopic.php?f=5&t=80492
But have no idea how to execute it in small window on click, instead running it on top of my game. Tried to load it like gamestate with hump plugin without success. Ideas?
love2duser
Prole
Posts: 7
Joined: Fri Jan 27, 2017 6:58 am

Re: 4 question so far (next letters, color picker/change color, scale/zoom on key, reverse key)

Post by love2duser »

Mostly was able to make first question work:

Code: Select all

  for x = 2, 60 do
    --love.graphics.setColor(0, 0, 0, 255)
    love.graphics.setColor(60, 150, 146, 50)
    love.graphics.print(string.char(string.byte("A") + x), (x - 1) * defaulPixelSize, 0)
  end
Unfortunately it starts from B, but not from A even when x=1. However I need that space before drawing letters, thats why I use 2. Through I need from A including it.
User avatar
steVeRoll
Party member
Posts: 139
Joined: Sun Feb 14, 2016 1:13 pm

Re: 4 question so far (next letters, color picker/change color, scale/zoom on key, reverse key)

Post by steVeRoll »

Welcome to the forums!
3) The code in this question is not correct. love.graphics.scale(0,5,0,5) should be love.graphics.scale(0.5,0.5). In most programming languages, a comma is used to separate arguments in a function, and a period for numbers.
4) You can do something like:

Code: Select all

function love.keypressed(key)
	if key == 'f' then
		love.window.setFullscreen(not love.window.getFullscreen())
	end
end
love2duser
Prole
Posts: 7
Joined: Fri Jan 27, 2017 6:58 am

Re: 4 question so far (next letters, color picker/change color, scale/zoom on key, reverse key)

Post by love2duser »

steVeRoll wrote:Welcome to the forums!
3) The code in this question is not correct. love.graphics.scale(0,5,0,5) should be love.graphics.scale(0.5,0.5). In most programming languages, a comma is used to separate arguments in a function, and a period for numbers.
4) You can do something like:

Code: Select all

function love.keypressed(key)
	if key == 'f' then
		love.window.setFullscreen(not love.window.getFullscreen())
	end
end
Thanks, reverse fullscreen key works! As for comma that was a misstype, since I used this code only to show what I want on forum (mostly every text editor will highlight it). Fixed in the initial message. Basically from what I could understand love.graphics.scale does work only as scaler on retina/hidpi screens, but I can't make all things 2x or 0.5 size with it. Most things drawn based on defaulPixelSize in my code. So maybe I could change it on the fly with on keyboard key press and redraw things. Or as google suggest I should use camera to zoom things, but I totally didn't understand how camera works yet, and not sure I should use camera just to scale/unscale things up (could be an overkill)
love2duser
Prole
Posts: 7
Joined: Fri Jan 27, 2017 6:58 am

Re: 4 question so far (next letters, color picker/change color, scale/zoom on key, reverse key)

Post by love2duser »

Was able to do the way I want for first question with this code:

Code: Select all

 for x = 2, 60 do
    love.graphics.setColor(131, 139, 139)
    love.graphics.print(string.char(string.byte(letters[1]) + x - 2), (x - 1) * defaulPixelSize, 0)
  end
end
 
So it backs to A here. But starts drawing from second position just as I want.
However looks I have no enough chars even with \ [] and small letters. Thinking about something like to make A-Z in different colors on the same line now.
love2duser
Prole
Posts: 7
Joined: Fri Jan 27, 2017 6:58 am

Re: 4 question so far (next letters, color picker/change color, scale/zoom on key, reverse key)

Post by love2duser »

1 question code I end up with, and it looks like: Image
(reverse rainbow colors)

Code: Select all

  for x = 2, 27 do
    love.graphics.setColor(238, 130, 238)
    love.graphics.print(string.char(string.byte("A") + x - 2), (x - 1) * defaulPixelSize, -1)
  end
  for x = 28, 53 do
    love.graphics.setColor(75, 0, 130)
    love.graphics.print(string.char(string.byte("A") + x - 28), (x - 1) * defaulPixelSize, -1)
  end

  for x = 54, 79 do
    love.graphics.setColor(0, 0, 255)
    love.graphics.print(string.char(string.byte("A") + x - 54), (x - 1) * defaulPixelSize, -1)
  end

  for x = 80, 96 do
    love.graphics.setColor(0, 128, 0)
    love.graphics.print(string.char(string.byte("A") + x - 80), (x - 1) * defaulPixelSize, -1)
  end
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

Re: 4 question so far (next letters, color picker/change color, scale/zoom on key, reverse key)

Post by Beelz »

You gotta learn to use that edit button. You posted 7 out of 8(9 including mine) of the messages in this thread, all in one day. I suggest taking a quick once over the Forum Etiquette thread, especially point #7.

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: 4 question so far (next letters, color picker/change color, scale/zoom on key, reverse key)

Post by zorg »

Why why and more why. :cry:
love.graphics.print(string.char(string.byte(letters[1]) + z), (x - 1) * defaulPixelSize, 0)
You have tables, you defined letters as a table, you can index tables, why are you not indexing tables, and why are you string.char string.byte comboing? That's both slow, ugly, slow, unnecessary, and last but not least, slow.

Also i have about zero idea what you really want to do, with all the loops and stuff, so here's a shot in the dark: :brows:

Code: Select all


-- This is only needed if you want a rainbow coloring
function HSL(h, s, l, a)
	if s<=0 then return l,l,l,a end
	h, s, l = h/256*6, s/255, l/255
	local c = (1-math.abs(2*l-1))*s
	local x = (1-math.abs(h%2-1))*c
	local m,r,g,b = (l-.5*c), 0,0,0
	if h < 1     then r,g,b = c,x,0
	elseif h < 2 then r,g,b = x,c,0
	elseif h < 3 then r,g,b = 0,c,x
	elseif h < 4 then r,g,b = 0,x,c
	elseif h < 5 then r,g,b = x,0,c
	else              r,g,b = c,0,x
	end return (r+m)*255,(g+m)*255,(b+m)*255,a
end
------------------------------------------------------

letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
font = love.graphics.getFont( )
function love.draw()
  for i=1,#letters do
    love.graphics.setColor(HSL((i / #letters) * 256, 255, 127))
    love.graphics.print(letters[i], 0, (i-1) * font:getHeight())
  end
end
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Google [Bot] and 3 guests