1. Stellar Project

I would like to create a set of dots beginning with small and ending with large where each dot would be representative of the brightness of a star(its magnitude). I would retreive a window from a star data base (which I have) and then would like to draw an image on the screen where each dot (star) would be positioned correctly.

Can someone point me where to look for a routine or win32lib routine where I could figure out how to do this? I don't have a clue how to start. This would be a windows 7 environment.

new topic     » topic index » view message » categorize

2. Re: Stellar Project

gwalters said...

I would like to create a set of dots beginning with small and ending with large where each dot would be representative of the brightness of a star(its magnitude). I would retreive a window from a star data base (which I have) and then would like to draw an image on the screen where each dot (star) would be positioned correctly.

Can someone point me where to look for a routine or win32lib routine where I could figure out how to do this? I don't have a clue how to start. This would be a windows 7 environment.


There's several at

http://rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=star

useless

new topic     » goto parent     » topic index » view message » categorize

3. Re: Stellar Project

Didn't find anything there that I could use.

This code opens a blank window but If I understand how creatDIB works I should get an object in the window. Any help would be appreciated.

 
global constant starWindow  = create(Window,"",0,sx + cx*10,sy + cy*3+5,600,635,0) 
       
				--Bitmap2 = create( Bitmap, "Bitmap", starWindow, sx-cx*7, cy*10, 0, 0, 0 ) 
				 
pal =   { 
		{  0,  0,  0}, 
		{100,100,100}, 
		{125,125,125}, 
		{255,255,255} 
		} 
		 
starTable = { 
		{ 
		{1,3,3,1}, 
	    {2,3,3,2}, 
	    {2,3,3,2}, 
	    {1,2,2,1} 
	    }, 
	     
	 	{ 
		{1,2,2,1}, 
		{2,2,2,2}, 
		{2,2,2,2}, 
		{1,2,2,1} 
		}, 
		 
		{ 
		{0,1,2,2,1,0}, 
		{1,2,3,3,2,1}, 
		{2,3,3,3,3,2}, 
		{2,3,3,3,3,2}, 
		{1,2,3,3,2,1}, 
		{0,1,2,2,1,0} 
		}, 
		 
		{ 
		{0,2,3,3,2,0}, 
		{2,3,3,3,3,2}, 
		{3,3,3,3,3,3}, 
		{3,3,3,3,3,3}, 
		{2,3,3,3,3,2}, 
		{0,2,3,3,2,0} 
		}, 
		 
		{ 
		{0,1,2,3,3,2,1,0}, 
		{1,2,3,3,3,3,2,1}, 
		{2,3,3,3,3,3,3,2}, 
		{3,3,3,3,3,3,3,3}, 
		{3,3,3,3,3,3,3,3}, 
		{2,3,3,3,3,3,3,2}, 
		{1,2,3,3,3,3,2,1}, 
		{0,1,2,3,3,2,1,0} 
		} 
		}	 
				 
          hBitmap = createDIB( {pal, starTable[5]} ) 
 
          drawBitmap(starWindow,hBitmap, 100,100) 
                 
         
    WinMain(starWindow, Normal) 
new topic     » goto parent     » topic index » view message » categorize

4. Re: Stellar Project

gwalters said...

This code opens a blank window but If I understand how creatDIB works I should get an object in the window. Any help would be appreciated.

You don't need a DIB (bitmap), just create a Pixmap the same size as your window then draw on the Pixmap, and on your window's Paint event, bitblt the pixmap onto your window. This is a very fast way of updating an animated display.

new topic     » goto parent     » topic index » view message » categorize

5. Re: Stellar Project

DerekParnell said...
gwalters said...

This code opens a blank window but If I understand how creatDIB works I should get an object in the window. Any help would be appreciated.

You don't need a DIB (bitmap), just create a Pixmap the same size as your window then draw on the Pixmap, and on your window's Paint event, bitblt the pixmap onto your window. This is a very fast way of updating an animated display.

Thanks, having never done any graphics, I need a little more help. How do you draw to a Pixmap? I understand the rest of what you said.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Stellar Project

Can someone explain my mistake?

This does not work but I need it to work

procedure starWindowOpen (integer self, integer event, sequence params)--params is () 
	atom hbitmap 
	 
	hbitmap =  createDIB( {pal, starTable[3]} ) 
	drawBitmap(pixWindow,hbitmap, 100,100) 
	copyBlt(starWindow,0,0,pixWindow) 
 
	 
end procedure 
 
	setHandler( starWindow, w32HOpen, routine_id("starWindowOpen")) 
	 
	WinMain(starWindow, Normal) 

This does work but I don't want the object where it puts it.

procedure starWindowOpen (integer self, integer event, sequence params)--params is () 
	atom hbitmap 
	 
	hbitmap =  createDIB( {pal, starTable[3]} ) 
	drawBitmap(bitWindow,hbitmap, 100,100) 
	setBitmap(bitWindow, hbitmap) 
	 
end procedure 
 
	setHandler( starWindow, w32HOpen, routine_id("starWindowOpen")) 
	 
	WinMain(starWindow, Normal) 

Any ideas what I am doing wrong.. thanks for help

new topic     » goto parent     » topic index » view message » categorize

7. Re: Stellar Project

gwalters said...

Can someone explain my mistake?

This does not work but I need it to work

snip...

This does work but I don't want the object where it puts it.

snip...

Any ideas what I am doing wrong.. thanks for help

This is a very common mistake when you first start out with drawing directly onto a window. We often assume that since controls persist visually on the window, so do the raw graphics we place there. This is however, simply incorrect. Your graphics might persist, but Windows will almost certainly draw over them again the next time anything happens to your window (move, resize, etc.). Your issue is made especially worse because the w32HOpen event occurs before the window is ever visible.

And so, to persist the graphics, you must only draw to the window during the w32HPaint event, like this:

-- declare your bitmap outside your events 
atom hbitmap 
 
procedure starWindowOpen (integer self, integer event, sequence params)--params is () 
 
	-- create the bitmap during the w32HOpen event 
	hbitmap =  createDIB( {pal, starTable[3]} ) 
	 
end procedure 
setHandler( starWindow, w32HOpen, routine_id("starWindowOpen")) 
 
procedure starWindowPaint( integer self, integer event, sequence params ) 
 
	-- draw the bitmap to the window during the w32HPaint event 
	copyBlt(starWindow,0,0,hbitmap) 
 
	 
end procedure 
setHandler( starWindow, w32HPaint, routine_id("starWindowPaint")) 
	 
WinMain(starWindow, Normal) 

You could also create a Pixmap instead of using createDIB, but you don't need both.

-Greg

new topic     » goto parent     » topic index » view message » categorize

8. Re: Stellar Project

gwalters said...

Thanks, having never done any graphics, I need a little more help. How do you draw to a Pixmap? I understand the rest of what you said.

I'll knock up a sample program after work, so give me about at least 8 hours from now.

new topic     » goto parent     » topic index » view message » categorize

9. Re: Stellar Project

Sorry it took longer. My daughter has her Politics exam tomorrow so she wanted me to quiz her on the subject matter. We did a good job of it smile

Anyhow, here's some sample Windows graphics code that you might be able to use.

include win32lib.ew 
include std/math.e 
 
integer starWindow 
        
integer starMap  
 
constant starShape =  
	{ 	{}, 
		{{1,0}}, 
		{{1,1}}, 
		{{0,1}}, 
		{{1,0}, {1,1}}, 
		{{1,0}, {1,1}, {0,1}}, 
		{{-1,0}, {1,0}, {0, 1}, {0, -1}}, 
		{{-1,-1}, {1,1}, {1, -1}, {-1, 1}}, 
		{{-1,-1}, {0, -1}, {-1,1},{1,0}, {1,1}, {0,1}, {1,-1}, {0, -1}} 
	} 
			 
constant deltadist = { 2,3,5,8,13,21,34,55,89,144,233,377} 
constant colors = {1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5} 
 
constant colorRGB = 
	{	{#FF, #FF, #FF}, 
	    {#FF, #FF,   0}, 
	    {  0, #FF, #FF}, 
	    {#FF,   0,   0}, 
	    {  0,   0, #FF} 
	} 
	 
sequence starTable 
integer lX, hX, lY, hY, spaceWidth, spaceHeight 
 
procedure Generate_Star_Data()     
	starTable = {} 
	 
	integer shape, dist, color 
	atom theta 
	atom bright 
	sequence starcolor 
	 
	integer X, Y, dX, dY 
	 
	X = 0 
	Y = 0 
	lX = 0 
	hX = 0 
	lY = 0 
	hY = 0 
	 
	-- Generate random data for a few (from 101 to 1000) stars 
	for i = 1 to 100 + rand(900) do 
		shape = rand(length(starShape)) -- Assign a shape (size) 
		 
		-- Get the distance from the previous star 
		dist  = deltadist[rand(length(deltadist))] 
		theta = rnd() * TWOPI 
		dX = floor(cos(theta) * dist) 
		dY = floor(sin(theta) * dist) 
		X = X + dX 
		Y = Y + dY 
		 
		-- Set its color and brightness 
		color = rand(length(colors))  
		bright = (25 * rand(4)) / 100 
		starcolor = floor(colorRGB[colors[color]] * bright) 
	 
		-- Add the star to the list 
		starTable = append(starTable, {shape, X, Y, starcolor})     
	 
		-- Capture the extent of the 'star space' generated.	 
		if X < lX then 
			lX = X 
		end if 
		if X > hX then 
			hX = X 
		end if 
		 
		if Y < lY then 
			lY = Y 
		end if 
		if Y > hY then 
			hY = Y 
		end if 
	 
	end for 
	spaceWidth = hX - lX + 1 
	spaceHeight = hY - lY + 1 
end procedure 
 
procedure Create_Stars() 
	sequence winsize 
	 
	-- Find out how big the display window is right now. 
	winsize = getCtlSize(starWindow) 
	 
	-- Either create the pixmap or resize it. 
	if starMap != 0 then 
		setCtlSize(starMap, winsize[1], winsize[2]) 
	else 
		starMap = create( Pixmap, "", 0, 0, 0, winsize[1], winsize[2], 0 )  
	end if 
	 
	-- Clear the pixmap to all black 
	setBackColor(starMap, 0) -- paint it black 
	 
	-- Draw each star onto the pixmap. 
	for i = 1 to length(starTable) do 
		sequence currStar = starTable[i] 
		integer X 
		integer Y 
		sequence shape 
			 
		-- Calculate the actual X/Y of the star 
		X = floor(winsize[1] * ((currStar[2] - lX) / spaceWidth) ) 
		Y = floor(winsize[2] * (((currStar[3] - lY) / spaceHeight)) ) 
	 
			 
		-- set the initial pixel 
		setPixel(starMap, X, Y, currStar[4]) 
		-- draw the rest of the star's shape 
		shape = starShape[currStar[1]] 
		for j = 1 to length(shape) do 
			setPixel(starMap, X + shape[j][1], Y + shape[j][2], currStar[4]) 
		end for 
		 
	end for 
	 
end procedure 
 
procedure onPaint(integer id, integer event, sequence parms) 
	if starMap = 0 then 
		-- No stars yet, so I better create them. 
		Create_Stars() 
	end if 
	 
	-- Copy the pixmap to the display window 
	copyBlt(starWindow, 0, 0, starMap) 
end procedure 
 
procedure onResize(integer id, integer event, sequence parms) 
	-- Changed the display window size, so I better redraw the pixmap 
	Create_Stars() 
	 
	-- Force the window to get the updated pixmap. 
	repaintFG(id) 
end procedure 
 
procedure onKeyDown(integer id, integer event, sequence parms) 
	-- User wants to view a new set of stars. 
	Generate_Star_Data() 
	Create_Stars() 
	repaintFG(id) 
end procedure 
 
procedure init_app() 
	Generate_Star_Data() 
	starMap = 0	 
	starWindow  = create(Window, "Star Viewport - Press a key for new stars", 0, 0.15,0.15,0.70,0.70,0)  
	setHandler(starWindow, w32HPaint, routine_id("onPaint"))	 
	setHandler(starWindow, w32HResize, routine_id("onResize"))	 
	setHandler(starWindow, w32HKeyDown, routine_id("onKeyDown"))	 
	 
end procedure 
 
init_app() 
WinMain(starWindow, Normal)  
new topic     » goto parent     » topic index » view message » categorize

10. Re: Stellar Project

Derek and Greg,

Thanks for the input. I've learned a lot. More to this project than I thought but I am making progress however.

George

new topic     » goto parent     » topic index » view message » categorize

11. Re: Stellar Project

Can someone tell me which function in win32lib that will return the pixel in a window that the the mouse clicked on?

new topic     » goto parent     » topic index » view message » categorize

12. Re: Stellar Project

gwalters said...

Can someone tell me which function in win32lib that will return the pixel in a window that the the mouse clicked on?

I think you could use these see mouse docs

func getPointerPos()   Find where the mouse pointer is on the screen. 
func getPointerRelPos(integer id)   Retrieves relative position of the mouse. 
 

new topic     » goto parent     » topic index » view message » categorize

13. Re: Stellar Project

Thanks

Where are the mouse docs? I couldn't find any.

new topic     » goto parent     » topic index » view message » categorize

14. Re: Stellar Project

gwalters said...

Thanks

Where are the mouse docs? I couldn't find any.

In the c:\win32lib_0_70_20\docs  directory 
 
  mouse.htm 

new topic     » goto parent     » topic index » view message » categorize

15. Re: Stellar Project

Thanks. Don't know how I missed it. I did look there.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu