TGC Codebase Backup



Lines and Dots by Mark Garrett

29th Jul 2005 6:44
Summary

Draws a 20 pixel line and 11 dots. Gives a rundown of the rgb values of each pixel. In the left column are seem the resulting line rgb color values of each line pixel. In the right



Description

Ever wonder why some programs written don't seem to work just right? Like programs dealing with pixels?

This basically demonstrates that lines are not constant in value, but dots are. Even diagonal lines drawn with the "line" command do not contain a constant value.

If a programmer wants to write a successfull pixel routine,one in which he can successfully use the point(x,y) command, using the dot command is the most reliable, and using the line command is most unreliable.

This program demonstrates this principle by drawing a line with the "line command" and 11 dots with the dot command.

Then it reads the pixels of the line and the dots and returns the values. If you look closely, you can see the line and dots displayed on the top of the screen.

First, it displays the original rgb value that is used to draw the line and the dots (a random color)

then the program reads each pixel from left to right and then displays the rgb and color value on the screen below from top to bottom.

What is the solution then to this dilema? The solution is to make a function that will draw "dot lines". You can see in the program that I constructed a line with 4 pixels at the top of the screen out of dots, and that even though they are joined together to form a line, they still give a consistent reading, each pixel identical to the next.

The values given for this line are the last 4 on the bottom right-hand side of the screen.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    ` This code was downloaded from The Game Creators
` It is reproduced here with full permission
` http://www.thegamecreators.com

Rem Project: line and dot experiment
Rem Created: 28.7.2005 11:31:54



doagain:

cls
r1 = rnd(255):g1 = rnd(255):b1 = rnd(255)
ink rgb(r1,g1,b1),1
line 50,50,70,50
dot 80,50: dot 85,50: dot 90,50: dot 93,50: dot 100,50
dot 105,50: dot 103,50:      dot 200,50: dot 201,50: dot 202,50: dot 203,50

set cursor 10,60
print "original rgb[",r1,",",g1,",",b1,"]    "
print " "




x5 = 49: y5 = 50

` --------------- print line values --------------------------
for sample = 1 to 20
inc x5
colorval = point(x5,y5)

r2=rgbr(colorval)
g2=rgbg(colorval)
b2=rgbb(colorval)

print "line rgb[",r2,",",g2,",",b2,"]    ","(",colorval,")",

if x5  = 53 then print " "
if x5  = 57 then print " "
if x5  = 61 then print " "
if x5  = 65 then print " "
next sample
`------------------ do dots ----------------------------
cursory = 60: rem begginning print position


a= 80:gosub printdot :a= 90:gosub printdot :a= 93:gosub printdot: a = 100: gosub printdot
a= 105:gosub printdot :a= 103:gosub printdot :a= 200:gosub printdot
a= 201:gosub printdot :a= 202:gosub printdot :a= 203:gosub printdot

cursory = (cursory + 75):set cursor 300,cursory: print "click left mouse button"
cursory = (cursory + 15):set cursor 300,cursory: print "for different color"




rem dot 85,50: dot 90,50: dot 93,50: dot 100,50
rem dot 105,50: dot 103,50:      dot 200,50: dot 201,50 dot 202,50: dot 203,50




do
if mouseclick() = 1 then goto doagain

loop

` --------------- print dot values -----------------------------
printdot:
b = 50: rem y position of dot
colorvald = point(a,b)

r4=rgbr(colorvald)
g4=rgbg(colorvald)
b4=rgbb(colorvald)
set cursor 300,cursory
print "dot rgb[",r4,",",g4,",",b4,"]    ","(",colorvald,")",
cursory = (cursory + 15)
return