Get Pixel colour
-
If you explain what you need it for then we might be able to help you find an alternative
-
@Martin I have 255 stars - circle(galaxy_x[I],galaxy_y[I], 2, 32 ,col,false) - randomly displayed. Using a cursor, move around the screen checking the present for a "star" and converting the x,y cords to a random star name.
I think I've managed it with:-namepart = ["EN", "LA", "CAN" etc 64 letter combinations.. "WE", "DE" ] pointx = 623 pointy = 351 circle (pointx, pointy, 8, 32, col, true) // my cursor if joy.x then drawText(422, 33, 26, white, "searching...") for i = 1 to 255 loop for dx = -8 to 8 loop if (point+dx) == galaxy_x[i] then for dy = -8 to 8 loop if (pointy+dy) == galaxy_y[i] then clear() starname = namepart[i/11] + namepart[i/5] + namepart[i/7] //generate starname from array parts drawText(822, 33, 26, white, i) drawText(900, 33, 26, white, starname) pointy = galaxy_y[i] // lock circle to star position pointx = galaxy_x[i] endif repeat endif repeat repeat endif
My aim is to write a simple Elite clone. I don't think I need a getPixel command as such. Another problem is the lack of str lower case to upper. This would have been useful. An earlier suggestion solved the random number problem - lack of a seed. It would be nice to be able to save more than one file This would give me more than one repeatable galaxy.
-
@faz808 Sorry, I did indent it correctly but it seems to have gone wonky.
-
-
If you have all the stars x and y positions use distance() to find which is the closest to your circle.
If the Distance( star_xy, circle_xy ) is less than circle radii it's within your circle -
@xevdev Thanks. That's shortened the code. I must learn to read the documentation !
-
You need to add code tags to the start and end, which is 3 'backticks' (obviously I can't type them) - i've done it for you.
SO, also, another way (admittedly, a rather wasteful way) would be to use sprites for the stars. Yes, it's wastefull if they are just a single pixel but it does make other operations such as scaling simpler should you need them and Fuze should easily cope with 255 of them. Then you can use collision detection against whatever your pointer might be. If you experiement with this then don't forget to
removeSprite()
when you are done with them because you are dealing with quite a lot of sprites.Yeah, maybe not the best of ideas but it should work.
For strLower and strUpper, just write one. I'm sure there are already examples on the forum but I'm not sure how good the search is. Very, very quickly knocked up, without Fuze in front of me, something along the lines of...
function toLower(str) string new int n = 0 int v = 0 for n = 0 to len(str) loop v = chrVal(str[n]) if v > 64 and v < 91 then new[n] = char(v + 32) endif repeat return
Should be somewhere in the ballpark of what you need?
PS: Yeah, the language should really have some kind of upper and lower functionality really
-
@Martin Thanks. It's all coming together nicely now.
-
@Martin Upper to Lower works fine. To keep the first character as caps I changed one line to:-
new[n] = chr(v + (( n > 0) * 32 ))
Many thanks. -
Oh, that's neat, i like that