Pixel
-
- Posts: 37
- Joined: Jan 26, 2017 7:54
Pixel
What's the easiest way to create a randomly colored pixel from 1 to 1001 for example?
Re: Pixel
is 1-1001 the range of colors or the number of pixels?TurtleProgrammer wrote:What's the easiest way to create a randomly colored pixel from 1 to 1001 for example?
-Vince
Re: Pixel
vdecampo wrote:is 1-1001 the range of colors or the number of pixels?TurtleProgrammer wrote:What's the easiest way to create a randomly colored pixel from 1 to 1001 for example?
-VinceCode: Select all
#Define RndColor Rnd*&hFFFFFF #Define ScrW 800 #Define ScrH 600 ScreenRes ScrW, ScrH For x As Integer = 0 To 1000 PSet (Rnd*ScrW,Rnd*ScrH),RndColor Next Sleep
Re: Pixel
vdecampo wrote:vdecampo wrote:is 1-1001 the range of colors or the number of pixels?TurtleProgrammer wrote:What's the easiest way to create a randomly colored pixel from 1 to 1001 for example?
-VinceCode: Select all
#Define RndColor Rnd*&hFFFFFF #Define ScrW 800 #Define ScrH 600 Randomize ScreenRes ScrW, ScrH For x As Integer = 0 To 1000 PSet (Rnd*ScrW,Rnd*ScrH),RndColor Next Sleep
Re: Pixel
Color Ranges (commonly used):
8 bit (1 Byte) = 0 to 255 (aka: Color-Palette)
32 bit (4 Byte) = 0 to &hFFFFFFFF (a ULong containing: 4 UBytes referred to as color channels)
Color Channels are:
b = blue
g = green
r = red
a = Alpha (see-through to opaque)
each of which, has a range of: 0 - 255 (&h00 - &hFF)
8 bit (1 Byte) = 0 to 255 (aka: Color-Palette)
32 bit (4 Byte) = 0 to &hFFFFFFFF (a ULong containing: 4 UBytes referred to as color channels)
Color Channels are:
b = blue
g = green
r = red
a = Alpha (see-through to opaque)
each of which, has a range of: 0 - 255 (&h00 - &hFF)
-
- Posts: 37
- Joined: Jan 26, 2017 7:54
Re: Pixel
To clarify more clearly, I am writing a program where
x = 1001 pixels per line * y = 1001 lines
Then each pixel is a random color
x = 1001 pixels per line * y = 1001 lines
Then each pixel is a random color
Re: Pixel
You will require a screen size 1001 by 1001, and 32 bits depth.
Just loop through every pixel, painting each one a random colour.
Saying that, 1001 picture height is big, many monitors (including this one) are not set to such a big vertical resolution.
Just loop through every pixel, painting each one a random colour.
Saying that, 1001 picture height is big, many monitors (including this one) are not set to such a big vertical resolution.
Code: Select all
screenres 1001,1001,32
for x as long=0 to 1000
for y as long=0 to 1000
pset(x,y),rgb(rnd*255,rnd*255,rnd*255)
next y
next x
sleep
Re: Pixel
You can also use a single line Macro called #Define to obtain a 32bit random color.
Without the use of the RGB/RGBA Macro's:
Without the use of the RGB/RGBA Macro's:
Code: Select all
#Define RndColor32() ( CULng(Rnd() * &hFFFFFF + &hFF000000) ) ' Alpha = 255, always
ScreenRes(1001, 1001, 32)
For j As UInteger = 0 To 1000 ' vertical
For i As UInteger = 0 To 1000 ' horizontal
PSet (i, j), RndColor32()
Next
Next
Sleep
-
- Posts: 37
- Joined: Jan 26, 2017 7:54
Re: Pixel
I need the program to start from 1 to and go to 1000 (for example), and pick a color from the standard, red, blue, green, yellow, orange, and white.
Re: Pixel
Which graphics mode? 32bit or 8bit?TurtleProgrammer wrote:I need the program to start from 1 to and go to 1000 (for example), and pick a color from the standard, red, blue, green, yellow, orange, and white.
-Vince
Re: Pixel
For six colours only, set them in an array (ulong here--32 bit).
Then pick any one of the six colours randomly (via the function RANGE), and colour your pixels that way.
Then pick any one of the six colours randomly (via the function RANGE), and colour your pixels that way.
Code: Select all
function range(f as long,l as long) as long
return int(Rnd*((l+1)-f)+f)
end function
dim as ulong a(1 to 6)
a(1)=rgb(255,0,0) 'red
a(2)=rgb(0,0,255) 'blue
a(3)=rgb(0,255,0) 'green
a(4)=rgb(255,255,0) 'yellow
a(5)=rgb(255,100,0) 'orange
a(6)=rgb(255,255,255)'white
screenres 1001,1001,32
for x as long=0 to 1000
for y as long=0 to 1000
pset(x,y),a(range(1,6))
next y
next x
sleep
Re: Pixel
This does not work well, because pixel addressing starts (in graphics mode) by: x = 0, y = 0TurtleProgrammer wrote:I need the program to start from 1 to and go to 1000 (for example)
(otherwise you'll have to correct for that, later on in the loop's):
Code: Select all
for y as uinteger = 1 to 1001
for x as uinteger = 1 to 1001
pset (x-1, y-1), ...
next
next
-
- Posts: 3906
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: Pixel
TurtleProgrammer's question has changed and it would be helpful if the desired use of these 1000 pixels was explained. The need to start with 1 may not be required but we wouldn't know without knowing what program using these 1000 pixels is supposed to do.TurtleProgrammer wrote:
What's the easiest way to create a randomly colored pixel from 1 to 1001 for example?
I need the program to start from 1 to and go to 1000 (for example), and pick a color from the standard, red, blue, green, yellow, orange, and white.
.
Re: Pixel
For the 8 bit screen these seem to be the six colours required:
I have kept the array as ulong, although for 8 bit ubyte would do.
Code: Select all
function range(f as long,l as long) as long
return int(Rnd*((l+1)-f)+f)
end function
dim as ulong a(1 to 6)
a(1)=4 'rgb(170,0,0) 'red
a(2)=1 'rgb(0,0,170) 'blue
a(3)=10 'rgb(85,255,85) 'green
a(4)=14 'rgb(255,255,85) 'yellow
a(5)=12 'rgb(255,85,85) 'orange
a(6)=15 'rgb(255,255,255) 'white
screenres 1001,1001
for x as long=0 to 1000
for y as long=0 to 1000
pset(x,y),a(range(1,6))
next y
next x
sleep
Re: Pixel
Code: Select all
'palette demo
ScreenRes 640, 480, 8 '8 bits per pixel
dim as long BigPixel = 16
dim as long m = BigPixel - 1
for yy as long = 0 to 15
for xx as long = 0 to 15
dim as long c = yy * 16 + xx
dim as long x = xx*BigPixel, y = yy*BigPixel
line (x,y)-(x+m,y+m), c, bf 'bar filled
next
next
sleep