Forum > General

canvas i need help

(1/7) > >>

shs:
i want the small square to bounce off from the canvas.rectangle when it's green and i want it to go through when it's red. please help me thank you.

please check the attachment

rvk:
You are checking for canvas.Brush.Color at the end of your Timer1Timer() (among the other coordinates).

But you need to check for a specific color at that point.
So you need to check with canvas.pixels[X,Y] what color exactly you have at X,Y and ONLY switch to red if that point is green.

shs:

--- Quote from: rvk on September 18, 2017, 01:00:18 pm ---You are checking for canvas.Brush.Color at the end of your Timer1Timer() (among the other coordinates).

But you need to check for a specific color at that point.
So you need to check with canvas.pixels[X,Y] what color exactly you have at X,Y and ONLY switch to red if that point is green.


--- End quote ---

can you help me coding with that please?

rvk:
You can start with changing the last part of Timer1Timer to this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  for i := 1 to 7 do    if (b.top < yy + hh) and (b.left > ww * i + (g * (i - 1)) + (xx - ww)) and      (b.Left < ww * i + (g * (i - 1) + ww) + (xx - ww)) then // << remove the green check    begin      if canvas.Pixels[b.left, b.top] = clGreen then // add the green check on canvas.Pixels[x,y] here      begin        b.top := 50;        canvas.brush.color := clred;        canvas.pen.color := clred;        canvas.rectangle(ww * i + (g * (i - 1)) + (xx - ww), yy, ww * i + (g * (i - 1) + ww) + (xx - ww), yy + hh);      end;    end;
After that you have some small line you draw in green when the cursor hits the box which prevents the cursor to pass through it (probably in FormPaint). You would need to color the entire box red to fix that.

rvk:
B.T.W. why are you not using TShapes for the boxes too? It would be much easier.

You can't control the FormPaint() which will redraw you boxes green again when the form needs to repaint.
With TShapes you don't have that problem.

Navigation

[0] Message Index

[#] Next page

Go to full version